Skip to content

Commit 6eac60e

Browse files
committed
fix format issues
1 parent db02416 commit 6eac60e

File tree

3 files changed

+102
-78
lines changed

3 files changed

+102
-78
lines changed

appsignals-tests/contract-tests/src/test/java/software/amazon/opentelemetry/appsignals/test/base/ContractTestBase.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,5 +161,7 @@ protected String getApplicationOtelResourceAttributes() {
161161
return "service.name=" + getApplicationOtelServiceName();
162162
}
163163

164-
protected String isRuntimeEnabled() { return "false"; }
164+
protected String isRuntimeEnabled() {
165+
return "false";
166+
}
165167
}
Lines changed: 74 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,25 @@
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+
116
package software.amazon.opentelemetry.appsignals.test.misc;
217

18+
import static org.assertj.core.api.Assertions.assertThat;
19+
320
import io.opentelemetry.proto.metrics.v1.NumberDataPoint;
21+
import java.util.List;
22+
import java.util.Set;
423
import org.junit.Assert;
524
import org.junit.jupiter.api.Nested;
625
import org.junit.jupiter.api.Test;
@@ -9,69 +28,68 @@
928
import software.amazon.opentelemetry.appsignals.test.base.ContractTestBase;
1029
import software.amazon.opentelemetry.appsignals.test.utils.AppSignalsConstants;
1130

12-
import java.util.List;
13-
import java.util.Set;
14-
15-
import static org.assertj.core.api.Assertions.assertThat;
16-
1731
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+
}
2342

24-
@Override
25-
protected String isRuntimeEnabled() { return "true"; }
43+
protected String getApplicationWaitPattern() {
44+
return ".*Started Application.*";
45+
}
2646

27-
protected String getApplicationWaitPattern() {
28-
return ".*Started Application.*";
29-
}
47+
protected void doTestRuntimeMetrics() {
48+
var response = appClient.get("/success").aggregate().join();
3049

31-
protected void doTestRuntimeMetrics() {
32-
var response = appClient.get("/success").aggregate().join();
50+
assertThat(response.status().isSuccess()).isTrue();
51+
assertRuntimeMetrics();
52+
}
3353

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+
}
6077

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+
});
6683
}
84+
}
6785

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();
7693
}
94+
}
7795
}

appsignals-tests/contract-tests/src/test/java/software/amazon/opentelemetry/appsignals/test/utils/MockCollectorClient.java

Lines changed: 25 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@ public List<ResourceScopeSpan> getTraces() {
132132
.map(x -> new ResourceScopeSpan(ss.getFirst(), ss.getSecond(), x)))
133133
.collect(toImmutableList());
134134
}
135+
135136
public List<ResourceScopeMetric> getRuntimeMetrics(Set<String> presentMetrics) {
136137
return fetchMetrics(presentMetrics, true);
137138
}
@@ -148,29 +149,32 @@ public List<ResourceScopeMetric> getMetrics(Set<String> presentMetrics) {
148149
*/
149150
private List<ResourceScopeMetric> fetchMetrics(Set<String> presentMetrics, boolean isRuntime) {
150151
List<ExportMetricsServiceRequest> exportedMetrics =
151-
waitForContent(
152-
"/get-metrics",
153-
EXPORT_METRICS_SERVICE_REQUEST_LIST,
154-
(exported, current) -> {
155-
Set<String> receivedMetrics =
156-
current.stream()
157-
.flatMap(x -> x.getResourceMetricsList().stream())
158-
.flatMap(x -> x.getScopeMetricsList().stream())
159-
.flatMap(x -> x.getMetricsList().stream())
160-
.map(x -> x.getName())
161-
.collect(Collectors.toSet());
162-
163-
return (isRuntime ? !exported.isEmpty() && receivedMetrics.size() == presentMetrics.size() : !exported.isEmpty() && current.size() == exported.size())
164-
&& receivedMetrics.containsAll(presentMetrics);
165-
});
152+
waitForContent(
153+
"/get-metrics",
154+
EXPORT_METRICS_SERVICE_REQUEST_LIST,
155+
(exported, current) -> {
156+
Set<String> receivedMetrics =
157+
current.stream()
158+
.flatMap(x -> x.getResourceMetricsList().stream())
159+
.flatMap(x -> x.getScopeMetricsList().stream())
160+
.flatMap(x -> x.getMetricsList().stream())
161+
.map(x -> x.getName())
162+
.collect(Collectors.toSet());
163+
164+
return (isRuntime
165+
? !exported.isEmpty() && receivedMetrics.size() == presentMetrics.size()
166+
: !exported.isEmpty() && current.size() == exported.size())
167+
&& receivedMetrics.containsAll(presentMetrics);
168+
});
166169

167170
return exportedMetrics.stream()
168-
.flatMap(req -> req.getResourceMetricsList().stream())
169-
.flatMap(rm -> rm.getScopeMetricsList().stream().map(x -> new Pair<>(rm, x)))
170-
.flatMap(sm ->
171-
sm.getSecond().getMetricsList().stream()
172-
.map(x -> new ResourceScopeMetric(sm.getFirst(), sm.getSecond(), x)))
173-
.collect(toImmutableList());
171+
.flatMap(req -> req.getResourceMetricsList().stream())
172+
.flatMap(rm -> rm.getScopeMetricsList().stream().map(x -> new Pair<>(rm, x)))
173+
.flatMap(
174+
sm ->
175+
sm.getSecond().getMetricsList().stream()
176+
.map(x -> new ResourceScopeMetric(sm.getFirst(), sm.getSecond(), x)))
177+
.collect(toImmutableList());
174178
}
175179

176180
private <T> List<T> waitForContent(String url, TypeReference<List<T>> t) {

0 commit comments

Comments
 (0)