From 1e2d6c7418662b888599bf2f713552a2d8d67f16 Mon Sep 17 00:00:00 2001 From: "Matt T. Proud" Date: Wed, 13 Feb 2013 17:44:35 -0800 Subject: [PATCH 1/4] GetFingerprintsForLabelName simplifications. ``MetricPersistence.GetFingerprintsForLabelName(l *model.LabelName)`` -> ``MetricPersistence.GetFingerprintsForLabelName(l model.LabelName)`` --- storage/metric/interface.go | 2 +- storage/metric/leveldb/leveldb_test.go | 8 ++++---- storage/metric/leveldb/reading.go | 4 ++-- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/storage/metric/interface.go b/storage/metric/interface.go index 1664ba7f5..1b57f036a 100644 --- a/storage/metric/interface.go +++ b/storage/metric/interface.go @@ -38,7 +38,7 @@ type MetricPersistence interface { // Get all of the metric fingerprints that are associated for a given label // name. - GetFingerprintsForLabelName(labelName *model.LabelName) ([]*model.Fingerprint, error) + GetFingerprintsForLabelName(labelName model.LabelName) ([]*model.Fingerprint, error) GetMetricForFingerprint(f *model.Fingerprint) (*model.Metric, error) diff --git a/storage/metric/leveldb/leveldb_test.go b/storage/metric/leveldb/leveldb_test.go index a849e0c83..38faa056f 100644 --- a/storage/metric/leveldb/leveldb_test.go +++ b/storage/metric/leveldb/leveldb_test.go @@ -791,7 +791,7 @@ func TestGetFingerprintsForLabelName(t *testing.T) { } b := model.LabelName("name") - result, getErr := persistence.GetFingerprintsForLabelName(&b) + result, getErr := persistence.GetFingerprintsForLabelName(b) if getErr != nil { t.Error(getErr) @@ -802,7 +802,7 @@ func TestGetFingerprintsForLabelName(t *testing.T) { } b = model.LabelName("request_type") - result, getErr = persistence.GetFingerprintsForLabelName(&b) + result, getErr = persistence.GetFingerprintsForLabelName(b) if getErr != nil { t.Error(getErr) @@ -813,7 +813,7 @@ func TestGetFingerprintsForLabelName(t *testing.T) { } b = model.LabelName("language") - result, getErr = persistence.GetFingerprintsForLabelName(&b) + result, getErr = persistence.GetFingerprintsForLabelName(b) if getErr != nil { t.Error(getErr) @@ -824,7 +824,7 @@ func TestGetFingerprintsForLabelName(t *testing.T) { } b = model.LabelName("sprache") - result, getErr = persistence.GetFingerprintsForLabelName(&b) + result, getErr = persistence.GetFingerprintsForLabelName(b) if getErr != nil { t.Error(getErr) diff --git a/storage/metric/leveldb/reading.go b/storage/metric/leveldb/reading.go index 7263a7c6c..bd2022dae 100644 --- a/storage/metric/leveldb/reading.go +++ b/storage/metric/leveldb/reading.go @@ -231,7 +231,7 @@ func (l *LevelDBMetricPersistence) GetFingerprintsForLabelSet(labelSet model.Lab return } -func (l *LevelDBMetricPersistence) GetFingerprintsForLabelName(labelName *model.LabelName) (fps []*model.Fingerprint, err error) { +func (l *LevelDBMetricPersistence) GetFingerprintsForLabelName(labelName model.LabelName) (fps []*model.Fingerprint, err error) { begin := time.Now() defer func() { @@ -242,7 +242,7 @@ func (l *LevelDBMetricPersistence) GetFingerprintsForLabelName(labelName *model. fps = make([]*model.Fingerprint, 0, 0) - raw, err := l.labelNameToFingerprints.Get(coding.NewProtocolBufferEncoder(model.LabelNameToDTO(labelName))) + raw, err := l.labelNameToFingerprints.Get(coding.NewProtocolBufferEncoder(model.LabelNameToDTO(&labelName))) if err != nil { return } From 56f069b3ec928f020b3c47566d401f6eb9637c99 Mon Sep 17 00:00:00 2001 From: "Matt T. Proud" Date: Wed, 13 Feb 2013 21:05:01 -0800 Subject: [PATCH 2/4] 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) } From 14788cf4f30f29db77e7353b030597757fb97d57 Mon Sep 17 00:00:00 2001 From: "Matt T. Proud" Date: Wed, 13 Feb 2013 21:07:42 -0800 Subject: [PATCH 3/4] Interface simplifications. GetBoundaryValues() from pointers to values. --- storage/metric/interface.go | 2 +- storage/metric/leveldb/reading.go | 6 +++--- storage/metric/leveldb/rule_integration_test.go | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/storage/metric/interface.go b/storage/metric/interface.go index 379988c07..a3c58ceb8 100644 --- a/storage/metric/interface.go +++ b/storage/metric/interface.go @@ -43,7 +43,7 @@ type MetricPersistence interface { GetMetricForFingerprint(model.Fingerprint) (*model.Metric, 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) GetAllMetricNames() ([]string, error) diff --git a/storage/metric/leveldb/reading.go b/storage/metric/leveldb/reading.go index 0be23a20e..a0a0952aa 100644 --- a/storage/metric/leveldb/reading.go +++ b/storage/metric/leveldb/reading.go @@ -290,7 +290,7 @@ func (l *LevelDBMetricPersistence) GetMetricForFingerprint(f model.Fingerprint) return } -func (l *LevelDBMetricPersistence) GetBoundaryValues(m *model.Metric, i *model.Interval, s *metric.StalenessPolicy) (open *model.Sample, end *model.Sample, err error) { +func (l *LevelDBMetricPersistence) GetBoundaryValues(m model.Metric, i model.Interval, s metric.StalenessPolicy) (open *model.Sample, end *model.Sample, err error) { begin := time.Now() defer func() { @@ -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 { diff --git a/storage/metric/leveldb/rule_integration_test.go b/storage/metric/leveldb/rule_integration_test.go index 9b25a4762..14beb6884 100644 --- a/storage/metric/leveldb/rule_integration_test.go +++ b/storage/metric/leveldb/rule_integration_test.go @@ -1058,7 +1058,7 @@ var testGetBoundaryValues = func(t test.Tester) { DeltaAllowance: input.staleness, } - openValue, endValue, err := persistence.GetBoundaryValues(&m, &interval, &p) + openValue, endValue, err := persistence.GetBoundaryValues(m, interval, p) if err != nil { t.Errorf("%d.%d(%s). Could not query for value: %q\n", i, j, behavior.name, err) } From f03091b139e2b1c37b1cf2271f3e5cef58f6c973 Mon Sep 17 00:00:00 2001 From: "Matt T. Proud" Date: Wed, 13 Feb 2013 21:11:23 -0800 Subject: [PATCH 4/4] Interface simplifications: GetRangeValues From pointers to copies. --- rules/ast/persistence_adapter.go | 4 ++-- storage/metric/interface.go | 2 +- storage/metric/leveldb/reading.go | 2 +- storage/metric/leveldb/rule_integration_test.go | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/rules/ast/persistence_adapter.go b/rules/ast/persistence_adapter.go index 23764f31e..d0c1c61f8 100644 --- a/rules/ast/persistence_adapter.go +++ b/rules/ast/persistence_adapter.go @@ -74,7 +74,7 @@ func (p *PersistenceAdapter) GetBoundaryValues(labels model.LabelSet, interval * sampleSets := []*model.SampleSet{} for _, metric := range metrics { // TODO: change to GetBoundaryValues() once it has the right return type. - sampleSet, err := p.persistence.GetRangeValues(metric, interval, p.stalenessPolicy) + sampleSet, err := p.persistence.GetRangeValues(*metric, *interval, *p.stalenessPolicy) if err != nil { return nil, err } @@ -97,7 +97,7 @@ func (p *PersistenceAdapter) GetRangeValues(labels model.LabelSet, interval *mod sampleSets := []*model.SampleSet{} for _, metric := range metrics { - sampleSet, err := p.persistence.GetRangeValues(metric, interval, p.stalenessPolicy) + sampleSet, err := p.persistence.GetRangeValues(*metric, *interval, *p.stalenessPolicy) if err != nil { return nil, err } diff --git a/storage/metric/interface.go b/storage/metric/interface.go index a3c58ceb8..74c4416c2 100644 --- a/storage/metric/interface.go +++ b/storage/metric/interface.go @@ -44,7 +44,7 @@ type MetricPersistence interface { 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) + GetRangeValues(model.Metric, model.Interval, StalenessPolicy) (*model.SampleSet, error) GetAllMetricNames() ([]string, error) diff --git a/storage/metric/leveldb/reading.go b/storage/metric/leveldb/reading.go index a0a0952aa..a45dfd245 100644 --- a/storage/metric/leveldb/reading.go +++ b/storage/metric/leveldb/reading.go @@ -553,7 +553,7 @@ func (l *LevelDBMetricPersistence) GetValueAtTime(m model.Metric, t time.Time, s return } -func (l *LevelDBMetricPersistence) GetRangeValues(m *model.Metric, i *model.Interval, s *metric.StalenessPolicy) (v *model.SampleSet, err error) { +func (l *LevelDBMetricPersistence) GetRangeValues(m model.Metric, i model.Interval, s metric.StalenessPolicy) (v *model.SampleSet, err error) { begin := time.Now() defer func() { diff --git a/storage/metric/leveldb/rule_integration_test.go b/storage/metric/leveldb/rule_integration_test.go index 14beb6884..5ffda9707 100644 --- a/storage/metric/leveldb/rule_integration_test.go +++ b/storage/metric/leveldb/rule_integration_test.go @@ -1652,7 +1652,7 @@ var testGetRangeValues = func(t test.Tester) { DeltaAllowance: input.staleness, } - values, err := persistence.GetRangeValues(&m, &i, &p) + values, err := persistence.GetRangeValues(m, i, p) if err != nil { t.Errorf("%d.%d(%s). Could not query for value: %q\n", i, j, behavior.name, err) }