Skip to content

Commit

Permalink
handling histograms with duplicate buckets
Browse files Browse the repository at this point in the history
  • Loading branch information
sravotto committed Jan 7, 2022
1 parent d22b1b5 commit 9ddbe61
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 3 deletions.
9 changes: 8 additions & 1 deletion internal/lib/histograms.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,10 +108,17 @@ func TranslateHistogram(config *BucketConfig, mf *dto.MetricFamily) {
var prev *dto.Bucket = nil
requiredBuckets := 1
max := 0.0
//fmt.Printf("Metric %+v\n", mf)
if len(m.Histogram.Bucket) >= 2 {
max = m.Histogram.Bucket[len(m.Histogram.Bucket)-2].GetUpperBound()
if config.Endns > 0 {
max = float64(config.Endns)
} else {
for _, b := range m.Histogram.Bucket {
u := b.GetUpperBound()
if u != math.Inf(1) && u > max {
max = u
}
}
}
requiredBuckets = requiredBuckets + int(math.Ceil(math.Log10(float64(max))))*bins
}
Expand Down
1 change: 0 additions & 1 deletion internal/lib/histograms_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ func TestHistogramConversion(t *testing.T) {
TranslateHistogram(config, mf)
var buf bytes.Buffer
expfmt.MetricFamilyToText(&buf, mf)

assert.Equal(output, buf.String())
}
}
Expand Down
2 changes: 1 addition & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ func main() {

metricFamilies, err := reader.ReadMetrics(ctx)
if err != nil {
w.WriteHeader(500)
w.WriteHeader(http.StatusInternalServerError)
fmt.Fprintln(w, err)
return
}
Expand Down

0 comments on commit 9ddbe61

Please sign in to comment.