Skip to content

Commit

Permalink
Replace jfr-streaming with opentelemetry-jfr-connection (#3803)
Browse files Browse the repository at this point in the history
  • Loading branch information
jeanbisutti authored Jul 24, 2024
1 parent d381258 commit 66d4b62
Show file tree
Hide file tree
Showing 7 changed files with 63 additions and 68 deletions.
2 changes: 1 addition & 1 deletion agent/agent-tooling/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ dependencies {
compileOnly("com.google.auto.value:auto-value-annotations")
annotationProcessor("com.google.auto.value:auto-value")

implementation("com.microsoft.jfr:jfr-streaming")
implementation("io.opentelemetry.contrib:opentelemetry-jfr-connection:1.37.0-alpha")
implementation("com.azure:azure-storage-blob")

implementation(project(":agent:agent-profiler:agent-alerting-api"))
Expand Down
2 changes: 1 addition & 1 deletion agent/agent-tooling/gradle.lockfile
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ com.github.stephenc.jcip:jcip-annotations:1.0-1=runtimeClasspath
com.google.errorprone:error_prone_annotations:2.29.2=runtimeClasspath
com.microsoft.azure:msal4j-persistence-extension:1.3.0=runtimeClasspath
com.microsoft.azure:msal4j:1.15.1=runtimeClasspath
com.microsoft.jfr:jfr-streaming:1.2.0=runtimeClasspath
com.nimbusds:content-type:2.3=runtimeClasspath
com.nimbusds:lang-tag:1.7=runtimeClasspath
com.nimbusds:nimbus-jose-jwt:9.37.3=runtimeClasspath
Expand Down Expand Up @@ -55,6 +54,7 @@ io.netty:netty-transport-native-epoll:4.1.112.Final=runtimeClasspath
io.netty:netty-transport-native-kqueue:4.1.112.Final=runtimeClasspath
io.netty:netty-transport-native-unix-common:4.1.112.Final=runtimeClasspath
io.netty:netty-transport:4.1.112.Final=runtimeClasspath
io.opentelemetry.contrib:opentelemetry-jfr-connection:1.37.0-alpha=runtimeClasspath
io.opentelemetry.instrumentation:opentelemetry-instrumentation-bom-alpha:2.6.0-alpha=runtimeClasspath
io.opentelemetry.instrumentation:opentelemetry-instrumentation-bom:2.6.0=runtimeClasspath
io.opentelemetry.semconv:opentelemetry-semconv-incubating:1.25.0-alpha=runtimeClasspath
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@

import com.microsoft.applicationinsights.agent.internal.configuration.Configuration;
import com.microsoft.applicationinsights.alerting.config.AlertMetricType;
import com.microsoft.jfr.RecordingConfiguration;
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import io.opentelemetry.contrib.jfr.connection.JfcFileConfiguration;
import io.opentelemetry.contrib.jfr.connection.RecordingConfiguration;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.InputStream;
Expand Down Expand Up @@ -34,11 +35,11 @@ private static RecordingConfiguration getRecordingConfiguration(
ProfileTypes profile, String reducedProfile, String diagnosticProfile) {
switch (profile) {
case PROFILE_WITHOUT_ENV_DATA:
return new RecordingConfiguration.JfcFileConfiguration(
return new JfcFileConfiguration(
Objects.requireNonNull(
AlternativeJfrConfigurations.class.getResourceAsStream(reducedProfile)));
case DIAGNOSTIC_PROFILE:
return new RecordingConfiguration.JfcFileConfiguration(
return new JfcFileConfiguration(
Objects.requireNonNull(
AlternativeJfrConfigurations.class.getResourceAsStream(diagnosticProfile)));
default:
Expand Down Expand Up @@ -79,7 +80,7 @@ private static RecordingConfiguration getRecordingConfiguration(
logger.warn(
"Diagnostics have been enabled, however a custom JFR config was provided. This is likely to prevent diagnostics from functioning");
}
return new RecordingConfiguration.JfcFileConfiguration(fis);
return new JfcFileConfiguration(fis);
}

try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,11 @@
import com.microsoft.applicationinsights.alerting.alert.AlertBreach;
import com.microsoft.applicationinsights.alerting.config.AlertConfiguration;
import com.microsoft.applicationinsights.alerting.config.AlertMetricType;
import com.microsoft.jfr.FlightRecorderConnection;
import com.microsoft.jfr.JfrStreamingException;
import com.microsoft.jfr.Recording;
import com.microsoft.jfr.RecordingConfiguration;
import com.microsoft.jfr.RecordingOptions;
import com.microsoft.jfr.dcmd.FlightRecorderDiagnosticCommandConnection;
import io.opentelemetry.contrib.jfr.connection.FlightRecorderConnection;
import io.opentelemetry.contrib.jfr.connection.JfrConnectionException;
import io.opentelemetry.contrib.jfr.connection.Recording;
import io.opentelemetry.contrib.jfr.connection.RecordingConfiguration;
import io.opentelemetry.contrib.jfr.connection.RecordingOptions;
import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileOutputStream;
Expand All @@ -30,7 +29,6 @@
import java.util.concurrent.TimeUnit;
import java.util.function.Consumer;
import javax.annotation.Nullable;
import javax.management.InstanceNotFoundException;
import javax.management.MBeanServerConnection;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand Down Expand Up @@ -91,8 +89,6 @@ public Profiler(Configuration.ProfilerConfiguration config, File tempDir) {
* Call init before run.
*
* @throws IOException Trouble communicating with MBean server
* @throws InstanceNotFoundException The JVM does not support JFR, or experimental option is not
* enabled.
*/
public void initialize(
UploadService uploadService, ScheduledExecutorService scheduledExecutorService)
Expand All @@ -107,9 +103,9 @@ public void initialize(
MBeanServerConnection mbeanServer = ManagementFactory.getPlatformMBeanServer();
try {
flightRecorderConnection = FlightRecorderConnection.connect(mbeanServer);
} catch (JfrStreamingException | InstanceNotFoundException jfrStreamingException) {
} catch (JfrConnectionException jfrConnectionException) {
// Possibly an older JVM, try using Diagnostic command
flightRecorderConnection = FlightRecorderDiagnosticCommandConnection.connect(mbeanServer);
flightRecorderConnection = FlightRecorderConnection.diagnosticCommandConnection(mbeanServer);
}
}

Expand Down Expand Up @@ -207,7 +203,7 @@ private void executeProfile(
logger.error("Failed to start JFR recording", ioException);
CompletableFuture<?> future = new CompletableFuture<>();
future.completeExceptionally(ioException);
} catch (JfrStreamingException internalError) {
} catch (JfrConnectionException internalError) {
logger.error("Internal JFR Error", internalError);
CompletableFuture<?> future = new CompletableFuture<>();
future.completeExceptionally(internalError);
Expand Down Expand Up @@ -246,26 +242,26 @@ private static void closeRecording(Recording recording, File recordingFile) {
recording.dump(recordingFile.getAbsolutePath());
} catch (IOException e) {
logger.error("Failed to close recording", e);
} catch (JfrStreamingException internalError) {
} catch (JfrConnectionException internalError) {
// Sometimes the mbean dump fails...Try alternative of streaming data out
try {
writeFileFromStream(recording, recordingFile);
} catch (IOException e) {
logger.error("Failed to close recording", e);
} catch (JfrStreamingException e) {
} catch (JfrConnectionException e) {
logger.error("Internal JFR Error", e);
}
} finally {
try {
recording.close();
} catch (IOException e) {
} catch (IOException | JfrConnectionException e) {
logger.error("Failed to close recording", e);
}
}
}

private static void writeFileFromStream(Recording recording, File recordingFile)
throws IOException, JfrStreamingException {
throws IOException, JfrConnectionException {
if (recordingFile.exists()) {
recordingFile.delete();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,13 @@ public class AlternativeJfrConfigurationsTest {
private static void assertForAllConfigs(
Configuration.ProfilerConfiguration config, Consumer<String> assertion) {

assertion.accept(AlternativeJfrConfigurations.getCpuProfileConfig(config).getConfiguration());
assertion.accept(AlternativeJfrConfigurations.getCpuProfileConfig(config).toString());

assertion.accept(
AlternativeJfrConfigurations.getMemoryProfileConfig(config).getConfiguration());
assertion.accept(AlternativeJfrConfigurations.getMemoryProfileConfig(config).toString());

assertion.accept(
AlternativeJfrConfigurations.getManualProfileConfig(config).getConfiguration());
assertion.accept(AlternativeJfrConfigurations.getManualProfileConfig(config).toString());

assertion.accept(AlternativeJfrConfigurations.getSpanProfileConfig(config).getConfiguration());
assertion.accept(AlternativeJfrConfigurations.getSpanProfileConfig(config).toString());
}

// To be able to remove sensitive events
Expand Down
2 changes: 1 addition & 1 deletion dependencyManagement/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ val DEPENDENCIES = listOf(
"org.assertj:assertj-core:3.26.3",
"org.awaitility:awaitility:4.2.1",
"io.github.hakky54:logcaptor:2.9.3",
"com.microsoft.jfr:jfr-streaming:1.2.0",
"io.opentelemetry.contrib:opentelemetry-jfr-connection:1.37.0-alpha",
"com.google.code.findbugs:jsr305:3.0.2",
"com.github.spotbugs:spotbugs-annotations:4.8.6"
)
Expand Down
Loading

0 comments on commit 66d4b62

Please sign in to comment.