mirror of
https://github.com/prometheus/prometheus.git
synced 2025-01-12 14:27:27 -08:00
Major LevelDB metric end-to-end test improvements.
Performance is enhanced through better range selection.
This commit is contained in:
parent
c1f0d8aefd
commit
9f4bdaab50
|
@ -16,7 +16,6 @@ package leveldb
|
||||||
import (
|
import (
|
||||||
"code.google.com/p/goprotobuf/proto"
|
"code.google.com/p/goprotobuf/proto"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
|
||||||
"github.com/matttproud/prometheus/coding"
|
"github.com/matttproud/prometheus/coding"
|
||||||
"github.com/matttproud/prometheus/coding/indexable"
|
"github.com/matttproud/prometheus/coding/indexable"
|
||||||
"github.com/matttproud/prometheus/model"
|
"github.com/matttproud/prometheus/model"
|
||||||
|
@ -447,8 +446,6 @@ func (l *LevelDBMetricPersistence) appendFingerprints(ddo *data.MetricDDO) error
|
||||||
}
|
}
|
||||||
|
|
||||||
func (l *LevelDBMetricPersistence) AppendSample(sample *model.Sample) error {
|
func (l *LevelDBMetricPersistence) AppendSample(sample *model.Sample) error {
|
||||||
fmt.Printf("Sample: %q\n", sample)
|
|
||||||
|
|
||||||
metricDDO := ddoFromSample(sample)
|
metricDDO := ddoFromSample(sample)
|
||||||
|
|
||||||
if indexHas, indexHasError := l.hasIndexMetric(metricDDO); indexHasError == nil {
|
if indexHas, indexHasError := l.hasIndexMetric(metricDDO); indexHasError == nil {
|
||||||
|
@ -628,7 +625,6 @@ func (l *LevelDBMetricPersistence) GetWatermarksForMetric(metric model.Metric) (
|
||||||
return emission, foundEntries, nil
|
return emission, foundEntries, nil
|
||||||
}
|
}
|
||||||
foundEntries++
|
foundEntries++
|
||||||
log.Printf("b foundEntries++ %d\n", foundEntries)
|
|
||||||
emission.NewestInclusive = indexable.DecodeTime(found.Timestamp)
|
emission.NewestInclusive = indexable.DecodeTime(found.Timestamp)
|
||||||
} else {
|
} else {
|
||||||
log.Printf("Could not de-serialize subsequent key: %q\n", subsequentUnmarshalErr)
|
log.Printf("Could not de-serialize subsequent key: %q\n", subsequentUnmarshalErr)
|
||||||
|
|
|
@ -27,6 +27,10 @@ import (
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
stochasticMaximumVariance = 64
|
||||||
|
)
|
||||||
|
|
||||||
func TestBasicLifecycle(t *testing.T) {
|
func TestBasicLifecycle(t *testing.T) {
|
||||||
temporaryDirectory, temporaryDirectoryErr := ioutil.TempDir("", "leveldb_metric_persistence_test")
|
temporaryDirectory, temporaryDirectoryErr := ioutil.TempDir("", "leveldb_metric_persistence_test")
|
||||||
|
|
||||||
|
@ -325,13 +329,15 @@ func TestAppendSampleAsPureSingleEntityAppend(t *testing.T) {
|
||||||
|
|
||||||
func TestStochastic(t *testing.T) {
|
func TestStochastic(t *testing.T) {
|
||||||
stochastic := func(x int) bool {
|
stochastic := func(x int) bool {
|
||||||
|
s := time.Now()
|
||||||
seed := rand.NewSource(int64(x))
|
seed := rand.NewSource(int64(x))
|
||||||
random := rand.New(seed)
|
random := rand.New(seed)
|
||||||
numberOfMetrics := random.Intn(5) + 1
|
|
||||||
numberOfSharedLabels := random.Intn(5)
|
numberOfMetrics := random.Intn(stochasticMaximumVariance) + 1
|
||||||
numberOfUnsharedLabels := random.Intn(5)
|
numberOfSharedLabels := random.Intn(stochasticMaximumVariance)
|
||||||
numberOfSamples := random.Intn(1024) + 2
|
numberOfUnsharedLabels := random.Intn(stochasticMaximumVariance)
|
||||||
numberOfRangeScans := random.Intn(3)
|
numberOfSamples := random.Intn(stochasticMaximumVariance) + 2
|
||||||
|
numberOfRangeScans := random.Intn(stochasticMaximumVariance)
|
||||||
|
|
||||||
temporaryDirectory, _ := ioutil.TempDir("", "leveldb_metric_persistence_test")
|
temporaryDirectory, _ := ioutil.TempDir("", "leveldb_metric_persistence_test")
|
||||||
|
|
||||||
|
@ -544,10 +550,6 @@ func TestStochastic(t *testing.T) {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
minimum := metricEarliestSample[metricIndex]
|
|
||||||
maximum := metricNewestSample[metricIndex]
|
|
||||||
spread := maximum - minimum
|
|
||||||
|
|
||||||
for i := 0; i < numberOfRangeScans; i++ {
|
for i := 0; i < numberOfRangeScans; i++ {
|
||||||
timestamps := metricTimestamps[metricIndex]
|
timestamps := metricTimestamps[metricIndex]
|
||||||
|
|
||||||
|
@ -555,34 +557,48 @@ func TestStochastic(t *testing.T) {
|
||||||
var second int64 = 0
|
var second int64 = 0
|
||||||
|
|
||||||
for {
|
for {
|
||||||
first = minimum + random.Int63n(spread)
|
firstCandidate := random.Int63n(int64(len(timestamps)))
|
||||||
if _, has := timestamps[first]; has {
|
secondCandidate := random.Int63n(int64(len(timestamps)))
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for {
|
smallest := int64(-1)
|
||||||
second = minimum + random.Int63n(spread)
|
largest := int64(-1)
|
||||||
if _, has := timestamps[second]; has && second != first {
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
var begin int64 = 0
|
if firstCandidate == secondCandidate {
|
||||||
var end int64 = 0
|
continue
|
||||||
|
} else if firstCandidate > secondCandidate {
|
||||||
if first > second {
|
largest = firstCandidate
|
||||||
begin = second
|
smallest = secondCandidate
|
||||||
end = first
|
|
||||||
} else {
|
} else {
|
||||||
begin = first
|
largest = secondCandidate
|
||||||
end = second
|
smallest = firstCandidate
|
||||||
|
}
|
||||||
|
|
||||||
|
j := int64(0)
|
||||||
|
for i := range timestamps {
|
||||||
|
if j == smallest {
|
||||||
|
first = i
|
||||||
|
} else if j == largest {
|
||||||
|
second = i
|
||||||
|
break
|
||||||
|
}
|
||||||
|
j++
|
||||||
|
}
|
||||||
|
|
||||||
|
break
|
||||||
|
}
|
||||||
|
|
||||||
|
begin := first
|
||||||
|
end := second
|
||||||
|
|
||||||
|
if second < first {
|
||||||
|
begin, end = second, first
|
||||||
}
|
}
|
||||||
|
|
||||||
interval := model.Interval{
|
interval := model.Interval{
|
||||||
OldestInclusive: time.Unix(begin, 0),
|
OldestInclusive: time.Unix(begin, 0),
|
||||||
NewestInclusive: time.Unix(end, 0),
|
NewestInclusive: time.Unix(end, 0),
|
||||||
}
|
}
|
||||||
|
|
||||||
rangeValues, rangeErr := persistence.GetSamplesForMetric(metric, interval)
|
rangeValues, rangeErr := persistence.GetSamplesForMetric(metric, interval)
|
||||||
|
|
||||||
if rangeErr != nil {
|
if rangeErr != nil {
|
||||||
|
@ -595,6 +611,8 @@ func TestStochastic(t *testing.T) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fmt.Printf("Duration %q\n", time.Now().Sub(s))
|
||||||
|
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue