Skip to content

Commit

Permalink
Fix test and references
Browse files Browse the repository at this point in the history
  • Loading branch information
shivanthzen committed Oct 18, 2024
1 parent d02b6e0 commit 96eeddd
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 17 deletions.
30 changes: 17 additions & 13 deletions prometheus/histogram.go
Original file line number Diff line number Diff line change
Expand Up @@ -1844,37 +1844,41 @@ type constNativeHistogram struct {
nativeHistogramSchema int32
nativeHistogramZeroThreshold float64
nativeHistogramMaxZeroThreshold float64
createdTimestamp time.Time
createdTimestamp time.Time
nativeExemplars []*dto.Exemplar

positiveBuckets map[int]int64
negativeBuckets map[int]int64
zeroBucket uint64
}

func NewconstNativeHistogram(desc *Desc, count uint64, sum float64, postiveBuckets, negativeBuckets map[int]int64, zeroBucket uint64,
labelPairs []*dto.LabelPair, nativeHistogramSchema int32, nativeHistogramZeroThreshold float64,
nativeHistogramMaxZeroThreshold float64, nativeHistogramMaxBuckets uint32,
nativeHistogramMinResetDuration time.Duration,
func NewConstNativeHistogram(desc *Desc, count uint64, sum float64, postiveBuckets, negativeBuckets map[int]int64, zeroBucket uint64,
nativeHistogramSchema int32, nativeHistogramZeroThreshold float64,
nativeHistogramMaxZeroThreshold float64,
createdTimestamp time.Time,
nativeExemplars []*dto.Exemplar,
) (constNativeHistogram, error) {
return constNativeHistogram{
labelValues ...string,
) (Metric, error) {
if desc.err != nil {
return nil, desc.err
}
if err := validateLabelValues(labelValues, len(desc.variableLabels.names)); err != nil {
return nil, err
}
return &constNativeHistogram{
desc: desc,
count: count,
sum: sum,
positiveBuckets: postiveBuckets,
negativeBuckets: negativeBuckets,
zeroBucket: zeroBucket,
labelPairs: labelPairs,
labelPairs: MakeLabelPairs(desc, labelValues),
nativeHistogramSchema: nativeHistogramSchema,
nativeHistogramZeroThreshold: nativeHistogramZeroThreshold,
nativeHistogramMaxZeroThreshold: nativeHistogramMaxZeroThreshold,
nativeHistogramMaxBuckets: nativeHistogramMaxBuckets,
nativeHistogramMinResetDuration: nativeHistogramMinResetDuration,
timeStamp: timeStamp,
createdTimestamp: createdTimestamp,
nativeExemplars: nativeExemplars,
}
}, nil
}

func (h *constNativeHistogram) Desc() *Desc {
Expand All @@ -1883,7 +1887,7 @@ func (h *constNativeHistogram) Desc() *Desc {

func (h *constNativeHistogram) Write(out *dto.Metric) error {
his := &dto.Histogram{
CreatedTimestamp: timestamppb.New(h.timeStamp),
CreatedTimestamp: timestamppb.New(h.createdTimestamp),
Schema: &h.nativeHistogramSchema,
ZeroThreshold: &h.nativeHistogramZeroThreshold,
Exemplars: h.nativeExemplars,
Expand Down
8 changes: 4 additions & 4 deletions prometheus/histogram_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1971,21 +1971,21 @@ func TestConstNativeHistogram(t *testing.T) {
n := atomic.LoadUint64(&_his.countAndHotIdx)
hotIdx := n >> 63
cold := _his.counts[hotIdx]
consthist := NewconstNativeHistogram(_his.Desc(),
consthist, err := NewConstNativeHistogram(_his.Desc(),
cold.count,
math.Float64frombits(cold.sumBits),
SyncMaptomap(&cold.nativeHistogramBucketsPositive),
SyncMaptomap(&cold.nativeHistogramBucketsNegative),
cold.nativeHistogramZeroBucket,
_his.labelPairs,
cold.nativeHistogramSchema,
math.Float64frombits(cold.nativeHistogramZeroThresholdBits),
_his.nativeHistogramMaxZeroThreshold,
_his.nativeHistogramMaxBuckets,
_his.nativeHistogramMinResetDuration,
_his.lastResetTime,
_his.nativeExemplars.exemplars,
)
if err != nil {
t.Fatal("unexpected error writing metric", err)
}
m2 := &dto.Metric{}

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

0 comments on commit 96eeddd

Please sign in to comment.