From b23acccea861d976c24ebc3b8e211a60bbc9a60b Mon Sep 17 00:00:00 2001 From: "Matt T. Proud" Date: Thu, 15 Aug 2013 11:35:50 +0200 Subject: [PATCH] Kill AppendSample interface definition. AppendSample will be repcated with AppendSamples, which will take advantage of bulks appends. This is a necessary step for indexing pipeline decoupling. Change-Id: Ia83811a87bcc89973d3b64d64b85a28710253ebc --- storage/metric/end_to_end_test.go | 14 +++++++------- storage/metric/helpers_test.go | 4 ++-- storage/metric/interface.go | 6 +++--- storage/metric/memory_test.go | 10 +++++----- storage/metric/regressions_test.go | 2 +- storage/metric/rule_integration_test.go | 4 ++-- storage/metric/stochastic_test.go | 8 ++++---- 7 files changed, 24 insertions(+), 24 deletions(-) diff --git a/storage/metric/end_to_end_test.go b/storage/metric/end_to_end_test.go index f970f97a2..cc5a7b44a 100644 --- a/storage/metric/end_to_end_test.go +++ b/storage/metric/end_to_end_test.go @@ -23,7 +23,7 @@ import ( ) func GetFingerprintsForLabelSetTests(p MetricPersistence, t test.Tester) { - testAppendSample(p, &clientmodel.Sample{ + testAppendSamples(p, &clientmodel.Sample{ Value: 0, Timestamp: time.Time{}, Metric: clientmodel.Metric{ @@ -32,7 +32,7 @@ func GetFingerprintsForLabelSetTests(p MetricPersistence, t test.Tester) { }, }, t) - testAppendSample(p, &clientmodel.Sample{ + testAppendSamples(p, &clientmodel.Sample{ Value: 0, Timestamp: time.Time{}, Metric: clientmodel.Metric{ @@ -79,7 +79,7 @@ func GetFingerprintsForLabelSetTests(p MetricPersistence, t test.Tester) { } func GetFingerprintsForLabelNameTests(p MetricPersistence, t test.Tester) { - testAppendSample(p, &clientmodel.Sample{ + testAppendSamples(p, &clientmodel.Sample{ Value: 0, Timestamp: time.Time{}, Metric: clientmodel.Metric{ @@ -89,7 +89,7 @@ func GetFingerprintsForLabelNameTests(p MetricPersistence, t test.Tester) { }, }, t) - testAppendSample(p, &clientmodel.Sample{ + testAppendSamples(p, &clientmodel.Sample{ Value: 0, Timestamp: time.Time{}, Metric: clientmodel.Metric{ @@ -145,7 +145,7 @@ func GetFingerprintsForLabelNameTests(p MetricPersistence, t test.Tester) { } func GetMetricForFingerprintTests(p MetricPersistence, t test.Tester) { - testAppendSample(p, &clientmodel.Sample{ + testAppendSamples(p, &clientmodel.Sample{ Value: 0, Timestamp: time.Time{}, Metric: clientmodel.Metric{ @@ -153,7 +153,7 @@ func GetMetricForFingerprintTests(p MetricPersistence, t test.Tester) { }, }, t) - testAppendSample(p, &clientmodel.Sample{ + testAppendSamples(p, &clientmodel.Sample{ Value: 0, Timestamp: time.Time{}, Metric: clientmodel.Metric{ @@ -264,7 +264,7 @@ func AppendRepeatingValuesTests(p MetricPersistence, t test.Tester) { for i := 0; i < increments; i++ { for j := 0; j < repetitions; j++ { time := time.Time{}.Add(time.Duration(i) * time.Hour).Add(time.Duration(j) * time.Second) - testAppendSample(p, &clientmodel.Sample{ + testAppendSamples(p, &clientmodel.Sample{ Value: clientmodel.SampleValue(i), Timestamp: time, Metric: metric, diff --git a/storage/metric/helpers_test.go b/storage/metric/helpers_test.go index 26c5b9d3f..58d703bfb 100644 --- a/storage/metric/helpers_test.go +++ b/storage/metric/helpers_test.go @@ -28,8 +28,8 @@ var ( testInstant = time.Date(1972, 7, 18, 19, 5, 45, 0, usEastern).In(time.UTC) ) -func testAppendSample(p MetricPersistence, s *clientmodel.Sample, t test.Tester) { - err := p.AppendSample(s) +func testAppendSamples(p MetricPersistence, s *clientmodel.Sample, t test.Tester) { + err := p.AppendSamples(clientmodel.Samples{s}) if err != nil { t.Fatal(err) } diff --git a/storage/metric/interface.go b/storage/metric/interface.go index cb6505bba..c0c8345a9 100644 --- a/storage/metric/interface.go +++ b/storage/metric/interface.go @@ -21,6 +21,9 @@ import ( "github.com/prometheus/prometheus/storage" ) +// AppendBatch models a batch of samples to be stored. +type AppendBatch map[clientmodel.Fingerprint]SampleSet + // MetricPersistence is a system for storing metric samples in a persistence // layer. type MetricPersistence interface { @@ -32,9 +35,6 @@ type MetricPersistence interface { // queue work on channels and operate on it in bulk. // Flush() error - // Record a new sample in the storage layer. - AppendSample(*clientmodel.Sample) error - // Record a group of new samples in the storage layer. AppendSamples(clientmodel.Samples) error diff --git a/storage/metric/memory_test.go b/storage/metric/memory_test.go index 67dbfb5af..2ddfa1942 100644 --- a/storage/metric/memory_test.go +++ b/storage/metric/memory_test.go @@ -47,7 +47,7 @@ func BenchmarkStreamAdd(b *testing.B) { b.Logf("%d cycles with %f bytes per cycle, totalling %d", b.N, float32(post.TotalAlloc-pre.TotalAlloc)/float32(b.N), post.TotalAlloc-pre.TotalAlloc) } -func benchmarkAppendSample(b *testing.B, labels int) { +func benchmarkAppendSamples(b *testing.B, labels int) { b.StopTimer() s := NewMemorySeriesStorage(MemorySeriesOptions{}) @@ -80,17 +80,17 @@ func benchmarkAppendSample(b *testing.B, labels int) { } func BenchmarkAppendSample1(b *testing.B) { - benchmarkAppendSample(b, 1) + benchmarkAppendSamples(b, 1) } func BenchmarkAppendSample10(b *testing.B) { - benchmarkAppendSample(b, 10) + benchmarkAppendSamples(b, 10) } func BenchmarkAppendSample100(b *testing.B) { - benchmarkAppendSample(b, 100) + benchmarkAppendSamples(b, 100) } func BenchmarkAppendSample1000(b *testing.B) { - benchmarkAppendSample(b, 1000) + benchmarkAppendSamples(b, 1000) } diff --git a/storage/metric/regressions_test.go b/storage/metric/regressions_test.go index a25321879..59eea2b57 100644 --- a/storage/metric/regressions_test.go +++ b/storage/metric/regressions_test.go @@ -38,7 +38,7 @@ func GetFingerprintsForLabelSetUsesAndForLabelMatchingTests(p MetricPersistence, m[clientmodel.LabelName(k)] = clientmodel.LabelValue(v) } - testAppendSample(p, &clientmodel.Sample{ + testAppendSamples(p, &clientmodel.Sample{ Value: clientmodel.SampleValue(0.0), Timestamp: time.Now(), Metric: m, diff --git a/storage/metric/rule_integration_test.go b/storage/metric/rule_integration_test.go index 1eeaafad5..21f698599 100644 --- a/storage/metric/rule_integration_test.go +++ b/storage/metric/rule_integration_test.go @@ -327,7 +327,7 @@ func GetValueAtTimeTests(persistenceMaker func() (MetricPersistence, test.Closer } for _, value := range context.values { - testAppendSample(p, &clientmodel.Sample{ + testAppendSamples(p, &clientmodel.Sample{ Value: clientmodel.SampleValue(value.value), Timestamp: time.Date(value.year, value.month, value.day, value.hour, 0, 0, 0, time.UTC), Metric: m, @@ -819,7 +819,7 @@ func GetRangeValuesTests(persistenceMaker func() (MetricPersistence, test.Closer } for _, value := range context.values { - testAppendSample(p, &clientmodel.Sample{ + testAppendSamples(p, &clientmodel.Sample{ Value: clientmodel.SampleValue(value.value), Timestamp: time.Date(value.year, value.month, value.day, value.hour, 0, 0, 0, time.UTC), Metric: m, diff --git a/storage/metric/stochastic_test.go b/storage/metric/stochastic_test.go index 91a4d98fe..372f4a0e4 100644 --- a/storage/metric/stochastic_test.go +++ b/storage/metric/stochastic_test.go @@ -107,7 +107,7 @@ func AppendSampleAsPureSparseAppendTests(p MetricPersistence, t test.Tester) { Metric: l, } - err := p.AppendSample(sample) + err := p.AppendSamples(clientmodel.Samples{sample}) success = err == nil if !success { @@ -136,7 +136,7 @@ func AppendSampleAsSparseAppendWithReadsTests(p MetricPersistence, t test.Tester Metric: l, } - err := p.AppendSample(sample) + err := p.AppendSamples(clientmodel.Samples{sample}) if err != nil { t.Error(err) return @@ -180,7 +180,7 @@ func AppendSampleAsPureSingleEntityAppendTests(p MetricPersistence, t test.Teste Metric: clientmodel.Metric{clientmodel.MetricNameLabel: "my_metric"}, } - err := p.AppendSample(sample) + err := p.AppendSamples(clientmodel.Samples{sample}) return err == nil } @@ -321,7 +321,7 @@ func StochasticTests(persistenceMaker func() (MetricPersistence, test.Closer), t sample.Timestamp = sortedTimestamps[sampleIndex] sample.Value = clientmodel.SampleValue(sampleIndex) - err := p.AppendSample(sample) + err := p.AppendSamples(clientmodel.Samples{sample}) if err != nil { t.Error(err)