-
Notifications
You must be signed in to change notification settings - Fork 371
Add support for shutdown API and add client docs #922
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
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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
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 |
|---|---|---|
|
|
@@ -289,49 +289,6 @@ public override HttpRequestMessage CreateInvokeMethodRequest<TRequest>(HttpMetho | |
| request.Content = JsonContent.Create<TRequest>(data, options: this.JsonSerializerOptions); | ||
| return request; | ||
| } | ||
|
|
||
| public override async Task<bool> CheckHealthAsync(CancellationToken cancellationToken = default) | ||
| { | ||
| var path = "/v1.0/healthz"; | ||
| var request = new HttpRequestMessage(HttpMethod.Get, new Uri(this.httpEndpoint, path)); | ||
| try | ||
| { | ||
| var response = await this.httpClient.SendAsync(request, cancellationToken); | ||
| return response.IsSuccessStatusCode; | ||
| } | ||
| catch (HttpRequestException) | ||
| { | ||
| return false; | ||
| } | ||
| } | ||
|
|
||
| public override async Task<bool> CheckOutboundHealthAsync(CancellationToken cancellationToken = default) | ||
| { | ||
| var path = "/v1.0/healthz/outbound"; | ||
| var request = new HttpRequestMessage(HttpMethod.Get, new Uri(this.httpEndpoint, path)); | ||
| try | ||
| { | ||
| var response = await this.httpClient.SendAsync(request, cancellationToken); | ||
| return response.IsSuccessStatusCode; | ||
| } | ||
| catch (HttpRequestException) | ||
| { | ||
| return false; | ||
| } | ||
| } | ||
|
|
||
| public override async Task WaitForSidecarAsync(CancellationToken cancellationToken = default) | ||
| { | ||
| while (true) | ||
| { | ||
| var response = await CheckOutboundHealthAsync(cancellationToken); | ||
| if (response) | ||
| { | ||
| break; | ||
| } | ||
| await Task.Delay(TimeSpan.FromMilliseconds(500), cancellationToken); | ||
| } | ||
| } | ||
|
|
||
| public override async Task<HttpResponseMessage> InvokeMethodWithResponseAsync(HttpRequestMessage request, CancellationToken cancellationToken = default) | ||
| { | ||
|
|
@@ -1356,7 +1313,63 @@ public async override Task<UnlockResponse> Unlock( | |
| return new UnlockResponse(GetUnLockStatus(response.Status)); | ||
| } | ||
|
|
||
| #endregion | ||
| #endregion | ||
|
|
||
| #region Dapr Sidecar Methods | ||
|
|
||
| /// <inheritdoc/> | ||
| public override async Task<bool> CheckHealthAsync(CancellationToken cancellationToken = default) | ||
| { | ||
| var path = "/v1.0/healthz"; | ||
| var request = new HttpRequestMessage(HttpMethod.Get, new Uri(this.httpEndpoint, path)); | ||
| try | ||
| { | ||
| using var response = await this.httpClient.SendAsync(request, HttpCompletionOption.ResponseHeadersRead, cancellationToken); | ||
| return response.IsSuccessStatusCode; | ||
| } | ||
| catch (HttpRequestException) | ||
| { | ||
| return false; | ||
| } | ||
| } | ||
|
|
||
| /// <inheritdoc/> | ||
| public override async Task<bool> CheckOutboundHealthAsync(CancellationToken cancellationToken = default) | ||
| { | ||
| var path = "/v1.0/healthz/outbound"; | ||
| var request = new HttpRequestMessage(HttpMethod.Get, new Uri(this.httpEndpoint, path)); | ||
| try | ||
| { | ||
| using var response = await this.httpClient.SendAsync(request, HttpCompletionOption.ResponseHeadersRead, cancellationToken); | ||
| return response.IsSuccessStatusCode; | ||
| } | ||
| catch (HttpRequestException) | ||
| { | ||
| return false; | ||
| } | ||
| } | ||
|
|
||
| /// <inheritdoc/> | ||
| public override async Task WaitForSidecarAsync(CancellationToken cancellationToken = default) | ||
| { | ||
| while (true) | ||
| { | ||
| var response = await CheckOutboundHealthAsync(cancellationToken); | ||
| if (response) | ||
| { | ||
| break; | ||
| } | ||
| await Task.Delay(TimeSpan.FromMilliseconds(500), cancellationToken); | ||
| } | ||
| } | ||
|
|
||
| /// <inheritdoc/> | ||
| public async override Task ShutdownSidecarAsync(CancellationToken cancellationToken = default) | ||
| { | ||
| await client.ShutdownAsync(new Empty(), CreateCallOptions(null, cancellationToken)); | ||
| } | ||
|
|
||
| #endregion | ||
|
Contributor
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. Pretty simple :) |
||
|
|
||
| protected override void Dispose(bool disposing) | ||
| { | ||
|
|
||
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
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.
nitpicking:
Do we generally try to keep the func/method name the same across SDKs?
I'm asking this because on go-sdk and python-sdk we named it as
Shutdownrather thanShutdownSidecar[Async]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.
This is something that we'll define in the sig-sdk group, but I do think it's important to keep naming consistent. I do worry that both of those are a little to lax on the name though.
Do you think it's worth being different here for clarity? Having the API just be Shutdown, to me, doesn't really tell the user what it's doing.
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 don't have a strong opinion here,
There are negative and positive effects of being explicit in this case, I do not feel much comfortable exposing the word
SidecarI would say that "ShutdownDaprd" sound better, and, if by any chance we would have more than one sidecar (probably won't happen) it becomes explicit which one is shutting down. But again, it's nitpicking and I agree with you that justShutdownis too genericThere 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.
+1 to everything said here. This seems like a good chance to be consistent on the terminology.