Correct Prometheus output for timer and JSON output for SimpleTimer (2.x) #4242
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Resolves #4237
Resolves #4240
There were two separate errors in creating metrics output.
Prometheus output for timers did not correctly scale the numeric values. In Prometheus, time values must always be expressed in seconds. Internally, Helidon stores the timer data in nanoseconds. So, to correctly format time values in Prometheus format, the timer code should always convert from nanoseconds (the stored values) to seconds. But the code incorrectly used the units stored in the metadata for the timer. That would've been OK if the values stored in the timer were in that unit, but our timer implementation always stored nanoseconds. And this is the correct thing to do in general, for other types of scaled quantities (such as storage) but not for time.
The fix here was to generalize a bit of the Prometheus output code so rather than always using the units stored in the metric metadata to decide how to convert values for output, the units object could be passed in. The timer now always passes in a fixed nanoseconds-to-seconds converter, rather than using a converter based on whatever units were declared in the timer's metadata.
While working on the Prometheus/timer problem, and while adding tests for JSON/timer output and for Prom. and JSON SimpleTimer output, I found that the SimpleTimer JSON output incorrectly always expressed the values as seconds, rather than in the specified units.
HelidonSimpleTimer
now correctly scales the values according to the units specified in the metadata. This fix involved refactoring some code (theconversionFactor
method) fromHelidonTimer
toMetricImpl
so it was available toHelidonSimpleTimer
as well.Signed-off-by: tim.quinn@oracle.com tim.quinn@oracle.com