prometheus: Fix formatBytes invalid output#854
Open
skools-here wants to merge 1 commit into
Open
Conversation
Signed-off-by: skools-here <sajalkulshreshtha9@gmail.com>
068a958 to
41f8d7a
Compare
Author
|
ptal @illume |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
This PR addresses an issue where the
formatBytesutility function produces invalid output strings (such asNaNundefined) when it receives negative,NaN, or non-finite inputs.Fixes: #853
Problem
In
prometheus/src/util.ts, theformatBytesfunction calculates the logarithm of the input to determine the formatting scale (KB, MB, etc.). However, when the input is:-1):Math.log(-1)returnsNaN, leading toNaNundefinedUI outputs. This case frequently arises briefly during counter resets or delta calculations in Prometheus metrics.NaNor out-of-bounds indices, causing the UI to renderNaNundefined.Solution
formatBytesto return a graceful fallback of"0.00B"if the input is negative (bytes < 0) or not finite (!Number. isFinite(bytes)). This aligns with the formatting of0bytes.util.test.tsto verify the handling.