From 6dbaa9dc7d6050024965805065488e770c53e358 Mon Sep 17 00:00:00 2001 From: Tadaya Tsuyukubo Date: Thu, 13 Jun 2024 01:13:42 -0700 Subject: [PATCH 1/3] Fix wrong reference in the deprecation javadoc (#5197) Signed-off-by: Tadaya Tsuyukubo --- .../src/main/java/io/micrometer/core/lang/NonNullFields.java | 2 +- .../src/main/java/io/micrometer/core/lang/Nullable.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/micrometer-core/src/main/java/io/micrometer/core/lang/NonNullFields.java b/micrometer-core/src/main/java/io/micrometer/core/lang/NonNullFields.java index bdb5a92680..4d472361c2 100644 --- a/micrometer-core/src/main/java/io/micrometer/core/lang/NonNullFields.java +++ b/micrometer-core/src/main/java/io/micrometer/core/lang/NonNullFields.java @@ -36,7 +36,7 @@ * @see io.micrometer.common.lang.NonNullFields * @see io.micrometer.common.lang.Nullable * @see io.micrometer.common.lang.NonNull - * @deprecated Please use {@link io.micrometer.common.lang.NonNullApi} instead. + * @deprecated Please use {@link io.micrometer.common.lang.NonNullFields} instead. */ @Target({ ElementType.PACKAGE, ElementType.TYPE }) @Retention(RetentionPolicy.RUNTIME) diff --git a/micrometer-core/src/main/java/io/micrometer/core/lang/Nullable.java b/micrometer-core/src/main/java/io/micrometer/core/lang/Nullable.java index eabe46f113..6fd0eafd5a 100644 --- a/micrometer-core/src/main/java/io/micrometer/core/lang/Nullable.java +++ b/micrometer-core/src/main/java/io/micrometer/core/lang/Nullable.java @@ -39,7 +39,7 @@ * @see io.micrometer.common.lang.NonNullApi * @see io.micrometer.common.lang.NonNullFields * @see io.micrometer.common.lang.NonNull - * @deprecated Please use {@link io.micrometer.common.lang.NonNullApi} instead. + * @deprecated Please use {@link io.micrometer.common.lang.Nullable} instead. */ @Target({ ElementType.METHOD, ElementType.PARAMETER, ElementType.FIELD }) @Retention(RetentionPolicy.RUNTIME) From f2fba9cf508bef456bd8bc0f9cb7ab4ddbf74a26 Mon Sep 17 00:00:00 2001 From: Johnny Lim Date: Fri, 21 Jun 2024 07:28:31 +0900 Subject: [PATCH 2/3] Polish gh-4780 (#5107) --- .../types/DynatraceLongTaskTimer.java | 2 +- .../types/DynatraceSummarySnapshot.java | 4 ++++ .../types/DynatraceLongTaskTimerTest.java | 22 ++++++------------- 3 files changed, 12 insertions(+), 16 deletions(-) diff --git a/implementations/micrometer-registry-dynatrace/src/main/java/io/micrometer/dynatrace/types/DynatraceLongTaskTimer.java b/implementations/micrometer-registry-dynatrace/src/main/java/io/micrometer/dynatrace/types/DynatraceLongTaskTimer.java index 758662fc9a..ed89209e56 100644 --- a/implementations/micrometer-registry-dynatrace/src/main/java/io/micrometer/dynatrace/types/DynatraceLongTaskTimer.java +++ b/implementations/micrometer-registry-dynatrace/src/main/java/io/micrometer/dynatrace/types/DynatraceLongTaskTimer.java @@ -59,7 +59,7 @@ public DynatraceSummarySnapshot takeSummarySnapshot(TimeUnit unit) { // sample.duration(...) will return -1 if the task is already finished // (only currently active tasks are measured). // -1 will be ignored in recordNonNegative. - super.forEachActive(sample -> summary.recordNonNegative(sample.duration(unit))); + forEachActive(sample -> summary.recordNonNegative(sample.duration(unit))); return summary.takeSummarySnapshot(); } diff --git a/implementations/micrometer-registry-dynatrace/src/main/java/io/micrometer/dynatrace/types/DynatraceSummarySnapshot.java b/implementations/micrometer-registry-dynatrace/src/main/java/io/micrometer/dynatrace/types/DynatraceSummarySnapshot.java index d5e6da44ac..a2f5b200a3 100644 --- a/implementations/micrometer-registry-dynatrace/src/main/java/io/micrometer/dynatrace/types/DynatraceSummarySnapshot.java +++ b/implementations/micrometer-registry-dynatrace/src/main/java/io/micrometer/dynatrace/types/DynatraceSummarySnapshot.java @@ -26,6 +26,10 @@ @Immutable public final class DynatraceSummarySnapshot { + /** + * For empty value. + * @since 1.9.18 + */ public static final DynatraceSummarySnapshot EMPTY = new DynatraceSummarySnapshot(0, 0, 0, 0); private final double min; diff --git a/implementations/micrometer-registry-dynatrace/src/test/java/io/micrometer/dynatrace/types/DynatraceLongTaskTimerTest.java b/implementations/micrometer-registry-dynatrace/src/test/java/io/micrometer/dynatrace/types/DynatraceLongTaskTimerTest.java index e2c3c39acb..383d39ca25 100644 --- a/implementations/micrometer-registry-dynatrace/src/test/java/io/micrometer/dynatrace/types/DynatraceLongTaskTimerTest.java +++ b/implementations/micrometer-registry-dynatrace/src/test/java/io/micrometer/dynatrace/types/DynatraceLongTaskTimerTest.java @@ -19,7 +19,6 @@ import io.micrometer.core.instrument.MockClock; import io.micrometer.core.instrument.Tags; import io.micrometer.core.instrument.distribution.DistributionStatisticConfig; -import org.assertj.core.data.Offset; import org.junit.jupiter.api.Test; import java.time.Duration; @@ -35,8 +34,6 @@ */ class DynatraceLongTaskTimerTest { - private static final Offset OFFSET = Offset.offset(0.0001); - private static final Meter.Id ID = new Meter.Id("test.id", Tags.empty(), "1", "desc", Meter.Type.DISTRIBUTION_SUMMARY); @@ -44,8 +41,6 @@ class DynatraceLongTaskTimerTest { private static final MockClock CLOCK = new MockClock(); - private static final Offset TOLERANCE = Offset.offset(0.000001); - @Test void singleTaskValuesAreRecorded() throws InterruptedException { DynatraceLongTaskTimer ltt = new DynatraceLongTaskTimer(ID, CLOCK, TimeUnit.MILLISECONDS, @@ -74,13 +69,11 @@ void singleTaskValuesAreRecorded() throws InterruptedException { // can release the background task stopLatch.countDown(); - assertThat(snapshot.getMin()).isCloseTo(100, TOLERANCE); - assertThat(snapshot.getMax()).isCloseTo(100, TOLERANCE); + assertThat(snapshot.getMin()).isEqualTo(100); + assertThat(snapshot.getMax()).isEqualTo(100); assertThat(snapshot.getCount()).isEqualTo(1); // in the case of count == 1, the total has to be equal to min and max - assertThat(snapshot.getTotal()).isGreaterThan(0) - .isCloseTo(snapshot.getMin(), TOLERANCE) - .isCloseTo(snapshot.getMax(), TOLERANCE); + assertThat(snapshot.getTotal()).isEqualTo(snapshot.getMin()).isEqualTo(snapshot.getMax()); } @Test @@ -152,20 +145,19 @@ void parallelTasksValuesAreRecorded() throws InterruptedException { // Task 1 has been "running" for 70ms at the time of recording and will // supply the max - assertThat(snapshot.getMax()).isCloseTo(70, OFFSET); + assertThat(snapshot.getMax()).isEqualTo(70); // Task 2 has been "running" for only 30ms at the time of recording and // will supply the min - assertThat(snapshot.getMin()).isCloseTo(30, OFFSET); + assertThat(snapshot.getMin()).isEqualTo(30); // Both tasks have been running in parallel. // After the second CLOCK.add(Duration) is called, the first task has been running // for 70ms, and the second task has been running for 30ms // together, they have been running for 100ms in total. - assertThat(snapshot.getTotal()).isCloseTo(100, OFFSET); + assertThat(snapshot.getTotal()).isEqualTo(100); // Two tasks were running in parallel. assertThat(snapshot.getCount()).isEqualTo(2); // On the clock, 70ms have passed. MockClock starts at 1, that's why the result - // here - // is 71 instead of 70. + // here is 71 instead of 70. assertThat(CLOCK.wallTime()).isEqualTo(71); } From 93e1117e880a922f3d07e477f916c6d793a30bd4 Mon Sep 17 00:00:00 2001 From: Johnny Lim Date: Fri, 21 Jun 2024 07:34:45 +0900 Subject: [PATCH 3/3] Apply NamingConvention to tags for OtlpMeterRegistry (#5114) See https://github.com/micrometer-metrics/micrometer/issues/4053#issuecomment-1702959975 --- .../registry/otlp/OtlpMeterRegistry.java | 2 +- .../registry/otlp/OtlpMeterRegistryTest.java | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/implementations/micrometer-registry-otlp/src/main/java/io/micrometer/registry/otlp/OtlpMeterRegistry.java b/implementations/micrometer-registry-otlp/src/main/java/io/micrometer/registry/otlp/OtlpMeterRegistry.java index 1fb0e2bc8a..66bfd7c3f2 100644 --- a/implementations/micrometer-registry-otlp/src/main/java/io/micrometer/registry/otlp/OtlpMeterRegistry.java +++ b/implementations/micrometer-registry-otlp/src/main/java/io/micrometer/registry/otlp/OtlpMeterRegistry.java @@ -298,7 +298,7 @@ private Metric.Builder getMetricBuilder(Meter.Id id) { } private Iterable getTagsForId(Meter.Id id) { - return id.getTags() + return id.getConventionTags(config().namingConvention()) .stream() .map(tag -> createKeyValue(tag.getKey(), tag.getValue())) .collect(Collectors.toList()); diff --git a/implementations/micrometer-registry-otlp/src/test/java/io/micrometer/registry/otlp/OtlpMeterRegistryTest.java b/implementations/micrometer-registry-otlp/src/test/java/io/micrometer/registry/otlp/OtlpMeterRegistryTest.java index 15196abff1..27c7bde880 100644 --- a/implementations/micrometer-registry-otlp/src/test/java/io/micrometer/registry/otlp/OtlpMeterRegistryTest.java +++ b/implementations/micrometer-registry-otlp/src/test/java/io/micrometer/registry/otlp/OtlpMeterRegistryTest.java @@ -16,6 +16,8 @@ package io.micrometer.registry.otlp; import io.micrometer.core.instrument.*; +import io.micrometer.core.instrument.config.NamingConvention; +import io.opentelemetry.proto.metrics.v1.Metric; import org.junit.jupiter.api.Test; import java.io.IOException; @@ -553,4 +555,21 @@ void setResourceAttributesFromEnvironmentVariables() throws Exception { }); } + @Test + void applyCustomNamingConvention() { + registry.config().namingConvention(NamingConvention.snakeCase); + + Gauge gauge = Gauge.builder("test.meter", () -> 1) + .tags("test.tag", "1") + .description("description") + .register(registry); + + Metric metric = registry.writeGauge(gauge); + + assertThat(metric.getName()).isEqualTo("test_meter"); + assertThat(metric.getGauge().getDataPointsList()).singleElement() + .satisfies(dataPoint -> assertThat(dataPoint.getAttributesList()).singleElement() + .satisfies(attribute -> assertThat(attribute.getKey()).isEqualTo("test_tag"))); + } + }