prometheusmetricsgraphitemicrometer

How does micrometer rate aggregation work?


I am reading through the micrometer's concept documentation and I have not been able to understand the rate aggregation section.

Especially this diagram which corresponds to the client side aggregation.

The documentation says the following:

Micrometer efficiently maintains rate data by means of a step value that accumulates data for the current publishing interval. When the step value is polled (when publishing, for example), if the step value detects that the current interval has elapsed, it moves current data to “previous” state. This previous state is what is reported until the next time current data overwrites it. The following image shows the interaction of current and previous state, along with polling:

As per my understanding, the step value is the interval at which metrics are sent to a monitoring system (graphite for example). Then what is meant by the current interval and how is it different from the step value?


Solution

  • Micrometer aggregates these values differently in case of different registries. There is step (also called delta) and cumulative aggregation flavors.

    Cumulative is basically a running total at the time of push/pull but step/delta is basically the difference since the previous step.

    The "step value" is basically the value that you recorded and accumulated (e.g.: you increment a counter 5 times, your step value is 5). The "step interval" is the time between step boundaries, or you can say the length of a step (e.g.: 1 minute).

    When publishing happens the value that will be published is the value that was accumulated in the previous step (except if the app is shutting down, then the current step is also published), let me illustrate this (credits to Tommy Ludwig). The legend is as follows:

    - marks the passage of time
    | marks step boundaries
    p marks publications
    s marks when start is called on the MeterRegistry
    S1/S2 indicate ordinal step intervals since the start

         S1         S2         S3         S4         S5
    |------s---|---p------|------p---|-----p----|---p------|---
    

    When a publication happens (p), metrics based on the values recorded during the previous step interval are published. So p in S4 publishes accumulated data that was recorded in S3.

    The above part of the docs you quoted is trying to explain that when you cross a step boundary, the data you recorded so far will be moved to a previous variable and the current will be incremented.

    Let's say we are towards the end of S2 right now and you incremented a counter 5 times so far. Time passes without any actions and now we are in S3. Then you increment the counter again. The mechanism in Micrometer will detect that you are now in a different step (crossed the step boundary and you are in S3). So it will not increment the value (5) that belongs to the previous step but "saves" it in a previous variable resets current and increments it. After this previous should be 5 and current should be one. Then time moves forward and the previous data will be published and reset, leaving current untouched.

    Does this explanation make sense?