-
Notifications
You must be signed in to change notification settings - Fork 212
Add manual profile triggering and cooldown mechanism #4730
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
Draft
johnoliver
wants to merge
7
commits into
microsoft:main
Choose a base branch
from
johnoliver:manual-profile-2
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
0095afe
Add the ability to manually trigger profiles via 2 routes:
johnoliver 6e3854a
Fix manual evaluation cycle
johnoliver 45a0d92
Fix tests
johnoliver 844f0fe
Potential fix for pull request finding
johnoliver b6cbda5
Fixes from review
johnoliver 48431ba
Merge remote-tracking branch 'joliver/manual-profile-2' into manual-p…
johnoliver 3ceb9f3
fix tests
johnoliver File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
91 changes: 91 additions & 0 deletions
91
...icrosoft/applicationinsights/alerting/config/AlertingProfileFileTriggerConfiguration.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,91 @@ | ||
| // Copyright (c) Microsoft Corporation. All rights reserved. | ||
| // Licensed under the MIT License. | ||
|
|
||
| package com.microsoft.applicationinsights.alerting.config; | ||
|
|
||
| import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; | ||
| import java.io.File; | ||
|
|
||
| /** | ||
| * Configuration for the file-based manual profile trigger. | ||
| * | ||
| * <p>When enabled, the alerting subsystem periodically checks for the existence of a trigger file. | ||
| * If the file exists and was recently modified (within {@link #MANUAL_TRIGGER_FILE_MAX_AGE_MS}), it | ||
| * is deleted and a manual profile recording is initiated. | ||
| * | ||
| * <p>This provides an operator-friendly mechanism for triggering on-demand profiles without | ||
| * requiring JMX access – simply {@code touch} the trigger file from a shell or orchestration tool. | ||
| */ | ||
| public class AlertingProfileFileTriggerConfiguration { | ||
|
|
||
| /** | ||
| * Maximum age (in milliseconds) of the trigger file for it to be considered valid. Files older | ||
| * than this threshold are ignored to prevent stale trigger files from initiating unexpected | ||
| * recordings (e.g., after a restart). | ||
| */ | ||
| public static final long MANUAL_TRIGGER_FILE_MAX_AGE_MS = 60_000; // 1 minute | ||
|
|
||
| // Whether the file-based manual trigger is enabled. | ||
| private final boolean enabled; | ||
|
|
||
| // Path to the file that triggers a manual profile when created/touched. | ||
| // If relative, it is resolved against the agent's temp directory. | ||
| private final File filePath; | ||
|
|
||
| /** The default duration (in seconds) used for profiles triggered via this file mechanism. */ | ||
| private final int defaultProfileDurationSeconds; | ||
|
|
||
| private AlertingProfileFileTriggerConfiguration( | ||
| boolean enabled, File filePath, int defaultProfileDurationSeconds) { | ||
| this.enabled = enabled; | ||
| this.filePath = filePath; | ||
| this.defaultProfileDurationSeconds = defaultProfileDurationSeconds; | ||
| } | ||
|
|
||
| /** | ||
| * Creates a file trigger configuration, resolving relative paths against the provided temp | ||
| * directory. | ||
| * | ||
| * @param enabled whether file-based triggering is active | ||
| * @param filePath path to the trigger file (absolute or relative to {@code tempDir}) | ||
| * @param defaultProfileDurationSeconds duration in seconds for the profile if no override is | ||
| * configured in the collection plan | ||
| * @param tempDir base directory used to resolve relative file paths | ||
| * @return a fully resolved configuration instance | ||
| */ | ||
| @SuppressFBWarnings( | ||
| value = "SECPTI", | ||
| justification = "File path is set by trusted user configuration (applicationinsights.json)") | ||
| public static AlertingProfileFileTriggerConfiguration create( | ||
| boolean enabled, String filePath, int defaultProfileDurationSeconds, File tempDir) { | ||
|
|
||
| File manualTriggerFile = new File(filePath); | ||
| if (!manualTriggerFile.isAbsolute()) { | ||
| manualTriggerFile = new File(tempDir, filePath); | ||
| } | ||
|
|
||
| return new AlertingProfileFileTriggerConfiguration( | ||
| enabled, manualTriggerFile, defaultProfileDurationSeconds); | ||
| } | ||
|
|
||
| /** Creates a disabled configuration suitable for tests. */ | ||
| public static AlertingProfileFileTriggerConfiguration createDefault() { | ||
| return new AlertingProfileFileTriggerConfiguration( | ||
| false, new File("applicationinsights-agent-profile-trigger"), 120); | ||
| } | ||
|
|
||
| /** Returns the default profile duration in seconds for file-triggered recordings. */ | ||
| public int getDefaultProfileDurationSeconds() { | ||
| return defaultProfileDurationSeconds; | ||
| } | ||
|
|
||
| /** Returns the resolved path of the trigger file. */ | ||
| public File getFilePath() { | ||
| return filePath; | ||
| } | ||
|
|
||
| /** Returns whether the file-based manual trigger is enabled. */ | ||
| public boolean isEnabled() { | ||
| return enabled; | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.