From ac50dc12d3a728b3a246083434437cf5432ce487 Mon Sep 17 00:00:00 2001 From: Tommy Ludwig <8924140+shakuzen@users.noreply.github.com> Date: Mon, 11 Mar 2024 23:24:24 +0900 Subject: [PATCH] Allow customizing start log message in PushMeterRegistry implementations It will be helpful in troubleshooting to be able to log more specific information to the implementation than is available at the level of PushMeterRegistry. Allowing this to be overridden also avoids registry implementations from logging similar messages resulting in multiple logs on start for essentially the same thing. --- .../core/instrument/push/PushMeterRegistry.java | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/micrometer-core/src/main/java/io/micrometer/core/instrument/push/PushMeterRegistry.java b/micrometer-core/src/main/java/io/micrometer/core/instrument/push/PushMeterRegistry.java index 3367689931..843b8e0782 100644 --- a/micrometer-core/src/main/java/io/micrometer/core/instrument/push/PushMeterRegistry.java +++ b/micrometer-core/src/main/java/io/micrometer/core/instrument/push/PushMeterRegistry.java @@ -107,8 +107,7 @@ public void start(ThreadFactory threadFactory) { stop(); if (config.enabled()) { - logger.info("publishing metrics for " + getClass().getSimpleName() + " every " - + TimeUtils.format(config.step())); + logger.info(startMessage()); scheduledExecutorService = Executors.newSingleThreadScheduledExecutor(threadFactory); long stepMillis = config.step().toMillis(); @@ -118,6 +117,17 @@ public void start(ThreadFactory threadFactory) { } } + /** + * Message that will be logged when the registry is {@link #start(ThreadFactory) + * started}. This can be overridden to customize the message with info specific to the + * registry implementation that may be helpful in troubleshooting. By default, the + * registry class name and step interval are included. + * @return message to log on registry start + */ + protected String startMessage() { + return "publishing metrics for " + getClass().getSimpleName() + " every " + TimeUtils.format(config.step()); + } + public void stop() { if (scheduledExecutorService != null) { scheduledExecutorService.shutdown();