autometrics-dev / autometrics-ts

Easily add metrics to your system – and actually understand them using automatically customized Prometheus queries

Home Page:https://autometrics.dev

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

πŸ› Change histogram buckets to reflect seconds, not milliseconds

brettimus opened this issue Β· comments

Environment information

n/a

What happened?

We recently changed the library (it's an unreleased change as of writing) to report seconds instead of milliseconds to the prometheus latency histogram.

One problem this introduced as I was playing with the push gateway support is that the histogram still uses the following buckets:

[ 0, 5, 10, 25, 50, 75, 100, 250, 500, 750, 1000, 2500, 5000, 7500, 10000 ]

Two possible solutions to this, and I'll follow up on trying them out later:

Solution 1: Report the unit when we create the histogram. Just based off of intuition, I don't think this is going to work.

const histogram = meter.createHistogram(HISTOGRAM_NAME, {
    description: HISTOGRAM_DESCRIPTION,
    unit: "s"
  });

Solution 2: Pass modified buckets to our MeterProvider

    autometricsMeterProvider = new MeterProvider({
      views: [
        new View({
          aggregation: new ExplicitBucketHistogramAggregation([
            0, 0.005, 0.01, 0.025, 0.05, 0.075, 0.1, 0.25, 0.5, 0.75, 1, 2.5, 5,
            7.5, 10,
          ]),
          instrumentName: HISTOGRAM_NAME,
        }),
      ],
    });

Expected result

Buckets for the latency histogram should be

[0, 0.005, 0.01, 0.025, 0.05, 0.075,  0.1,  0.25,  0.5,  0.75,    1,   2.5,     5,   7.5,   10 ]

not

[ 0, 5, 10, 25, 50, 75, 100, 250, 500, 750, 1000, 2500, 5000, 7500, 10000 ]