Skip to content

Commit 96eeddd

Browse files
committed
Fix test and references
1 parent d02b6e0 commit 96eeddd

File tree

2 files changed

+21
-17
lines changed

2 files changed

+21
-17
lines changed

prometheus/histogram.go

+17-13
Original file line numberDiff line numberDiff line change
@@ -1844,37 +1844,41 @@ type constNativeHistogram struct {
18441844
nativeHistogramSchema int32
18451845
nativeHistogramZeroThreshold float64
18461846
nativeHistogramMaxZeroThreshold float64
1847-
createdTimestamp time.Time
1847+
createdTimestamp time.Time
18481848
nativeExemplars []*dto.Exemplar
18491849

18501850
positiveBuckets map[int]int64
18511851
negativeBuckets map[int]int64
18521852
zeroBucket uint64
18531853
}
18541854

1855-
func NewconstNativeHistogram(desc *Desc, count uint64, sum float64, postiveBuckets, negativeBuckets map[int]int64, zeroBucket uint64,
1856-
labelPairs []*dto.LabelPair, nativeHistogramSchema int32, nativeHistogramZeroThreshold float64,
1857-
nativeHistogramMaxZeroThreshold float64, nativeHistogramMaxBuckets uint32,
1858-
nativeHistogramMinResetDuration time.Duration,
1855+
func NewConstNativeHistogram(desc *Desc, count uint64, sum float64, postiveBuckets, negativeBuckets map[int]int64, zeroBucket uint64,
1856+
nativeHistogramSchema int32, nativeHistogramZeroThreshold float64,
1857+
nativeHistogramMaxZeroThreshold float64,
18591858
createdTimestamp time.Time,
18601859
nativeExemplars []*dto.Exemplar,
1861-
) (constNativeHistogram, error) {
1862-
return constNativeHistogram{
1860+
labelValues ...string,
1861+
) (Metric, error) {
1862+
if desc.err != nil {
1863+
return nil, desc.err
1864+
}
1865+
if err := validateLabelValues(labelValues, len(desc.variableLabels.names)); err != nil {
1866+
return nil, err
1867+
}
1868+
return &constNativeHistogram{
18631869
desc: desc,
18641870
count: count,
18651871
sum: sum,
18661872
positiveBuckets: postiveBuckets,
18671873
negativeBuckets: negativeBuckets,
18681874
zeroBucket: zeroBucket,
1869-
labelPairs: labelPairs,
1875+
labelPairs: MakeLabelPairs(desc, labelValues),
18701876
nativeHistogramSchema: nativeHistogramSchema,
18711877
nativeHistogramZeroThreshold: nativeHistogramZeroThreshold,
18721878
nativeHistogramMaxZeroThreshold: nativeHistogramMaxZeroThreshold,
1873-
nativeHistogramMaxBuckets: nativeHistogramMaxBuckets,
1874-
nativeHistogramMinResetDuration: nativeHistogramMinResetDuration,
1875-
timeStamp: timeStamp,
1879+
createdTimestamp: createdTimestamp,
18761880
nativeExemplars: nativeExemplars,
1877-
}
1881+
}, nil
18781882
}
18791883

18801884
func (h *constNativeHistogram) Desc() *Desc {
@@ -1883,7 +1887,7 @@ func (h *constNativeHistogram) Desc() *Desc {
18831887

18841888
func (h *constNativeHistogram) Write(out *dto.Metric) error {
18851889
his := &dto.Histogram{
1886-
CreatedTimestamp: timestamppb.New(h.timeStamp),
1890+
CreatedTimestamp: timestamppb.New(h.createdTimestamp),
18871891
Schema: &h.nativeHistogramSchema,
18881892
ZeroThreshold: &h.nativeHistogramZeroThreshold,
18891893
Exemplars: h.nativeExemplars,

prometheus/histogram_test.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -1971,21 +1971,21 @@ func TestConstNativeHistogram(t *testing.T) {
19711971
n := atomic.LoadUint64(&_his.countAndHotIdx)
19721972
hotIdx := n >> 63
19731973
cold := _his.counts[hotIdx]
1974-
consthist := NewconstNativeHistogram(_his.Desc(),
1974+
consthist, err := NewConstNativeHistogram(_his.Desc(),
19751975
cold.count,
19761976
math.Float64frombits(cold.sumBits),
19771977
SyncMaptomap(&cold.nativeHistogramBucketsPositive),
19781978
SyncMaptomap(&cold.nativeHistogramBucketsNegative),
19791979
cold.nativeHistogramZeroBucket,
1980-
_his.labelPairs,
19811980
cold.nativeHistogramSchema,
19821981
math.Float64frombits(cold.nativeHistogramZeroThresholdBits),
19831982
_his.nativeHistogramMaxZeroThreshold,
1984-
_his.nativeHistogramMaxBuckets,
1985-
_his.nativeHistogramMinResetDuration,
19861983
_his.lastResetTime,
19871984
_his.nativeExemplars.exemplars,
19881985
)
1986+
if err != nil {
1987+
t.Fatal("unexpected error writing metric", err)
1988+
}
19891989
m2 := &dto.Metric{}
19901990

19911991
if err := consthist.Write(m2); err != nil {

0 commit comments

Comments
 (0)