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?
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 boundariespmarks publicationssmarks when start is called on the MeterRegistryS1/S2indicate ordinal step intervals since the startWhen a publication happens (
p), metrics based on the values recorded during the previous step interval are published. SopinS4publishes accumulated data that was recorded inS3.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
previousvariable and thecurrentwill be incremented.Let's say we are towards the end of
S2right now and you incremented a counter 5 times so far. Time passes without any actions and now we are inS3. 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 inS3). So it will not increment the value (5) that belongs to the previous step but "saves" it in apreviousvariable resetscurrentand increments it. After thispreviousshould be 5 andcurrentshould be one. Then time moves forward and thepreviousdata will be published and reset, leavingcurrentuntouched.Does this explanation make sense?