mirror of
https://github.com/prometheus/prometheus.git
synced 2024-12-26 06:04:05 -08:00
Interface simplifications: GetValueAtTime().
Pointer arguments to copies.
This commit is contained in:
parent
1e2d6c7418
commit
56f069b3ec
|
@ -37,7 +37,7 @@ func (p *PersistenceAdapter) getMetricsWithLabels(labels model.LabelSet) ([]*mod
|
||||||
}
|
}
|
||||||
metrics := []*model.Metric{}
|
metrics := []*model.Metric{}
|
||||||
for _, fingerprint := range fingerprints {
|
for _, fingerprint := range fingerprints {
|
||||||
metric, err := p.persistence.GetMetricForFingerprint(fingerprint)
|
metric, err := p.persistence.GetMetricForFingerprint(*fingerprint)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -53,7 +53,7 @@ func (p *PersistenceAdapter) GetValueAtTime(labels model.LabelSet, timestamp *ti
|
||||||
}
|
}
|
||||||
samples := []*model.Sample{}
|
samples := []*model.Sample{}
|
||||||
for _, metric := range metrics {
|
for _, metric := range metrics {
|
||||||
sample, err := p.persistence.GetValueAtTime(metric, timestamp, p.stalenessPolicy)
|
sample, err := p.persistence.GetValueAtTime(*metric, *timestamp, *p.stalenessPolicy)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
|
@ -30,19 +30,19 @@ type MetricPersistence interface {
|
||||||
Close() error
|
Close() error
|
||||||
|
|
||||||
// Record a new sample in the storage layer.
|
// Record a new sample in the storage layer.
|
||||||
AppendSample(sample model.Sample) error
|
AppendSample(model.Sample) error
|
||||||
|
|
||||||
// Get all of the metric fingerprints that are associated with the provided
|
// Get all of the metric fingerprints that are associated with the provided
|
||||||
// label set.
|
// label set.
|
||||||
GetFingerprintsForLabelSet(labelSet model.LabelSet) ([]*model.Fingerprint, error)
|
GetFingerprintsForLabelSet(model.LabelSet) ([]*model.Fingerprint, error)
|
||||||
|
|
||||||
// Get all of the metric fingerprints that are associated for a given label
|
// Get all of the metric fingerprints that are associated for a given label
|
||||||
// name.
|
// name.
|
||||||
GetFingerprintsForLabelName(labelName model.LabelName) ([]*model.Fingerprint, error)
|
GetFingerprintsForLabelName(model.LabelName) ([]*model.Fingerprint, error)
|
||||||
|
|
||||||
GetMetricForFingerprint(f *model.Fingerprint) (*model.Metric, error)
|
GetMetricForFingerprint(model.Fingerprint) (*model.Metric, error)
|
||||||
|
|
||||||
GetValueAtTime(*model.Metric, *time.Time, *StalenessPolicy) (*model.Sample, error)
|
GetValueAtTime(model.Metric, time.Time, StalenessPolicy) (*model.Sample, error)
|
||||||
GetBoundaryValues(*model.Metric, *model.Interval, *StalenessPolicy) (*model.Sample, *model.Sample, error)
|
GetBoundaryValues(*model.Metric, *model.Interval, *StalenessPolicy) (*model.Sample, *model.Sample, error)
|
||||||
GetRangeValues(*model.Metric, *model.Interval, *StalenessPolicy) (*model.SampleSet, error)
|
GetRangeValues(*model.Metric, *model.Interval, *StalenessPolicy) (*model.SampleSet, error)
|
||||||
|
|
||||||
|
|
|
@ -887,7 +887,7 @@ func TestGetMetricForFingerprint(t *testing.T) {
|
||||||
t.Errorf("Expected one element.")
|
t.Errorf("Expected one element.")
|
||||||
}
|
}
|
||||||
|
|
||||||
v, e := persistence.GetMetricForFingerprint(result[0])
|
v, e := persistence.GetMetricForFingerprint(*result[0])
|
||||||
if e != nil {
|
if e != nil {
|
||||||
t.Error(e)
|
t.Error(e)
|
||||||
}
|
}
|
||||||
|
@ -912,7 +912,7 @@ func TestGetMetricForFingerprint(t *testing.T) {
|
||||||
t.Errorf("Expected one element.")
|
t.Errorf("Expected one element.")
|
||||||
}
|
}
|
||||||
|
|
||||||
v, e = persistence.GetMetricForFingerprint(result[0])
|
v, e = persistence.GetMetricForFingerprint(*result[0])
|
||||||
|
|
||||||
if e != nil {
|
if e != nil {
|
||||||
t.Error(e)
|
t.Error(e)
|
||||||
|
|
|
@ -262,7 +262,7 @@ func (l *LevelDBMetricPersistence) GetFingerprintsForLabelName(labelName model.L
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func (l *LevelDBMetricPersistence) GetMetricForFingerprint(f *model.Fingerprint) (m *model.Metric, err error) {
|
func (l *LevelDBMetricPersistence) GetMetricForFingerprint(f model.Fingerprint) (m *model.Metric, err error) {
|
||||||
begin := time.Now()
|
begin := time.Now()
|
||||||
|
|
||||||
defer func() {
|
defer func() {
|
||||||
|
@ -271,7 +271,7 @@ func (l *LevelDBMetricPersistence) GetMetricForFingerprint(f *model.Fingerprint)
|
||||||
recordOutcome(storageOperations, storageLatency, duration, err, map[string]string{operation: getMetricForFingerprint, result: success}, map[string]string{operation: getMetricForFingerprint, result: failure})
|
recordOutcome(storageOperations, storageLatency, duration, err, map[string]string{operation: getMetricForFingerprint, result: success}, map[string]string{operation: getMetricForFingerprint, result: failure})
|
||||||
}()
|
}()
|
||||||
|
|
||||||
raw, err := l.fingerprintToMetrics.Get(coding.NewProtocolBufferEncoder(model.FingerprintToDTO(f)))
|
raw, err := l.fingerprintToMetrics.Get(coding.NewProtocolBufferEncoder(model.FingerprintToDTO(&f)))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -300,14 +300,14 @@ func (l *LevelDBMetricPersistence) GetBoundaryValues(m *model.Metric, i *model.I
|
||||||
}()
|
}()
|
||||||
|
|
||||||
// XXX: Maybe we will want to emit incomplete sets?
|
// XXX: Maybe we will want to emit incomplete sets?
|
||||||
open, err = l.GetValueAtTime(m, &i.OldestInclusive, s)
|
open, err = l.GetValueAtTime(*m, i.OldestInclusive, *s)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
} else if open == nil {
|
} else if open == nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
end, err = l.GetValueAtTime(m, &i.NewestInclusive, s)
|
end, err = l.GetValueAtTime(*m, i.NewestInclusive, *s)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
} else if end == nil {
|
} else if end == nil {
|
||||||
|
@ -339,7 +339,7 @@ type iterator interface {
|
||||||
Value() []byte
|
Value() []byte
|
||||||
}
|
}
|
||||||
|
|
||||||
func (l *LevelDBMetricPersistence) GetValueAtTime(m *model.Metric, t *time.Time, s *metric.StalenessPolicy) (sample *model.Sample, err error) {
|
func (l *LevelDBMetricPersistence) GetValueAtTime(m model.Metric, t time.Time, s metric.StalenessPolicy) (sample *model.Sample, err error) {
|
||||||
begin := time.Now()
|
begin := time.Now()
|
||||||
|
|
||||||
defer func() {
|
defer func() {
|
||||||
|
@ -353,7 +353,7 @@ func (l *LevelDBMetricPersistence) GetValueAtTime(m *model.Metric, t *time.Time,
|
||||||
// Candidate for Refactoring
|
// Candidate for Refactoring
|
||||||
k := &dto.SampleKey{
|
k := &dto.SampleKey{
|
||||||
Fingerprint: f,
|
Fingerprint: f,
|
||||||
Timestamp: indexable.EncodeTime(*t),
|
Timestamp: indexable.EncodeTime(t),
|
||||||
}
|
}
|
||||||
|
|
||||||
e, err := coding.NewProtocolBufferEncoder(k).Encode()
|
e, err := coding.NewProtocolBufferEncoder(k).Encode()
|
||||||
|
@ -473,7 +473,7 @@ func (l *LevelDBMetricPersistence) GetValueAtTime(m *model.Metric, t *time.Time,
|
||||||
firstTime = alternativeTime
|
firstTime = alternativeTime
|
||||||
}
|
}
|
||||||
|
|
||||||
firstDelta := firstTime.Sub(*t)
|
firstDelta := firstTime.Sub(t)
|
||||||
if firstDelta < 0 {
|
if firstDelta < 0 {
|
||||||
firstDelta *= -1
|
firstDelta *= -1
|
||||||
}
|
}
|
||||||
|
@ -486,7 +486,7 @@ func (l *LevelDBMetricPersistence) GetValueAtTime(m *model.Metric, t *time.Time,
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
sample = model.SampleFromDTO(m, t, firstValue)
|
sample = model.SampleFromDTO(&m, &t, firstValue)
|
||||||
|
|
||||||
if firstDelta == time.Duration(0) {
|
if firstDelta == time.Duration(0) {
|
||||||
return
|
return
|
||||||
|
@ -542,13 +542,13 @@ func (l *LevelDBMetricPersistence) GetValueAtTime(m *model.Metric, t *time.Time,
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
interpolated := interpolate(firstTime, secondTime, *firstValue.Value, *secondValue.Value, *t)
|
interpolated := interpolate(firstTime, secondTime, *firstValue.Value, *secondValue.Value, t)
|
||||||
|
|
||||||
sampleValue := &dto.SampleValue{
|
sampleValue := &dto.SampleValue{
|
||||||
Value: &interpolated,
|
Value: &interpolated,
|
||||||
}
|
}
|
||||||
|
|
||||||
sample = model.SampleFromDTO(m, t, sampleValue)
|
sample = model.SampleFromDTO(&m, &t, sampleValue)
|
||||||
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
|
@ -592,7 +592,7 @@ var testGetValueAtTime = func(t test.Tester) {
|
||||||
DeltaAllowance: input.staleness,
|
DeltaAllowance: input.staleness,
|
||||||
}
|
}
|
||||||
|
|
||||||
actual, err := persistence.GetValueAtTime(&m, &time, &p)
|
actual, err := persistence.GetValueAtTime(m, time, p)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("%d.%d(%s). Could not query for value: %q\n", i, j, behavior.name, err)
|
t.Errorf("%d.%d(%s). Could not query for value: %q\n", i, j, behavior.name, err)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue