From 56f069b3ec928f020b3c47566d401f6eb9637c99 Mon Sep 17 00:00:00 2001 From: "Matt T. Proud" Date: Wed, 13 Feb 2013 21:05:01 -0800 Subject: [PATCH] Interface simplifications: GetValueAtTime(). Pointer arguments to copies. --- rules/ast/persistence_adapter.go | 4 ++-- storage/metric/interface.go | 10 +++++----- storage/metric/leveldb/leveldb_test.go | 4 ++-- storage/metric/leveldb/reading.go | 20 +++++++++---------- .../metric/leveldb/rule_integration_test.go | 2 +- 5 files changed, 20 insertions(+), 20 deletions(-) diff --git a/rules/ast/persistence_adapter.go b/rules/ast/persistence_adapter.go index 9ce60046d..23764f31e 100644 --- a/rules/ast/persistence_adapter.go +++ b/rules/ast/persistence_adapter.go @@ -37,7 +37,7 @@ func (p *PersistenceAdapter) getMetricsWithLabels(labels model.LabelSet) ([]*mod } metrics := []*model.Metric{} for _, fingerprint := range fingerprints { - metric, err := p.persistence.GetMetricForFingerprint(fingerprint) + metric, err := p.persistence.GetMetricForFingerprint(*fingerprint) if err != nil { return nil, err } @@ -53,7 +53,7 @@ func (p *PersistenceAdapter) GetValueAtTime(labels model.LabelSet, timestamp *ti } samples := []*model.Sample{} 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 { return nil, err } diff --git a/storage/metric/interface.go b/storage/metric/interface.go index 1b57f036a..379988c07 100644 --- a/storage/metric/interface.go +++ b/storage/metric/interface.go @@ -30,19 +30,19 @@ type MetricPersistence interface { Close() error // 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 // 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 // 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) GetRangeValues(*model.Metric, *model.Interval, *StalenessPolicy) (*model.SampleSet, error) diff --git a/storage/metric/leveldb/leveldb_test.go b/storage/metric/leveldb/leveldb_test.go index 38faa056f..9d4f9310f 100644 --- a/storage/metric/leveldb/leveldb_test.go +++ b/storage/metric/leveldb/leveldb_test.go @@ -887,7 +887,7 @@ func TestGetMetricForFingerprint(t *testing.T) { t.Errorf("Expected one element.") } - v, e := persistence.GetMetricForFingerprint(result[0]) + v, e := persistence.GetMetricForFingerprint(*result[0]) if e != nil { t.Error(e) } @@ -912,7 +912,7 @@ func TestGetMetricForFingerprint(t *testing.T) { t.Errorf("Expected one element.") } - v, e = persistence.GetMetricForFingerprint(result[0]) + v, e = persistence.GetMetricForFingerprint(*result[0]) if e != nil { t.Error(e) diff --git a/storage/metric/leveldb/reading.go b/storage/metric/leveldb/reading.go index bd2022dae..0be23a20e 100644 --- a/storage/metric/leveldb/reading.go +++ b/storage/metric/leveldb/reading.go @@ -262,7 +262,7 @@ func (l *LevelDBMetricPersistence) GetFingerprintsForLabelName(labelName model.L 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() 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}) }() - raw, err := l.fingerprintToMetrics.Get(coding.NewProtocolBufferEncoder(model.FingerprintToDTO(f))) + raw, err := l.fingerprintToMetrics.Get(coding.NewProtocolBufferEncoder(model.FingerprintToDTO(&f))) if err != nil { return } @@ -300,14 +300,14 @@ func (l *LevelDBMetricPersistence) GetBoundaryValues(m *model.Metric, i *model.I }() // 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 { return } else if open == nil { return } - end, err = l.GetValueAtTime(m, &i.NewestInclusive, s) + end, err = l.GetValueAtTime(*m, i.NewestInclusive, *s) if err != nil { return } else if end == nil { @@ -339,7 +339,7 @@ type iterator interface { 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() defer func() { @@ -353,7 +353,7 @@ func (l *LevelDBMetricPersistence) GetValueAtTime(m *model.Metric, t *time.Time, // Candidate for Refactoring k := &dto.SampleKey{ Fingerprint: f, - Timestamp: indexable.EncodeTime(*t), + Timestamp: indexable.EncodeTime(t), } e, err := coding.NewProtocolBufferEncoder(k).Encode() @@ -473,7 +473,7 @@ func (l *LevelDBMetricPersistence) GetValueAtTime(m *model.Metric, t *time.Time, firstTime = alternativeTime } - firstDelta := firstTime.Sub(*t) + firstDelta := firstTime.Sub(t) if firstDelta < 0 { firstDelta *= -1 } @@ -486,7 +486,7 @@ func (l *LevelDBMetricPersistence) GetValueAtTime(m *model.Metric, t *time.Time, return } - sample = model.SampleFromDTO(m, t, firstValue) + sample = model.SampleFromDTO(&m, &t, firstValue) if firstDelta == time.Duration(0) { return @@ -542,13 +542,13 @@ func (l *LevelDBMetricPersistence) GetValueAtTime(m *model.Metric, t *time.Time, return } - interpolated := interpolate(firstTime, secondTime, *firstValue.Value, *secondValue.Value, *t) + interpolated := interpolate(firstTime, secondTime, *firstValue.Value, *secondValue.Value, t) sampleValue := &dto.SampleValue{ Value: &interpolated, } - sample = model.SampleFromDTO(m, t, sampleValue) + sample = model.SampleFromDTO(&m, &t, sampleValue) return } diff --git a/storage/metric/leveldb/rule_integration_test.go b/storage/metric/leveldb/rule_integration_test.go index 17eda2611..9b25a4762 100644 --- a/storage/metric/leveldb/rule_integration_test.go +++ b/storage/metric/leveldb/rule_integration_test.go @@ -592,7 +592,7 @@ var testGetValueAtTime = func(t test.Tester) { DeltaAllowance: input.staleness, } - actual, err := persistence.GetValueAtTime(&m, &time, &p) + actual, err := persistence.GetValueAtTime(m, time, p) if err != nil { t.Errorf("%d.%d(%s). Could not query for value: %q\n", i, j, behavior.name, err) }