From 2668700e549e7e607a0d66a88987919b7214e0aa Mon Sep 17 00:00:00 2001 From: Julius Volz Date: Wed, 27 Mar 2013 18:50:30 +0100 Subject: [PATCH] Fix bug in GetFingerprintsForLabelSet(). --- storage/metric/tiered.go | 2 +- storage/metric/tiered_test.go | 61 +++++++++++++++++++++++++++++++++++ 2 files changed, 62 insertions(+), 1 deletion(-) diff --git a/storage/metric/tiered.go b/storage/metric/tiered.go index c8dc40d1e..eabcc99bd 100644 --- a/storage/metric/tiered.go +++ b/storage/metric/tiered.go @@ -562,7 +562,7 @@ func (t *tieredStorage) GetFingerprintsForLabelSet(labelSet model.LabelSet) (fin if err != nil { return } - diskFingerprints, err := t.memoryArena.GetFingerprintsForLabelSet(labelSet) + diskFingerprints, err := t.diskStorage.GetFingerprintsForLabelSet(labelSet) if err != nil { return } diff --git a/storage/metric/tiered_test.go b/storage/metric/tiered_test.go index ed01cab08..5293a75b8 100644 --- a/storage/metric/tiered_test.go +++ b/storage/metric/tiered_test.go @@ -530,3 +530,64 @@ func TestGetAllValuesForLabel(t *testing.T) { } } } + +func TestGetFingerprintsForLabelSet(t *testing.T) { + tiered, closer := newTestTieredStorage(t) + defer closer.Close() + memorySample := model.Sample{ + Metric: model.Metric{model.MetricNameLabel: "http_requests", "method": "/foo"}, + } + diskSample := model.Sample{ + Metric: model.Metric{model.MetricNameLabel: "http_requests", "method": "/bar"}, + } + if err := tiered.(*tieredStorage).memoryArena.AppendSample(memorySample); err != nil { + t.Fatalf("Failed to add fixture data: %s", err) + } + if err := tiered.(*tieredStorage).diskStorage.AppendSample(diskSample); err != nil { + t.Fatalf("Failed to add fixture data: %s", err) + } + tiered.Flush() + + scenarios := []struct { + labels model.LabelSet + fpCount int + }{ + { + labels: model.LabelSet{}, + fpCount: 0, + },{ + labels: model.LabelSet{ + model.MetricNameLabel: "http_requests", + }, + fpCount: 2, + }, { + labels: model.LabelSet{ + model.MetricNameLabel: "http_requests", + "method": "/foo", + }, + fpCount: 1, + }, { + labels: model.LabelSet{ + model.MetricNameLabel: "http_requests", + "method": "/bar", + }, + fpCount: 1, + }, { + labels: model.LabelSet{ + model.MetricNameLabel: "http_requests", + "method": "/baz", + }, + fpCount: 0, + }, + } + + for i, scenario := range scenarios { + fingerprints, err := tiered.GetFingerprintsForLabelSet(scenario.labels) + if err != nil { + t.Fatalf("%d. Error getting metric names: %s", i, err) + } + if len(fingerprints) != scenario.fpCount { + t.Fatalf("%d. Expected metric count %d, got %d", i, scenario.fpCount, len(fingerprints)) + } + } +}