Skip to content

Precision truncation possibly not intended on timed with Seconds #152

@zmccoy

Description

@zmccoy

https://github.com/ChristopherDavenport/epimetheus/blob/efc69b90ff6f04dbdfa84504d67fecaa8c1d70a6/core/src/main/scala/io/chrisdavenport/epimetheus/Histogram.scala#L54-L57

In the function timed more specifically timedSeconds we're currently doing integer division in the case of SECONDS and truncating valuable information that would be good for the metric.

For example if start and end were: 1000 ms in and 3300 ms past then we'd have a difference of 2.3 seconds but with the current implementation we would be 1s in and then 3s in which would be 2.0 in the end result as it is currently coded.

Something like the below would fix the truncation of data problem for the default sized buckets (seconds) at least.

def timedFixed[E, F[_]: Bracket[?[_], E]: Clock, A](h: Histogram[F], fa: F[A]): F[A] =
    Bracket[F, E].bracket(Clock[F].monotonic(NANOSECONDS))
    {_: Long => fa}
    {start: Long => Clock[F].monotonic(NANOSECONDS).flatMap(now => h.observe(io.prometheus.client.SimpleTimer. elapsedSecondsFromNanos(start, now))}

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