From 1ff3b2e901eedd3eb0dae7eb06d87c95909c7a3e Mon Sep 17 00:00:00 2001 From: Mateusz Rzeszutek Date: Mon, 10 Jan 2022 11:33:18 +0100 Subject: [PATCH] code review suggestions --- .../micrometer/v1_5/OpenTelemetryCounter.java | 2 +- .../v1_5/OpenTelemetryFunctionCounter.java | 2 +- .../v1_5/OpenTelemetryFunctionTimer.java | 31 +++++++------------ 3 files changed, 14 insertions(+), 21 deletions(-) diff --git a/instrumentation/micrometer/micrometer-1.5/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/micrometer/v1_5/OpenTelemetryCounter.java b/instrumentation/micrometer/micrometer-1.5/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/micrometer/v1_5/OpenTelemetryCounter.java index 88d3103e2607..18299258fda2 100644 --- a/instrumentation/micrometer/micrometer-1.5/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/micrometer/v1_5/OpenTelemetryCounter.java +++ b/instrumentation/micrometer/micrometer-1.5/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/micrometer/v1_5/OpenTelemetryCounter.java @@ -50,7 +50,7 @@ public void increment(double v) { @Override public double count() { UnsupportedReadLogger.logWarning(); - return 0; + return Double.NaN; } @Override diff --git a/instrumentation/micrometer/micrometer-1.5/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/micrometer/v1_5/OpenTelemetryFunctionCounter.java b/instrumentation/micrometer/micrometer-1.5/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/micrometer/v1_5/OpenTelemetryFunctionCounter.java index ba58dcca81fb..55965c424fd6 100644 --- a/instrumentation/micrometer/micrometer-1.5/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/micrometer/v1_5/OpenTelemetryFunctionCounter.java +++ b/instrumentation/micrometer/micrometer-1.5/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/micrometer/v1_5/OpenTelemetryFunctionCounter.java @@ -36,7 +36,7 @@ final class OpenTelemetryFunctionCounter implements FunctionCounter, Removabl @Override public double count() { UnsupportedReadLogger.logWarning(); - return 0; + return Double.NaN; } @Override diff --git a/instrumentation/micrometer/micrometer-1.5/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/micrometer/v1_5/OpenTelemetryFunctionTimer.java b/instrumentation/micrometer/micrometer-1.5/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/micrometer/v1_5/OpenTelemetryFunctionTimer.java index 077ad37cd8a7..a157f057a95e 100644 --- a/instrumentation/micrometer/micrometer-1.5/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/micrometer/v1_5/OpenTelemetryFunctionTimer.java +++ b/instrumentation/micrometer/micrometer-1.5/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/micrometer/v1_5/OpenTelemetryFunctionTimer.java @@ -51,13 +51,17 @@ final class OpenTelemetryFunctionTimer implements FunctionTimer, RemovableMet /* baseUnit = */ "ms", attributes, obj, - new ConvertToMillisDecorator<>(totalTimeFunction, totalTimeFunctionUnit)); + val -> + TimeUtils.convert( + totalTimeFunction.applyAsDouble(val), + totalTimeFunctionUnit, + TimeUnit.MILLISECONDS)); } @Override public double count() { UnsupportedReadLogger.logWarning(); - return 0; + return Double.NaN; } @Override @@ -66,6 +70,12 @@ public double totalTime(TimeUnit unit) { return Double.NaN; } + @Override + public double mean(TimeUnit unit) { + UnsupportedReadLogger.logWarning(); + return Double.NaN; + } + @Override public TimeUnit baseTimeUnit() { return TimeUnit.MILLISECONDS; @@ -98,21 +108,4 @@ public boolean equals(Object o) { public int hashCode() { return MeterEquivalence.hashCode(this); } - - private static final class ConvertToMillisDecorator implements ToDoubleFunction { - - private final ToDoubleFunction original; - private final TimeUnit originalUnit; - - private ConvertToMillisDecorator(ToDoubleFunction original, TimeUnit originalUnit) { - this.original = original; - this.originalUnit = originalUnit; - } - - @Override - public double applyAsDouble(T value) { - double time = original.applyAsDouble(value); - return TimeUtils.convert(time, originalUnit, TimeUnit.MILLISECONDS); - } - } }