Skip to content

Counts in ClassicHistogramBuckets cannot be negative throws when using SimpleclientCollector bridge #887

@turchenkoalex

Description

@turchenkoalex

If I use non-integer numbers in buckets for a classic histogram, an error is thrown when scraping metrics

Sample code to reproduce the error

package io.prometheus.metrics.simpleclient.bridge;

import io.prometheus.client.CollectorRegistry;
import io.prometheus.client.Histogram;
import io.prometheus.metrics.model.registry.PrometheusRegistry;

public class Test {
    public static void main(String[] args) {
        CollectorRegistry origRegistry = new CollectorRegistry();
        PrometheusRegistry newRegistry = new PrometheusRegistry();
        SimpleclientCollector.builder()
                .collectorRegistry(origRegistry)
                .register(newRegistry);

        Histogram histogram = Histogram.build()
                .name("response_size_bytes")
                .help("response size in Bytes")
                .labelNames("status")
                .buckets(0.01, 0.1)
                .register(origRegistry);

        histogram.labels("200").observe(1);

        newRegistry.scrape(); // throws IllegalArgumentException: Counts in ClassicHistogramBuckets cannot be negative.
    }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions