-
Notifications
You must be signed in to change notification settings - Fork 869
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make it possible to configure base time unit used by the Micrometer b…
…ridge (#5304) * Make it possible to configure base time unit used by the Micrometer bridge * add readme
- Loading branch information
Mateusz Rzeszutek
authored
Feb 8, 2022
1 parent
551418c
commit 0b7f466
Showing
13 changed files
with
491 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# Settings for the Micrometer bridge instrumentation | ||
|
||
| 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> | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 22 additions & 0 deletions
22
.../io/opentelemetry/javaagent/instrumentation/micrometer/v1_5/LongTaskTimerSecondsTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
/* | ||
* Copyright The OpenTelemetry Authors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package io.opentelemetry.javaagent.instrumentation.micrometer.v1_5; | ||
|
||
import io.opentelemetry.instrumentation.micrometer.v1_5.AbstractLongTaskTimerSecondsTest; | ||
import io.opentelemetry.instrumentation.testing.junit.AgentInstrumentationExtension; | ||
import io.opentelemetry.instrumentation.testing.junit.InstrumentationExtension; | ||
import org.junit.jupiter.api.extension.RegisterExtension; | ||
|
||
class LongTaskTimerSecondsTest extends AbstractLongTaskTimerSecondsTest { | ||
|
||
@RegisterExtension | ||
static final InstrumentationExtension testing = AgentInstrumentationExtension.create(); | ||
|
||
@Override | ||
protected InstrumentationExtension testing() { | ||
return testing; | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
...est/java/io/opentelemetry/javaagent/instrumentation/micrometer/v1_5/TimerSecondsTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
/* | ||
* Copyright The OpenTelemetry Authors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package io.opentelemetry.javaagent.instrumentation.micrometer.v1_5; | ||
|
||
import io.opentelemetry.instrumentation.micrometer.v1_5.AbstractTimerSecondsTest; | ||
import io.opentelemetry.instrumentation.testing.junit.AgentInstrumentationExtension; | ||
import io.opentelemetry.instrumentation.testing.junit.InstrumentationExtension; | ||
import org.junit.jupiter.api.extension.RegisterExtension; | ||
|
||
class TimerSecondsTest extends AbstractTimerSecondsTest { | ||
|
||
@RegisterExtension | ||
static final InstrumentationExtension testing = AgentInstrumentationExtension.create(); | ||
|
||
@Override | ||
protected InstrumentationExtension testing() { | ||
return testing; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
75 changes: 75 additions & 0 deletions
75
...ibrary/src/main/java/io/opentelemetry/instrumentation/micrometer/v1_5/TimeUnitHelper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
/* | ||
* Copyright The OpenTelemetry Authors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package io.opentelemetry.instrumentation.micrometer.v1_5; | ||
|
||
import java.util.Locale; | ||
import java.util.concurrent.TimeUnit; | ||
import javax.annotation.Nullable; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
final class TimeUnitHelper { | ||
|
||
private static final Logger logger = LoggerFactory.getLogger(OpenTelemetryMeterRegistry.class); | ||
|
||
static TimeUnit parseConfigValue(@Nullable String value) { | ||
if (value == null) { | ||
return TimeUnit.MILLISECONDS; | ||
} | ||
// short names are UCUM names | ||
// long names are just TimeUnit values lowercased | ||
switch (value.toLowerCase(Locale.ROOT)) { | ||
case "ns": | ||
case "nanoseconds": | ||
return TimeUnit.NANOSECONDS; | ||
case "us": | ||
case "microseconds": | ||
return TimeUnit.MICROSECONDS; | ||
case "ms": | ||
case "milliseconds": | ||
return TimeUnit.MILLISECONDS; | ||
case "s": | ||
case "seconds": | ||
return TimeUnit.SECONDS; | ||
case "min": | ||
case "minutes": | ||
return TimeUnit.MINUTES; | ||
case "h": | ||
case "hours": | ||
return TimeUnit.HOURS; | ||
case "d": | ||
case "days": | ||
return TimeUnit.DAYS; | ||
default: | ||
logger.warn( | ||
"Invalid base time unit: '{}'; using microseconds as the base time unit instead", | ||
value); | ||
return TimeUnit.MILLISECONDS; | ||
} | ||
} | ||
|
||
static String getUnitString(TimeUnit unit) { | ||
switch (unit) { | ||
case NANOSECONDS: | ||
return "ns"; | ||
case MICROSECONDS: | ||
return "us"; | ||
case MILLISECONDS: | ||
return "ms"; | ||
case SECONDS: | ||
return "s"; | ||
case MINUTES: | ||
return "min"; | ||
case HOURS: | ||
return "h"; | ||
case DAYS: | ||
return "d"; | ||
} | ||
throw new IllegalStateException("Should not ever happen"); | ||
} | ||
|
||
private TimeUnitHelper() {} | ||
} |
42 changes: 42 additions & 0 deletions
42
.../test/java/io/opentelemetry/instrumentation/micrometer/v1_5/LongTaskTimerSecondsTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
/* | ||
* Copyright The OpenTelemetry Authors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package io.opentelemetry.instrumentation.micrometer.v1_5; | ||
|
||
import io.micrometer.core.instrument.MeterRegistry; | ||
import io.micrometer.core.instrument.Metrics; | ||
import io.opentelemetry.instrumentation.testing.junit.InstrumentationExtension; | ||
import io.opentelemetry.instrumentation.testing.junit.LibraryInstrumentationExtension; | ||
import java.util.concurrent.TimeUnit; | ||
import org.junit.jupiter.api.AfterAll; | ||
import org.junit.jupiter.api.BeforeAll; | ||
import org.junit.jupiter.api.extension.RegisterExtension; | ||
|
||
class LongTaskTimerSecondsTest extends AbstractLongTaskTimerSecondsTest { | ||
|
||
@RegisterExtension | ||
static final InstrumentationExtension testing = LibraryInstrumentationExtension.create(); | ||
|
||
static MeterRegistry otelMeterRegistry; | ||
|
||
@BeforeAll | ||
public static void setUpRegistry() { | ||
otelMeterRegistry = | ||
OpenTelemetryMeterRegistry.builder(testing.getOpenTelemetry()) | ||
.setBaseTimeUnit(TimeUnit.SECONDS) | ||
.build(); | ||
Metrics.addRegistry(otelMeterRegistry); | ||
} | ||
|
||
@AfterAll | ||
public static void tearDownRegistry() { | ||
Metrics.removeRegistry(otelMeterRegistry); | ||
} | ||
|
||
@Override | ||
protected InstrumentationExtension testing() { | ||
return testing; | ||
} | ||
} |
Oops, something went wrong.