Skip to content

Commit

Permalink
Small daemon threads implementation clean up (open-telemetry#6740)
Browse files Browse the repository at this point in the history
  • Loading branch information
trask committed Sep 28, 2022
1 parent bd6831c commit 0e0bbf6
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
package io.opentelemetry.instrumentation.runtimemetrics;

import io.opentelemetry.api.OpenTelemetry;
import io.opentelemetry.api.common.AttributeKey;
import io.opentelemetry.api.common.Attributes;
import io.opentelemetry.api.metrics.Meter;
import java.lang.management.ManagementFactory;
Expand All @@ -32,7 +33,7 @@ public final class Threads {
// Visible for testing
static final Threads INSTANCE = new Threads();

static final String DAEMON_KEY = "daemon";
static final AttributeKey<Boolean> DAEMON = AttributeKey.booleanKey("daemon");

/** Register observers for java runtime class metrics. */
public static void registerObservers(OpenTelemetry openTelemetry) {
Expand All @@ -51,10 +52,10 @@ void registerObservers(OpenTelemetry openTelemetry, ThreadMXBean threadBean) {
observableMeasurement -> {
observableMeasurement.record(
threadBean.getDaemonThreadCount(),
Attributes.builder().put(DAEMON_KEY, true).build());
Attributes.builder().put(DAEMON, true).build());
observableMeasurement.record(
threadBean.getThreadCount() - threadBean.getDaemonThreadCount(),
Attributes.builder().put(DAEMON_KEY, false).build());
Attributes.builder().put(DAEMON, false).build());
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@

package io.opentelemetry.instrumentation.runtimemetrics;

import static io.opentelemetry.instrumentation.runtimemetrics.Threads.DAEMON_KEY;
import static io.opentelemetry.instrumentation.runtimemetrics.Threads.DAEMON;
import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.assertThat;
import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.equalTo;
import static org.mockito.Mockito.when;

import io.opentelemetry.api.common.Attributes;
import io.opentelemetry.instrumentation.testing.junit.InstrumentationExtension;
import io.opentelemetry.instrumentation.testing.junit.LibraryInstrumentationExtension;
import java.lang.management.ThreadMXBean;
Expand Down Expand Up @@ -50,16 +50,11 @@ void registerObservers() {
point ->
point
.hasValue(2)
.hasAttributes(
Attributes.builder()
.put(DAEMON_KEY, true)
.build()),
.hasAttributesSatisfying(equalTo(DAEMON, true)),
point ->
point
.hasValue(5)
.hasAttributes(
Attributes.builder()
.put(DAEMON_KEY, false)
.build())))));
.hasAttributesSatisfying(
equalTo(DAEMON, false))))));
}
}

0 comments on commit 0e0bbf6

Please sign in to comment.