Skip to content

Commit 02a7f4d

Browse files
authored
Spam less with KafkaMetrics and Prometheus (#2311)
Logging each occurrence of this at INFO level has been too verbose. Switch to logging the first occurrence at WARN and subsequent occurrences at DEBUG to create less spam for most common logging configurations.
1 parent 976eff8 commit 02a7f4d

File tree

1 file changed

+3
-1
lines changed
  • micrometer-core/src/main/java/io/micrometer/core/instrument/binder/kafka

1 file changed

+3
-1
lines changed

micrometer-core/src/main/java/io/micrometer/core/instrument/binder/kafka/KafkaMetrics.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636

3737
import io.micrometer.core.util.internal.logging.InternalLogger;
3838
import io.micrometer.core.util.internal.logging.InternalLoggerFactory;
39+
import io.micrometer.core.util.internal.logging.WarnThenDebugLogger;
3940
import org.apache.kafka.common.Metric;
4041
import org.apache.kafka.common.MetricName;
4142

@@ -54,6 +55,7 @@
5455
@NonNullFields
5556
class KafkaMetrics implements MeterBinder, AutoCloseable {
5657
private final static InternalLogger log = InternalLoggerFactory.getInstance(KafkaMetrics.class);
58+
private final static WarnThenDebugLogger warnThenDebugLogger = new WarnThenDebugLogger(KafkaMetrics.class);
5759

5860
static final String METRIC_NAME_PREFIX = "kafka.";
5961
static final String METRIC_GROUP_APP_INFO = "app-info";
@@ -166,7 +168,7 @@ else if (tags.size() == meterTagsWithCommonTags.size())
166168
catch (Exception ex) {
167169
String message = ex.getMessage();
168170
if (message != null && message.contains("Prometheus requires")) {
169-
log.info("Failed to bind meter: " + meterName + " " + tags
171+
warnThenDebugLogger.log("Failed to bind meter: " + meterName + " " + tags
170172
+ ". However, this could happen and might be restored in the next refresh.");
171173
}
172174
else {

0 commit comments

Comments
 (0)