From 81f0b850131c1f60dc4e6cba05a8eb69f89e4fd9 Mon Sep 17 00:00:00 2001 From: Julius Volz Date: Thu, 25 Jul 2013 12:16:32 +0200 Subject: [PATCH] Return [] instead of null for empty result vectors. --- retrieval/targetmanager_test.go | 2 +- rules/ast/ast.go | 6 +++--- rules/ast/persistence_adapter.go | 17 ++++++++++------- 3 files changed, 14 insertions(+), 11 deletions(-) diff --git a/retrieval/targetmanager_test.go b/retrieval/targetmanager_test.go index 25f44b1519..08115a3f17 100644 --- a/retrieval/targetmanager_test.go +++ b/retrieval/targetmanager_test.go @@ -75,7 +75,7 @@ func (t *fakeTarget) ScheduledFor() (time time.Time) { func (t *fakeTarget) Merge(newTarget Target) {} -func (t *fakeTarget) EstimatedTimeToExecute() time.Duration { return 0 } +func (t *fakeTarget) EstimatedTimeToExecute() time.Duration { return 0 } func testTargetManager(t test.Tester) { results := make(chan *extraction.Result, 5) diff --git a/rules/ast/ast.go b/rules/ast/ast.go index 82eaeb8677..1ca9760109 100644 --- a/rules/ast/ast.go +++ b/rules/ast/ast.go @@ -401,7 +401,7 @@ func (node *VectorAggregation) Eval(timestamp time.Time, view *viewAdapter) Vect func (node *VectorLiteral) Eval(timestamp time.Time, view *viewAdapter) Vector { values, err := view.GetValueAtTime(node.fingerprints, timestamp) if err != nil { - log.Printf("Unable to get vector values") + log.Println("Unable to get vector values:", err) return Vector{} } return values @@ -589,7 +589,7 @@ func (node *MatrixLiteral) Eval(timestamp time.Time, view *viewAdapter) Matrix { } values, err := view.GetRangeValues(node.fingerprints, interval) if err != nil { - log.Printf("Unable to get values for vector interval") + log.Println("Unable to get values for vector interval:", err) return Matrix{} } return values @@ -602,7 +602,7 @@ func (node *MatrixLiteral) EvalBoundaries(timestamp time.Time, view *viewAdapter } values, err := view.GetBoundaryValues(node.fingerprints, interval) if err != nil { - log.Printf("Unable to get boundary values for vector interval") + log.Printf("Unable to get boundary values for vector interval:", err) return Matrix{} } return values diff --git a/rules/ast/persistence_adapter.go b/rules/ast/persistence_adapter.go index fcd37614c2..52e3d001fd 100644 --- a/rules/ast/persistence_adapter.go +++ b/rules/ast/persistence_adapter.go @@ -109,14 +109,15 @@ func (v *viewAdapter) chooseClosestSample(samples metric.Values, timestamp time. } } -func (v *viewAdapter) GetValueAtTime(fingerprints clientmodel.Fingerprints, timestamp time.Time) (samples Vector, err error) { +func (v *viewAdapter) GetValueAtTime(fingerprints clientmodel.Fingerprints, timestamp time.Time) (Vector, error) { timer := v.stats.GetTimer(stats.GetValueAtTimeTime).Start() + samples := Vector{} for _, fingerprint := range fingerprints { sampleCandidates := v.view.GetValueAtTime(fingerprint, timestamp) samplePair := v.chooseClosestSample(sampleCandidates, timestamp) m, err := v.storage.GetMetricForFingerprint(fingerprint) if err != nil { - continue + return nil, err } if samplePair != nil { samples = append(samples, &clientmodel.Sample{ @@ -127,11 +128,12 @@ func (v *viewAdapter) GetValueAtTime(fingerprints clientmodel.Fingerprints, time } } timer.Stop() - return samples, err + return samples, nil } -func (v *viewAdapter) GetBoundaryValues(fingerprints clientmodel.Fingerprints, interval *metric.Interval) (sampleSets []metric.SampleSet, err error) { +func (v *viewAdapter) GetBoundaryValues(fingerprints clientmodel.Fingerprints, interval *metric.Interval) ([]metric.SampleSet, error) { timer := v.stats.GetTimer(stats.GetBoundaryValuesTime).Start() + sampleSets := []metric.SampleSet{} for _, fingerprint := range fingerprints { samplePairs := v.view.GetBoundaryValues(fingerprint, *interval) if len(samplePairs) == 0 { @@ -141,7 +143,7 @@ func (v *viewAdapter) GetBoundaryValues(fingerprints clientmodel.Fingerprints, i // TODO: memoize/cache this. m, err := v.storage.GetMetricForFingerprint(fingerprint) if err != nil { - continue + return nil, err } sampleSet := metric.SampleSet{ @@ -154,8 +156,9 @@ func (v *viewAdapter) GetBoundaryValues(fingerprints clientmodel.Fingerprints, i return sampleSets, nil } -func (v *viewAdapter) GetRangeValues(fingerprints clientmodel.Fingerprints, interval *metric.Interval) (sampleSets []metric.SampleSet, err error) { +func (v *viewAdapter) GetRangeValues(fingerprints clientmodel.Fingerprints, interval *metric.Interval) ([]metric.SampleSet, error) { timer := v.stats.GetTimer(stats.GetRangeValuesTime).Start() + sampleSets := []metric.SampleSet{} for _, fingerprint := range fingerprints { samplePairs := v.view.GetRangeValues(fingerprint, *interval) if len(samplePairs) == 0 { @@ -165,7 +168,7 @@ func (v *viewAdapter) GetRangeValues(fingerprints clientmodel.Fingerprints, inte // TODO: memoize/cache this. m, err := v.storage.GetMetricForFingerprint(fingerprint) if err != nil { - continue + return nil, err } sampleSet := metric.SampleSet{