|
5 | 5 | import static io.restassured.RestAssured.given; |
6 | 6 | import static java.net.HttpURLConnection.HTTP_OK; |
7 | 7 | import static java.util.concurrent.TimeUnit.SECONDS; |
8 | | -import static org.assertj.core.api.AssertionsForClassTypes.assertThat; |
| 8 | +import static org.assertj.core.api.Assertions.assertThat; |
9 | 9 | import static org.awaitility.Awaitility.await; |
10 | 10 | import static org.junit.jupiter.api.Assertions.assertEquals; |
11 | 11 |
|
| 12 | +import java.util.HashSet; |
12 | 13 | import java.util.List; |
13 | 14 | import java.util.Map; |
14 | 15 | import java.util.Set; |
|
19 | 20 | import org.junit.jupiter.api.Test; |
20 | 21 |
|
21 | 22 | import io.opentelemetry.sdk.metrics.data.MetricDataType; |
| 23 | +import io.quarkus.test.common.JdkUtil; |
22 | 24 | import io.quarkus.test.junit.QuarkusTest; |
23 | 25 | import io.restassured.common.mapper.TypeRef; |
24 | 26 |
|
@@ -98,18 +100,17 @@ void testAllJvmMetrics() { |
98 | 100 |
|
99 | 101 | await().atMost(10, SECONDS).untilAsserted(() -> { |
100 | 102 | Set<String> allMetricNames = getAllMetricNames("jvm."); |
101 | | - assertThat(allMetricNames.size()) |
102 | | - .withFailMessage("The jvm metrics are " + allMetricNames) |
103 | | - .isGreaterThanOrEqualTo(allMetrics.size()); |
| 103 | + assertThat(allMetricNames) |
| 104 | + .containsAll(allMetrics.stream().map(MetricToAssert::name).toList()); |
104 | 105 | }); |
105 | 106 |
|
106 | 107 | allMetrics.forEach(metricToAssert -> { |
107 | 108 |
|
108 | 109 | // metric is there and has at least 1 reading |
109 | 110 | await().atMost(10, SECONDS) |
110 | | - .untilAsserted(() -> assertThat(getMetrics(metricToAssert.name()).size()) |
111 | | - .withFailMessage("The metric " + metricToAssert.name()) |
112 | | - .isGreaterThan(0)); |
| 111 | + .untilAsserted(() -> assertThat(getMetrics(metricToAssert.name())) |
| 112 | + .withFailMessage("The metric " + metricToAssert.name() + " is not defined") |
| 113 | + .hasSizeGreaterThan(0)); |
113 | 114 |
|
114 | 115 | // skip assertions from flaky metrics |
115 | 116 | if (!metricToAssert.name().equals("jvm.memory.used_after_last_gc") && |
@@ -164,40 +165,44 @@ record MetricToAssert(String name, String description, String metricUnit, Metric |
164 | 165 | } |
165 | 166 |
|
166 | 167 | protected Set<MetricToAssert> getJvmMetricsToAssert() { |
167 | | - return Set.of( |
168 | | - // new MetricToAssert("http.server.request.duration", "Duration of HTTP server requests.", "s", |
169 | | - // HISTOGRAM), // just because we generate load with HTTP |
170 | | - new MetricToAssert("jvm.memory.committed", "Measure of memory committed.", "By", LONG_SUM), |
171 | | - new MetricToAssert("jvm.memory.used", "Measure of memory used.", "By", LONG_SUM), |
172 | | - // Not on native |
173 | | - new MetricToAssert("jvm.memory.limit", "Measure of max obtainable memory.", "By", LONG_SUM), |
174 | | - new MetricToAssert("jvm.memory.used_after_last_gc", |
175 | | - "Measure of memory used, as measured after the most recent garbage collection event on this pool.", |
176 | | - "By", LONG_SUM), |
177 | | - // not on native |
178 | | - new MetricToAssert("jvm.gc.duration", "Duration of JVM garbage collection actions.", "s", |
179 | | - HISTOGRAM), |
180 | | - new MetricToAssert("jvm.class.count", "Number of classes currently loaded.", "{class}", |
181 | | - LONG_SUM), |
182 | | - new MetricToAssert("jvm.class.loaded", "Number of classes loaded since JVM start.", "{class}", |
183 | | - LONG_SUM), |
184 | | - new MetricToAssert("jvm.class.unloaded", "Number of classes unloaded since JVM start.", |
185 | | - "{class}", LONG_SUM), |
186 | | - new MetricToAssert("jvm.cpu.count", |
187 | | - "Number of processors available to the Java virtual machine.", "{cpu}", LONG_SUM), |
188 | | - new MetricToAssert("jvm.cpu.limit", "", "1", LONG_SUM), |
189 | | - //jvm.system.cpu.utilization instead, on native |
190 | | - new MetricToAssert("jvm.cpu.time", "CPU time used by the process as reported by the JVM.", "s", |
191 | | - DOUBLE_SUM), |
192 | | - new MetricToAssert("jvm.cpu.recent_utilization", |
193 | | - "Recent CPU utilization for the process as reported by the JVM.", "1", DOUBLE_GAUGE), |
194 | | - new MetricToAssert("jvm.cpu.longlock", "Long lock times", "s", HISTOGRAM), |
195 | | - new MetricToAssert("jvm.cpu.context_switch", "", "Hz", DOUBLE_SUM), |
196 | | - // not on native |
197 | | - new MetricToAssert("jvm.network.io", "Network read/write bytes.", "By", HISTOGRAM), |
198 | | - new MetricToAssert("jvm.network.time", "Network read/write duration.", "s", HISTOGRAM), |
199 | | - new MetricToAssert("jvm.thread.count", "Number of executing platform threads.", "{thread}", |
200 | | - LONG_SUM)); |
| 168 | + Set<MetricToAssert> jvmMetrics = new HashSet<>(); |
| 169 | + |
| 170 | + // metrics.add(new MetricToAssert("http.server.request.duration", "Duration of HTTP server requests.", "s", HISTOGRAM)); // just because we generate load with HTTP |
| 171 | + jvmMetrics.add(new MetricToAssert("jvm.memory.committed", "Measure of memory committed.", "By", LONG_SUM)); |
| 172 | + jvmMetrics.add(new MetricToAssert("jvm.memory.used", "Measure of memory used.", "By", LONG_SUM)); |
| 173 | + // Not on native |
| 174 | + jvmMetrics.add(new MetricToAssert("jvm.memory.limit", "Measure of max obtainable memory.", "By", LONG_SUM)); |
| 175 | + jvmMetrics.add(new MetricToAssert("jvm.memory.used_after_last_gc", |
| 176 | + "Measure of memory used, as measured after the most recent garbage collection event on this pool.", |
| 177 | + "By", LONG_SUM)); |
| 178 | + // not on native |
| 179 | + jvmMetrics.add(new MetricToAssert("jvm.gc.duration", "Duration of JVM garbage collection actions.", "s", HISTOGRAM)); |
| 180 | + jvmMetrics.add(new MetricToAssert("jvm.class.count", "Number of classes currently loaded.", "{class}", LONG_SUM)); |
| 181 | + jvmMetrics |
| 182 | + .add(new MetricToAssert("jvm.class.loaded", "Number of classes loaded since JVM start.", "{class}", LONG_SUM)); |
| 183 | + jvmMetrics.add( |
| 184 | + new MetricToAssert("jvm.class.unloaded", "Number of classes unloaded since JVM start.", "{class}", LONG_SUM)); |
| 185 | + jvmMetrics.add(new MetricToAssert("jvm.cpu.count", "Number of processors available to the Java virtual machine.", |
| 186 | + "{cpu}", LONG_SUM)); |
| 187 | + // jvm.system.cpu.utilization instead, on native |
| 188 | + jvmMetrics.add( |
| 189 | + new MetricToAssert("jvm.cpu.time", "CPU time used by the process as reported by the JVM.", "s", DOUBLE_SUM)); |
| 190 | + jvmMetrics.add(new MetricToAssert("jvm.cpu.recent_utilization", |
| 191 | + "Recent CPU utilization for the process as reported by the JVM.", "1", DOUBLE_GAUGE)); |
| 192 | + jvmMetrics.add(new MetricToAssert("jvm.thread.count", "Number of executing platform threads.", "{thread}", LONG_SUM)); |
| 193 | + |
| 194 | + // not supported on Semeru |
| 195 | + if (!JdkUtil.isSemeru()) { |
| 196 | + jvmMetrics.add(new MetricToAssert("jvm.cpu.limit", "", "1", LONG_SUM)); |
| 197 | + jvmMetrics.add(new MetricToAssert("jvm.cpu.longlock", "Long lock times", "s", HISTOGRAM)); |
| 198 | + jvmMetrics.add(new MetricToAssert("jvm.cpu.context_switch", "", "Hz", DOUBLE_SUM)); |
| 199 | + |
| 200 | + // not on native |
| 201 | + jvmMetrics.add(new MetricToAssert("jvm.network.io", "Network read/write bytes.", "By", HISTOGRAM)); |
| 202 | + jvmMetrics.add(new MetricToAssert("jvm.network.time", "Network read/write duration.", "s", HISTOGRAM)); |
| 203 | + } |
| 204 | + |
| 205 | + return jvmMetrics; |
201 | 206 | } |
202 | 207 |
|
203 | 208 | private Double getLastReading(MetricToAssert metricToAssert) { |
|
0 commit comments