Skip to content

Commit ac0af6e

Browse files
authored
Merge branch 'main' into dependabot/gradle/org.junit-junit-bom-5.14.2
2 parents 5e86d80 + ec4fba8 commit ac0af6e

68 files changed

Lines changed: 1764 additions & 343 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/build-common.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ jobs:
120120
${{ inputs.no-build-cache && '--no-build-cache' || '' }}
121121
122122
- name: Upload snapshot
123-
uses: actions/upload-artifact@v6
123+
uses: actions/upload-artifact@v7
124124
with:
125125
path: agent/agent/build/libs/applicationinsights-agent-*-SNAPSHOT.jar
126126

@@ -254,7 +254,7 @@ jobs:
254254
echo "UPLOAD_ARTIFACT_NAME=$artifact_name" >> $GITHUB_ENV
255255
256256
- name: Upload smoke test reports
257-
uses: actions/upload-artifact@v6
257+
uses: actions/upload-artifact@v7
258258
if: failure()
259259
with:
260260
name: ${{ env.UPLOAD_ARTIFACT_NAME }}

.github/workflows/owasp-dependency-check-daily.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ jobs:
2828

2929
- name: Upload report
3030
if: always()
31-
uses: actions/upload-artifact@v6
31+
uses: actions/upload-artifact@v7
3232
with:
3333
path: agent/agent/build/reports
3434

.github/workflows/release.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ jobs:
4646
else
4747
opt_prerelease="--prerelease"
4848
fi
49-
gh release create --target HEAD \
49+
gh release create --target main \
5050
--title "Application Insights Java $VERSION$opt_ga" \
5151
--notes-file /tmp/release-notes.txt \
5252
$opt_prerelease \

agent/agent-gc-monitor/gc-monitor-api/gradle.lockfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
# This file is expected to be part of source control.
44
com.azure:azure-sdk-bom:1.3.3=runtimeClasspath
55
com.fasterxml.jackson:jackson-bom:2.20.1=runtimeClasspath
6-
com.google.errorprone:error_prone_annotations:2.44.0=runtimeClasspath
6+
com.google.errorprone:error_prone_annotations:2.46.0=runtimeClasspath
77
io.netty:netty-bom:4.2.9.Final=runtimeClasspath
88
io.opentelemetry.instrumentation:opentelemetry-instrumentation-bom-alpha:2.21.0-alpha=runtimeClasspath
99
io.opentelemetry.instrumentation:opentelemetry-instrumentation-bom:2.21.0=runtimeClasspath

agent/agent-gc-monitor/gc-monitor-core/gradle.lockfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
# This file is expected to be part of source control.
44
com.azure:azure-sdk-bom:1.3.3=runtimeClasspath
55
com.fasterxml.jackson:jackson-bom:2.20.1=runtimeClasspath
6-
com.google.errorprone:error_prone_annotations:2.44.0=runtimeClasspath
6+
com.google.errorprone:error_prone_annotations:2.46.0=runtimeClasspath
77
io.netty:netty-bom:4.2.9.Final=runtimeClasspath
88
io.opentelemetry.instrumentation:opentelemetry-instrumentation-bom-alpha:2.21.0-alpha=runtimeClasspath
99
io.opentelemetry.instrumentation:opentelemetry-instrumentation-bom:2.21.0=runtimeClasspath

agent/agent-profiler/agent-diagnostics-api/src/main/java/com/microsoft/applicationinsights/diagnostics/DiagnosticEngineFactory.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,14 @@
44
package com.microsoft.applicationinsights.diagnostics;
55

66
import java.util.concurrent.ScheduledExecutorService;
7+
import javax.annotation.Nullable;
78

89
/**
910
* Factory to be invoked to create a DiagnosticEngine. This factory will be service loaded by the
1011
* agent and invoked. It is up to the provider of a DiagnosticEngine to provide a service loader for
1112
* this interface.
1213
*/
1314
public interface DiagnosticEngineFactory {
14-
DiagnosticEngine create(ScheduledExecutorService executorService);
15+
DiagnosticEngine create(
16+
ScheduledExecutorService executorService, @Nullable String cgroupBasePath);
1517
}

agent/agent-profiler/agent-diagnostics/src/main/java/com/microsoft/applicationinsights/diagnostics/appinsights/CodeOptimizerApplicationInsightFactoryJfr.java

Lines changed: 47 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,58 @@
66
import com.google.auto.service.AutoService;
77
import com.microsoft.applicationinsights.diagnostics.DiagnosticEngine;
88
import com.microsoft.applicationinsights.diagnostics.DiagnosticEngineFactory;
9+
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
10+
import java.nio.file.Files;
11+
import java.nio.file.Path;
12+
import java.nio.file.Paths;
913
import java.util.concurrent.ScheduledExecutorService;
14+
import javax.annotation.Nullable;
15+
import org.slf4j.Logger;
16+
import org.slf4j.LoggerFactory;
1017

1118
/** Factory for Code Optimizer diagnostics to be service loaded */
1219
@AutoService(DiagnosticEngineFactory.class)
1320
public class CodeOptimizerApplicationInsightFactoryJfr implements DiagnosticEngineFactory {
21+
22+
private static final Path FILE_SYSTEM_ROOT =
23+
Paths.get(System.getProperty("applicationinsights.profiler.filesystemRoot", "/"));
24+
private static final Path CGROUP_DIR = Paths.get("./sys/fs/cgroup");
25+
26+
private static final Logger logger =
27+
LoggerFactory.getLogger(CodeOptimizerApplicationInsightFactoryJfr.class);
28+
1429
@Override
15-
public DiagnosticEngine create(ScheduledExecutorService executorService) {
16-
return new CodeOptimizerDiagnosticEngineJfr(executorService);
30+
public DiagnosticEngine create(
31+
ScheduledExecutorService executorService, @Nullable String cgroupBasePath) {
32+
Path cgroupPath = getCgroupPath(cgroupBasePath);
33+
return new CodeOptimizerDiagnosticEngineJfr(executorService, cgroupPath);
34+
}
35+
36+
@SuppressFBWarnings(
37+
value = "SECPTI", // Potential Path Traversal
38+
justification =
39+
"The constructed file path cannot be controlled by an end user of the instrumented application")
40+
@Nullable
41+
private static Path getCgroupPath(@Nullable String cgroupBasePath) {
42+
Path cgroupPath = null;
43+
if (cgroupBasePath != null) {
44+
cgroupPath = Paths.get(cgroupBasePath);
45+
46+
if (!Files.exists(cgroupPath)) {
47+
logger.warn("Configured Cgroup path {} does not exist, setting to default", cgroupBasePath);
48+
cgroupPath = null;
49+
}
50+
}
51+
52+
if (cgroupPath == null) {
53+
cgroupPath = FILE_SYSTEM_ROOT.resolve(CGROUP_DIR);
54+
55+
if (!Files.exists(cgroupPath)) {
56+
logger.warn("Expected default Cgroup path {} does not exist", cgroupBasePath);
57+
cgroupPath = null;
58+
}
59+
}
60+
61+
return cgroupPath;
1762
}
1863
}

agent/agent-profiler/agent-diagnostics/src/main/java/com/microsoft/applicationinsights/diagnostics/appinsights/CodeOptimizerDiagnosticEngineJfr.java

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
import com.microsoft.applicationinsights.diagnostics.jfr.SystemStatsProvider;
1515
import java.io.IOException;
1616
import java.io.StringWriter;
17+
import java.nio.file.Path;
1718
import java.util.concurrent.CompletableFuture;
1819
import java.util.concurrent.Future;
1920
import java.util.concurrent.ScheduledExecutorService;
@@ -33,10 +34,13 @@ public class CodeOptimizerDiagnosticEngineJfr implements DiagnosticEngine {
3334
public static final long TIME_BEFORE_END_OF_PROFILE_TO_EMIT_EVENT = 10L;
3435
private final ScheduledExecutorService executorService;
3536
private final Semaphore semaphore = new Semaphore(1, false);
37+
private final Path cgroupBasePath;
3638
private int thisPid;
3739

38-
public CodeOptimizerDiagnosticEngineJfr(ScheduledExecutorService executorService) {
40+
public CodeOptimizerDiagnosticEngineJfr(
41+
ScheduledExecutorService executorService, Path cgroupBasePath) {
3942
this.executorService = executorService;
43+
this.cgroupBasePath = cgroupBasePath;
4044
}
4145

4246
@Override
@@ -49,14 +53,14 @@ public void init(int thisPid) {
4953
this.thisPid = thisPid;
5054

5155
logger.debug("Initialising Code Optimizer Diagnostic Engine");
52-
CodeOptimizerDiagnosticsJfrInit.initFeature(thisPid);
56+
CodeOptimizerDiagnosticsJfrInit.initFeature(thisPid, cgroupBasePath);
5357
logger.debug("Code Optimizer Diagnostic Engine Initialised");
5458
}
5559

56-
private static void startDiagnosticCycle(int thisPid) {
60+
private static void startDiagnosticCycle(int thisPid, Path cgroupBasePath) {
5761
logger.debug("Starting Code Optimizer Diagnostic Cycle");
58-
CodeOptimizerDiagnosticsJfrInit.initFeature(thisPid);
59-
CodeOptimizerDiagnosticsJfrInit.start(thisPid);
62+
CodeOptimizerDiagnosticsJfrInit.initFeature(thisPid, cgroupBasePath);
63+
CodeOptimizerDiagnosticsJfrInit.start(thisPid, cgroupBasePath);
6064
}
6165

6266
private static void endDiagnosticCycle() {
@@ -70,13 +74,13 @@ public Future<DiagnosisResult<?>> performDiagnosis(AlertBreach alert) {
7074
new CompletableFuture<>();
7175
try {
7276
if (semaphore.tryAcquire(SEMAPHORE_TIMEOUT_IN_SEC, TimeUnit.SECONDS)) {
73-
emitInfo(alert);
77+
emitInfo(alert, cgroupBasePath);
7478

7579
long profileDurationInSec = alert.getAlertConfiguration().getProfileDurationSeconds();
7680

7781
long end = profileDurationInSec - TIME_BEFORE_END_OF_PROFILE_TO_EMIT_EVENT;
7882

79-
startDiagnosticCycle(thisPid);
83+
startDiagnosticCycle(thisPid, cgroupBasePath);
8084

8185
scheduleEmittingAlertBreachEvent(alert, end);
8286

@@ -101,7 +105,7 @@ private void scheduleShutdown(
101105
executorService.schedule(
102106
() -> {
103107
try {
104-
emitInfo(alert);
108+
emitInfo(alert, cgroupBasePath);
105109

106110
// We do not return a result atm
107111
diagnosisResultCompletableFuture.complete(null);
@@ -123,7 +127,7 @@ private void scheduleEmittingAlertBreachEvent(AlertBreach alert, long end) {
123127
executorService.schedule(
124128
() -> {
125129
try {
126-
emitInfo(alert);
130+
emitInfo(alert, cgroupBasePath);
127131
} catch (RuntimeException e) {
128132
logger.error("Failed to emit breach", e);
129133
}
@@ -132,10 +136,10 @@ private void scheduleEmittingAlertBreachEvent(AlertBreach alert, long end) {
132136
TimeUnit.SECONDS);
133137
}
134138

135-
private static void emitInfo(AlertBreach alert) {
139+
private static void emitInfo(AlertBreach alert, Path cgroupBasePath) {
136140
logger.debug("Emitting Code Optimizer Diagnostic Event");
137141
emitAlertBreachJfrEvent(alert);
138-
CodeOptimizerDiagnosticsJfrInit.emitCGroupData();
142+
CodeOptimizerDiagnosticsJfrInit.emitCGroupData(cgroupBasePath);
139143
emitMachineStats();
140144
}
141145

agent/agent-profiler/agent-diagnostics/src/main/java/com/microsoft/applicationinsights/diagnostics/collection/libos/kernel/CGroupDataReader.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,6 @@ public interface CGroupDataReader {
1919
long getCpuLimit() throws OperatingSystemInteractionException;
2020

2121
long getCpuPeriod() throws OperatingSystemInteractionException;
22+
23+
boolean isAvailable();
2224
}

agent/agent-profiler/agent-diagnostics/src/main/java/com/microsoft/applicationinsights/diagnostics/collection/libos/kernel/CGroupUsageDataReader.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,6 @@
1313
public interface CGroupUsageDataReader extends TwoStepUpdatable, Closeable {
1414
@Nullable
1515
List<Double> getTelemetry();
16+
17+
boolean isAvailable();
1618
}

0 commit comments

Comments
 (0)