Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix JarAnalyzer warnings on Payara #10458

Merged
merged 5 commits into from
Feb 12, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import static io.opentelemetry.instrumentation.javaagent.runtimemetrics.java8.JarDetails.EAR_EXTENSION;
import static io.opentelemetry.instrumentation.javaagent.runtimemetrics.java8.JarDetails.JAR_EXTENSION;
import static io.opentelemetry.instrumentation.javaagent.runtimemetrics.java8.JarDetails.WAR_EXTENSION;
import static java.util.logging.Level.FINE;

import io.opentelemetry.api.OpenTelemetry;
import io.opentelemetry.api.common.AttributeKey;
Expand All @@ -18,6 +19,7 @@
import io.opentelemetry.instrumentation.runtimemetrics.java8.internal.JmxRuntimeMetricsUtil;
import io.opentelemetry.sdk.common.Clock;
import io.opentelemetry.sdk.internal.DaemonThreadFactory;
import java.io.File;
import java.io.IOException;
import java.lang.instrument.ClassFileTransformer;
import java.net.URI;
Expand Down Expand Up @@ -108,7 +110,9 @@ private void handle(ProtectionDomain protectionDomain) {
try {
locationUri = archiveUrl.toURI();
} catch (URISyntaxException e) {
logger.log(Level.WARNING, "Unable to get URI for code location URL: " + archiveUrl, e);
if (logger.isLoggable(FINE)) {
logger.log(Level.WARNING, "Unable to get URI for code location URL: " + archiveUrl, e);
}
laurit marked this conversation as resolved.
Show resolved Hide resolved
return;
}

Expand All @@ -127,10 +131,30 @@ private void handle(ProtectionDomain protectionDomain) {
if (!file.endsWith(JAR_EXTENSION)
&& !file.endsWith(WAR_EXTENSION)
&& !file.endsWith(EAR_EXTENSION)) {
logger.log(Level.INFO, "Skipping processing unrecognized code location: {0}", archiveUrl);
if (logger.isLoggable(FINE)) {
logger.log(Level.INFO, "Skipping processing unrecognized code location: {0}", archiveUrl);
}
return;
}

// Payara 5 and 6 have url with file protocol that fail on openStream with
// java.io.IOException: no entry name specified
// at
// java.base/sun.net.www.protocol.jar.JarURLConnection.getInputStream(JarURLConnection.java:160)
// To avoid this here we recreate the URL when it points to a file.
if ("file".equals(archiveUrl.getProtocol())) {
try {
File archiveFile = new File(archiveUrl.toURI().getSchemeSpecificPart());
if (archiveFile.exists() && archiveFile.isFile()) {
archiveUrl = archiveFile.toURI().toURL();
}
} catch (Exception e) {
if (logger.isLoggable(FINE)) {
logger.log(Level.WARNING, "Unable to normalize location URL: " + archiveUrl, e);
}
}
}

// Only code locations with .jar and .war extension should make it here
toProcess.add(archiveUrl);
}
Expand Down Expand Up @@ -174,10 +198,14 @@ public void run() {
// events
processUrl(eventEmitter, archiveUrl);
} catch (Throwable e) {
logger.log(Level.WARNING, "Unexpected error processing archive URL: " + archiveUrl, e);
if (logger.isLoggable(FINE)) {
logger.log(Level.WARNING, "Unexpected error processing archive URL: " + archiveUrl, e);
}
}
}
logger.warning("JarAnalyzer stopped");
if (logger.isLoggable(FINE)) {
logger.warning("JarAnalyzer stopped");
}
}
}

Expand All @@ -190,7 +218,9 @@ static void processUrl(EventEmitter eventEmitter, URL archiveUrl) {
try {
jarDetails = JarDetails.forUrl(archiveUrl);
} catch (IOException e) {
logger.log(Level.WARNING, "Error reading package for archive URL: " + archiveUrl, e);
if (logger.isLoggable(FINE)) {
logger.log(Level.WARNING, "Error reading package for archive URL: " + archiveUrl, e);
}
return;
}
AttributesBuilder builder = Attributes.builder();
Expand Down
Loading