Skip to content

Commit

Permalink
Add "_bucket" suffix to histogram samples, closes #21
Browse files Browse the repository at this point in the history
  • Loading branch information
DeusExLibris authored and fredrikekre committed Oct 23, 2024
1 parent fc768fb commit c4fb688
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/Prometheus.jl
Original file line number Diff line number Diff line change
Expand Up @@ -422,7 +422,7 @@ function collect!(metrics::Vector, histogram::Histogram)
samples[2] = Sample("_sum", nothing, nothing, @atomic(histogram._sum))
for i in 1:length(histogram.buckets)
sample = Sample(
nothing, label_names, make_label_values(label_names, (histogram.buckets[i],)),
"_bucket", label_names, make_label_values(label_names, (histogram.buckets[i],)),
histogram.bucket_counters[i][],
)
samples[2 + i] = sample
Expand Down
10 changes: 5 additions & 5 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ end
@test s1.value == 2
@test s2.value == 0.5 + 1.6
for (ub, counter, sample, known_count) in zip(c.buckets, c.bucket_counters, metric.samples[3:end], [1, 2, 2])
@test sample.suffix === nothing
@test sample.suffix == "_bucket"
@test (sample.label_names::Prometheus.LabelNames{1}).label_names === (:le,)
@test (sample.label_values::Prometheus.LabelValues{1}).label_values == (string(ub),)
@test sample.value == counter[] == known_count
Expand All @@ -233,9 +233,9 @@ end
# TYPE metric_name_histogram histogram
metric_name_histogram_count 2
metric_name_histogram_sum 2.1
metric_name_histogram{le="1.0"} 1
metric_name_histogram{le="2.0"} 2
metric_name_histogram{le="Inf"} 2
metric_name_histogram_bucket{le="1.0"} 1
metric_name_histogram_bucket{le="2.0"} 2
metric_name_histogram_bucket{le="Inf"} 2
"""
end

Expand Down Expand Up @@ -491,7 +491,7 @@ end
# {le} samples
for (ls, subrange) in ((l1, 7:8), (l2, 3:4))
for (ub, counter, sample) in zip(buckets, Prometheus.labels(c, ls).bucket_counters, metric.samples[subrange])
@test sample.suffix === nothing
@test sample.suffix == "_bucket"
@test (sample.label_names::Prometheus.LabelNames{3}).label_names ===
(:endpoint, :status_code, :le)
@test (sample.label_values::Prometheus.LabelValues{3}).label_values ==
Expand Down

0 comments on commit c4fb688

Please sign in to comment.