Skip to content

Commit

Permalink
Reduce function signature on classicHistograms
Browse files Browse the repository at this point in the history
  • Loading branch information
zalegrala committed Oct 31, 2024
1 parent 1cb9643 commit c6b7153
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions modules/generator/registry/native_histogram.go
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ func (h *nativeHistogram) collectMetrics(appender storage.Appender, timeMs int64

// If we are in "both" or "classic" mode, also emit classic histograms.
if hasClassicHistograms(h.histogramOverride) {
classicSeries, classicErr := h.classicHistograms(appender, s.lb, timeMs, s)
classicSeries, classicErr := h.classicHistograms(appender, timeMs, s)
if classicErr != nil {
return activeSeries, classicErr
}
Expand Down Expand Up @@ -308,7 +308,7 @@ func (h *nativeHistogram) nativeHistograms(appender storage.Appender, lbls label
return
}

func (h *nativeHistogram) classicHistograms(appender storage.Appender, lb *labels.Builder, timeMs int64, s *nativeHistogramSeries) (activeSeries int, err error) {
func (h *nativeHistogram) classicHistograms(appender storage.Appender, timeMs int64, s *nativeHistogramSeries) (activeSeries int, err error) {
if s.isNew() {
endOfLastMinuteMs := getEndOfLastMinuteMs(timeMs)
_, err = appender.Append(0, s.countLabels, endOfLastMinuteMs, 0)
Expand All @@ -333,28 +333,28 @@ func (h *nativeHistogram) classicHistograms(appender storage.Appender, lb *label
activeSeries++

// bucket
lb.Set(labels.MetricName, h.metricName+"_bucket")
s.lb.Set(labels.MetricName, h.metricName+"_bucket")

// the Prometheus histogram will sometimes add the +Inf bucket, it depends on whether there is an exemplar
// for that bucket or not. To avoid adding it twice, keep track of it with this boolean.
infBucketWasAdded := false

for _, bucket := range s.histogram.Bucket {
// add "le" label
lb.Set(labels.BucketLabel, formatFloat(bucket.GetUpperBound()))
s.lb.Set(labels.BucketLabel, formatFloat(bucket.GetUpperBound()))

if bucket.GetUpperBound() == math.Inf(1) {
infBucketWasAdded = true
}

ref, appendErr := appender.Append(0, lb.Labels(), timeMs, getIfGreaterThenZeroOr(bucket.GetCumulativeCountFloat(), bucket.GetCumulativeCount()))
ref, appendErr := appender.Append(0, s.lb.Labels(), timeMs, getIfGreaterThenZeroOr(bucket.GetCumulativeCountFloat(), bucket.GetCumulativeCount()))
if appendErr != nil {
return activeSeries, appendErr
}
activeSeries++

if bucket.Exemplar != nil && len(bucket.Exemplar.Label) > 0 {
_, err = appender.AppendExemplar(ref, lb.Labels(), exemplar.Exemplar{
_, err = appender.AppendExemplar(ref, s.lb.Labels(), exemplar.Exemplar{
Labels: convertLabelPairToLabels(bucket.Exemplar.GetLabel()),
Value: bucket.Exemplar.GetValue(),
Ts: timeMs,
Expand All @@ -368,17 +368,17 @@ func (h *nativeHistogram) classicHistograms(appender storage.Appender, lb *label

if !infBucketWasAdded {
// Add +Inf bucket
lb.Set(labels.BucketLabel, "+Inf")
s.lb.Set(labels.BucketLabel, "+Inf")

_, err = appender.Append(0, lb.Labels(), timeMs, getIfGreaterThenZeroOr(s.histogram.GetSampleCountFloat(), s.histogram.GetSampleCount()))
_, err = appender.Append(0, s.lb.Labels(), timeMs, getIfGreaterThenZeroOr(s.histogram.GetSampleCountFloat(), s.histogram.GetSampleCount()))
if err != nil {
return activeSeries, err
}
activeSeries++
}

// drop "le" label again
lb.Del(labels.BucketLabel)
s.lb.Del(labels.BucketLabel)

return
}
Expand Down

0 comments on commit c6b7153

Please sign in to comment.