mirror of
https://github.com/prometheus/prometheus.git
synced 2025-03-05 20:59:13 -08:00
Comment and "go fmt" fixups in compaction tests.
Change-Id: Iaa0eda6a22a5caa0590bae87ff579f9ace21e80a
This commit is contained in:
parent
8c08a5031f
commit
db015de65b
|
@ -14,9 +14,9 @@
|
||||||
package metric
|
package metric
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"flag"
|
||||||
"fmt"
|
"fmt"
|
||||||
"testing"
|
"testing"
|
||||||
"flag"
|
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/prometheus/prometheus/storage"
|
"github.com/prometheus/prometheus/storage"
|
||||||
|
@ -25,10 +25,11 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
type nopCurationStateUpdater struct{}
|
type nopCurationStateUpdater struct{}
|
||||||
|
|
||||||
func (n *nopCurationStateUpdater) UpdateCurationState(*CurationState) {}
|
func (n *nopCurationStateUpdater) UpdateCurationState(*CurationState) {}
|
||||||
|
|
||||||
func generateTestSamples(endTime time.Time, numTs int, samplesPerTs int, interval time.Duration) clientmodel.Samples {
|
func generateTestSamples(endTime time.Time, numTs int, samplesPerTs int, interval time.Duration) clientmodel.Samples {
|
||||||
samples := clientmodel.Samples{}
|
samples := make(clientmodel.Samples, 0, numTs*samplesPerTs)
|
||||||
|
|
||||||
startTime := endTime.Add(-interval * time.Duration(samplesPerTs-1))
|
startTime := endTime.Add(-interval * time.Duration(samplesPerTs-1))
|
||||||
for ts := 0; ts < numTs; ts++ {
|
for ts := 0; ts < numTs; ts++ {
|
||||||
|
@ -57,16 +58,16 @@ func (c *compactionChecker) Operate(key, value interface{}) *storage.OperatorErr
|
||||||
c.numChunks++
|
c.numChunks++
|
||||||
sampleKey := key.(*SampleKey)
|
sampleKey := key.(*SampleKey)
|
||||||
if sampleKey.FirstTimestamp.After(sampleKey.LastTimestamp) {
|
if sampleKey.FirstTimestamp.After(sampleKey.LastTimestamp) {
|
||||||
c.t.Fatalf("Chunk FirstTimestamp (%v) is after LastTimestamp (%v): %v\n", sampleKey.FirstTimestamp.Unix(), sampleKey.LastTimestamp.Unix(), sampleKey)
|
c.t.Fatalf("Chunk FirstTimestamp (%v) is after LastTimestamp (%v): %v", sampleKey.FirstTimestamp.Unix(), sampleKey.LastTimestamp.Unix(), sampleKey)
|
||||||
}
|
}
|
||||||
|
fp := new(clientmodel.Fingerprint)
|
||||||
for _, sample := range value.(Values) {
|
for _, sample := range value.(Values) {
|
||||||
if sample.Timestamp.Before(sampleKey.FirstTimestamp) || sample.Timestamp.After(sampleKey.LastTimestamp) {
|
if sample.Timestamp.Before(sampleKey.FirstTimestamp) || sample.Timestamp.After(sampleKey.LastTimestamp) {
|
||||||
c.t.Fatalf("Sample not within chunk boundaries: chunk FirstTimestamp (%v), chunk LastTimestamp (%v) vs. sample Timestamp (%v)\n", sampleKey.FirstTimestamp.Unix(), sampleKey.LastTimestamp.Unix(), sample.Timestamp)
|
c.t.Fatalf("Sample not within chunk boundaries: chunk FirstTimestamp (%v), chunk LastTimestamp (%v) vs. sample Timestamp (%v)", sampleKey.FirstTimestamp.Unix(), sampleKey.LastTimestamp.Unix(), sample.Timestamp)
|
||||||
}
|
}
|
||||||
|
|
||||||
expected := c.expectedSamples[c.sampleIdx]
|
expected := c.expectedSamples[c.sampleIdx]
|
||||||
|
|
||||||
fp := &clientmodel.Fingerprint{}
|
|
||||||
fp.LoadFromMetric(expected.Metric)
|
fp.LoadFromMetric(expected.Metric)
|
||||||
if !sampleKey.Fingerprint.Equal(fp) {
|
if !sampleKey.Fingerprint.Equal(fp) {
|
||||||
c.t.Fatalf("%d. Expected fingerprint %s, got %s", c.sampleIdx, fp, sampleKey.Fingerprint)
|
c.t.Fatalf("%d. Expected fingerprint %s, got %s", c.sampleIdx, fp, sampleKey.Fingerprint)
|
||||||
|
@ -84,7 +85,6 @@ func (c *compactionChecker) Operate(key, value interface{}) *storage.OperatorErr
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
func checkStorageSaneAndEquivalent(t *testing.T, name string, ts *TieredStorage, samples clientmodel.Samples, expectedNumChunks int) {
|
func checkStorageSaneAndEquivalent(t *testing.T, name string, ts *TieredStorage, samples clientmodel.Samples, expectedNumChunks int) {
|
||||||
cc := &compactionChecker{
|
cc := &compactionChecker{
|
||||||
expectedSamples: samples,
|
expectedSamples: samples,
|
||||||
|
@ -115,9 +115,9 @@ type compactionTestScenario struct {
|
||||||
compactedChunks int
|
compactedChunks int
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s compactionTestScenario) run(t *testing.T) {
|
func (s compactionTestScenario) test(t *testing.T) {
|
||||||
|
defer flag.Set("leveldbChunkSize", flag.Lookup("leveldbChunkSize").Value.String())
|
||||||
flag.Set("leveldbChunkSize", fmt.Sprintf("%d", s.leveldbChunkSize))
|
flag.Set("leveldbChunkSize", fmt.Sprintf("%d", s.leveldbChunkSize))
|
||||||
defer flag.Set("leveldbChunkSize", "200")
|
|
||||||
|
|
||||||
ts, closer := NewTestTieredStorage(t)
|
ts, closer := NewTestTieredStorage(t)
|
||||||
defer closer.Close()
|
defer closer.Close()
|
||||||
|
@ -143,7 +143,6 @@ func (s compactionTestScenario) run(t *testing.T) {
|
||||||
})
|
})
|
||||||
defer curator.Close()
|
defer curator.Close()
|
||||||
|
|
||||||
fmt.Println("test instant:", testInstant)
|
|
||||||
err := curator.Run(s.ignoreYoungerThan, testInstant, processor, ts.DiskStorage.CurationRemarks, ts.DiskStorage.MetricSamples, ts.DiskStorage.MetricHighWatermarks, &nopCurationStateUpdater{})
|
err := curator.Run(s.ignoreYoungerThan, testInstant, processor, ts.DiskStorage.CurationRemarks, ts.DiskStorage.MetricSamples, ts.DiskStorage.MetricHighWatermarks, &nopCurationStateUpdater{})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("Failed to run curator: %s", err)
|
t.Fatalf("Failed to run curator: %s", err)
|
||||||
|
@ -239,6 +238,6 @@ func TestCompaction(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, s := range scenarios {
|
for _, s := range scenarios {
|
||||||
s.run(t)
|
s.test(t)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue