Skip to content

Commit bb538a6

Browse files
committed
Suppress warning for forbidden usage of System.out in tests
1 parent 9493a73 commit bb538a6

File tree

1 file changed

+36
-29
lines changed

1 file changed

+36
-29
lines changed

modules/ingest-otel/src/test/java/org/elasticsearch/ingest/otel/ResourceAttributesTests.java

Lines changed: 36 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
package org.elasticsearch.ingest.otel;
1111

12+
import org.elasticsearch.core.SuppressForbidden;
1213
import org.elasticsearch.test.ESTestCase;
1314

1415
import java.util.HashSet;
@@ -17,6 +18,7 @@
1718

1819
public class ResourceAttributesTests extends ESTestCase {
1920

21+
@SuppressForbidden(reason = "Used specifically for the output. Only meant to be run manually, not through CI.")
2022
public void testResourceAttributesWebCrawler() {
2123
Set<String> resourceAttributes = OTelSemConvWebCrawler.collectOTelSemConvResourceAttributes();
2224
System.out.println("Resource Attributes: " + resourceAttributes.size());
@@ -25,6 +27,7 @@ public void testResourceAttributesWebCrawler() {
2527
}
2628
}
2729

30+
@SuppressForbidden(reason = "Used specifically for the output. Only meant to be run manually, not through CI.")
2831
public void testEcsToOTelAttributeNames() {
2932
Map<String, String> attributes = EcsFieldsDiscoverer.getInstance().getEcsToOTelAttributeNames();
3033
System.out.println("ECS to OTel attribute mappings: " + attributes.size());
@@ -43,38 +46,42 @@ public void testAttributesSetUpToDate() {
4346
}
4447
});
4548
latestEcsOTelResourceAttributes.addAll(EcsFieldsDiscoverer.getInstance().getEcsResourceFields());
46-
if (latestEcsOTelResourceAttributes.equals(EcsOTelResourceAttributes.LATEST)) {
47-
System.out.println("ECS to OTel resource attributes are up to date.");
48-
} else {
49-
System.out.println("ECS to OTel resource attributes are not up to date.");
50-
// find and print the diff
51-
Set<String> addedAttributes = new HashSet<>(latestEcsOTelResourceAttributes);
52-
addedAttributes.removeAll(EcsOTelResourceAttributes.LATEST);
53-
if (addedAttributes.isEmpty() == false) {
54-
System.out.println();
55-
System.out.println("The current resource attributes set doesn't contain the following attributes:");
56-
System.out.println("-----------------------------------------------------------------------------");
57-
for (String attribute : addedAttributes) {
58-
System.out.println(attribute);
59-
}
60-
System.out.println("-----------------------------------------------------------------------------");
61-
System.out.println();
49+
boolean upToDate = latestEcsOTelResourceAttributes.equals(EcsOTelResourceAttributes.LATEST);
50+
if (upToDate == false) {
51+
printComparisonResults(latestEcsOTelResourceAttributes);
52+
}
53+
assertTrue("ECS-to-OTel resource attributes set is not up to date.", upToDate);
54+
}
55+
56+
@SuppressForbidden(reason = "Output is used for updating the resource attributes set, not running in the normal PR CI build pipeline")
57+
private static void printComparisonResults(Set<String> latestEcsOTelResourceAttributes) {
58+
// find and print the diff
59+
Set<String> addedAttributes = new HashSet<>(latestEcsOTelResourceAttributes);
60+
addedAttributes.removeAll(EcsOTelResourceAttributes.LATEST);
61+
if (addedAttributes.isEmpty() == false) {
62+
System.out.println();
63+
System.out.println("The current resource attributes set doesn't contain the following attributes:");
64+
System.out.println("-----------------------------------------------------------------------------");
65+
for (String attribute : addedAttributes) {
66+
System.out.println(attribute);
6267
}
63-
Set<String> removedAttributes = new HashSet<>(EcsOTelResourceAttributes.LATEST);
64-
removedAttributes.removeAll(latestEcsOTelResourceAttributes);
65-
if (removedAttributes.isEmpty() == false) {
66-
System.out.println();
67-
System.out.println("The following attributes are no longer considered resource attributes:");
68-
System.out.println("----------------------------------------------------------------------");
69-
for (String attribute : removedAttributes) {
70-
System.out.println(attribute);
71-
}
72-
System.out.println("----------------------------------------------------------------------");
73-
System.out.println();
68+
System.out.println("-----------------------------------------------------------------------------");
69+
System.out.println();
70+
}
71+
Set<String> removedAttributes = new HashSet<>(EcsOTelResourceAttributes.LATEST);
72+
removedAttributes.removeAll(latestEcsOTelResourceAttributes);
73+
if (removedAttributes.isEmpty() == false) {
74+
System.out.println();
75+
System.out.println("The following attributes are no longer considered resource attributes:");
76+
System.out.println("----------------------------------------------------------------------");
77+
for (String attribute : removedAttributes) {
78+
System.out.println(attribute);
7479
}
75-
System.out.println("Consider updating EcsOTelResourceAttributes accordingly");
80+
System.out.println("----------------------------------------------------------------------");
7681
System.out.println();
77-
fail("ECS to OTel resource attributes are not up to date");
7882
}
83+
System.out.println("Consider updating EcsOTelResourceAttributes accordingly");
84+
System.out.println();
85+
fail("ECS to OTel resource attributes are not up to date");
7986
}
8087
}

0 commit comments

Comments
 (0)