|
| 1 | +/* |
| 2 | + * Copyright Amazon.com, Inc. or its affiliates. |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"). |
| 5 | + * You may not use this file except in compliance with the License. |
| 6 | + * A copy of the License is located at |
| 7 | + * |
| 8 | + * http://aws.amazon.com/apache2.0 |
| 9 | + * |
| 10 | + * or in the "license" file accompanying this file. This file is distributed |
| 11 | + * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either |
| 12 | + * express or implied. See the License for the specific language governing |
| 13 | + * permissions and limitations under the License. |
| 14 | + */ |
| 15 | + |
1 | 16 | package software.amazon.opentelemetry.appsignals.test.misc; |
2 | 17 |
|
| 18 | +import static org.assertj.core.api.Assertions.assertThat; |
| 19 | + |
3 | 20 | import io.opentelemetry.proto.metrics.v1.NumberDataPoint; |
| 21 | +import java.util.List; |
| 22 | +import java.util.Set; |
4 | 23 | import org.junit.Assert; |
5 | 24 | import org.junit.jupiter.api.Nested; |
6 | 25 | import org.junit.jupiter.api.Test; |
|
9 | 28 | import software.amazon.opentelemetry.appsignals.test.base.ContractTestBase; |
10 | 29 | import software.amazon.opentelemetry.appsignals.test.utils.AppSignalsConstants; |
11 | 30 |
|
12 | | -import java.util.List; |
13 | | -import java.util.Set; |
14 | | - |
15 | | -import static org.assertj.core.api.Assertions.assertThat; |
16 | | - |
17 | 31 | public class RuntimeMetricsTest { |
18 | | - private abstract static class RuntimeMetricsContractTestBase extends ContractTestBase { |
19 | | - @Override |
20 | | - protected String getApplicationImageName() { |
21 | | - return "aws-appsignals-tests-http-server-spring-mvc"; |
22 | | - } |
| 32 | + private abstract static class RuntimeMetricsContractTestBase extends ContractTestBase { |
| 33 | + @Override |
| 34 | + protected String getApplicationImageName() { |
| 35 | + return "aws-appsignals-tests-http-server-spring-mvc"; |
| 36 | + } |
| 37 | + |
| 38 | + @Override |
| 39 | + protected String isRuntimeEnabled() { |
| 40 | + return "true"; |
| 41 | + } |
23 | 42 |
|
24 | | - @Override |
25 | | - protected String isRuntimeEnabled() { return "true"; } |
| 43 | + protected String getApplicationWaitPattern() { |
| 44 | + return ".*Started Application.*"; |
| 45 | + } |
26 | 46 |
|
27 | | - protected String getApplicationWaitPattern() { |
28 | | - return ".*Started Application.*"; |
29 | | - } |
| 47 | + protected void doTestRuntimeMetrics() { |
| 48 | + var response = appClient.get("/success").aggregate().join(); |
30 | 49 |
|
31 | | - protected void doTestRuntimeMetrics() { |
32 | | - var response = appClient.get("/success").aggregate().join(); |
| 50 | + assertThat(response.status().isSuccess()).isTrue(); |
| 51 | + assertRuntimeMetrics(); |
| 52 | + } |
33 | 53 |
|
34 | | - assertThat(response.status().isSuccess()).isTrue(); |
35 | | - assertRuntimeMetrics(); |
36 | | - } |
37 | | - protected void assertRuntimeMetrics() { |
38 | | - var metrics = |
39 | | - mockCollectorClient.getRuntimeMetrics( |
40 | | - Set.of( |
41 | | - AppSignalsConstants.JVM_GC_METRIC, |
42 | | - AppSignalsConstants.JVM_GC_COUNT, |
43 | | - AppSignalsConstants.JVM_HEAP_USED, |
44 | | - AppSignalsConstants.JVM_NON_HEAP_USED, |
45 | | - AppSignalsConstants.JVM_AFTER_GC, |
46 | | - AppSignalsConstants.JVM_POOL_USED, |
47 | | - AppSignalsConstants.JVM_THREAD_COUNT, |
48 | | - AppSignalsConstants.JVM_CLASS_LOADED, |
49 | | - AppSignalsConstants.JVM_CPU_TIME, |
50 | | - AppSignalsConstants.JVM_CPU_UTILIZATION, |
51 | | - AppSignalsConstants.LATENCY_METRIC, |
52 | | - AppSignalsConstants.ERROR_METRIC, |
53 | | - AppSignalsConstants.FAULT_METRIC |
54 | | - )); |
55 | | - metrics.forEach(metric -> { |
56 | | - var dataPoints = metric.getMetric().getGauge().getDataPointsList(); |
57 | | - assertNonNegativeValue(dataPoints); |
58 | | - }); |
59 | | - } |
| 54 | + protected void assertRuntimeMetrics() { |
| 55 | + var metrics = |
| 56 | + mockCollectorClient.getRuntimeMetrics( |
| 57 | + Set.of( |
| 58 | + AppSignalsConstants.JVM_GC_METRIC, |
| 59 | + AppSignalsConstants.JVM_GC_COUNT, |
| 60 | + AppSignalsConstants.JVM_HEAP_USED, |
| 61 | + AppSignalsConstants.JVM_NON_HEAP_USED, |
| 62 | + AppSignalsConstants.JVM_AFTER_GC, |
| 63 | + AppSignalsConstants.JVM_POOL_USED, |
| 64 | + AppSignalsConstants.JVM_THREAD_COUNT, |
| 65 | + AppSignalsConstants.JVM_CLASS_LOADED, |
| 66 | + AppSignalsConstants.JVM_CPU_TIME, |
| 67 | + AppSignalsConstants.JVM_CPU_UTILIZATION, |
| 68 | + AppSignalsConstants.LATENCY_METRIC, |
| 69 | + AppSignalsConstants.ERROR_METRIC, |
| 70 | + AppSignalsConstants.FAULT_METRIC)); |
| 71 | + metrics.forEach( |
| 72 | + metric -> { |
| 73 | + var dataPoints = metric.getMetric().getGauge().getDataPointsList(); |
| 74 | + assertNonNegativeValue(dataPoints); |
| 75 | + }); |
| 76 | + } |
60 | 77 |
|
61 | | - private void assertNonNegativeValue(List<NumberDataPoint> dps) { |
62 | | - dps.forEach(datapoint -> { |
63 | | - Assert.assertTrue(datapoint.getAsInt() >= 0); |
64 | | - }); |
65 | | - } |
| 78 | + private void assertNonNegativeValue(List<NumberDataPoint> dps) { |
| 79 | + dps.forEach( |
| 80 | + datapoint -> { |
| 81 | + Assert.assertTrue(datapoint.getAsInt() >= 0); |
| 82 | + }); |
66 | 83 | } |
| 84 | + } |
67 | 85 |
|
68 | | - @Testcontainers(disabledWithoutDocker = true) |
69 | | - @TestInstance(TestInstance.Lifecycle.PER_CLASS) |
70 | | - @Nested |
71 | | - class ValidateRuntimeMetricsTest extends RuntimeMetricsContractTestBase { |
72 | | - @Test |
73 | | - void testRuntimeMetrics() { |
74 | | - doTestRuntimeMetrics(); |
75 | | - } |
| 86 | + @Testcontainers(disabledWithoutDocker = true) |
| 87 | + @TestInstance(TestInstance.Lifecycle.PER_CLASS) |
| 88 | + @Nested |
| 89 | + class ValidateRuntimeMetricsTest extends RuntimeMetricsContractTestBase { |
| 90 | + @Test |
| 91 | + void testRuntimeMetrics() { |
| 92 | + doTestRuntimeMetrics(); |
76 | 93 | } |
| 94 | + } |
77 | 95 | } |
0 commit comments