Add targeted profiling feature - #4833
Conversation
a73fa5a to
e8d567a
Compare
Add role- and instance-targeted profile collection, backward-compatible Service Profiler protocol negotiation, and settings moniker correlation. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
e8d567a to
1d23d18
Compare
There was a problem hiding this comment.
🟡 Changes recommended
Removing the public no-argument trigger-check method breaks existing consumers of the alerting API.
Once you've addressed the issues Copilot identified, you can request another Copilot review.
Pull request overview
Adds targeted Java profiling for selected cloud roles or role-qualified instances.
Changes:
- Adds targeted-plan parsing, validation, selection, execution, and smoke tests.
- Propagates settings monikers into uploaded profiler metadata.
- Adds feature-version negotiation and bounded duplicate-trigger tracking.
File summaries
| File | Description |
|---|---|
.gitignore |
Ignores a profiling design document. |
CHANGELOG.md |
Documents targeted profiling. |
ProfilerState.java |
Adds targeted smoke-test states. |
MockedProfilerSettingsServlet.java |
Serves targeted test plans. |
JavaProfileConfigTest.java |
Tests matched and unmatched targets. |
ConfigServiceTest.pullSettings.json |
Updates expected protocol version. |
ConfigServiceTest.badServiceResponseDoesNotProvideReturn.json |
Updates recorded request version. |
UploadServiceTest.java |
Verifies moniker upload metadata. |
AlertConfigParserTest.java |
Tests targeted-plan conversion and validation. |
ServiceProfilerClientTest.java |
Tests protocol fallback and caching. |
ProfilingInitializerTest.java |
Tests targeted profiler activation. |
ProfilerConfigurationTest.java |
Tests targeted-plan deserialization. |
UploadService.java |
Propagates settings monikers. |
ServiceProfilerIndex.java |
Adds moniker index metadata. |
AlertingSubsystemInit.java |
Passes role identity into alerting. |
AlertConfigParser.java |
Parses targeted plans safely. |
ServiceProfilerClient.java |
Negotiates settings protocol versions. |
ProfilingInitializer.java |
Evaluates identity-aware triggers. |
PerformanceMonitoringService.java |
Builds subsystem identity configuration. |
TargetedInstance.java |
Models targeted-instance JSON. |
TargetedCollectionPlan.java |
Models targeted-plan JSON. |
ExecutedMonikerTrackerTest.java |
Tests duplicate retention and eviction. |
AlertingSubsystemTest.java |
Tests targeted dispatch behavior. |
ExecutedMonikerTracker.java |
Bounds executed-trigger tracking. |
AlertingSubsystem.java |
Evaluates and dispatches targeted plans. |
TargetedInstanceConfiguration.java |
Adds immutable target identity. |
TargetedCollectionPlanConfiguration.java |
Validates and matches targeted plans. |
AlertingSubsystemConfiguration.java |
Encapsulates subsystem identity settings. |
AlertingConfiguration.java |
Adds targeted-plan trigger evaluation. |
AlertBreach.java |
Carries settings monikers. |
Review details
- Files reviewed: 30/31 changed files
- Comments generated: 1
- Review effort level: Balanced
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Derek Keeler (d3r3kk)
left a comment
There was a problem hiding this comment.
Ensure targeted matching uses the identity advertised by heartbeat
Plan matching must use the same final OpenTelemetry Resource -derived cloud role name and role instance that the agent publishes through heartbeat.
Heartbeat initialization received Resource.empty(), while profiler targeting could use service.name, service.namespace, service.instance.id, or AKS-derived attributes. This could may lead to the portal targeting incorrect roles/instances.
- We could defer initial heartbeat startup until OpenTelemetry resource initialization has completed.
- We could use the same resource-resolution logic for both heartbeat and profiler targeting.
This would preserve runtime-configuration behavior and safely contain optional profiler initialization failures.
Targeted profiling duration should be respected when continuous profiling is enabled
A targeted request should use immediateProfilingDuration for the complete supported range of 1–360 seconds. Previously, continuous profiling dumped its entire retained circular buffer, so a short request could return too much data and a request longer than the buffer could return too little.
I had copilot create a patch with the above notes implemented, have a look and if you agree, use what you like.
eededf1dc9-targeted-profiling-improvements.patch
The proposed patch:
• Adds an explicit targeted marker to AlertBreach and does not infer targeting from settingsMoniker because legacy "Profile Now" requests also contain a moniker.
• Runs targeted requests as independent, forward-looking on-demand JFR recordings for exactly the requested duration, even while the continuous recording remains active.
• Preserves existing circular-buffer snapshots for legacy Profile Now and other non-targeted triggers.
• Prevents continuous snapshots from overlapping an active targeted recording.
• Emits diagnostic events only after capture admission and in the correct order for the selected recording strategy.
• Contains creation, startup, scheduling, upload, diagnostic, and cleanup failures so they cannot escape into the instrumented application.
• Adds coverage for the 1-second and 360-second boundaries, legacy behavior, concurrent admission, cooldown behavior, resource cleanup, and failure containment.
Align heartbeat identity with profiler targeting and honor targeted profile durations while continuous profiling is enabled. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Derek Keeler (d3r3kk)
left a comment
There was a problem hiding this comment.
Looks good, thanks John (@johnoliver) - 🚢
Keep heartbeat initialization in SecondEntryPoint while resolving the finalized OpenTelemetry resource lazily for each emission. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Avoid swallowing JVM errors while retaining profiler cleanup and failure containment for exceptions. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Catch only expected JFR, recording-state, scheduling, and diagnostic failures introduced by targeted profiling. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Derek Keeler (d3r3kk)
left a comment
There was a problem hiding this comment.
Better than the more generic exception handling for sure. Thanks John (@johnoliver).
This pull request adds support for Java agent profiling based on targeted collection plans, allowing profiling to be triggered for specific cloud roles or role-qualified instances. It introduces new configuration classes and logic to handle these targeted plans, updates the alerting subsystem to support them, and refactors how manual triggers are tracked and executed. The changes also include enhancements to configuration APIs and internal tracking for executed triggers.
Targeted Profiling Support:
TargetedCollectionPlanConfigurationandTargetedInstanceConfigurationto define and validate targeted profiling plans for specific roles or instances. These classes provide methods to check if a plan applies to the current instance and if it is actionable based on expiration and selection criteria. [1] [2]AlertingConfigurationto optionally include aTargetedCollectionPlanConfiguration, and enhanced the API to determine if a profiling trigger is enabled for a given role or instance at a specific time. [1] [2]Alerting Subsystem Enhancements:
AlertingSubsystemto support targeted collection plan triggers, including new logic to evaluate and dispatch alerts for targeted plans, and to pass role and instance information throughout the subsystem. [1] [2] [3] [4] [5] [6]AlertingSubsystemConfigurationto encapsulate subsystem-level configuration, including role and instance identifiers.Manual Trigger Execution Tracking:
manualTriggersExecutedset with a newExecutedMonikerTrackerutility, which tracks executed triggers with retention and capacity limits to prevent duplicate profiling within a time window. [1] [2]Documentation and Test Updates:
CHANGELOG.mdto document the addition of Java agent support for targeted collection plans.For significant contributions please make sure you have completed the following items: