deadtrickster / prometheus.ex

Prometheus.io Elixir client
411 stars 68 forks source link

Microseconds getting automatically converted to milliseconds? #29

Closed ghost closed 1 month ago

ghost commented 5 years ago

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

deadtrickster commented 5 years ago

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

danielfbnunes commented 4 years ago

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 😄

deadtrickster commented 4 years ago

Cool question!

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

danielfbnunes commented 4 years ago

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?