mirror of
https://github.com/prometheus/prometheus.git
synced 2025-03-05 20:59:13 -08:00
fix(web): properly format sub-millisecond durations in target status page
Previously, scrapes durations that are very short (e.g., connection refused) could show as empty (durations under 1 millisecond). This commit ensures that sub-millisecond durations are correctly displayed as "0ms" or "1ms" when necessary. - Adjusted `humanizeDuration` to round sub-millisecond durations to the nearest millisecond. - Updated unit tests to verify the correct handling of sub-millisecond values. Signed-off-by: Julien <roidelapluie@o11y.eu>
This commit is contained in:
parent
005bd33fe2
commit
7ebda924b8
|
@ -57,6 +57,12 @@ describe("humanizeDuration", () => {
|
||||||
expect(humanizeDuration(0)).toBe("0s");
|
expect(humanizeDuration(0)).toBe("0s");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test("formats submilliseconds correctly", () => {
|
||||||
|
expect(humanizeDuration(0.1)).toBe("0ms");
|
||||||
|
expect(humanizeDuration(0.6)).toBe("1ms");
|
||||||
|
expect(humanizeDuration(0.000001)).toBe("0ms");
|
||||||
|
});
|
||||||
|
|
||||||
test("formats milliseconds correctly", () => {
|
test("formats milliseconds correctly", () => {
|
||||||
expect(humanizeDuration(1)).toBe("1ms");
|
expect(humanizeDuration(1)).toBe("1ms");
|
||||||
expect(humanizeDuration(999)).toBe("999ms");
|
expect(humanizeDuration(999)).toBe("999ms");
|
||||||
|
|
|
@ -86,6 +86,9 @@ const formatDuration = (
|
||||||
r.push(`${v}${unit}`);
|
r.push(`${v}${unit}`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (r.length == 0 && unit == "ms") {
|
||||||
|
r.push(`${Math.round(ms)}ms`)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return sign + r.join(componentSeparator || "");
|
return sign + r.join(componentSeparator || "");
|
||||||
|
|
Loading…
Reference in a new issue