Skip to content

Commit e7c1f9d

Browse files
committed
Eliminating some more forbidden APIs
1 parent bb538a6 commit e7c1f9d

File tree

4 files changed

+34
-21
lines changed

4 files changed

+34
-21
lines changed

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

Lines changed: 27 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99

1010
package org.elasticsearch.ingest.otel;
1111

12+
import org.apache.logging.log4j.LogManager;
13+
import org.apache.logging.log4j.Logger;
1214
import org.elasticsearch.xcontent.XContentFactory;
1315
import org.elasticsearch.xcontent.XContentParser;
1416
import org.elasticsearch.xcontent.XContentParserConfiguration;
@@ -44,6 +46,8 @@ class OTelSemConvWebCrawler {
4446

4547
private static final String GITHUB_TOKEN = System.getenv("GITHUB_TOKEN");
4648

49+
private static final Logger logger = LogManager.getLogger(OTelSemConvWebCrawler.class);
50+
4751
/**
4852
* Relies on GitHub API to crawl the OpenTelemetry semantic conventions repo.
4953
* This method blocks until all resource attributes are collected, which may take a while.
@@ -142,15 +146,15 @@ private static Stream<String> findAllYamlFiles(HttpClient client) {
142146
}
143147
}
144148
} else if (response.statusCode() == 403) {
145-
System.err.println(
149+
logger.error(
146150
"GitHub API rate limit exceeded. "
147151
+ "Please provide a GitHub token via GITHUB_TOKEN environment variable"
148152
);
149153
} else {
150-
System.err.println("GitHub API request failed: HTTP " + response.statusCode());
154+
logErrorHttpStatusCode(response);
151155
}
152156
} catch (IOException e) {
153-
System.err.println("Error processing response: " + e.getMessage());
157+
logger.error("Error processing response: {}", e.getMessage());
154158
}
155159
return null;
156160
});
@@ -204,6 +208,10 @@ public boolean tryAdvance(Consumer<? super String> action) {
204208
});
205209
}
206210

211+
private static void logErrorHttpStatusCode(HttpResponse<InputStream> response) {
212+
logger.error("GitHub API request failed: HTTP {}", response.statusCode());
213+
}
214+
207215
private static CompletableFuture<Set<String>> extractResourceAttributesFromFile(String fileDownloadUrl, HttpClient httpClient) {
208216
return downloadAndParseYaml(fileDownloadUrl, httpClient).thenApply(yamlData -> {
209217
Set<String> resourceAttributes = new HashSet<>();
@@ -261,21 +269,22 @@ private static HttpRequest createRequest(String currentUrl) {
261269
private static CompletableFuture<Map<String, Object>> downloadAndParseYaml(String rawFileUrl, HttpClient client) {
262270
HttpRequest request = HttpRequest.newBuilder(URI.create(rawFileUrl)).build();
263271
CompletableFuture<HttpResponse<InputStream>> responseFuture = client.sendAsync(request, HttpResponse.BodyHandlers.ofInputStream());
264-
return responseFuture.thenApply(response -> {
265-
try (
266-
InputStream inputStream = response.body();
267-
XContentParser parser = XContentFactory.xContent(XContentType.YAML)
268-
.createParser(XContentParserConfiguration.EMPTY, inputStream)
269-
) {
270-
return parser.map();
271-
} catch (IOException e) {
272-
System.err.println("Error parsing YAML file: " + e.getMessage());
273-
return Map.of();
274-
} finally {
275-
if (response.statusCode() != 200) {
276-
System.err.println("GitHub API request failed: HTTP " + response.statusCode());
277-
}
272+
return responseFuture.thenApply(OTelSemConvWebCrawler::apply);
273+
}
274+
275+
private static Map<String, Object> apply(HttpResponse<InputStream> response) {
276+
try (
277+
InputStream inputStream = response.body();
278+
XContentParser parser = XContentFactory.xContent(XContentType.YAML).createParser(XContentParserConfiguration.EMPTY, inputStream)
279+
) {
280+
return parser.map();
281+
} catch (IOException e) {
282+
logger.error("Error parsing YAML file: {}", e.getMessage());
283+
return Map.of();
284+
} finally {
285+
if (response.statusCode() != 200) {
286+
logErrorHttpStatusCode(response);
278287
}
279-
});
288+
}
280289
}
281290
}

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,13 @@
1111

1212
import org.elasticsearch.core.SuppressForbidden;
1313
import org.elasticsearch.test.ESTestCase;
14+
import org.junit.Ignore;
1415

1516
import java.util.HashSet;
1617
import java.util.Map;
1718
import java.util.Set;
1819

20+
//@Ignore
1921
public class ResourceAttributesTests extends ESTestCase {
2022

2123
@SuppressForbidden(reason = "Used specifically for the output. Only meant to be run manually, not through CI.")
@@ -53,7 +55,9 @@ public void testAttributesSetUpToDate() {
5355
assertTrue("ECS-to-OTel resource attributes set is not up to date.", upToDate);
5456
}
5557

56-
@SuppressForbidden(reason = "Output is used for updating the resource attributes set, not running in the normal PR CI build pipeline")
58+
@SuppressForbidden(
59+
reason = "Output is used for updating the resource attributes set. Running nightly and only prints when not up to date."
60+
)
5761
private static void printComparisonResults(Set<String> latestEcsOTelResourceAttributes) {
5862
// find and print the diff
5963
Set<String> addedAttributes = new HashSet<>(latestEcsOTelResourceAttributes);

server/src/internalClusterTest/java/org/elasticsearch/versioning/ConcurrentSeqNoVersioningIT.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -683,7 +683,7 @@ private static LinearizabilityChecker.Event readEvent(StreamInput input) throws
683683
@SuppressForbidden(reason = "system err is ok for a command line tool")
684684
public static void main(String[] args) throws Exception {
685685
if (args.length < 3) {
686-
System.err.println("usage: <file> <primaryTerm> <seqNo>");
686+
logger.error("usage: <file> <primaryTerm> <seqNo>");
687687
} else {
688688
runLinearizabilityChecker(new FileInputStream(args[0]), Long.parseLong(args[1]), Long.parseLong(args[2]));
689689
}

x-pack/plugin/esql/compute/src/test/java/org/elasticsearch/compute/operator/mvdedupe/MultivalueDedupeTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -465,7 +465,7 @@ private void assertLookup(
465465
for (int i = start; i < end; i++) {
466466
actualValues.add(valueLookup.apply(lookup.getInt(i) - 1));
467467
}
468-
// System.err.println(actualValues + " " +
468+
// logger.error(actualValues + " " +
469469
// v.stream().filter(contained::contains).collect(Collectors.toCollection(TreeSet::new)));
470470
assertThat(actualValues, equalTo(v.stream().filter(contained::contains).collect(Collectors.toCollection(TreeSet::new))));
471471
}

0 commit comments

Comments
 (0)