MCPcopy
hub / github.com/prometheus/client_golang / TestConstNativeHistogram

Function TestConstNativeHistogram

prometheus/histogram_test.go:1557–2087  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

1555}
1556
1557func TestConstNativeHistogram(t *testing.T) {
1558 now := time.Now()
1559
1560 scenarios := []struct {
1561 name string
1562 observations []float64 // With simulated interval of 1m.
1563 factor float64
1564 zeroThreshold float64
1565 maxBuckets uint32
1566 minResetDuration time.Duration
1567 maxZeroThreshold float64
1568 want *dto.Histogram
1569 }{
1570 {
1571 name: "no observations",
1572 factor: 1.1,
1573 want: &dto.Histogram{
1574 SampleCount: proto.Uint64(0),
1575 SampleSum: proto.Float64(0),
1576 Schema: proto.Int32(3),
1577 ZeroThreshold: proto.Float64(2.938735877055719e-39),
1578 ZeroCount: proto.Uint64(0),
1579 CreatedTimestamp: timestamppb.New(now),
1580 },
1581 },
1582 {
1583 name: "no observations and zero threshold of zero resulting in no-op span",
1584 factor: 1.1,
1585 zeroThreshold: NativeHistogramZeroThresholdZero,
1586 want: &dto.Histogram{
1587 SampleCount: proto.Uint64(0),
1588 SampleSum: proto.Float64(0),
1589 Schema: proto.Int32(3),
1590 ZeroThreshold: proto.Float64(0),
1591 ZeroCount: proto.Uint64(0),
1592 PositiveSpan: []*dto.BucketSpan{
1593 {Offset: proto.Int32(0), Length: proto.Uint32(0)},
1594 },
1595 CreatedTimestamp: timestamppb.New(now),
1596 },
1597 },
1598 {
1599 name: "factor 1.1 results in schema 3",
1600 observations: []float64{0, 1, 2, 3},
1601 factor: 1.1,
1602 want: &dto.Histogram{
1603 SampleCount: proto.Uint64(4),
1604 SampleSum: proto.Float64(6),
1605 Schema: proto.Int32(3),
1606 ZeroThreshold: proto.Float64(2.938735877055719e-39),
1607 ZeroCount: proto.Uint64(1),
1608 PositiveSpan: []*dto.BucketSpan{
1609 {Offset: proto.Int32(0), Length: proto.Uint32(1)},
1610 {Offset: proto.Int32(7), Length: proto.Uint32(1)},
1611 {Offset: proto.Int32(4), Length: proto.Uint32(1)},
1612 },
1613 PositiveDelta: []int64{1, 0, 0},
1614 CreatedTimestamp: timestamppb.New(now),

Callers

nothing calls this directly

Calls 8

ObserveMethod · 0.95
NewConstNativeHistogramFunction · 0.85
syncMapToMapFunction · 0.85
RunMethod · 0.80
NewHistogramFunction · 0.70
AddMethod · 0.65
DescMethod · 0.65
WriteMethod · 0.65

Tested by

no test coverage detected