Add manual profile triggering and cooldown mechanism#4730
Conversation
- Creating/Touching a file at a well known location, by default "<temp_dir>/applicationinsights-agent-profile-trigger" - Add a JMX mbean, can be called via "jcmd <pid> MBean.invoke com.microsoft:type=AI-alert,name=ProfilerControl triggerProfile" - Add a global cooldown on the profile to ensure that we dont get repeat profiles from multiple sources
There was a problem hiding this comment.
Pull request overview
Adds operator-initiated profiling to the Application Insights Java agent (file-based trigger + JMX MBean) and introduces a cross-trigger global cooldown to reduce rapid back-to-back recordings from different trigger sources.
Changes:
- Added manual profile triggering via (1) a “touch file” trigger and (2) a JMX MBean (
ProfilerControl). - Added a global profiler cooldown (
globalCooldownSeconds) enforced across CPU/memory/request/manual/periodic triggers. - Updated docs and tests, including new test suites for file-trigger behavior and global cooldown.
Reviewed changes
Copilot reviewed 18 out of 18 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| docs/README.md | Documents new profiler settings and manual triggering mechanisms. |
| agent/agent-tooling/src/test/java/com/microsoft/applicationinsights/agent/internal/profiler/triggers/GcEventInitTest.java | Updates test wiring for new AlertingSubsystem.create(...) signature. |
| agent/agent-tooling/src/test/java/com/microsoft/applicationinsights/agent/internal/profiler/triggers/AlertTriggerSpanProcessorTest.java | Updates test wiring for new AlertingSubsystem.create(...) signature. |
| agent/agent-tooling/src/test/java/com/microsoft/applicationinsights/agent/internal/profiler/ProfilerGlobalCooldownTest.java | Adds tests for new global cooldown behavior. |
| agent/agent-tooling/src/test/java/com/microsoft/applicationinsights/agent/internal/profiler/ProfilerControlTest.java | Adds tests for JMX MBean registration and triggering behavior. |
| agent/agent-tooling/src/main/java/com/microsoft/applicationinsights/agent/internal/profiler/triggers/AlertingSubsystemInit.java | Wires file-trigger config into alerting subsystem and optionally registers the profiler control MBean. |
| agent/agent-tooling/src/main/java/com/microsoft/applicationinsights/agent/internal/profiler/ProfilingInitializer.java | Ensures file-trigger evaluation is performed on the config polling cycle. |
| agent/agent-tooling/src/main/java/com/microsoft/applicationinsights/agent/internal/profiler/ProfilerControlMBean.java | Introduces the JMX MBean interface for manual triggering. |
| agent/agent-tooling/src/main/java/com/microsoft/applicationinsights/agent/internal/profiler/ProfilerControl.java | Implements and registers the JMX MBean that emits MANUAL alert breaches. |
| agent/agent-tooling/src/main/java/com/microsoft/applicationinsights/agent/internal/profiler/Profiler.java | Adds global cooldown enforcement and a TimeSource for deterministic time handling. |
| agent/agent-tooling/src/main/java/com/microsoft/applicationinsights/agent/internal/profiler/PerformanceMonitoringService.java | Builds/resolves the file-trigger config and exposes evaluateFileTrigger(). |
| agent/agent-tooling/src/main/java/com/microsoft/applicationinsights/agent/internal/configuration/Configuration.java | Adds config fields for manual settings, global cooldown, MBean enablement, and file trigger settings. |
| agent/agent-profiler/request-triggers.md | Notes that global cooldown suppresses all triggers. |
| agent/agent-profiler/agent-alerting/src/test/java/com/microsoft/applicationinsights/alerting/TestTimeSource.java | Adds ability to set “now” for tests. |
| agent/agent-profiler/agent-alerting/src/test/java/com/microsoft/applicationinsights/alerting/AlertingSubsystemTest.java | Updates test wiring for new AlertingSubsystem.create(...) signature. |
| agent/agent-profiler/agent-alerting/src/test/java/com/microsoft/applicationinsights/alerting/AlertingSubsystemFileTriggerTest.java | Adds test coverage for file-trigger scenarios. |
| agent/agent-profiler/agent-alerting/src/main/java/com/microsoft/applicationinsights/alerting/AlertingSubsystem.java | Implements file-trigger evaluation and refactors manual-trigger evaluation. |
| agent/agent-profiler/agent-alerting-api/src/main/java/com/microsoft/applicationinsights/alerting/config/AlertingProfileFileTriggerConfiguration.java | Introduces configuration object for the file-based manual trigger. |
Comments suppressed due to low confidence (1)
agent/agent-profiler/agent-alerting/src/main/java/com/microsoft/applicationinsights/alerting/AlertingSubsystem.java:181
evaluateCollectionPlanTrigger()usesInstant.now()for expiration checks while the rest of the alerting subsystem uses the injectedTimeSource. This makes behavior inconsistent (and harder to test) when a non-defaultTimeSourceis provided. Consider usingtimeSource.getNow()here as well.
boolean shouldTrigger =
config.isSingle()
&& config.getMode() == EngineMode.immediate
&& Instant.now().isBefore(config.getExpiration())
&& !manualTriggersExecuted.contains(config.getSettingsMoniker());
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
fcfeb8b to
78063a0
Compare
| /** | ||
| * Trigger a manual profile with the default duration (120 seconds). | ||
| * | ||
| * @return a status message indicating whether the profile was started |
There was a problem hiding this comment.
| * @return a status message indicating whether the profile was started | |
| * @return a status message indicating whether the profile was requested |
Nit: it was triggered (or requested), but not actually started yet.
| * Trigger a manual profile with the specified duration. | ||
| * | ||
| * @param durationSeconds the desired recording duration in seconds; must be positive | ||
| * @return a status message indicating whether the profile was started |
There was a problem hiding this comment.
| * @return a status message indicating whether the profile was started | |
| * @return a status message indicating whether the profile was requested |
Same nitpick as above. Not blocking.
| @@ -1,82 +1,82 @@ | |||
| @rem | |||
There was a problem hiding this comment.
Can you discard this diff? There is no change. There seems to an issue with the line ending across Windows/Linux and git that I was in the middle of fixing.
| @@ -1,82 +1,82 @@ | |||
| @rem | |||
This pull request adds support for triggering manual profiling triggering profiles via 2 routes:
Additionally this pr adds a global cooldown on the profile to ensure that we dont get repeat profiles from multiple sources
File-based manual profiling trigger:
AlertingProfileFileTriggerConfiguration, a new configuration class that controls the file-based manual profile trigger, including enablement, file path resolution, and default profile duration.AlertingSubsystemto support the file-based trigger: checks for the presence and recency of the trigger file, deletes it after use, and initiates a manual profile when appropriate. The subsystem now accepts the file trigger configuration as a dependency and has been refactored to evaluate both collection plan and file-based triggers. [1] [2] [3] [4] [5]Testing enhancements:
AlertingSubsystemFileTriggerTest, a new test suite covering scenarios for the file-based trigger, such as firing when the file exists and is recent, not firing when disabled, not firing for old or missing files, and correct profile duration selection.AlertingSubsystemTest) to use the new configuration and maintain compatibility. [1] [2] [3] [4]TestTimeSourceto allow setting the current time, supporting precise control in tests.Documentation:
request-triggers.mdthat a global cooldown is enforced after any profile recording, affecting all trigger types, including the new file-based manual trigger.