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 (
|
||||
"code.google.com/p/goprotobuf/proto"
|
||||
"errors"
|
||||
"fmt"
|
||||
"github.com/matttproud/prometheus/coding"
|
||||
"github.com/matttproud/prometheus/coding/indexable"
|
||||
"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 {
|
||||
fmt.Printf("Sample: %q\n", sample)
|
||||
|
||||
metricDDO := ddoFromSample(sample)
|
||||
|
||||
if indexHas, indexHasError := l.hasIndexMetric(metricDDO); indexHasError == nil {
|
||||
|
@ -628,7 +625,6 @@ func (l *LevelDBMetricPersistence) GetWatermarksForMetric(metric model.Metric) (
|
|||
return emission, foundEntries, nil
|
||||
}
|
||||
foundEntries++
|
||||
log.Printf("b foundEntries++ %d\n", foundEntries)
|
||||
emission.NewestInclusive = indexable.DecodeTime(found.Timestamp)
|
||||
} else {
|
||||
log.Printf("Could not de-serialize subsequent key: %q\n", subsequentUnmarshalErr)
|
||||
|
|
|
@ -27,6 +27,10 @@ import (
|
|||
"time"
|
||||
)
|
||||
|
||||
const (
|
||||
stochasticMaximumVariance = 64
|
||||
)
|
||||
|
||||
func TestBasicLifecycle(t *testing.T) {
|
||||
temporaryDirectory, temporaryDirectoryErr := ioutil.TempDir("", "leveldb_metric_persistence_test")
|
||||
|
||||
|
@ -325,13 +329,15 @@ func TestAppendSampleAsPureSingleEntityAppend(t *testing.T) {
|
|||
|
||||
func TestStochastic(t *testing.T) {
|
||||
stochastic := func(x int) bool {
|
||||
s := time.Now()
|
||||
seed := rand.NewSource(int64(x))
|
||||
random := rand.New(seed)
|
||||
numberOfMetrics := random.Intn(5) + 1
|
||||
numberOfSharedLabels := random.Intn(5)
|
||||
numberOfUnsharedLabels := random.Intn(5)
|
||||
numberOfSamples := random.Intn(1024) + 2
|
||||
numberOfRangeScans := random.Intn(3)
|
||||
|
||||
numberOfMetrics := random.Intn(stochasticMaximumVariance) + 1
|
||||
numberOfSharedLabels := random.Intn(stochasticMaximumVariance)
|
||||
numberOfUnsharedLabels := random.Intn(stochasticMaximumVariance)
|
||||
numberOfSamples := random.Intn(stochasticMaximumVariance) + 2
|
||||
numberOfRangeScans := random.Intn(stochasticMaximumVariance)
|
||||
|
||||
temporaryDirectory, _ := ioutil.TempDir("", "leveldb_metric_persistence_test")
|
||||
|
||||
|
@ -544,10 +550,6 @@ func TestStochastic(t *testing.T) {
|
|||
return false
|
||||
}
|
||||
|
||||
minimum := metricEarliestSample[metricIndex]
|
||||
maximum := metricNewestSample[metricIndex]
|
||||
spread := maximum - minimum
|
||||
|
||||
for i := 0; i < numberOfRangeScans; i++ {
|
||||
timestamps := metricTimestamps[metricIndex]
|
||||
|
||||
|
@ -555,34 +557,48 @@ func TestStochastic(t *testing.T) {
|
|||
var second int64 = 0
|
||||
|
||||
for {
|
||||
first = minimum + random.Int63n(spread)
|
||||
if _, has := timestamps[first]; has {
|
||||
break
|
||||
firstCandidate := random.Int63n(int64(len(timestamps)))
|
||||
secondCandidate := random.Int63n(int64(len(timestamps)))
|
||||
|
||||
smallest := int64(-1)
|
||||
largest := int64(-1)
|
||||
|
||||
if firstCandidate == secondCandidate {
|
||||
continue
|
||||
} else if firstCandidate > secondCandidate {
|
||||
largest = firstCandidate
|
||||
smallest = secondCandidate
|
||||
} else {
|
||||
largest = secondCandidate
|
||||
smallest = firstCandidate
|
||||
}
|
||||
|
||||
j := int64(0)
|
||||
for i := range timestamps {
|
||||
if j == smallest {
|
||||
first = i
|
||||
} else if j == largest {
|
||||
second = i
|
||||
break
|
||||
}
|
||||
j++
|
||||
}
|
||||
|
||||
break
|
||||
}
|
||||
|
||||
for {
|
||||
second = minimum + random.Int63n(spread)
|
||||
if _, has := timestamps[second]; has && second != first {
|
||||
break
|
||||
}
|
||||
}
|
||||
begin := first
|
||||
end := second
|
||||
|
||||
var begin int64 = 0
|
||||
var end int64 = 0
|
||||
|
||||
if first > second {
|
||||
begin = second
|
||||
end = first
|
||||
} else {
|
||||
begin = first
|
||||
end = second
|
||||
if second < first {
|
||||
begin, end = second, first
|
||||
}
|
||||
|
||||
interval := model.Interval{
|
||||
OldestInclusive: time.Unix(begin, 0),
|
||||
NewestInclusive: time.Unix(end, 0),
|
||||
}
|
||||
|
||||
rangeValues, rangeErr := persistence.GetSamplesForMetric(metric, interval)
|
||||
|
||||
if rangeErr != nil {
|
||||
|
@ -595,6 +611,8 @@ func TestStochastic(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
fmt.Printf("Duration %q\n", time.Now().Sub(s))
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue