Fix bug in GetFingerprintsForLabelSet().

This commit is contained in:
Julius Volz 2013-03-27 18:50:30 +01:00
parent 7034c3981f
commit 2668700e54
2 changed files with 62 additions and 1 deletions

View File

@ -562,7 +562,7 @@ func (t *tieredStorage) GetFingerprintsForLabelSet(labelSet model.LabelSet) (fin
if err != nil { if err != nil {
return return
} }
diskFingerprints, err := t.memoryArena.GetFingerprintsForLabelSet(labelSet) diskFingerprints, err := t.diskStorage.GetFingerprintsForLabelSet(labelSet)
if err != nil { if err != nil {
return return
} }

View File

@ -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))
}
}
}