Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid NaN values causing problems in metrics output #2812

Merged
merged 1 commit into from
Feb 26, 2021
Merged

Avoid NaN values causing problems in metrics output #2812

merged 1 commit into from
Feb 26, 2021

Conversation

tjquinno
Copy link
Member

Resolves #464

Long-running but very low (i.e., no) traffic servers would report problems when formatting timer output in JSON because there would be cases in which a double would be computed by dividing 0 by 0, yielding Double.NaN.

This 0-by-0 division can occur when an underlying data structure used by the timer (and histogram) accumulates samples with zero weight and then attempts to compute the relative weight of one of those samples. That weight is zero, the total weight is zero, and the relative weight division results in NaN.

JSON formats a double value by converting it to a string and then converting the string as a BigDecimal. BigDecimal rejects this when the string is NaN, and that's the exception at the root of the stack trace.

The changes in this PR avoid storing samples in the underlying data structure that have no weight (and would not factor in any statistics anyway).

In the course of working on this, I found and fixed a bug unrelated to the problem. (The timer implementation accepts a clock, as does the histogram implementation. The timer delegates some work to a histogram but was not initializing the histogram with the same clock the timer itself uses. This caused several minutes of frustration in trying to create a timer-based test using a clock which the test artificially advances over several hours.)

Signed-off-by: tim.quinn@oracle.com tim.quinn@oracle.com

…cases where double NaN can occur and, among other things, spoil JSON formatting as a BigDecimal; add tests

Signed-off-by: tim.quinn@oracle.com <tim.quinn@oracle.com>
@tjquinno tjquinno self-assigned this Feb 26, 2021
@tjquinno tjquinno merged commit 9ab6191 into helidon-io:master Feb 26, 2021
@tjquinno tjquinno deleted the metrics-NaN branch February 26, 2021 21:04
paulparkinson pushed a commit that referenced this pull request Mar 29, 2021
…cases where double NaN can occur and, among other things, spoil JSON formatting as a BigDecimal; add tests (#2812)

Signed-off-by: tim.quinn@oracle.com <tim.quinn@oracle.com>
barchetta pushed a commit that referenced this pull request Mar 30, 2021
…cases where double NaN can occur and, among other things, spoil JSON formatting as a BigDecimal; add tests (#2812)

Signed-off-by: tim.quinn@oracle.com <tim.quinn@oracle.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Request to endpoint /metrics fails occasionally
2 participants