mirror of
https://github.com/prometheus/prometheus.git
synced 2025-12-04 09:01:02 +01:00
refactor(histogram): rename types for clarity in histogram conversion tests
Signed-off-by: Naman-B-Parlecha <namanparlecha@gmail.com>
This commit is contained in:
parent
f71f911040
commit
ed67a0cbf1
@ -22,13 +22,13 @@ import (
|
|||||||
"github.com/prometheus/prometheus/model/labels"
|
"github.com/prometheus/prometheus/model/labels"
|
||||||
)
|
)
|
||||||
|
|
||||||
type BucketExpectation struct {
|
type ExpectedBucket struct {
|
||||||
le string
|
le string
|
||||||
val float64
|
val float64
|
||||||
}
|
}
|
||||||
|
|
||||||
type ExpectedHistogram struct {
|
type ExpectedClassicHistogram struct {
|
||||||
buckets []BucketExpectation
|
buckets []ExpectedBucket
|
||||||
count float64
|
count float64
|
||||||
sum float64
|
sum float64
|
||||||
}
|
}
|
||||||
@ -39,19 +39,19 @@ func TestConvertNHCBToClassicHistogram(t *testing.T) {
|
|||||||
nhcb any
|
nhcb any
|
||||||
labels labels.Labels
|
labels labels.Labels
|
||||||
expectErr bool
|
expectErr bool
|
||||||
expected ExpectedHistogram
|
expected ExpectedClassicHistogram
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
name: "Valid Histogram",
|
name: "Valid Histogram",
|
||||||
nhcb: &Histogram{
|
nhcb: &Histogram{
|
||||||
CustomValues: []float64{1, 2, 3},
|
CustomValues: []float64{1, 2, 3},
|
||||||
PositiveBuckets: []int64{10, 20, 30}, // Delta format: {10, 20, 30} -> Absolute: {10, 30, 60}
|
PositiveBuckets: []int64{10, 20, 30},
|
||||||
Count: 60,
|
Count: 60,
|
||||||
Sum: 100.0,
|
Sum: 100.0,
|
||||||
},
|
},
|
||||||
labels: labels.FromStrings("__name__", "test_metric"),
|
labels: labels.FromStrings("__name__", "test_metric"),
|
||||||
expected: ExpectedHistogram{
|
expected: ExpectedClassicHistogram{
|
||||||
buckets: []BucketExpectation{
|
buckets: []ExpectedBucket{
|
||||||
{le: "1", val: 10},
|
{le: "1", val: 10},
|
||||||
{le: "2", val: 30},
|
{le: "2", val: 30},
|
||||||
{le: "3", val: 60},
|
{le: "3", val: 60},
|
||||||
@ -70,8 +70,8 @@ func TestConvertNHCBToClassicHistogram(t *testing.T) {
|
|||||||
Sum: 100.0,
|
Sum: 100.0,
|
||||||
},
|
},
|
||||||
labels: labels.FromStrings("__name__", "test_metric"),
|
labels: labels.FromStrings("__name__", "test_metric"),
|
||||||
expected: ExpectedHistogram{
|
expected: ExpectedClassicHistogram{
|
||||||
buckets: []BucketExpectation{
|
buckets: []ExpectedBucket{
|
||||||
{le: "1", val: 20},
|
{le: "1", val: 20},
|
||||||
{le: "2", val: 40},
|
{le: "2", val: 40},
|
||||||
{le: "3", val: 60},
|
{le: "3", val: 60},
|
||||||
@ -90,8 +90,8 @@ func TestConvertNHCBToClassicHistogram(t *testing.T) {
|
|||||||
Sum: 0.0,
|
Sum: 0.0,
|
||||||
},
|
},
|
||||||
labels: labels.FromStrings("__name__", "test_metric"),
|
labels: labels.FromStrings("__name__", "test_metric"),
|
||||||
expected: ExpectedHistogram{
|
expected: ExpectedClassicHistogram{
|
||||||
buckets: []BucketExpectation{
|
buckets: []ExpectedBucket{
|
||||||
{le: "+Inf", val: 0},
|
{le: "+Inf", val: 0},
|
||||||
},
|
},
|
||||||
count: 0,
|
count: 0,
|
||||||
@ -102,7 +102,7 @@ func TestConvertNHCBToClassicHistogram(t *testing.T) {
|
|||||||
name: "Missing __name__ label",
|
name: "Missing __name__ label",
|
||||||
nhcb: &Histogram{
|
nhcb: &Histogram{
|
||||||
CustomValues: []float64{1, 2, 3},
|
CustomValues: []float64{1, 2, 3},
|
||||||
PositiveBuckets: []int64{10, 20, 30}, // Delta format: {10, 20, 30} -> Absolute: {10, 30, 60}
|
PositiveBuckets: []int64{10, 20, 30},
|
||||||
Count: 60,
|
Count: 60,
|
||||||
Sum: 100.0,
|
Sum: 100.0,
|
||||||
},
|
},
|
||||||
@ -119,13 +119,13 @@ func TestConvertNHCBToClassicHistogram(t *testing.T) {
|
|||||||
name: "Histogram with zero bucket counts",
|
name: "Histogram with zero bucket counts",
|
||||||
nhcb: &Histogram{
|
nhcb: &Histogram{
|
||||||
CustomValues: []float64{1, 2, 3},
|
CustomValues: []float64{1, 2, 3},
|
||||||
PositiveBuckets: []int64{0, 10, 0}, // Delta format: {0, 10, 0} -> Absolute: {0, 10, 10}
|
PositiveBuckets: []int64{0, 10, 0},
|
||||||
Count: 10,
|
Count: 10,
|
||||||
Sum: 50.0,
|
Sum: 50.0,
|
||||||
},
|
},
|
||||||
labels: labels.FromStrings("__name__", "test_metric"),
|
labels: labels.FromStrings("__name__", "test_metric"),
|
||||||
expected: ExpectedHistogram{
|
expected: ExpectedClassicHistogram{
|
||||||
buckets: []BucketExpectation{
|
buckets: []ExpectedBucket{
|
||||||
{le: "1", val: 0},
|
{le: "1", val: 0},
|
||||||
{le: "2", val: 10},
|
{le: "2", val: 10},
|
||||||
{le: "3", val: 10},
|
{le: "3", val: 10},
|
||||||
@ -139,7 +139,7 @@ func TestConvertNHCBToClassicHistogram(t *testing.T) {
|
|||||||
name: "Mismatched bucket lengths",
|
name: "Mismatched bucket lengths",
|
||||||
nhcb: &Histogram{
|
nhcb: &Histogram{
|
||||||
CustomValues: []float64{1, 2},
|
CustomValues: []float64{1, 2},
|
||||||
PositiveBuckets: []int64{10, 20, 30}, // Mismatched lengths: 2 vs 3
|
PositiveBuckets: []int64{10, 20, 30},
|
||||||
Count: 60,
|
Count: 60,
|
||||||
Sum: 100.0,
|
Sum: 100.0,
|
||||||
},
|
},
|
||||||
@ -150,13 +150,13 @@ func TestConvertNHCBToClassicHistogram(t *testing.T) {
|
|||||||
name: "single series Histogram",
|
name: "single series Histogram",
|
||||||
nhcb: &Histogram{
|
nhcb: &Histogram{
|
||||||
CustomValues: []float64{1},
|
CustomValues: []float64{1},
|
||||||
PositiveBuckets: []int64{10}, // Delta format: {10} -> Absolute: {10}
|
PositiveBuckets: []int64{10},
|
||||||
Count: 10,
|
Count: 10,
|
||||||
Sum: 20.0,
|
Sum: 20.0,
|
||||||
},
|
},
|
||||||
labels: labels.FromStrings("__name__", "test_metric"),
|
labels: labels.FromStrings("__name__", "test_metric"),
|
||||||
expected: ExpectedHistogram{
|
expected: ExpectedClassicHistogram{
|
||||||
buckets: []BucketExpectation{
|
buckets: []ExpectedBucket{
|
||||||
{le: "1", val: 10},
|
{le: "1", val: 10},
|
||||||
{le: "+Inf", val: 10},
|
{le: "+Inf", val: 10},
|
||||||
},
|
},
|
||||||
@ -169,11 +169,11 @@ func TestConvertNHCBToClassicHistogram(t *testing.T) {
|
|||||||
labelBuilder := labels.NewBuilder(labels.EmptyLabels())
|
labelBuilder := labels.NewBuilder(labels.EmptyLabels())
|
||||||
for _, tt := range tests {
|
for _, tt := range tests {
|
||||||
t.Run(tt.name, func(t *testing.T) {
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
var got ExpectedHistogram
|
var got ExpectedClassicHistogram
|
||||||
err := ConvertNHCBToClassicHistogram(tt.nhcb, tt.labels, labelBuilder, func(lbls labels.Labels, val float64) error {
|
err := ConvertNHCBToClassicHistogram(tt.nhcb, tt.labels, labelBuilder, func(lbls labels.Labels, val float64) error {
|
||||||
switch lbls.Get("__name__") {
|
switch lbls.Get("__name__") {
|
||||||
case tt.labels.Get("__name__") + "_bucket":
|
case tt.labels.Get("__name__") + "_bucket":
|
||||||
got.buckets = append(got.buckets, BucketExpectation{
|
got.buckets = append(got.buckets, ExpectedBucket{
|
||||||
le: lbls.Get("le"),
|
le: lbls.Get("le"),
|
||||||
val: val,
|
val: val,
|
||||||
})
|
})
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user