mirror of
https://github.com/prometheus/prometheus.git
synced 2024-12-25 21:54:10 -08:00
Merge pull request #340 from prometheus/ui/console-null-values
Send [] instead of "null" for empty result vectors, fix retrieval tests
This commit is contained in:
commit
8eb1e8e679
|
@ -21,7 +21,7 @@ func TestInterfaces(t *testing.T) {
|
||||||
var (
|
var (
|
||||||
_ Target = &target{}
|
_ Target = &target{}
|
||||||
_ TargetManager = &targetManager{}
|
_ TargetManager = &targetManager{}
|
||||||
_ healthReporter = target{}
|
_ healthReporter = &target{}
|
||||||
_ scheduler = &healthScheduler{}
|
_ scheduler = &healthScheduler{}
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
|
@ -58,9 +58,42 @@ func testHealthScheduler(t test.Tester) {
|
||||||
expectedSchedule: []time.Time{now, now.Add(time.Second * 2), now.Add(time.Minute * 2)},
|
expectedSchedule: []time.Time{now, now.Add(time.Second * 2), now.Add(time.Minute * 2)},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
futureHealthState: []TargetState{UNKNOWN, UNREACHABLE, UNREACHABLE, UNREACHABLE, UNREACHABLE, UNREACHABLE, UNREACHABLE, UNREACHABLE, UNREACHABLE, UNREACHABLE, UNREACHABLE, UNREACHABLE, UNREACHABLE},
|
futureHealthState: []TargetState{
|
||||||
preloadedTimes: []time.Time{now, now.Add(time.Minute), now.Add(time.Minute * 2), now.Add(time.Minute * 3), now.Add(time.Minute * 4), now.Add(time.Minute * 5), now.Add(time.Minute * 6), now.Add(time.Minute * 7), now.Add(time.Minute * 8), now.Add(time.Minute * 9), now.Add(time.Minute * 10), now.Add(time.Minute * 11), now.Add(time.Minute * 12)},
|
UNKNOWN,
|
||||||
expectedSchedule: []time.Time{now, now.Add(time.Second * 2), now.Add(time.Minute * 1).Add(time.Second * 4), now.Add(time.Minute * 2).Add(time.Second * 8), now.Add(time.Minute * 3).Add(time.Second * 16), now.Add(time.Minute * 4).Add(time.Second * 32), now.Add(time.Minute * 5).Add(time.Second * 64), now.Add(time.Minute * 6).Add(time.Second * 128), now.Add(time.Minute * 7).Add(time.Second * 256), now.Add(time.Minute * 8).Add(time.Second * 512), now.Add(time.Minute * 9).Add(time.Second * 1024), now.Add(time.Minute * 10).Add(time.Minute * 30), now.Add(time.Minute * 11).Add(time.Minute * 30)},
|
UNREACHABLE,
|
||||||
|
UNREACHABLE,
|
||||||
|
UNREACHABLE,
|
||||||
|
UNREACHABLE,
|
||||||
|
UNREACHABLE,
|
||||||
|
UNREACHABLE,
|
||||||
|
UNREACHABLE,
|
||||||
|
UNREACHABLE,
|
||||||
|
UNREACHABLE,
|
||||||
|
},
|
||||||
|
preloadedTimes: []time.Time{
|
||||||
|
now,
|
||||||
|
now.Add(time.Minute),
|
||||||
|
now.Add(time.Minute * 2),
|
||||||
|
now.Add(time.Minute * 3),
|
||||||
|
now.Add(time.Minute * 4),
|
||||||
|
now.Add(time.Minute * 5),
|
||||||
|
now.Add(time.Minute * 6),
|
||||||
|
now.Add(time.Minute * 7),
|
||||||
|
now.Add(time.Minute * 8),
|
||||||
|
now.Add(time.Minute * 9),
|
||||||
|
},
|
||||||
|
expectedSchedule: []time.Time{
|
||||||
|
now,
|
||||||
|
now.Add(time.Second * 2),
|
||||||
|
now.Add(time.Minute * 1).Add(time.Second * 4),
|
||||||
|
now.Add(time.Minute * 2).Add(time.Second * 8),
|
||||||
|
now.Add(time.Minute * 3).Add(time.Second * 16),
|
||||||
|
now.Add(time.Minute * 4).Add(time.Second * 32),
|
||||||
|
now.Add(time.Minute * 5).Add(time.Second * 64),
|
||||||
|
now.Add(time.Minute * 6).Add(time.Minute * 2),
|
||||||
|
now.Add(time.Minute * 7).Add(time.Minute * 2),
|
||||||
|
now.Add(time.Minute * 8).Add(time.Minute * 2),
|
||||||
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -75,6 +75,8 @@ func (t *fakeTarget) ScheduledFor() (time time.Time) {
|
||||||
|
|
||||||
func (t *fakeTarget) Merge(newTarget Target) {}
|
func (t *fakeTarget) Merge(newTarget Target) {}
|
||||||
|
|
||||||
|
func (t *fakeTarget) EstimatedTimeToExecute() time.Duration { return 0 }
|
||||||
|
|
||||||
func testTargetManager(t test.Tester) {
|
func testTargetManager(t test.Tester) {
|
||||||
results := make(chan *extraction.Result, 5)
|
results := make(chan *extraction.Result, 5)
|
||||||
targetManager := NewTargetManager(results, 3)
|
targetManager := NewTargetManager(results, 3)
|
||||||
|
|
|
@ -401,7 +401,7 @@ func (node *VectorAggregation) Eval(timestamp time.Time, view *viewAdapter) Vect
|
||||||
func (node *VectorLiteral) Eval(timestamp time.Time, view *viewAdapter) Vector {
|
func (node *VectorLiteral) Eval(timestamp time.Time, view *viewAdapter) Vector {
|
||||||
values, err := view.GetValueAtTime(node.fingerprints, timestamp)
|
values, err := view.GetValueAtTime(node.fingerprints, timestamp)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("Unable to get vector values")
|
log.Println("Unable to get vector values:", err)
|
||||||
return Vector{}
|
return Vector{}
|
||||||
}
|
}
|
||||||
return values
|
return values
|
||||||
|
@ -589,7 +589,7 @@ func (node *MatrixLiteral) Eval(timestamp time.Time, view *viewAdapter) Matrix {
|
||||||
}
|
}
|
||||||
values, err := view.GetRangeValues(node.fingerprints, interval)
|
values, err := view.GetRangeValues(node.fingerprints, interval)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("Unable to get values for vector interval")
|
log.Println("Unable to get values for vector interval:", err)
|
||||||
return Matrix{}
|
return Matrix{}
|
||||||
}
|
}
|
||||||
return values
|
return values
|
||||||
|
@ -602,7 +602,7 @@ func (node *MatrixLiteral) EvalBoundaries(timestamp time.Time, view *viewAdapter
|
||||||
}
|
}
|
||||||
values, err := view.GetBoundaryValues(node.fingerprints, interval)
|
values, err := view.GetBoundaryValues(node.fingerprints, interval)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("Unable to get boundary values for vector interval")
|
log.Printf("Unable to get boundary values for vector interval:", err)
|
||||||
return Matrix{}
|
return Matrix{}
|
||||||
}
|
}
|
||||||
return values
|
return values
|
||||||
|
|
|
@ -109,14 +109,15 @@ func (v *viewAdapter) chooseClosestSample(samples metric.Values, timestamp time.
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (v *viewAdapter) GetValueAtTime(fingerprints clientmodel.Fingerprints, timestamp time.Time) (samples Vector, err error) {
|
func (v *viewAdapter) GetValueAtTime(fingerprints clientmodel.Fingerprints, timestamp time.Time) (Vector, error) {
|
||||||
timer := v.stats.GetTimer(stats.GetValueAtTimeTime).Start()
|
timer := v.stats.GetTimer(stats.GetValueAtTimeTime).Start()
|
||||||
|
samples := Vector{}
|
||||||
for _, fingerprint := range fingerprints {
|
for _, fingerprint := range fingerprints {
|
||||||
sampleCandidates := v.view.GetValueAtTime(fingerprint, timestamp)
|
sampleCandidates := v.view.GetValueAtTime(fingerprint, timestamp)
|
||||||
samplePair := v.chooseClosestSample(sampleCandidates, timestamp)
|
samplePair := v.chooseClosestSample(sampleCandidates, timestamp)
|
||||||
m, err := v.storage.GetMetricForFingerprint(fingerprint)
|
m, err := v.storage.GetMetricForFingerprint(fingerprint)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
continue
|
return nil, err
|
||||||
}
|
}
|
||||||
if samplePair != nil {
|
if samplePair != nil {
|
||||||
samples = append(samples, &clientmodel.Sample{
|
samples = append(samples, &clientmodel.Sample{
|
||||||
|
@ -127,11 +128,12 @@ func (v *viewAdapter) GetValueAtTime(fingerprints clientmodel.Fingerprints, time
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
timer.Stop()
|
timer.Stop()
|
||||||
return samples, err
|
return samples, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (v *viewAdapter) GetBoundaryValues(fingerprints clientmodel.Fingerprints, interval *metric.Interval) (sampleSets []metric.SampleSet, err error) {
|
func (v *viewAdapter) GetBoundaryValues(fingerprints clientmodel.Fingerprints, interval *metric.Interval) ([]metric.SampleSet, error) {
|
||||||
timer := v.stats.GetTimer(stats.GetBoundaryValuesTime).Start()
|
timer := v.stats.GetTimer(stats.GetBoundaryValuesTime).Start()
|
||||||
|
sampleSets := []metric.SampleSet{}
|
||||||
for _, fingerprint := range fingerprints {
|
for _, fingerprint := range fingerprints {
|
||||||
samplePairs := v.view.GetBoundaryValues(fingerprint, *interval)
|
samplePairs := v.view.GetBoundaryValues(fingerprint, *interval)
|
||||||
if len(samplePairs) == 0 {
|
if len(samplePairs) == 0 {
|
||||||
|
@ -141,7 +143,7 @@ func (v *viewAdapter) GetBoundaryValues(fingerprints clientmodel.Fingerprints, i
|
||||||
// TODO: memoize/cache this.
|
// TODO: memoize/cache this.
|
||||||
m, err := v.storage.GetMetricForFingerprint(fingerprint)
|
m, err := v.storage.GetMetricForFingerprint(fingerprint)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
continue
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
sampleSet := metric.SampleSet{
|
sampleSet := metric.SampleSet{
|
||||||
|
@ -154,8 +156,9 @@ func (v *viewAdapter) GetBoundaryValues(fingerprints clientmodel.Fingerprints, i
|
||||||
return sampleSets, nil
|
return sampleSets, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (v *viewAdapter) GetRangeValues(fingerprints clientmodel.Fingerprints, interval *metric.Interval) (sampleSets []metric.SampleSet, err error) {
|
func (v *viewAdapter) GetRangeValues(fingerprints clientmodel.Fingerprints, interval *metric.Interval) ([]metric.SampleSet, error) {
|
||||||
timer := v.stats.GetTimer(stats.GetRangeValuesTime).Start()
|
timer := v.stats.GetTimer(stats.GetRangeValuesTime).Start()
|
||||||
|
sampleSets := []metric.SampleSet{}
|
||||||
for _, fingerprint := range fingerprints {
|
for _, fingerprint := range fingerprints {
|
||||||
samplePairs := v.view.GetRangeValues(fingerprint, *interval)
|
samplePairs := v.view.GetRangeValues(fingerprint, *interval)
|
||||||
if len(samplePairs) == 0 {
|
if len(samplePairs) == 0 {
|
||||||
|
@ -165,7 +168,7 @@ func (v *viewAdapter) GetRangeValues(fingerprints clientmodel.Fingerprints, inte
|
||||||
// TODO: memoize/cache this.
|
// TODO: memoize/cache this.
|
||||||
m, err := v.storage.GetMetricForFingerprint(fingerprint)
|
m, err := v.storage.GetMetricForFingerprint(fingerprint)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
continue
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
sampleSet := metric.SampleSet{
|
sampleSet := metric.SampleSet{
|
||||||
|
|
Loading…
Reference in a new issue