-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Exit ephemeral runners on broker acknowledge job-not-found #4540
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
base: main
Are you sure you want to change the base?
Changes from 2 commits
4fc7538
b287711
5d65d6f
bcfe9f3
6cc27b6
52a21fc
836ff78
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -256,11 +256,24 @@ public async Task AcknowledgeRunnerRequestAsync( | |
| default: | ||
| break; | ||
| } | ||
|
|
||
| if (IsAcknowledgeJobNotFound(result.StatusCode, brokerError)) | ||
| { | ||
| throw new RunnerRequestJobNotFoundException(brokerError.Message); | ||
| } | ||
|
Member
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. should this merge with the switch above somehow? since they are both kind of checking the brokererror and throw exception. |
||
| } | ||
|
|
||
| throw new Exception($"Failed to acknowledge runner request. Request to {requestUri} failed with status: {result.StatusCode}. Error message {result.Error}"); | ||
| } | ||
|
|
||
| private static bool IsAcknowledgeJobNotFound(HttpStatusCode statusCode, BrokerError brokerError) | ||
| { | ||
| return statusCode == HttpStatusCode.NotFound && | ||
| brokerError?.StatusCode == (int)HttpStatusCode.NotFound && | ||
| !string.Equals(brokerError.ErrorKind, BrokerErrorKind.RunnerNotFound, StringComparison.Ordinal) && | ||
| string.Equals(brokerError.Message, "Job not found", StringComparison.OrdinalIgnoreCase); | ||
|
Collaborator
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. Can you help me understand more about this? Is there an error kind we could rely on, instead of message? I'm worried relying on the error message might be fragile. That's why error kind exists.
Member
Author
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 point, let me have a look at the API. |
||
| } | ||
|
|
||
| private static bool TryParseErrorBody(string errorBody, out BrokerError error) | ||
| { | ||
| if (!string.IsNullOrEmpty(errorBody)) | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| using System; | ||
|
|
||
| namespace GitHub.Services.WebApi | ||
| { | ||
| [Serializable] | ||
| public sealed class RunnerRequestJobNotFoundException : Exception | ||
| { | ||
| public RunnerRequestJobNotFoundException() | ||
| : base() | ||
| { | ||
| } | ||
|
|
||
| public RunnerRequestJobNotFoundException(String message) | ||
| : base(message) | ||
| { | ||
| } | ||
|
|
||
| public RunnerRequestJobNotFoundException(String message, Exception innerException) | ||
| : base(message, innerException) | ||
| { | ||
| } | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,76 @@ | ||
| using System; | ||
| using System.Net; | ||
| using System.Net.Http; | ||
| using System.Text; | ||
| using System.Threading; | ||
| using System.Threading.Tasks; | ||
| using GitHub.DistributedTask.WebApi; | ||
| using GitHub.Runner.Sdk; | ||
| using GitHub.Services.WebApi; | ||
| using GitHub.Services.WebApi.Jwt; | ||
| using Xunit; | ||
|
Copilot marked this conversation as resolved.
|
||
|
|
||
| namespace GitHub.Actions.RunService.WebApi.Tests; | ||
|
|
||
| public sealed class BrokerHttpClientL0 | ||
| { | ||
| [Fact] | ||
| public async Task AcknowledgeRunnerRequestAsyncThrowsRunnerRequestJobNotFoundException() | ||
| { | ||
| using var client = CreateClient( | ||
| HttpStatusCode.NotFound, | ||
| new BrokerError | ||
| { | ||
| Source = "actions-broker-listener", | ||
| StatusCode = (int)HttpStatusCode.NotFound, | ||
| Message = "Job not found", | ||
| }); | ||
|
|
||
| await Assert.ThrowsAsync<RunnerRequestJobNotFoundException>(() => | ||
| client.AcknowledgeRunnerRequestAsync("runner-request", Guid.NewGuid(), "2.0.0", TaskAgentStatus.Online, cancellationToken: CancellationToken.None)); | ||
| } | ||
|
|
||
| [Fact] | ||
| public async Task AcknowledgeRunnerRequestAsyncKeepsRunnerNotFoundClassification() | ||
| { | ||
| using var client = CreateClient( | ||
| HttpStatusCode.NotFound, | ||
| new BrokerError | ||
| { | ||
| Source = "actions-broker-listener", | ||
| ErrorKind = BrokerErrorKind.RunnerNotFound, | ||
| StatusCode = (int)HttpStatusCode.NotFound, | ||
| Message = "Runner not found", | ||
| }); | ||
|
|
||
| await Assert.ThrowsAsync<RunnerNotFoundException>(() => | ||
| client.AcknowledgeRunnerRequestAsync("runner-request", Guid.NewGuid(), "2.0.0", TaskAgentStatus.Online, cancellationToken: CancellationToken.None)); | ||
| } | ||
|
|
||
| private static BrokerHttpClient CreateClient(HttpStatusCode statusCode, BrokerError brokerError) | ||
| { | ||
| return new BrokerHttpClient( | ||
| new Uri("https://broker.actions.githubusercontent.com/"), | ||
| new StaticResponseHandler(new HttpResponseMessage(statusCode) | ||
| { | ||
| Content = new StringContent(JsonUtility.ToString(brokerError), Encoding.UTF8, "application/json"), | ||
| }), | ||
| disposeHandler: true); | ||
| } | ||
|
|
||
| private sealed class StaticResponseHandler : HttpMessageHandler | ||
| { | ||
| private readonly HttpResponseMessage _response; | ||
|
|
||
| public StaticResponseHandler(HttpResponseMessage response) | ||
| { | ||
| _response = response; | ||
| } | ||
|
|
||
| protected override Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken) | ||
| { | ||
| _response.RequestMessage = request; | ||
| return Task.FromResult(_response); | ||
| } | ||
| } | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.