deadtrickster / prometheus.ex

Prometheus.io Elixir client

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Microseconds getting automatically converted to milliseconds?

bryanhuntesl opened this issue · comments

Is this expected behavior ?

I declare a metric with a microseconds suffix :

@histogram [
    name: :http_check_duration_microseconds,
    labels: [:target],
    buckets: :default,
    help: "Http check execution time"
  ]

And I then feed it a microseconds value (20481):

Histogram.observe(
      [name: :http_check_duration_microseconds, labels: [target]],
      time
    )

It is then silently converted to milliseconds - but the metric name still indicates microseconds.

http_check_duration_gauge_microseconds{target="http://google.com"} 20.481
# TYPE http_check_duration_microseconds histogram
# HELP http_check_duration_microseconds Http check execution time
http_check_duration_microseconds_bucket{target="http://google.com",le="0.005"} 0
http_check_duration_microseconds_bucket{target="http://google.com",le="0.01"} 0
http_check_duration_microseconds_bucket{target="http://google.com",le="0.025"} 0
http_check_duration_microseconds_bucket{target="http://google.com",le="0.05"} 0
http_check_duration_microseconds_bucket{target="http://google.com",le="0.1"} 0
http_check_duration_microseconds_bucket{target="http://google.com",le="0.25"} 0
http_check_duration_microseconds_bucket{target="http://google.com",le="0.5"} 0
http_check_duration_microseconds_bucket{target="http://google.com",le="1"} 0
http_check_duration_microseconds_bucket{target="http://google.com",le="2.5"} 0
http_check_duration_microseconds_bucket{target="http://google.com",le="5"} 0
http_check_duration_microseconds_bucket{target="http://google.com",le="10"} 0
http_check_duration_microseconds_bucket{target="http://google.com",le="+Inf"} 17
http_check_duration_microseconds_count{target="http://google.com"} 17
http_check_duration_microseconds_sum{target="http://google.com"} 364.862

The code in it's entirity can be seen here

Basically, when it sees suffix like _microseconds it expects values to be native_time_unit. Please read here: https://hexdocs.pm/prometheus_ex/time.html#content

Hey @deadtrickster . In the documentation, this is what we can see:

Users can specify time unit explicitly via duration_unit or implicitly via
metric name (preferred, since prometheus best practices guide insists on
<name>_duration_<unit> metric name format).

I had a metric that contained milliseconds in its name but it didn't have the duration_ part. This converts the metric value too. Is this the expected behaviour?

Thanks 😄

Cool question!

According to current code - yes that's expected. Does it disturb you? What is your metrics?

What is your metrics?

The metric was created to measure the time that certain queries take to run. Since they are pretty fast, I want the metric value to be in milliseconds as an Integer.

Does it disturb you?

No, it's no problem. Can you just update the docs?