Use seconds by default in the Micrometer bridge (#8490)
Co-authored-by: Lauri Tulmin <tulmin@gmail.com>
This commit is contained in:
parent
3dd8ad7669
commit
0b774af1ee
|
@ -2,6 +2,6 @@
|
||||||
|
|
||||||
| System property | Type | Default | Description |
|
| System property | Type | Default | Description |
|
||||||
|------------------------------------------------------------|---------|---------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|
|------------------------------------------------------------|---------|---------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|
||||||
| `otel.instrumentation.micrometer.base-time-unit` | String | `ms` | Set the base time unit for the OpenTelemetry `MeterRegistry` implementation. <details><summary>Valid values</summary>`ns`, `nanoseconds`, `us`, `microseconds`, `ms`, `microseconds`, `s`, `seconds`, `min`, `minutes`, `h`, `hours`, `d`, `days`</details> |
|
| `otel.instrumentation.micrometer.base-time-unit` | String | `s` | Set the base time unit for the OpenTelemetry `MeterRegistry` implementation. <details><summary>Valid values</summary>`ns`, `nanoseconds`, `us`, `microseconds`, `ms`, `milliseconds`, `s`, `seconds`, `min`, `minutes`, `h`, `hours`, `d`, `days`</details> |
|
||||||
| `otel.instrumentation.micrometer.prometheus-mode.enabled` | boolean | false | Enable the "Prometheus mode" this will simulate the behavior of Micrometer's PrometheusMeterRegistry. The instruments will be renamed to match Micrometer instrument naming, and the base time unit will be set to seconds. |
|
| `otel.instrumentation.micrometer.prometheus-mode.enabled` | boolean | false | Enable the "Prometheus mode" this will simulate the behavior of Micrometer's PrometheusMeterRegistry. The instruments will be renamed to match Micrometer instrument naming, and the base time unit will be set to seconds. |
|
||||||
| `otel.instrumentation.micrometer.histogram-gauges.enabled` | boolean | false | Enables the generation of gauge-based Micrometer histograms for `DistributionSummary` and `Timer` instruments. |
|
| `otel.instrumentation.micrometer.histogram-gauges.enabled` | boolean | false | Enables the generation of gauge-based Micrometer histograms for `DistributionSummary` and `Timer` instruments. |
|
||||||
|
|
|
@ -30,10 +30,10 @@ tasks {
|
||||||
|
|
||||||
val testBaseTimeUnit by registering(Test::class) {
|
val testBaseTimeUnit by registering(Test::class) {
|
||||||
filter {
|
filter {
|
||||||
includeTestsMatching("*TimerSecondsTest")
|
includeTestsMatching("*TimerMillisecondsTest")
|
||||||
}
|
}
|
||||||
include("**/*TimerSecondsTest.*")
|
include("**/*TimerMillisecondsTest.*")
|
||||||
jvmArgs("-Dotel.instrumentation.micrometer.base-time-unit=seconds")
|
jvmArgs("-Dotel.instrumentation.micrometer.base-time-unit=milliseconds")
|
||||||
}
|
}
|
||||||
|
|
||||||
val testHistogramGauges by registering(Test::class) {
|
val testHistogramGauges by registering(Test::class) {
|
||||||
|
@ -46,7 +46,7 @@ tasks {
|
||||||
|
|
||||||
test {
|
test {
|
||||||
filter {
|
filter {
|
||||||
excludeTestsMatching("*TimerSecondsTest")
|
excludeTestsMatching("*TimerMillisecondsTest")
|
||||||
excludeTestsMatching("*PrometheusModeTest")
|
excludeTestsMatching("*PrometheusModeTest")
|
||||||
excludeTestsMatching("*HistogramGaugesTest")
|
excludeTestsMatching("*HistogramGaugesTest")
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,7 +19,7 @@ final class TimeUnitParser {
|
||||||
|
|
||||||
static TimeUnit parseConfigValue(@Nullable String value) {
|
static TimeUnit parseConfigValue(@Nullable String value) {
|
||||||
if (value == null) {
|
if (value == null) {
|
||||||
return TimeUnit.MILLISECONDS;
|
return TimeUnit.SECONDS;
|
||||||
}
|
}
|
||||||
// short names are UCUM names
|
// short names are UCUM names
|
||||||
// long names are just TimeUnit values lowercased
|
// long names are just TimeUnit values lowercased
|
||||||
|
@ -49,10 +49,10 @@ final class TimeUnitParser {
|
||||||
if (logger.isLoggable(WARNING)) {
|
if (logger.isLoggable(WARNING)) {
|
||||||
logger.log(
|
logger.log(
|
||||||
WARNING,
|
WARNING,
|
||||||
"Invalid base time unit: \"{0}\"; using 'ms' as the base time unit instead",
|
"Invalid base time unit: \"{0}\"; using \"s\" as the base time unit instead",
|
||||||
value);
|
value);
|
||||||
}
|
}
|
||||||
return TimeUnit.MILLISECONDS;
|
return TimeUnit.SECONDS;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -6,13 +6,13 @@
|
||||||
package io.opentelemetry.javaagent.instrumentation.micrometer.v1_5;
|
package io.opentelemetry.javaagent.instrumentation.micrometer.v1_5;
|
||||||
|
|
||||||
import io.micrometer.core.instrument.Metrics;
|
import io.micrometer.core.instrument.Metrics;
|
||||||
import io.opentelemetry.instrumentation.micrometer.v1_5.AbstractFunctionTimerSecondsTest;
|
import io.opentelemetry.instrumentation.micrometer.v1_5.AbstractFunctionTimerMillisecondsTest;
|
||||||
import io.opentelemetry.instrumentation.testing.junit.AgentInstrumentationExtension;
|
import io.opentelemetry.instrumentation.testing.junit.AgentInstrumentationExtension;
|
||||||
import io.opentelemetry.instrumentation.testing.junit.InstrumentationExtension;
|
import io.opentelemetry.instrumentation.testing.junit.InstrumentationExtension;
|
||||||
import org.junit.jupiter.api.AfterEach;
|
import org.junit.jupiter.api.AfterEach;
|
||||||
import org.junit.jupiter.api.extension.RegisterExtension;
|
import org.junit.jupiter.api.extension.RegisterExtension;
|
||||||
|
|
||||||
class FunctionTimerSecondsTest extends AbstractFunctionTimerSecondsTest {
|
class FunctionTimerMillisecondsTest extends AbstractFunctionTimerMillisecondsTest {
|
||||||
|
|
||||||
@RegisterExtension
|
@RegisterExtension
|
||||||
static final InstrumentationExtension testing = AgentInstrumentationExtension.create();
|
static final InstrumentationExtension testing = AgentInstrumentationExtension.create();
|
|
@ -6,13 +6,13 @@
|
||||||
package io.opentelemetry.javaagent.instrumentation.micrometer.v1_5;
|
package io.opentelemetry.javaagent.instrumentation.micrometer.v1_5;
|
||||||
|
|
||||||
import io.micrometer.core.instrument.Metrics;
|
import io.micrometer.core.instrument.Metrics;
|
||||||
import io.opentelemetry.instrumentation.micrometer.v1_5.AbstractLongTaskTimerSecondsTest;
|
import io.opentelemetry.instrumentation.micrometer.v1_5.AbstractLongTaskTimerMillisecondsTest;
|
||||||
import io.opentelemetry.instrumentation.testing.junit.AgentInstrumentationExtension;
|
import io.opentelemetry.instrumentation.testing.junit.AgentInstrumentationExtension;
|
||||||
import io.opentelemetry.instrumentation.testing.junit.InstrumentationExtension;
|
import io.opentelemetry.instrumentation.testing.junit.InstrumentationExtension;
|
||||||
import org.junit.jupiter.api.AfterEach;
|
import org.junit.jupiter.api.AfterEach;
|
||||||
import org.junit.jupiter.api.extension.RegisterExtension;
|
import org.junit.jupiter.api.extension.RegisterExtension;
|
||||||
|
|
||||||
class LongTaskTimerSecondsTest extends AbstractLongTaskTimerSecondsTest {
|
class LongTaskTimerMillisecondsTest extends AbstractLongTaskTimerMillisecondsTest {
|
||||||
|
|
||||||
@RegisterExtension
|
@RegisterExtension
|
||||||
static final InstrumentationExtension testing = AgentInstrumentationExtension.create();
|
static final InstrumentationExtension testing = AgentInstrumentationExtension.create();
|
|
@ -6,13 +6,13 @@
|
||||||
package io.opentelemetry.javaagent.instrumentation.micrometer.v1_5;
|
package io.opentelemetry.javaagent.instrumentation.micrometer.v1_5;
|
||||||
|
|
||||||
import io.micrometer.core.instrument.Metrics;
|
import io.micrometer.core.instrument.Metrics;
|
||||||
import io.opentelemetry.instrumentation.micrometer.v1_5.AbstractTimerSecondsTest;
|
import io.opentelemetry.instrumentation.micrometer.v1_5.AbstractTimerMillisecondsTest;
|
||||||
import io.opentelemetry.instrumentation.testing.junit.AgentInstrumentationExtension;
|
import io.opentelemetry.instrumentation.testing.junit.AgentInstrumentationExtension;
|
||||||
import io.opentelemetry.instrumentation.testing.junit.InstrumentationExtension;
|
import io.opentelemetry.instrumentation.testing.junit.InstrumentationExtension;
|
||||||
import org.junit.jupiter.api.AfterEach;
|
import org.junit.jupiter.api.AfterEach;
|
||||||
import org.junit.jupiter.api.extension.RegisterExtension;
|
import org.junit.jupiter.api.extension.RegisterExtension;
|
||||||
|
|
||||||
class TimerSecondsTest extends AbstractTimerSecondsTest {
|
class TimerMillisecondsTest extends AbstractTimerMillisecondsTest {
|
||||||
|
|
||||||
@RegisterExtension
|
@RegisterExtension
|
||||||
static final InstrumentationExtension testing = AgentInstrumentationExtension.create();
|
static final InstrumentationExtension testing = AgentInstrumentationExtension.create();
|
|
@ -23,7 +23,7 @@ public final class OpenTelemetryMeterRegistryBuilder {
|
||||||
|
|
||||||
private final OpenTelemetry openTelemetry;
|
private final OpenTelemetry openTelemetry;
|
||||||
private Clock clock = Clock.SYSTEM;
|
private Clock clock = Clock.SYSTEM;
|
||||||
private TimeUnit baseTimeUnit = TimeUnit.MILLISECONDS;
|
private TimeUnit baseTimeUnit = TimeUnit.SECONDS;
|
||||||
private boolean prometheusMode = false;
|
private boolean prometheusMode = false;
|
||||||
private boolean histogramGaugesEnabled = false;
|
private boolean histogramGaugesEnabled = false;
|
||||||
|
|
||||||
|
|
|
@ -10,7 +10,7 @@ import io.opentelemetry.instrumentation.testing.junit.LibraryInstrumentationExte
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
import org.junit.jupiter.api.extension.RegisterExtension;
|
import org.junit.jupiter.api.extension.RegisterExtension;
|
||||||
|
|
||||||
class LongTaskTimerSecondsTest extends AbstractLongTaskTimerSecondsTest {
|
class FunctionTimerMillisecondsTest extends AbstractFunctionTimerMillisecondsTest {
|
||||||
|
|
||||||
@RegisterExtension
|
@RegisterExtension
|
||||||
static final InstrumentationExtension testing = LibraryInstrumentationExtension.create();
|
static final InstrumentationExtension testing = LibraryInstrumentationExtension.create();
|
||||||
|
@ -21,7 +21,7 @@ class LongTaskTimerSecondsTest extends AbstractLongTaskTimerSecondsTest {
|
||||||
@Override
|
@Override
|
||||||
OpenTelemetryMeterRegistryBuilder configureOtelRegistry(
|
OpenTelemetryMeterRegistryBuilder configureOtelRegistry(
|
||||||
OpenTelemetryMeterRegistryBuilder registry) {
|
OpenTelemetryMeterRegistryBuilder registry) {
|
||||||
return registry.setBaseTimeUnit(TimeUnit.SECONDS);
|
return registry.setBaseTimeUnit(TimeUnit.MILLISECONDS);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
@ -10,7 +10,7 @@ import io.opentelemetry.instrumentation.testing.junit.LibraryInstrumentationExte
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
import org.junit.jupiter.api.extension.RegisterExtension;
|
import org.junit.jupiter.api.extension.RegisterExtension;
|
||||||
|
|
||||||
class FunctionTimerSecondsTest extends AbstractFunctionTimerSecondsTest {
|
class LongTaskTimerMillisecondsTest extends AbstractLongTaskTimerMillisecondsTest {
|
||||||
|
|
||||||
@RegisterExtension
|
@RegisterExtension
|
||||||
static final InstrumentationExtension testing = LibraryInstrumentationExtension.create();
|
static final InstrumentationExtension testing = LibraryInstrumentationExtension.create();
|
||||||
|
@ -21,7 +21,7 @@ class FunctionTimerSecondsTest extends AbstractFunctionTimerSecondsTest {
|
||||||
@Override
|
@Override
|
||||||
OpenTelemetryMeterRegistryBuilder configureOtelRegistry(
|
OpenTelemetryMeterRegistryBuilder configureOtelRegistry(
|
||||||
OpenTelemetryMeterRegistryBuilder registry) {
|
OpenTelemetryMeterRegistryBuilder registry) {
|
||||||
return registry.setBaseTimeUnit(TimeUnit.SECONDS);
|
return registry.setBaseTimeUnit(TimeUnit.MILLISECONDS);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
@ -10,7 +10,7 @@ import io.opentelemetry.instrumentation.testing.junit.LibraryInstrumentationExte
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
import org.junit.jupiter.api.extension.RegisterExtension;
|
import org.junit.jupiter.api.extension.RegisterExtension;
|
||||||
|
|
||||||
class TimerSecondsTest extends AbstractTimerSecondsTest {
|
class TimerMillisecondsTest extends AbstractTimerMillisecondsTest {
|
||||||
|
|
||||||
@RegisterExtension
|
@RegisterExtension
|
||||||
static final InstrumentationExtension testing = LibraryInstrumentationExtension.create();
|
static final InstrumentationExtension testing = LibraryInstrumentationExtension.create();
|
||||||
|
@ -21,7 +21,7 @@ class TimerSecondsTest extends AbstractTimerSecondsTest {
|
||||||
@Override
|
@Override
|
||||||
OpenTelemetryMeterRegistryBuilder configureOtelRegistry(
|
OpenTelemetryMeterRegistryBuilder configureOtelRegistry(
|
||||||
OpenTelemetryMeterRegistryBuilder registry) {
|
OpenTelemetryMeterRegistryBuilder registry) {
|
||||||
return registry.setBaseTimeUnit(TimeUnit.SECONDS);
|
return registry.setBaseTimeUnit(TimeUnit.MILLISECONDS);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
@ -17,7 +17,7 @@ import org.assertj.core.api.AbstractIterableAssert;
|
||||||
import org.junit.jupiter.api.BeforeEach;
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
public abstract class AbstractFunctionTimerSecondsTest {
|
public abstract class AbstractFunctionTimerMillisecondsTest {
|
||||||
|
|
||||||
protected abstract InstrumentationExtension testing();
|
protected abstract InstrumentationExtension testing();
|
||||||
|
|
||||||
|
@ -30,11 +30,11 @@ public abstract class AbstractFunctionTimerSecondsTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void testFunctionTimerWithBaseUnitSeconds() {
|
void testFunctionTimerWithBaseUnitMilliseconds() {
|
||||||
// given
|
// given
|
||||||
FunctionTimer functionTimer =
|
FunctionTimer functionTimer =
|
||||||
FunctionTimer.builder(
|
FunctionTimer.builder(
|
||||||
"testFunctionTimerSeconds",
|
"testFunctionTimerMilliseconds",
|
||||||
timerObj,
|
timerObj,
|
||||||
TestTimer::getCount,
|
TestTimer::getCount,
|
||||||
TestTimer::getTotalTimeNanos,
|
TestTimer::getTotalTimeNanos,
|
||||||
|
@ -50,7 +50,7 @@ public abstract class AbstractFunctionTimerSecondsTest {
|
||||||
testing()
|
testing()
|
||||||
.waitAndAssertMetrics(
|
.waitAndAssertMetrics(
|
||||||
INSTRUMENTATION_NAME,
|
INSTRUMENTATION_NAME,
|
||||||
"testFunctionTimerSeconds.count",
|
"testFunctionTimerMilliseconds.count",
|
||||||
metrics ->
|
metrics ->
|
||||||
metrics.anySatisfy(
|
metrics.anySatisfy(
|
||||||
metric ->
|
metric ->
|
||||||
|
@ -69,19 +69,19 @@ public abstract class AbstractFunctionTimerSecondsTest {
|
||||||
testing()
|
testing()
|
||||||
.waitAndAssertMetrics(
|
.waitAndAssertMetrics(
|
||||||
INSTRUMENTATION_NAME,
|
INSTRUMENTATION_NAME,
|
||||||
"testFunctionTimerSeconds.sum",
|
"testFunctionTimerMilliseconds.sum",
|
||||||
metrics ->
|
metrics ->
|
||||||
metrics.anySatisfy(
|
metrics.anySatisfy(
|
||||||
metric ->
|
metric ->
|
||||||
assertThat(metric)
|
assertThat(metric)
|
||||||
.hasDescription("This is a test function timer")
|
.hasDescription("This is a test function timer")
|
||||||
.hasUnit("s")
|
.hasUnit("ms")
|
||||||
.hasDoubleSumSatisfying(
|
.hasDoubleSumSatisfying(
|
||||||
sum ->
|
sum ->
|
||||||
sum.hasPointsSatisfying(
|
sum.hasPointsSatisfying(
|
||||||
point ->
|
point ->
|
||||||
point
|
point
|
||||||
.hasValue(42)
|
.hasValue(42_000)
|
||||||
.hasAttributes(attributeEntry("tag", "value"))))));
|
.hasAttributes(attributeEntry("tag", "value"))))));
|
||||||
|
|
||||||
// when
|
// when
|
||||||
|
@ -92,7 +92,7 @@ public abstract class AbstractFunctionTimerSecondsTest {
|
||||||
testing()
|
testing()
|
||||||
.waitAndAssertMetrics(
|
.waitAndAssertMetrics(
|
||||||
INSTRUMENTATION_NAME,
|
INSTRUMENTATION_NAME,
|
||||||
"testFunctionTimerSeconds.count",
|
"testFunctionTimerMilliseconds.count",
|
||||||
AbstractIterableAssert::isEmpty);
|
AbstractIterableAssert::isEmpty);
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -78,13 +78,13 @@ public abstract class AbstractFunctionTimerTest {
|
||||||
metric ->
|
metric ->
|
||||||
assertThat(metric)
|
assertThat(metric)
|
||||||
.hasDescription("This is a test function timer")
|
.hasDescription("This is a test function timer")
|
||||||
.hasUnit("ms")
|
.hasUnit("s")
|
||||||
.hasDoubleSumSatisfying(
|
.hasDoubleSumSatisfying(
|
||||||
sum ->
|
sum ->
|
||||||
sum.hasPointsSatisfying(
|
sum.hasPointsSatisfying(
|
||||||
point ->
|
point ->
|
||||||
point
|
point
|
||||||
.hasValue(42_000)
|
.hasValue(42)
|
||||||
.hasAttributes(attributeEntry("tag", "value"))))));
|
.hasAttributes(attributeEntry("tag", "value"))))));
|
||||||
|
|
||||||
// when
|
// when
|
||||||
|
@ -120,13 +120,13 @@ public abstract class AbstractFunctionTimerTest {
|
||||||
metrics.anySatisfy(
|
metrics.anySatisfy(
|
||||||
metric ->
|
metric ->
|
||||||
assertThat(metric)
|
assertThat(metric)
|
||||||
.hasUnit("ms")
|
.hasUnit("s")
|
||||||
.hasDoubleSumSatisfying(
|
.hasDoubleSumSatisfying(
|
||||||
sum ->
|
sum ->
|
||||||
sum.hasPointsSatisfying(
|
sum.hasPointsSatisfying(
|
||||||
point ->
|
point ->
|
||||||
point
|
point
|
||||||
.hasValue(1.234)
|
.hasValue(0.001234)
|
||||||
.hasAttributes(Attributes.empty())))));
|
.hasAttributes(Attributes.empty())))));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -163,17 +163,17 @@ public abstract class AbstractFunctionTimerTest {
|
||||||
metrics.anySatisfy(
|
metrics.anySatisfy(
|
||||||
metric ->
|
metric ->
|
||||||
assertThat(metric)
|
assertThat(metric)
|
||||||
.hasUnit("ms")
|
.hasUnit("s")
|
||||||
.hasDoubleSumSatisfying(
|
.hasDoubleSumSatisfying(
|
||||||
sum ->
|
sum ->
|
||||||
sum.hasPointsSatisfying(
|
sum.hasPointsSatisfying(
|
||||||
point ->
|
point ->
|
||||||
point
|
point
|
||||||
.hasValue(12_000)
|
.hasValue(12)
|
||||||
.hasAttributes(attributeEntry("tag", "1")),
|
.hasAttributes(attributeEntry("tag", "1")),
|
||||||
point ->
|
point ->
|
||||||
point
|
point
|
||||||
.hasValue(42_000)
|
.hasValue(42)
|
||||||
.hasAttributes(attributeEntry("tag", "2"))))));
|
.hasAttributes(attributeEntry("tag", "2"))))));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -70,7 +70,7 @@ public abstract class AbstractLongTaskTimerHistogramTest {
|
||||||
metric ->
|
metric ->
|
||||||
assertThat(metric)
|
assertThat(metric)
|
||||||
.hasDescription("This is a test timer")
|
.hasDescription("This is a test timer")
|
||||||
.hasUnit("ms")
|
.hasUnit("s")
|
||||||
.hasDoubleSumSatisfying(
|
.hasDoubleSumSatisfying(
|
||||||
sum ->
|
sum ->
|
||||||
sum.isNotMonotonic()
|
sum.isNotMonotonic()
|
||||||
|
@ -95,11 +95,11 @@ public abstract class AbstractLongTaskTimerHistogramTest {
|
||||||
gauge.hasPointsSatisfying(
|
gauge.hasPointsSatisfying(
|
||||||
point ->
|
point ->
|
||||||
point
|
point
|
||||||
.hasAttributes(attributeEntry("le", "100"))
|
.hasAttributes(attributeEntry("le", "0.1"))
|
||||||
.hasValue(2),
|
.hasValue(2),
|
||||||
point ->
|
point ->
|
||||||
point
|
point
|
||||||
.hasAttributes(attributeEntry("le", "1000"))
|
.hasAttributes(attributeEntry("le", "1"))
|
||||||
.hasValue(3)))));
|
.hasValue(3)))));
|
||||||
|
|
||||||
// when
|
// when
|
||||||
|
@ -136,7 +136,7 @@ public abstract class AbstractLongTaskTimerHistogramTest {
|
||||||
metric ->
|
metric ->
|
||||||
assertThat(metric)
|
assertThat(metric)
|
||||||
.hasDescription("This is a test timer")
|
.hasDescription("This is a test timer")
|
||||||
.hasUnit("ms")
|
.hasUnit("s")
|
||||||
.hasDoubleSumSatisfying(
|
.hasDoubleSumSatisfying(
|
||||||
sum ->
|
sum ->
|
||||||
sum.isNotMonotonic()
|
sum.isNotMonotonic()
|
||||||
|
@ -159,10 +159,10 @@ public abstract class AbstractLongTaskTimerHistogramTest {
|
||||||
point ->
|
point ->
|
||||||
point
|
point
|
||||||
.hasValue(0)
|
.hasValue(0)
|
||||||
.hasAttributes(attributeEntry("le", "100")),
|
.hasAttributes(attributeEntry("le", "0.1")),
|
||||||
point ->
|
point ->
|
||||||
point
|
point
|
||||||
.hasValue(0)
|
.hasValue(0)
|
||||||
.hasAttributes(attributeEntry("le", "1000"))))));
|
.hasAttributes(attributeEntry("le", "1"))))));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,15 +16,15 @@ import java.util.concurrent.TimeUnit;
|
||||||
import org.assertj.core.api.AbstractIterableAssert;
|
import org.assertj.core.api.AbstractIterableAssert;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
public abstract class AbstractLongTaskTimerSecondsTest {
|
public abstract class AbstractLongTaskTimerMillisecondsTest {
|
||||||
|
|
||||||
protected abstract InstrumentationExtension testing();
|
protected abstract InstrumentationExtension testing();
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void testLongTaskTimerWithBaseUnitSeconds() throws InterruptedException {
|
void testLongTaskTimerWithBaseUnitMilliseconds() throws InterruptedException {
|
||||||
// given
|
// given
|
||||||
LongTaskTimer timer =
|
LongTaskTimer timer =
|
||||||
LongTaskTimer.builder("testLongTaskTimerSeconds")
|
LongTaskTimer.builder("testLongTaskTimerMilliseconds")
|
||||||
.description("This is a test long task timer")
|
.description("This is a test long task timer")
|
||||||
.tags("tag", "value")
|
.tags("tag", "value")
|
||||||
.register(Metrics.globalRegistry);
|
.register(Metrics.globalRegistry);
|
||||||
|
@ -36,7 +36,7 @@ public abstract class AbstractLongTaskTimerSecondsTest {
|
||||||
testing()
|
testing()
|
||||||
.waitAndAssertMetrics(
|
.waitAndAssertMetrics(
|
||||||
INSTRUMENTATION_NAME,
|
INSTRUMENTATION_NAME,
|
||||||
"testLongTaskTimerSeconds.active",
|
"testLongTaskTimerMilliseconds.active",
|
||||||
metrics ->
|
metrics ->
|
||||||
metrics.anySatisfy(
|
metrics.anySatisfy(
|
||||||
metric ->
|
metric ->
|
||||||
|
@ -55,13 +55,13 @@ public abstract class AbstractLongTaskTimerSecondsTest {
|
||||||
testing()
|
testing()
|
||||||
.waitAndAssertMetrics(
|
.waitAndAssertMetrics(
|
||||||
INSTRUMENTATION_NAME,
|
INSTRUMENTATION_NAME,
|
||||||
"testLongTaskTimerSeconds.duration",
|
"testLongTaskTimerMilliseconds.duration",
|
||||||
metrics ->
|
metrics ->
|
||||||
metrics.anySatisfy(
|
metrics.anySatisfy(
|
||||||
metric ->
|
metric ->
|
||||||
assertThat(metric)
|
assertThat(metric)
|
||||||
.hasDescription("This is a test long task timer")
|
.hasDescription("This is a test long task timer")
|
||||||
.hasUnit("s")
|
.hasUnit("ms")
|
||||||
.hasDoubleSumSatisfying(
|
.hasDoubleSumSatisfying(
|
||||||
sum ->
|
sum ->
|
||||||
sum.isNotMonotonic()
|
sum.isNotMonotonic()
|
||||||
|
@ -82,7 +82,7 @@ public abstract class AbstractLongTaskTimerSecondsTest {
|
||||||
testing()
|
testing()
|
||||||
.waitAndAssertMetrics(
|
.waitAndAssertMetrics(
|
||||||
INSTRUMENTATION_NAME,
|
INSTRUMENTATION_NAME,
|
||||||
"testLongTaskTimerSeconds.active",
|
"testLongTaskTimerMilliseconds.active",
|
||||||
metrics ->
|
metrics ->
|
||||||
metrics.anySatisfy(
|
metrics.anySatisfy(
|
||||||
metric ->
|
metric ->
|
||||||
|
@ -97,7 +97,7 @@ public abstract class AbstractLongTaskTimerSecondsTest {
|
||||||
testing()
|
testing()
|
||||||
.waitAndAssertMetrics(
|
.waitAndAssertMetrics(
|
||||||
INSTRUMENTATION_NAME,
|
INSTRUMENTATION_NAME,
|
||||||
"testLongTaskTimerSeconds.duration",
|
"testLongTaskTimerMilliseconds.duration",
|
||||||
metrics ->
|
metrics ->
|
||||||
metrics.anySatisfy(
|
metrics.anySatisfy(
|
||||||
metric ->
|
metric ->
|
||||||
|
@ -119,7 +119,7 @@ public abstract class AbstractLongTaskTimerSecondsTest {
|
||||||
testing()
|
testing()
|
||||||
.waitAndAssertMetrics(
|
.waitAndAssertMetrics(
|
||||||
INSTRUMENTATION_NAME,
|
INSTRUMENTATION_NAME,
|
||||||
"testLongTaskTimerSeconds.active",
|
"testLongTaskTimerMilliseconds.active",
|
||||||
AbstractIterableAssert::isEmpty);
|
AbstractIterableAssert::isEmpty);
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -61,7 +61,7 @@ public abstract class AbstractLongTaskTimerTest {
|
||||||
metric ->
|
metric ->
|
||||||
assertThat(metric)
|
assertThat(metric)
|
||||||
.hasDescription("This is a test long task timer")
|
.hasDescription("This is a test long task timer")
|
||||||
.hasUnit("ms")
|
.hasUnit("s")
|
||||||
.hasDoubleSumSatisfying(
|
.hasDoubleSumSatisfying(
|
||||||
sum ->
|
sum ->
|
||||||
sum.isNotMonotonic()
|
sum.isNotMonotonic()
|
||||||
|
|
|
@ -52,13 +52,13 @@ public abstract class AbstractTimerHistogramGaugesTest {
|
||||||
metric ->
|
metric ->
|
||||||
assertThat(metric)
|
assertThat(metric)
|
||||||
.hasDescription("This is a test timer")
|
.hasDescription("This is a test timer")
|
||||||
.hasUnit("ms")
|
.hasUnit("s")
|
||||||
.hasHistogramSatisfying(
|
.hasHistogramSatisfying(
|
||||||
histogram ->
|
histogram ->
|
||||||
histogram.hasPointsSatisfying(
|
histogram.hasPointsSatisfying(
|
||||||
point ->
|
point ->
|
||||||
point
|
point
|
||||||
.hasSum(555500)
|
.hasSum(555.5)
|
||||||
.hasCount(4)
|
.hasCount(4)
|
||||||
.hasAttributes(attributeEntry("tag", "value"))))));
|
.hasAttributes(attributeEntry("tag", "value"))))));
|
||||||
testing()
|
testing()
|
||||||
|
@ -75,7 +75,7 @@ public abstract class AbstractTimerHistogramGaugesTest {
|
||||||
gauge.hasPointsSatisfying(
|
gauge.hasPointsSatisfying(
|
||||||
point ->
|
point ->
|
||||||
point
|
point
|
||||||
.hasValue(500000)
|
.hasValue(500)
|
||||||
.hasAttributes(attributeEntry("tag", "value"))))));
|
.hasAttributes(attributeEntry("tag", "value"))))));
|
||||||
testing()
|
testing()
|
||||||
.waitAndAssertMetrics(
|
.waitAndAssertMetrics(
|
||||||
|
@ -92,25 +92,25 @@ public abstract class AbstractTimerHistogramGaugesTest {
|
||||||
point
|
point
|
||||||
.hasValue(1)
|
.hasValue(1)
|
||||||
.hasAttributes(
|
.hasAttributes(
|
||||||
attributeEntry("le", "1000"),
|
attributeEntry("le", "1"),
|
||||||
attributeEntry("tag", "value")),
|
attributeEntry("tag", "value")),
|
||||||
point ->
|
point ->
|
||||||
point
|
point
|
||||||
.hasValue(2)
|
.hasValue(2)
|
||||||
.hasAttributes(
|
.hasAttributes(
|
||||||
attributeEntry("le", "10000"),
|
attributeEntry("le", "10"),
|
||||||
attributeEntry("tag", "value")),
|
attributeEntry("tag", "value")),
|
||||||
point ->
|
point ->
|
||||||
point
|
point
|
||||||
.hasValue(3)
|
.hasValue(3)
|
||||||
.hasAttributes(
|
.hasAttributes(
|
||||||
attributeEntry("le", "100000"),
|
attributeEntry("le", "100"),
|
||||||
attributeEntry("tag", "value")),
|
attributeEntry("tag", "value")),
|
||||||
point ->
|
point ->
|
||||||
point
|
point
|
||||||
.hasValue(4)
|
.hasValue(4)
|
||||||
.hasAttributes(
|
.hasAttributes(
|
||||||
attributeEntry("le", "1000000"),
|
attributeEntry("le", "1000"),
|
||||||
attributeEntry("tag", "value"))))));
|
attributeEntry("tag", "value"))))));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -126,7 +126,7 @@ public abstract class AbstractTimerHistogramGaugesTest {
|
||||||
|
|
||||||
// when
|
// when
|
||||||
timer.record(50, TimeUnit.MILLISECONDS);
|
timer.record(50, TimeUnit.MILLISECONDS);
|
||||||
timer.record(100, TimeUnit.MILLISECONDS);
|
timer.record(500, TimeUnit.MILLISECONDS);
|
||||||
|
|
||||||
// then
|
// then
|
||||||
testing()
|
testing()
|
||||||
|
@ -138,13 +138,13 @@ public abstract class AbstractTimerHistogramGaugesTest {
|
||||||
metric ->
|
metric ->
|
||||||
assertThat(metric)
|
assertThat(metric)
|
||||||
.hasDescription("This is a test timer")
|
.hasDescription("This is a test timer")
|
||||||
.hasUnit("ms")
|
.hasUnit("s")
|
||||||
.hasHistogramSatisfying(
|
.hasHistogramSatisfying(
|
||||||
histogram ->
|
histogram ->
|
||||||
histogram.hasPointsSatisfying(
|
histogram.hasPointsSatisfying(
|
||||||
point ->
|
point ->
|
||||||
point
|
point
|
||||||
.hasSum(150)
|
.hasSum(0.55)
|
||||||
.hasCount(2)
|
.hasCount(2)
|
||||||
.hasAttributes(attributeEntry("tag", "value"))))));
|
.hasAttributes(attributeEntry("tag", "value"))))));
|
||||||
testing()
|
testing()
|
||||||
|
@ -161,7 +161,7 @@ public abstract class AbstractTimerHistogramGaugesTest {
|
||||||
gauge.hasPointsSatisfying(
|
gauge.hasPointsSatisfying(
|
||||||
point ->
|
point ->
|
||||||
point
|
point
|
||||||
.hasValue(100)
|
.hasValue(0.5)
|
||||||
.hasAttributes(attributeEntry("tag", "value"))))));
|
.hasAttributes(attributeEntry("tag", "value"))))));
|
||||||
testing()
|
testing()
|
||||||
.waitAndAssertMetrics(
|
.waitAndAssertMetrics(
|
||||||
|
|
|
@ -17,15 +17,15 @@ import org.assertj.core.api.AbstractIterableAssert;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
@SuppressWarnings("PreferJavaTimeOverload")
|
@SuppressWarnings("PreferJavaTimeOverload")
|
||||||
public abstract class AbstractTimerSecondsTest {
|
public abstract class AbstractTimerMillisecondsTest {
|
||||||
|
|
||||||
protected abstract InstrumentationExtension testing();
|
protected abstract InstrumentationExtension testing();
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void testTimerWithBaseUnitSeconds() {
|
void testTimerWithBaseUnitMilliseconds() {
|
||||||
// given
|
// given
|
||||||
Timer timer =
|
Timer timer =
|
||||||
Timer.builder("testTimerSeconds")
|
Timer.builder("testTimerMilliseconds")
|
||||||
.description("This is a test timer")
|
.description("This is a test timer")
|
||||||
.tags("tag", "value")
|
.tags("tag", "value")
|
||||||
.register(Metrics.globalRegistry);
|
.register(Metrics.globalRegistry);
|
||||||
|
@ -39,37 +39,37 @@ public abstract class AbstractTimerSecondsTest {
|
||||||
testing()
|
testing()
|
||||||
.waitAndAssertMetrics(
|
.waitAndAssertMetrics(
|
||||||
INSTRUMENTATION_NAME,
|
INSTRUMENTATION_NAME,
|
||||||
"testTimerSeconds",
|
"testTimerMilliseconds",
|
||||||
metrics ->
|
metrics ->
|
||||||
metrics.anySatisfy(
|
metrics.anySatisfy(
|
||||||
metric ->
|
metric ->
|
||||||
assertThat(metric)
|
assertThat(metric)
|
||||||
.hasDescription("This is a test timer")
|
.hasDescription("This is a test timer")
|
||||||
.hasUnit("s")
|
.hasUnit("ms")
|
||||||
.hasHistogramSatisfying(
|
.hasHistogramSatisfying(
|
||||||
histogram ->
|
histogram ->
|
||||||
histogram.hasPointsSatisfying(
|
histogram.hasPointsSatisfying(
|
||||||
point ->
|
point ->
|
||||||
point
|
point
|
||||||
.hasSum(23.345)
|
.hasSum(23_345)
|
||||||
.hasCount(3)
|
.hasCount(3)
|
||||||
.hasAttributes(attributeEntry("tag", "value"))))));
|
.hasAttributes(attributeEntry("tag", "value"))))));
|
||||||
testing()
|
testing()
|
||||||
.waitAndAssertMetrics(
|
.waitAndAssertMetrics(
|
||||||
INSTRUMENTATION_NAME,
|
INSTRUMENTATION_NAME,
|
||||||
"testTimerSeconds.max",
|
"testTimerMilliseconds.max",
|
||||||
metrics ->
|
metrics ->
|
||||||
metrics.anySatisfy(
|
metrics.anySatisfy(
|
||||||
metric ->
|
metric ->
|
||||||
assertThat(metric)
|
assertThat(metric)
|
||||||
.hasDescription("This is a test timer")
|
.hasDescription("This is a test timer")
|
||||||
.hasUnit("s")
|
.hasUnit("ms")
|
||||||
.hasDoubleGaugeSatisfying(
|
.hasDoubleGaugeSatisfying(
|
||||||
gauge ->
|
gauge ->
|
||||||
gauge.hasPointsSatisfying(
|
gauge.hasPointsSatisfying(
|
||||||
point ->
|
point ->
|
||||||
point
|
point
|
||||||
.hasValue(12.345)
|
.hasValue(12_345)
|
||||||
.hasAttributes(attributeEntry("tag", "value"))))));
|
.hasAttributes(attributeEntry("tag", "value"))))));
|
||||||
|
|
||||||
// when
|
// when
|
|
@ -8,15 +8,18 @@ package io.opentelemetry.instrumentation.micrometer.v1_5;
|
||||||
import static io.opentelemetry.instrumentation.micrometer.v1_5.AbstractCounterTest.INSTRUMENTATION_NAME;
|
import static io.opentelemetry.instrumentation.micrometer.v1_5.AbstractCounterTest.INSTRUMENTATION_NAME;
|
||||||
import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.assertThat;
|
import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.assertThat;
|
||||||
import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.attributeEntry;
|
import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.attributeEntry;
|
||||||
|
import static org.assertj.core.api.Assertions.within;
|
||||||
|
|
||||||
import io.micrometer.core.instrument.Metrics;
|
import io.micrometer.core.instrument.Metrics;
|
||||||
import io.micrometer.core.instrument.Timer;
|
import io.micrometer.core.instrument.Timer;
|
||||||
import io.opentelemetry.api.common.Attributes;
|
import io.opentelemetry.api.common.Attributes;
|
||||||
import io.opentelemetry.instrumentation.testing.junit.InstrumentationExtension;
|
import io.opentelemetry.instrumentation.testing.junit.InstrumentationExtension;
|
||||||
|
import io.opentelemetry.sdk.metrics.data.HistogramPointData;
|
||||||
import io.opentelemetry.sdk.metrics.internal.aggregator.ExplicitBucketHistogramUtils;
|
import io.opentelemetry.sdk.metrics.internal.aggregator.ExplicitBucketHistogramUtils;
|
||||||
import java.time.Duration;
|
import java.time.Duration;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
import org.assertj.core.api.AbstractIterableAssert;
|
import org.assertj.core.api.AbstractIterableAssert;
|
||||||
|
import org.assertj.core.api.ThrowingConsumer;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
@SuppressWarnings("PreferJavaTimeOverload")
|
@SuppressWarnings("PreferJavaTimeOverload")
|
||||||
|
@ -51,13 +54,13 @@ public abstract class AbstractTimerTest {
|
||||||
metric ->
|
metric ->
|
||||||
assertThat(metric)
|
assertThat(metric)
|
||||||
.hasDescription("This is a test timer")
|
.hasDescription("This is a test timer")
|
||||||
.hasUnit("ms")
|
.hasUnit("s")
|
||||||
.hasHistogramSatisfying(
|
.hasHistogramSatisfying(
|
||||||
histogram ->
|
histogram ->
|
||||||
histogram.hasPointsSatisfying(
|
histogram.hasPointsSatisfying(
|
||||||
point ->
|
point ->
|
||||||
point
|
point
|
||||||
.hasSum(42_000)
|
.hasSum(42)
|
||||||
.hasCount(1)
|
.hasCount(1)
|
||||||
.hasAttributes(attributeEntry("tag", "value"))
|
.hasAttributes(attributeEntry("tag", "value"))
|
||||||
.hasBucketBoundaries(DEFAULT_BUCKETS)))));
|
.hasBucketBoundaries(DEFAULT_BUCKETS)))));
|
||||||
|
@ -75,7 +78,7 @@ public abstract class AbstractTimerTest {
|
||||||
gauge.hasPointsSatisfying(
|
gauge.hasPointsSatisfying(
|
||||||
point ->
|
point ->
|
||||||
point
|
point
|
||||||
.hasValue(42_000)
|
.hasValue(42)
|
||||||
.hasAttributes(attributeEntry("tag", "value"))))));
|
.hasAttributes(attributeEntry("tag", "value"))))));
|
||||||
|
|
||||||
// micrometer gauge histogram is not emitted
|
// micrometer gauge histogram is not emitted
|
||||||
|
@ -110,13 +113,13 @@ public abstract class AbstractTimerTest {
|
||||||
metrics.anySatisfy(
|
metrics.anySatisfy(
|
||||||
metric ->
|
metric ->
|
||||||
assertThat(metric)
|
assertThat(metric)
|
||||||
.hasUnit("ms")
|
.hasUnit("s")
|
||||||
.hasHistogramSatisfying(
|
.hasHistogramSatisfying(
|
||||||
histogram ->
|
histogram ->
|
||||||
histogram.hasPointsSatisfying(
|
histogram.hasPointsSatisfying(
|
||||||
point ->
|
point ->
|
||||||
point
|
point
|
||||||
.hasSum(1.234)
|
.hasSum(0.001234)
|
||||||
.hasCount(1)
|
.hasCount(1)
|
||||||
.hasAttributes(Attributes.empty())))));
|
.hasAttributes(Attributes.empty())))));
|
||||||
testing()
|
testing()
|
||||||
|
@ -132,7 +135,7 @@ public abstract class AbstractTimerTest {
|
||||||
gauge.hasPointsSatisfying(
|
gauge.hasPointsSatisfying(
|
||||||
point ->
|
point ->
|
||||||
point
|
point
|
||||||
.hasValue(1.234)
|
.hasValue(0.001234)
|
||||||
.hasAttributes(Attributes.empty())))));
|
.hasAttributes(Attributes.empty())))));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -167,17 +170,22 @@ public abstract class AbstractTimerTest {
|
||||||
metric ->
|
metric ->
|
||||||
assertThat(metric)
|
assertThat(metric)
|
||||||
.hasDescription("This is a test timer")
|
.hasDescription("This is a test timer")
|
||||||
.hasUnit("ms")
|
.hasUnit("s")
|
||||||
.hasHistogramSatisfying(
|
.hasHistogramSatisfying(
|
||||||
histogram ->
|
histogram ->
|
||||||
histogram.hasPointsSatisfying(
|
histogram.hasPointsSatisfying(
|
||||||
point ->
|
point ->
|
||||||
point
|
point
|
||||||
.hasSum(555500)
|
.hasSum(555.5)
|
||||||
.hasCount(4)
|
.hasCount(4)
|
||||||
.hasAttributes(attributeEntry("tag", "value"))
|
.hasAttributes(attributeEntry("tag", "value"))
|
||||||
.hasBucketBoundaries(
|
.satisfies(hasBucketBoundaries(1, 10, 100, 1_000))
|
||||||
1_000, 10_000, 100_000, 1_000_000)
|
|
||||||
.hasBucketCounts(1, 1, 1, 1, 0)))));
|
.hasBucketCounts(1, 1, 1, 1, 0)))));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static ThrowingConsumer<HistogramPointData> hasBucketBoundaries(double... buckets) {
|
||||||
|
return pointData ->
|
||||||
|
assertThat(pointData.getBoundaries().stream().mapToDouble(d -> d).toArray())
|
||||||
|
.contains(buckets, within(0.00001));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue