Skip to content

Commit

Permalink
Merge branch '1.13.x'
Browse files Browse the repository at this point in the history
  • Loading branch information
jonatan-ivanov committed Jun 20, 2024
2 parents a5d62cc + 1d45f62 commit c1dfbbc
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -35,17 +34,13 @@
*/
class DynatraceLongTaskTimerTest {

private static final Offset<Double> OFFSET = Offset.offset(0.0001);

private static final Meter.Id ID = new Meter.Id("test.id", Tags.empty(), "1", "desc",
Meter.Type.DISTRIBUTION_SUMMARY);

private static final DistributionStatisticConfig DISTRIBUTION_STATISTIC_CONFIG = DistributionStatisticConfig.NONE;

private static final MockClock CLOCK = new MockClock();

private static final Offset<Double> TOLERANCE = Offset.offset(0.000001);

@Test
void singleTaskValuesAreRecorded() throws InterruptedException {
DynatraceLongTaskTimer ltt = new DynatraceLongTaskTimer(ID, CLOCK, TimeUnit.MILLISECONDS,
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ private Metric.Builder createMetricBuilder(MetricMetaData metricMetaData) {
}

private Iterable<KeyValue> getKeyValuesForId(Meter.Id id) {
return id.getTags()
return id.getConventionTags(namingConvention)
.stream()
.map(tag -> createKeyValue(tag.getKey(), tag.getValue()))
.collect(Collectors.toList());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,20 @@
*/
package io.micrometer.registry.otlp;

import static org.assertj.core.api.Assertions.assertThat;

import java.time.Duration;
import java.util.List;
import java.util.concurrent.TimeUnit;

import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import io.micrometer.core.instrument.Gauge;
import io.micrometer.core.instrument.MockClock;
import io.micrometer.core.instrument.Tags;
import io.micrometer.core.instrument.Timer;
import io.micrometer.core.instrument.config.NamingConvention;
import io.opentelemetry.proto.metrics.v1.Metric;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

import java.time.Duration;
import java.util.List;
import java.util.concurrent.TimeUnit;

import static org.assertj.core.api.Assertions.assertThat;

class OtlpMetricConverterTest {

Expand Down Expand Up @@ -157,4 +157,23 @@ void timerWithSummaryAndHistogramShouldBeMultipleMetrics() {
}));
}

@Test
void applyCustomNamingConvention() {
Gauge gauge = Gauge.builder("test.meter", () -> 1)
.tags("test.tag", "1")
.description("description")
.register(otlpMeterRegistry);

OtlpMetricConverter otlpMetricConverter = new OtlpMetricConverter(mockClock, Duration.ofMillis(1),
TimeUnit.MILLISECONDS, AggregationTemporality.CUMULATIVE, NamingConvention.snakeCase);
otlpMetricConverter.addMeter(gauge);

assertThat(otlpMetricConverter.getAllMetrics()).singleElement().satisfies(metric -> {
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")));
});
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit c1dfbbc

Please sign in to comment.