From 81fe098de6ff20f2b7f0f5638029b7f714b2b1b6 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 10 Jan 2023 17:10:30 +0900 Subject: [PATCH 1/2] Bump com.gradle.enterprise from 3.12.1 to 3.12.2 (#3583) Bumps com.gradle.enterprise from 3.12.1 to 3.12.2. --- updated-dependencies: - dependency-name: com.gradle.enterprise dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- settings.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/settings.gradle b/settings.gradle index 3f4847354e..bdb0fee384 100644 --- a/settings.gradle +++ b/settings.gradle @@ -5,7 +5,7 @@ pluginManagement { } plugins { - id 'com.gradle.enterprise' version '3.12.1' + id 'com.gradle.enterprise' version '3.12.2' id 'io.spring.ge.conventions' version '0.0.13' } From b6dc948cc2c2f26d69ee8046fca33d84df6a5da1 Mon Sep 17 00:00:00 2001 From: Georg Pirklbauer Date: Tue, 10 Jan 2023 10:14:19 +0100 Subject: [PATCH 2/2] Log NaNs at DEBUG instead of WARNING (#3557) --- .../dynatrace/v2/DynatraceExporterV2.java | 37 ++++++++++++++----- 1 file changed, 28 insertions(+), 9 deletions(-) diff --git a/implementations/micrometer-registry-dynatrace/src/main/java/io/micrometer/dynatrace/v2/DynatraceExporterV2.java b/implementations/micrometer-registry-dynatrace/src/main/java/io/micrometer/dynatrace/v2/DynatraceExporterV2.java index 4ff4ccb49e..cb00053221 100644 --- a/implementations/micrometer-registry-dynatrace/src/main/java/io/micrometer/dynatrace/v2/DynatraceExporterV2.java +++ b/implementations/micrometer-registry-dynatrace/src/main/java/io/micrometer/dynatrace/v2/DynatraceExporterV2.java @@ -62,7 +62,11 @@ public final class DynatraceExporterV2 extends AbstractDynatraceExporter { private static final Pattern IS_NULL_ERROR_RESPONSE = Pattern.compile("\"error\":\\s?null"); - private static final WarnThenDebugLogger warnThenDebugLogger = new WarnThenDebugLogger(DynatraceExporterV2.class); + private static final WarnThenDebugLogger stackTraceWarnThenDebugLogger = new WarnThenDebugLogger( + DynatraceExporterV2.class); + + private static final WarnThenDebugLogger nanGaugeWarnThenDebugLogger = new WarnThenDebugLogger( + DynatraceExporterV2.class); private static final Map staticDimensions = Collections.singletonMap("dt.metrics.source", "micrometer"); @@ -132,13 +136,9 @@ private DimensionList parseDefaultDimensions(Map defaultDimensio @Override public void export(List meters) { // Lines that are too long to be ingested into Dynatrace, as well as lines that - // contain NaN - // or Inf values are dropped and not returned from "toMetricLines", and are + // contain NaN or Inf values are not returned from "toMetricLines", and are // therefore dropped. - List metricLines = meters.stream().flatMap(this::toMetricLines) // Stream - // to - // Stream - .collect(Collectors.toList()); + List metricLines = meters.stream().flatMap(this::toMetricLines).collect(Collectors.toList()); sendInBatches(metricLines); } @@ -155,7 +155,25 @@ Stream toGaugeLine(Gauge meter) { private String createGaugeLine(Meter meter, Measurement measurement) { try { - return createMetricBuilder(meter).setDoubleGaugeValue(measurement.getValue()).serialize(); + double value = measurement.getValue(); + if (Double.isNaN(value)) { + // NaNs can be caused by garbage collecting the backing field for a weak + // reference or by setting the value of the backing field to NaN. At this + // point it is impossible to distinguish these cases. This information is + // logged once at WARN then on DEBUG level, as otherwise the serialization + // would throw an exception and get logged at WARNING level. This can lead + // to a lot of warning logs for the remainder of the application execution + // if an object holding the weakly referenced objects has been garbage + // collected, but the meter has not been removed from the registry. + // NaN's are currently dropped on the Dynatrace side, so dropping them + // on the client side here will not change the metrics in Dynatrace. + + nanGaugeWarnThenDebugLogger.log(() -> String.format( + "Meter '%s' returned a value of NaN, which will not be exported. This can be a deliberate value or because the weak reference to the backing object expired.", + meter.getId().getName())); + return null; + } + return createMetricBuilder(meter).setDoubleGaugeValue(value).serialize(); } catch (MetricException e) { logger.warn(METER_EXCEPTION_LOG_FORMAT, meter.getId().getName(), e.getMessage()); @@ -317,7 +335,8 @@ private void send(List metricLines) { } catch (Throwable throwable) { logger.warn("Failed metric ingestion: " + throwable); - warnThenDebugLogger.log("Stack trace for previous 'Failed metric ingestion' warning log: ", throwable); + stackTraceWarnThenDebugLogger.log("Stack trace for previous 'Failed metric ingestion' warning log: ", + throwable); } }