-
-
Notifications
You must be signed in to change notification settings - Fork 206
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
feat: Check-In Upserts #3330
Merged
Merged
feat: Check-In Upserts #3330
Changes from 34 commits
Commits
Show all changes
37 commits
Select commit
Hold shift + click to select a range
4337094
added missing properties
bitsandfoxes f3e54e4
enriching checkins
bitsandfoxes d3097ea
adding the trace id to the check-in
bitsandfoxes 16f7bcd
simplify
bitsandfoxes c527a33
tests
bitsandfoxes bfc4098
real tests
bitsandfoxes 4431428
Updated CHANGELOG.md
bitsandfoxes 0111dcc
verify
bitsandfoxes b04d045
Merge branch 'main' into fix/crons-1
bitsandfoxes e1832d1
Merge branch 'fix/crons-1' of https://github.com/getsentry/sentry-dot…
bitsandfoxes 8dfe884
Update test/Sentry.Tests/HubTests.cs
bitsandfoxes 7803f45
added monitor config to checkins
bitsandfoxes 45a283d
.
bitsandfoxes d8e7525
fixed test
bitsandfoxes fa23112
.
bitsandfoxes 7cad476
verify
bitsandfoxes 775b908
merge
bitsandfoxes d549bbb
iterating on it
bitsandfoxes 77cdd2f
Merge branch 'main' into fix/crons-2
bitsandfoxes fbb0017
Merge branch 'main' into fix/crons-2
bitsandfoxes 9d25bc5
pass the config callback to the client
bitsandfoxes a485094
tests
bitsandfoxes f9297ad
verify
bitsandfoxes 899cf7f
timezones. how about no
bitsandfoxes f5f6c81
verify
bitsandfoxes ece0995
Updated CHANGELOG.md
bitsandfoxes c3149de
Updated CHANGELOG.md
bitsandfoxes 2490e22
forward options
bitsandfoxes a81774c
validating crontab
bitsandfoxes 07dcc56
.
bitsandfoxes a868b2e
Merge branch 'main' into fix/crons-2
bitsandfoxes 5a30c16
verify
bitsandfoxes f23ab39
Merge branch 'fix/crons-2' of https://github.com/getsentry/sentry-dot…
bitsandfoxes 4b28b64
Merge branch 'main' into fix/crons-2
bitsandfoxes 5554bd4
regex optimization
bitsandfoxes cf2cec3
fixes
bitsandfoxes 8875318
verify
bitsandfoxes 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
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
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
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
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
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
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
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
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 |
---|---|---|
@@ -0,0 +1,188 @@ | ||
using Sentry.Extensibility; | ||
using Sentry.Internal.Extensions; | ||
|
||
namespace Sentry; | ||
|
||
internal enum SentryMonitorScheduleType | ||
{ | ||
None, | ||
Crontab, | ||
Interval | ||
} | ||
|
||
/// <summary> | ||
/// Sentry's intervals for monitors | ||
/// </summary> | ||
public enum SentryMonitorInterval | ||
{ | ||
/// <summary> | ||
/// Year | ||
/// </summary> | ||
Year, | ||
|
||
/// <summary> | ||
/// Month | ||
/// </summary> | ||
Month, | ||
|
||
/// <summary> | ||
/// Week | ||
/// </summary> | ||
Week, | ||
|
||
/// <summary> | ||
/// Day | ||
/// </summary> | ||
Day, | ||
|
||
/// <summary> | ||
/// Hour | ||
/// </summary> | ||
Hour, | ||
|
||
/// <summary> | ||
/// Minute | ||
/// </summary> | ||
Minute | ||
} | ||
|
||
/// <summary> | ||
/// Sentry's options for monitors | ||
/// </summary> | ||
public class SentryMonitorOptions : ISentryJsonSerializable | ||
{ | ||
private SentryMonitorScheduleType _type = SentryMonitorScheduleType.None; | ||
private string? _crontab; | ||
private int? _interval; | ||
private SentryMonitorInterval? _unit; | ||
|
||
// Breakdown of the validation | ||
// ^(\*|([0-5]?\d)) Minute 0 - 59 | ||
// (\s+)(\*|([01]?\d|2[0-3])) Hour 0 - 23 | ||
// (\s+)(\*|([1-9]|[12]\d|3[01])) Day 1 - 31 | ||
// (\s+)(\*|([1-9]|1[0-2])) Month 1 - 12 | ||
// (\s+)(\*|([0-7])) Weekday 0 - 7 | ||
// $ End of string | ||
private readonly Regex _crontabValidation = new( | ||
@"^(\*|([0-5]?\d))(\s+)(\*|([01]?\d|2[0-3]))(\s+)(\*|([1-9]|[12]\d|3[01]))(\s+)(\*|([1-9]|1[0-2]))(\s+)(\*|([0-7]))$", | ||
RegexOptions.Compiled | RegexOptions.CultureInvariant); | ||
|
||
/// <summary> | ||
/// Set Interval | ||
/// </summary> | ||
/// <param name="cronTab"></param> | ||
public void Interval(string cronTab) | ||
{ | ||
if (_type is not SentryMonitorScheduleType.None) | ||
{ | ||
throw new ArgumentException("You tried to set the interval twice. The Check-Ins interval is supposed to be set only once."); | ||
} | ||
|
||
if (!_crontabValidation.IsMatch(cronTab)) | ||
{ | ||
throw new ArgumentException("The provided crontab does not match the expected format of '* * * * *' " + | ||
"translating to 'minute', 'hour', 'day of the month', 'month', and 'day of the week'."); | ||
} | ||
|
||
_type = SentryMonitorScheduleType.Crontab; | ||
_crontab = cronTab; | ||
bitsandfoxes marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
|
||
/// <summary> | ||
/// Set Interval | ||
/// </summary> | ||
/// <param name="interval"></param> | ||
/// <param name="unit"></param> | ||
public void Interval(int interval, SentryMonitorInterval unit) | ||
jamescrosswell marked this conversation as resolved.
Show resolved
Hide resolved
|
||
{ | ||
if (_type is not SentryMonitorScheduleType.None) | ||
{ | ||
throw new ArgumentException("You tried to set the interval twice. The Check-Ins interval is supposed to be set only once."); | ||
} | ||
|
||
_type = SentryMonitorScheduleType.Interval; | ||
_interval = interval; | ||
jamescrosswell marked this conversation as resolved.
Show resolved
Hide resolved
|
||
_unit = unit; | ||
} | ||
|
||
/// <summary> | ||
/// The allowed margin of minutes after the expected check-in time that the monitor will not be considered missed for. | ||
/// </summary> | ||
public TimeSpan? CheckInMargin { get; set; } | ||
|
||
/// <summary> | ||
/// The allowed duration in minutes that the monitor may be in_progress for before being considered failed due to timeout. | ||
/// </summary> | ||
public TimeSpan? MaxRuntime { get; set; } | ||
|
||
/// <summary> | ||
/// The number of consecutive failed check-ins it takes before an issue is created. | ||
/// </summary> | ||
public int? FailureIssueThreshold { get; set; } | ||
|
||
/// <summary> | ||
/// The number of consecutive OK check-ins it takes before an issue is resolved. | ||
/// </summary> | ||
public int RecoveryThreshold { get; set; } | ||
|
||
/// <summary> | ||
/// A tz database string representing the timezone which the monitor's execution schedule is in (i.e. "America/Los_Angeles"). | ||
/// </summary> | ||
public string? Timezone { get; set; } | ||
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. IIRC I raised this before but it's 2 words: time zone |
||
|
||
/// <summary> | ||
/// An actor identifier string. This looks like 'user:john@example.com team:a-sentry-team'. IDs can also be used but will result in a poor DX. | ||
/// </summary> | ||
public string? Owner { get; set; } | ||
|
||
internal SentryMonitorOptions() { } | ||
|
||
/// <inheritdoc /> | ||
public void WriteTo(Utf8JsonWriter writer, IDiagnosticLogger? logger) | ||
{ | ||
Debug.Assert(_type != SentryMonitorScheduleType.None, "The Monitor Options do not contain a valid interval." + | ||
"Please update your monitor options by setting the Interval."); | ||
bitsandfoxes marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
writer.WriteStartObject("monitor_config"); | ||
writer.WriteStartObject("schedule"); | ||
|
||
writer.WriteString("type", TypeToString(_type)); | ||
switch (_type) | ||
{ | ||
case SentryMonitorScheduleType.Crontab: | ||
Debug.Assert(string.IsNullOrEmpty(_crontab), "The provided 'crontab' cannot be an empty string."); | ||
writer.WriteStringIfNotWhiteSpace("value", _crontab); | ||
break; | ||
case SentryMonitorScheduleType.Interval: | ||
Debug.Assert(_interval != null, "The provided 'interval' cannot be null."); | ||
writer.WriteNumberIfNotNull("value", _interval); | ||
Debug.Assert(_unit != null, "The provided 'unit' cannot be null."); | ||
writer.WriteStringIfNotWhiteSpace("unit", _unit.ToString()!.ToLower()); | ||
break; | ||
default: | ||
logger?.LogError("Invalid MonitorScheduleType: '{0}'", _type.ToString()); | ||
break; | ||
} | ||
|
||
writer.WriteEndObject(); | ||
|
||
writer.WriteNumberIfNotNull("checkin_margin", CheckInMargin?.TotalMinutes); | ||
writer.WriteNumberIfNotNull("max_runtime", MaxRuntime?.TotalMinutes); | ||
writer.WriteNumberIfNotNull("failure_issue_threshold", FailureIssueThreshold); | ||
writer.WriteNumberIfNotNull("recovery_threshold", RecoveryThreshold); | ||
writer.WriteStringIfNotWhiteSpace("timezone", Timezone); | ||
writer.WriteStringIfNotWhiteSpace("owner", Owner); | ||
|
||
writer.WriteEndObject(); | ||
} | ||
|
||
private static string TypeToString(SentryMonitorScheduleType type) | ||
{ | ||
return type switch | ||
{ | ||
SentryMonitorScheduleType.Crontab => "crontab", | ||
SentryMonitorScheduleType.Interval => "interval", | ||
_ => throw new ArgumentException($"Unsupported Monitor Schedule Type: '{type}'.") | ||
}; | ||
} | ||
} |
Oops, something went wrong.
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.
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.
On .NET 8 we could use Source Generated regular expressions for better performance.
We do this for the BuiltInSystemDiagnosticsMeters, for example.