-
Notifications
You must be signed in to change notification settings - Fork 967
Migrate "runtime-metrics" test from groovy to java #8928
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 4 commits
b99629e
762bb16
a05a18d
50c6169
f0dcd4b
7266219
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
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.javaagent.runtimemetrics.java17; | ||
|
||
import io.opentelemetry.instrumentation.testing.junit.AgentInstrumentationExtension; | ||
import io.opentelemetry.instrumentation.testing.junit.InstrumentationExtension; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.RegisterExtension; | ||
|
||
public class JmxRuntimeMetricsTest { | ||
|
||
@RegisterExtension | ||
static final InstrumentationExtension testing = AgentInstrumentationExtension.create(); | ||
|
||
@Test | ||
void runtimeMetricsAreEnabled() { | ||
// Force a gc to "ensure" gc metrics | ||
System.gc(); | ||
|
||
testing.waitAndAssertMetrics( | ||
"io.opentelemetry.runtime-telemetry-java8", | ||
metric -> metric.hasName("process.runtime.jvm.classes.loaded"), | ||
metric -> metric.hasName("process.runtime.jvm.classes.unloaded"), | ||
metric -> metric.hasName("process.runtime.jvm.classes.current_loaded"), | ||
metric -> metric.hasName("process.runtime.jvm.system.cpu.load_1m"), | ||
metric -> metric.hasName("process.runtime.jvm.system.cpu.utilization"), | ||
metric -> metric.hasName("process.runtime.jvm.cpu.utilization"), | ||
metric -> metric.hasName("process.runtime.jvm.gc.duration"), | ||
metric -> metric.hasName("process.runtime.jvm.memory.init"), | ||
metric -> metric.hasName("process.runtime.jvm.memory.usage"), | ||
metric -> metric.hasName("process.runtime.jvm.memory.committed"), | ||
metric -> metric.hasName("process.runtime.jvm.memory.limit"), | ||
metric -> metric.hasName("process.runtime.jvm.memory.usage_after_last_gc"), | ||
metric -> metric.hasName("process.runtime.jvm.threads.count"), | ||
metric -> metric.hasName("process.runtime.jvm.buffer.limit"), | ||
metric -> metric.hasName("process.runtime.jvm.buffer.count"), | ||
metric -> metric.hasName("process.runtime.jvm.buffer.usage")); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -18,12 +18,16 @@ | |||||
import io.opentelemetry.sdk.OpenTelemetrySdk; | ||||||
import io.opentelemetry.sdk.logs.data.LogRecordData; | ||||||
import io.opentelemetry.sdk.metrics.data.MetricData; | ||||||
import io.opentelemetry.sdk.testing.assertj.MetricAssert; | ||||||
import io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions; | ||||||
import io.opentelemetry.sdk.testing.assertj.TraceAssert; | ||||||
import io.opentelemetry.sdk.trace.data.SpanData; | ||||||
import java.time.Duration; | ||||||
import java.util.Collection; | ||||||
import java.util.Comparator; | ||||||
import java.util.List; | ||||||
import java.util.function.Consumer; | ||||||
import java.util.stream.Collectors; | ||||||
import org.assertj.core.api.ListAssert; | ||||||
import org.junit.jupiter.api.extension.AfterAllCallback; | ||||||
import org.junit.jupiter.api.extension.AfterEachCallback; | ||||||
|
@@ -76,6 +80,13 @@ public List<MetricData> metrics() { | |||||
return testRunner.getExportedMetrics(); | ||||||
} | ||||||
|
||||||
/** Returns a list of metrics, filtered by instrumentation name */ | ||||||
public List<MetricData> instrumentationMetrics(String instrumentationName) { | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We don't have analogous methods for any other signal; and it's only used in this class. WDYT about making it private?
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I intended it to be a public helper, analogous to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's make it private -- there's just one use case for that now; and I think all 3 signals should have very similar API, so if we're introducing some new thing here we should do similar thing everywhere. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ok I relent. :) I think you have a higher standard for test code than I do. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hah, I'm just thinking that YAGNI (probably) when it comes to making that method public |
||||||
return metrics().stream() | ||||||
.filter(m -> m.getInstrumentationScopeInfo().getName().equals(instrumentationName)) | ||||||
.collect(Collectors.toList()); | ||||||
} | ||||||
|
||||||
/** Return a list of all captured logs. */ | ||||||
public List<LogRecordData> logRecords() { | ||||||
return testRunner.getExportedLogRecords(); | ||||||
|
@@ -100,6 +111,22 @@ public void waitAndAssertMetrics( | |||||
&& data.getName().equals(metricName)))); | ||||||
} | ||||||
|
||||||
@SafeVarargs | ||||||
public final void waitAndAssertMetrics( | ||||||
String instrumentationName, Consumer<MetricAssert>... assertions) { | ||||||
await() | ||||||
.untilAsserted( | ||||||
() -> { | ||||||
Collection<MetricData> metrics = instrumentationMetrics(instrumentationName); | ||||||
assertThat(metrics).isNotEmpty(); | ||||||
for (Consumer<MetricAssert> assertion : assertions) { | ||||||
assertThat(metrics) | ||||||
.anySatisfy( | ||||||
metric -> assertion.accept(OpenTelemetryAssertions.assertThat(metric))); | ||||||
} | ||||||
}); | ||||||
} | ||||||
|
||||||
/** | ||||||
* Removes all captured telemetry data. After calling this method {@link #spans()} and {@link | ||||||
* #metrics()} will return empty lists until more telemetry data is captured. | ||||||
|
Uh oh!
There was an error while loading. Please reload this page.