-
Notifications
You must be signed in to change notification settings - Fork 295
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
Fix heartbeat for short-running WorkerServices #2762
Open
304NotModified
wants to merge
6
commits into
microsoft:main
Choose a base branch
from
304NotModified:patch-3
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.
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
9735199
Added support for firstInterval
304NotModified 3b87a1c
Merge branch 'main' into patch-3
304NotModified eff03ab
Use property instead of field (consistency)
304NotModified 760dad5
Update CHANGELOG.md
304NotModified cd56648
Merge branch 'main' into patch-3
304NotModified 9cde9f0
Update CHANGELOG.md
304NotModified 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 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 |
---|---|---|
|
@@ -58,6 +58,7 @@ internal class HeartbeatProvider : IDisposable, IHeartbeatProvider | |
|
||
private bool disposedValue = false; // To detect redundant calls to dispose | ||
private TimeSpan interval; // time between heartbeats emitted | ||
private TimeSpan firstInterval; // time for the first interval | ||
private TelemetryClient telemetryClient; // client to use in sending our heartbeat | ||
private volatile bool isEnabled; // no need for locks or volatile here, we can skip/add a beat if the module is disabled between heartbeats | ||
|
||
|
@@ -67,6 +68,7 @@ public HeartbeatProvider() | |
this.heartbeatProperties = new ConcurrentDictionary<string, HeartbeatPropertyPayload>(StringComparer.OrdinalIgnoreCase); | ||
this.heartbeatsSent = 0; // count up from construction time | ||
this.isEnabled = true; | ||
this.firstInterval = TimeSpan.FromSeconds(1); | ||
} | ||
|
||
/// <summary> | ||
|
@@ -89,6 +91,19 @@ public TimeSpan HeartbeatInterval | |
this.InitTimer(); | ||
} | ||
} | ||
|
||
/// <summary> | ||
/// Gets or sets the currently defined interval of the first heartbeat. Defaults to 1 second. | ||
/// </summary> | ||
public TimeSpan HeartbeatFirstInterval | ||
{ | ||
get => this.firstInterval; | ||
set | ||
{ | ||
this.firstInterval = value; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add some bounds checking? At least make sure it's not negative (less than TimeSpan.Zero) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good idea 👍 |
||
this.InitTimer(); | ||
} | ||
} | ||
|
||
/// <summary> | ||
/// Gets or sets the currently defined instrumentation key to send heartbeat telemetry items to. | ||
|
@@ -272,11 +287,11 @@ internal void InitTimer() | |
{ | ||
if (this.IsHeartbeatEnabled && this.HeartbeatTimer == null) | ||
{ | ||
this.HeartbeatTimer = new Timer(callback: this.HeartbeatPulse, state: this, dueTime: this.HeartbeatInterval, period: this.HeartbeatInterval); | ||
this.HeartbeatTimer = new Timer(callback: this.HeartbeatPulse, state: this, dueTime: this.HeartbeatFirstInterval, period: this.HeartbeatInterval); | ||
} | ||
else if (this.IsHeartbeatEnabled) | ||
{ | ||
this.HeartbeatTimer.Change(dueTime: this.HeartbeatInterval, period: this.HeartbeatInterval); | ||
this.HeartbeatTimer.Change(dueTime: this.HeartbeatFirstInterval, period: this.HeartbeatInterval); | ||
} | ||
else if (this.HeartbeatTimer != null) | ||
{ | ||
|
This file contains 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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Initial... Is maybe a better term
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
InitialHeartbeatDelay