From 20f60b4b9c5f5c3226ed1e117fe813f1a0d7da79 Mon Sep 17 00:00:00 2001 From: Danny Thomas Date: Thu, 14 Nov 2024 14:43:06 +1100 Subject: [PATCH] Avoid 0 duration GC event times (#1170) We noticed `:dist-avg` under 1ms for ZGC and `getDuration` is in milliseconds, so we must be regularly seeing events that start and end in the same millisecond. --- .../src/main/java/com/netflix/spectator/gc/GcLogger.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/spectator-ext-gc/src/main/java/com/netflix/spectator/gc/GcLogger.java b/spectator-ext-gc/src/main/java/com/netflix/spectator/gc/GcLogger.java index 35a4b5218..1a90befab 100644 --- a/spectator-ext-gc/src/main/java/com/netflix/spectator/gc/GcLogger.java +++ b/spectator-ext-gc/src/main/java/com/netflix/spectator/gc/GcLogger.java @@ -252,7 +252,8 @@ private void processGcEvent(GarbageCollectionNotificationInfo info) { .withTag("action", info.getGcAction()) .withTag("cause", info.getGcCause()); Timer timer = Spectator.globalRegistry().timer(eventId); - timer.record(info.getGcInfo().getDuration(), TimeUnit.MILLISECONDS); + long duration = Math.max(1, info.getGcInfo().getDuration()); + timer.record(duration, TimeUnit.MILLISECONDS); // Update promotion and allocation counters updateMetrics(info.getGcName(), info.getGcInfo());