-
Notifications
You must be signed in to change notification settings - Fork 472
[HealthChecks] Add AzureWebJobsStorage health check #11471
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
Open
jviau
wants to merge
6
commits into
dev
Choose a base branch
from
u/jviau/storage-check
base: dev
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
efafd99
Add AzureWebJobsStorage health check
jviau aae0cde
Address copilot review
jviau 3445c74
Add comments to HealthCheckData
jviau cdab4f0
Fix unit tests
jviau 6ccbbad
Add Connectivity tag
jviau 4d48aa2
Update WebJobs tag
jviau 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
142 changes: 142 additions & 0 deletions
142
src/WebJobs.Script/Diagnostics/HealthChecks/HealthCheckData.cs
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,142 @@ | ||
| // Copyright (c) .NET Foundation. All rights reserved. | ||
| // Licensed under the MIT License. See License.txt in the project root for license information. | ||
|
|
||
| using System; | ||
| using System.Collections; | ||
| using System.Collections.Generic; | ||
| using System.Linq; | ||
| using System.Runtime.CompilerServices; | ||
| using Azure; | ||
|
|
||
| namespace Microsoft.Azure.WebJobs.Script.Diagnostics.HealthChecks | ||
| { | ||
| /// <summary> | ||
| /// A helper for providing data with a health check result. | ||
| /// </summary> | ||
| internal partial class HealthCheckData | ||
| { | ||
| // exposed to the HealthCheckResult through IReadOnlyDictionary. | ||
| private readonly Dictionary<string, object> _data = []; | ||
|
|
||
| /// <summary> | ||
| /// Gets or sets the area of the health check data failure. | ||
| /// </summary> | ||
| /// <remarks> | ||
| /// This is the area that has failed. Such as "configuration", "connectivity", etc. | ||
| /// </remarks> | ||
| public string Area | ||
| { | ||
| get => GetOrDefault<string>(); | ||
| set => Set(value); | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Gets or sets the configuration section related to the health check data. | ||
| /// </summary> | ||
| /// <remarks> | ||
| /// Useful for when the component being checked is related to a specific configuration section. | ||
| /// </remarks> | ||
| public string ConfigurationSection | ||
| { | ||
| get => GetOrDefault<string>(); | ||
| set => Set(value); | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Gets or sets the status code related to the health check data. | ||
| /// For HTTP related related checks, this is the HTTP status code. | ||
| /// </summary> | ||
| public int StatusCode | ||
| { | ||
| get => GetOrDefault<int>(); | ||
| set => Set(value); | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Gets or sets the error code related to the health check data. | ||
| /// </summary> | ||
| /// <remarks> | ||
| /// For Azure SDK related checks, this is typically the RequestFailedException.ErrorCode value. | ||
| /// </remarks> | ||
| public string ErrorCode | ||
| { | ||
| get => GetOrDefault<string>(); | ||
| set => Set(value); | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Sets exception details into the health check data. | ||
| /// </summary> | ||
| /// <param name="ex">The exception to set details from.</param> | ||
| /// <remarks> | ||
| /// This will set various properties based on the type of exception. | ||
| /// </remarks> | ||
| public void SetExceptionDetails(Exception ex) | ||
| { | ||
| ArgumentNullException.ThrowIfNull(ex); | ||
| if (ex is AggregateException aggregate) | ||
| { | ||
| // Azure SDK will retry a few times in some cases, leading to multiple inner exceptions. | ||
| // We only care about the last one. | ||
| ex = aggregate.InnerExceptions.Last(); | ||
| } | ||
|
|
||
| if (ex is TimeoutException) | ||
| { | ||
| ErrorCode = "Timeout"; | ||
| } | ||
| else if (ex is OperationCanceledException) | ||
| { | ||
| ErrorCode = "OperationCanceled"; | ||
| } | ||
| else if (ex is RequestFailedException rfe) | ||
| { | ||
| StatusCode = rfe.Status; | ||
| ErrorCode = rfe.ErrorCode; | ||
| } | ||
| } | ||
|
|
||
| private void Set<T>(T value, [CallerMemberName] string key = null) | ||
| { | ||
| _data[key] = value; | ||
| } | ||
|
|
||
| private T GetOrDefault<T>([CallerMemberName] string key = null, T defaultValue = default) | ||
| { | ||
| if (_data.TryGetValue(key, out var value) && value is T typedValue) | ||
| { | ||
| return typedValue; | ||
| } | ||
|
|
||
| return defaultValue; | ||
| } | ||
| } | ||
|
|
||
| // Partial class down here to separate IReadOnlyDictionary implementation details. | ||
| internal partial class HealthCheckData : IReadOnlyDictionary<string, object> | ||
| { | ||
| IEnumerable<string> IReadOnlyDictionary<string, object>.Keys | ||
| => _data.Keys; | ||
|
|
||
| IEnumerable<object> IReadOnlyDictionary<string, object>.Values | ||
| => _data.Values; | ||
|
|
||
| int IReadOnlyCollection<KeyValuePair<string, object>>.Count | ||
| => _data.Count; | ||
|
|
||
| object IReadOnlyDictionary<string, object>.this[string key] | ||
| => _data[key]; | ||
|
|
||
| bool IReadOnlyDictionary<string, object>.ContainsKey(string key) | ||
| => _data.ContainsKey(key); | ||
|
|
||
| IEnumerator<KeyValuePair<string, object>> IEnumerable<KeyValuePair<string, object>>.GetEnumerator() | ||
| => _data.GetEnumerator(); | ||
|
|
||
| IEnumerator IEnumerable.GetEnumerator() | ||
| => _data.GetEnumerator(); | ||
|
|
||
| bool IReadOnlyDictionary<string, object>.TryGetValue(string key, out object value) | ||
| => _data.TryGetValue(key, out value); | ||
| } | ||
| } |
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
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.
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.
A good area of discussion for this PR is the names of these properties I have here.
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.
I think this is fine as is. The only one where I'm like I wish there was a word more descriptive is "Area" but I also can't think of anything
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.
I bounced around on that naming a few times. I had
SourceandCausebefore. MaybeCategory? orErrorCategory?