Skip to content

Commit

Permalink
Fix metric units (#6931)
Browse files Browse the repository at this point in the history
Follow-up to #6930
  • Loading branch information
trask authored Oct 22, 2022
1 parent 47cbdf3 commit 9ce68fb
Show file tree
Hide file tree
Showing 13 changed files with 29 additions and 27 deletions.
2 changes: 1 addition & 1 deletion docs/contributing/using-instrumenter-api.md
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,7 @@ class MyOperationMetrics implements OperationListener {
MyOperationMetrics(Meter meter) {
activeRequests = meter
.upDownCounterBuilder("mylib.active_requests")
.setUnit("requests")
.setUnit("{requests}")
.build();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ private HttpServerMetrics(Meter meter) {
activeRequests =
meter
.upDownCounterBuilder("http.server.active_requests")
.setUnit("requests")
.setUnit("{requests}")
.setDescription("The number of concurrent HTTP requests that are currently in-flight")
.build();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public static DbConnectionPoolMetrics create(
public ObservableLongMeasurement connections() {
return meter
.upDownCounterBuilder("db.client.connections.usage")
.setUnit("connections")
.setUnit("{connections}")
.setDescription(
"The number of connections that are currently in state described by the state attribute.")
.buildObserver();
Expand All @@ -67,31 +67,31 @@ public ObservableLongMeasurement connections() {
public ObservableLongMeasurement minIdleConnections() {
return meter
.upDownCounterBuilder("db.client.connections.idle.min")
.setUnit("connections")
.setUnit("{connections}")
.setDescription("The minimum number of idle open connections allowed.")
.buildObserver();
}

public ObservableLongMeasurement maxIdleConnections() {
return meter
.upDownCounterBuilder("db.client.connections.idle.max")
.setUnit("connections")
.setUnit("{connections}")
.setDescription("The maximum number of idle open connections allowed.")
.buildObserver();
}

public ObservableLongMeasurement maxConnections() {
return meter
.upDownCounterBuilder("db.client.connections.max")
.setUnit("connections")
.setUnit("{connections}")
.setDescription("The maximum number of open connections allowed.")
.buildObserver();
}

public ObservableLongMeasurement pendingRequestsForConnection() {
return meter
.upDownCounterBuilder("db.client.connections.pending_requests")
.setUnit("requests")
.setUnit("{requests}")
.setDescription(
"The number of pending requests for an open connection, cumulative for the entire pool.")
.buildObserver();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ void collectsMetrics() {
.hasName("http.server.active_requests")
.hasDescription(
"The number of concurrent HTTP requests that are currently in-flight")
.hasUnit("requests")
.hasUnit("{requests}")
.hasLongSumSatisfying(
sum ->
sum.hasPointsSatisfying(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ final class OpenTelemetryLongTaskTimer extends DefaultLongTaskTimer implements R
otelMeter
.upDownCounterBuilder(name + ".active")
.setDescription(Bridging.description(id))
.setUnit("tasks")
.setUnit("{tasks}")
.buildWithCallback(
new LongMeasurementRecorder<>(this, DefaultLongTaskTimer::activeTasks, attributes));
this.observableDuration =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ void testMicrometerHistogram() {
metric ->
assertThat(metric)
.hasDescription("This is a test timer")
.hasUnit("tasks")
.hasUnit("{tasks}")
.hasLongSumSatisfying(
sum ->
sum.isNotMonotonic()
Expand Down Expand Up @@ -118,7 +118,7 @@ void testMicrometerHistogram() {
metric ->
assertThat(metric)
.hasDescription("This is a test timer")
.hasUnit("tasks")
.hasUnit("{tasks}")
.hasLongSumSatisfying(
sum ->
sum.isNotMonotonic()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ void testLongTaskTimerWithBaseUnitSeconds() throws InterruptedException {
metric ->
assertThat(metric)
.hasDescription("This is a test long task timer")
.hasUnit("tasks")
.hasUnit("{tasks}")
.hasLongSumSatisfying(
sum ->
sum.isNotMonotonic()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ void testLongTaskTimer() throws InterruptedException {
metric ->
assertThat(metric)
.hasDescription("This is a test long task timer")
.hasUnit("tasks")
.hasUnit("{tasks}")
.hasLongSumSatisfying(
sum ->
sum.isNotMonotonic()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ void testLongTaskTimer() throws InterruptedException {
metric ->
assertThat(metric)
.hasDescription("This is a test long task timer")
.hasUnit("tasks")
.hasUnit("{tasks}")
.hasLongSumSatisfying(
sum ->
sum.isNotMonotonic()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public static void registerObservers(OpenTelemetry openTelemetry) {
meter
.counterBuilder("system.network.packets")
.setDescription("System network packets")
.setUnit("packets")
.setUnit("{packets}")
.buildWithCallback(
r -> {
for (NetworkIF networkIf : hal.getNetworkIFs()) {
Expand All @@ -92,7 +92,7 @@ public static void registerObservers(OpenTelemetry openTelemetry) {
meter
.counterBuilder("system.network.errors")
.setDescription("System network errors")
.setUnit("errors")
.setUnit("{errors}")
.buildWithCallback(
r -> {
for (NetworkIF networkIf : hal.getNetworkIFs()) {
Expand Down Expand Up @@ -123,7 +123,7 @@ public static void registerObservers(OpenTelemetry openTelemetry) {
meter
.counterBuilder("system.disk.operations")
.setDescription("System disk operations")
.setUnit("operations")
.setUnit("{operations}")
.buildWithCallback(
r -> {
for (HWDiskStore diskStore : hal.getDiskStores()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,15 +66,15 @@ public void test() {
metrics ->
metrics.anySatisfy(
metric ->
assertThat(metric).hasUnit("packets").hasLongSumSatisfying(sum -> {})));
assertThat(metric).hasUnit("{packets}").hasLongSumSatisfying(sum -> {})));
testing()
.waitAndAssertMetrics(
"io.opentelemetry.oshi",
"system.network.errors",
metrics ->
metrics.anySatisfy(
metric ->
assertThat(metric).hasUnit("errors").hasLongSumSatisfying(sum -> {})));
assertThat(metric).hasUnit("{errors}").hasLongSumSatisfying(sum -> {})));
testing()
.waitAndAssertMetrics(
"io.opentelemetry.oshi",
Expand All @@ -89,6 +89,8 @@ public void test() {
metrics ->
metrics.anySatisfy(
metric ->
assertThat(metric).hasUnit("operations").hasLongSumSatisfying(sum -> {})));
assertThat(metric)
.hasUnit("{operations}")
.hasLongSumSatisfying(sum -> {})));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public static void registerObservers(OpenTelemetry openTelemetry) {
meter
.upDownCounterBuilder("process.runtime.jvm.buffer.count")
.setDescription("The number of buffers in the pool")
.setUnit("buffers")
.setUnit("{buffers}")
.buildWithCallback(callback(bufferBeans, BufferPoolMXBean::getCount));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ private void verifyConnectionUsage() {

private void verifyUsageMetric(MetricData metric) {
assertThat(metric)
.hasUnit("connections")
.hasUnit("{connections}")
.hasDescription(
"The number of connections that are currently in state described by the state attribute.")
.hasLongSumSatisfying(
Expand All @@ -156,7 +156,7 @@ private void verifyMaxConnections() {

private void verifyMaxConnectionsMetric(MetricData metric) {
assertThat(metric)
.hasUnit("connections")
.hasUnit("{connections}")
.hasDescription("The maximum number of open connections allowed.")
.hasLongSumSatisfying(this::verifyPoolName);
}
Expand All @@ -170,7 +170,7 @@ private void verifyMinIdleConnections() {

private void verifyMinIdleConnectionsMetric(MetricData metric) {
assertThat(metric)
.hasUnit("connections")
.hasUnit("{connections}")
.hasDescription("The minimum number of idle open connections allowed.")
.hasLongSumSatisfying(this::verifyPoolName);
}
Expand All @@ -184,7 +184,7 @@ private void verifyMaxIdleConnections() {

private void verifyMaxIdleConnectionsMetric(MetricData metric) {
assertThat(metric)
.hasUnit("connections")
.hasUnit("{connections}")
.hasDescription("The maximum number of idle open connections allowed.")
.hasLongSumSatisfying(this::verifyPoolName);
}
Expand All @@ -203,7 +203,7 @@ private void verifyPendingRequests() {

private void verifyPendingRequestsMetric(MetricData metric) {
assertThat(metric)
.hasUnit("requests")
.hasUnit("{requests}")
.hasDescription(
"The number of pending requests for an open connection, cumulative for the entire pool.")
.hasLongSumSatisfying(this::verifyPoolName);
Expand All @@ -218,7 +218,7 @@ private void verifyTimeouts() {

private void verifyTimeoutsMetric(MetricData metric) {
assertThat(metric)
.hasUnit("timeouts")
.hasUnit("{timeouts}")
.hasDescription(
"The number of connection timeouts that have occurred trying to obtain a connection from the pool.")
.hasLongSumSatisfying(
Expand Down

0 comments on commit 9ce68fb

Please sign in to comment.