You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm seeing similar behaviour as reported in #494 with Counters. This time with Histograms. I've written the following failing test
funcTestCollectAndCompareHistogram(t*testing.T) {
inputs:= []struct {
namestringc prometheus.Collectormetadatastringexpectstringobservationfloat64
}{
{
name: "Testing Histogram Collector",
c: prometheus.NewHistogram(prometheus.HistogramOpts{
Name: "some_histogram",
Help: "An example of a histogram",
Buckets: []float64{1, 2, 3},
}),
metadata: ` # HELP some_histogram An example of a histogram # TYPE some_histogram histogram `,
expect: ` some_histogram{le="1"} 0 some_histogram{le="2"} 0 some_histogram{le="3"} 1 some_histogram_bucket{le="+Inf"} 1 some_histogram_sum 2.5 some_histogram_count 1 `,
observation: 2.5,
},
{
name: "Testing HistogramVec Collector",
c: prometheus.NewHistogramVec(prometheus.HistogramOpts{
Name: "some_histogram",
Help: "An example of a histogram",
Buckets: []float64{1, 2, 3},
}, []string{"test"}),
metadata: ` # HELP some_histogram An example of a histogram # TYPE some_histogram histogram `,
expect: ` some_histogram{le="1"} 0 some_histogram{le="2"} 0 some_histogram{le="3"} 1 some_histogram_bucket{le="+Inf"} 1 some_histogram_sum 2.5 some_histogram_count 1 `,
observation: 2.5,
},
}
for_, input:=rangeinputs {
switchcollector:=input.c.(type) {
case prometheus.Histogram:
collector.Observe(input.observation)
case*prometheus.HistogramVec:
collector.WithLabelValues("test").Observe(input.observation)
default:
t.Fatalf("unsuported collector tested")
}
t.Run(input.name, func(t*testing.T) {
iferr:=CollectAndCompare(input.c, strings.NewReader(input.metadata+input.expect)); err!=nil {
t.Errorf("unexpected collecting result:\n%s", err)
}
})
}
}
It returns the following output:
FAIL
--- FAIL: TestCollectAndCompareHistogram/Testing_Histogram_Collector (0.00s)
testutil_test.go:237: unexpected collecting result:
metric output does not match expectation; want:
# HELP some_histogram An example of a histogram# TYPE some_histogram histogram
some_histogram_bucket{le="1"} 0
some_histogram_bucket{le="2"} 0
some_histogram_bucket{le="3"} 1
some_histogram_bucket{le="+Inf"} 1
some_histogram_sum 2.5
some_histogram_count 1
got:
# HELP some_histogram An example of a histogram# TYPE some_histogram histogram
some_histogram_bucket{le="1"} 0
some_histogram_bucket{le="2"} 0
some_histogram_bucket{le="3"} 1
some_histogram_bucket{le="+Inf"} 1
some_histogram_sum 2.5
some_histogram_count 1
Comparing the want and the got strings:
name:"some_histogram" help:"An example of a histogram" type:HISTOGRAM metric:<histogram:<sample_count:1 sample_sum:2.5 bucket:<cumulative_count:0 upper_bound:1 > bucket:<cumulative_count:0 upper_bound:2 > bucket:<cumulative_count:1 upper_bound:3 > > >
name:"some_histogram" help:"An example of a histogram" type:HISTOGRAM metric:<histogram:<sample_count:1 sample_sum:2.5 bucket:<cumulative_count:0 upper_bound:1 > bucket:<cumulative_count:0 upper_bound:2 > bucket:<cumulative_count:1 upper_bound:3 > bucket:<cumulative_count:1 upper_bound:inf > > >
The text was updated successfully, but these errors were encountered:
I see, that's the +Inf bucket, which is redundant/optional. Hmmm, I think I'll just go one step further and compare the text format directly. Currently, in real-life Prometheus settings, the text format is the one Prometheus uses anyway, so it's most relevant.
Will create another PR at my next convenience.
philipgough
added a commit
to philipgough/client_golang
that referenced
this issue
Nov 14, 2018
@beorn7 this follows up from our chat in #497
I'm seeing similar behaviour as reported in #494 with Counters. This time with Histograms. I've written the following failing test
It returns the following output:
Comparing the want and the got strings:
The text was updated successfully, but these errors were encountered: