diff --git a/src/Runner.Common/RunnerDotcomServer.cs b/src/Runner.Common/RunnerDotcomServer.cs index 64cef9255..dd80ea02f 100644 --- a/src/Runner.Common/RunnerDotcomServer.cs +++ b/src/Runner.Common/RunnerDotcomServer.cs @@ -19,8 +19,6 @@ namespace GitHub.Runner.Common Task AddRunnerAsync(int runnerGroupId, TaskAgent agent, string githubUrl, string githubToken, string publicKey); Task> GetRunnerGroupsAsync(string githubUrl, string githubToken); - - string GetGitHubRequestId(HttpResponseHeaders headers); } public enum RequestType @@ -195,7 +193,7 @@ namespace GitHub.Runner.Common if (response != null) { responseStatus = response.StatusCode; - var githubRequestId = GetGitHubRequestId(response.Headers); + var githubRequestId = UrlUtil.GetGitHubRequestId(response.Headers); if (response.IsSuccessStatusCode) { @@ -224,14 +222,5 @@ namespace GitHub.Runner.Common await Task.Delay(backOff); } } - - public string GetGitHubRequestId(HttpResponseHeaders headers) - { - if (headers.TryGetValues("x-github-request-id", out var headerValues)) - { - return headerValues.FirstOrDefault(); - } - return string.Empty; - } } } diff --git a/src/Runner.Listener/Configuration/ConfigurationManager.cs b/src/Runner.Listener/Configuration/ConfigurationManager.cs index b98216938..597b80078 100644 --- a/src/Runner.Listener/Configuration/ConfigurationManager.cs +++ b/src/Runner.Listener/Configuration/ConfigurationManager.cs @@ -709,7 +709,7 @@ namespace GitHub.Runner.Listener.Configuration { var response = await httpClient.PostAsync(githubApiUrl, new StringContent(string.Empty)); responseStatus = response.StatusCode; - var githubRequestId = _dotcomServer.GetGitHubRequestId(response.Headers); + var githubRequestId = UrlUtil.GetGitHubRequestId(response.Headers); if (response.IsSuccessStatusCode) { @@ -772,7 +772,7 @@ namespace GitHub.Runner.Listener.Configuration { var response = await httpClient.PostAsync(githubApiUrl, new StringContent(StringUtil.ConvertToJson(bodyObject), null, "application/json")); responseStatus = response.StatusCode; - var githubRequestId = _dotcomServer.GetGitHubRequestId(response.Headers); + var githubRequestId = UrlUtil.GetGitHubRequestId(response.Headers); if (response.IsSuccessStatusCode) { diff --git a/src/Runner.Sdk/Util/UrlUtil.cs b/src/Runner.Sdk/Util/UrlUtil.cs index 8a51b8344..01658da05 100644 --- a/src/Runner.Sdk/Util/UrlUtil.cs +++ b/src/Runner.Sdk/Util/UrlUtil.cs @@ -1,4 +1,6 @@ using System; +using System.Linq; +using System.Net.Http.Headers; namespace GitHub.Runner.Sdk { @@ -48,5 +50,15 @@ namespace GitHub.Runner.Sdk return credUri.Uri; } + + public static string GetGitHubRequestId(HttpResponseHeaders headers) + { + if (headers != null && + headers.TryGetValues("x-github-request-id", out var headerValues)) + { + return headerValues.FirstOrDefault(); + } + return string.Empty; + } } } diff --git a/src/Runner.Worker/ActionManager.cs b/src/Runner.Worker/ActionManager.cs index b11b69947..69c4a338d 100644 --- a/src/Runner.Worker/ActionManager.cs +++ b/src/Runner.Worker/ActionManager.cs @@ -10,15 +10,15 @@ using System.Text; using System.Threading; using System.Threading.Tasks; using GitHub.DistributedTask.ObjectTemplating.Tokens; +using GitHub.DistributedTask.WebApi; using GitHub.Runner.Common; using GitHub.Runner.Common.Util; using GitHub.Runner.Sdk; using GitHub.Runner.Worker.Container; using GitHub.Services.Common; -using WebApi = GitHub.DistributedTask.WebApi; using Pipelines = GitHub.DistributedTask.Pipelines; using PipelineTemplateConstants = GitHub.DistributedTask.Pipelines.ObjectTemplating.PipelineTemplateConstants; -using GitHub.DistributedTask.WebApi; +using WebApi = GitHub.DistributedTask.WebApi; namespace GitHub.Runner.Worker { @@ -835,6 +835,12 @@ namespace GitHub.Runner.Worker httpClient.DefaultRequestHeaders.UserAgent.AddRange(HostContext.UserAgents); using (var response = await httpClient.GetAsync(link)) { + var requestId = UrlUtil.GetGitHubRequestId(response.Headers); + if (!string.IsNullOrEmpty(requestId)) + { + Trace.Info($"Request URL: {link} X-GitHub-Request-Id: {requestId} Http Status: {response.StatusCode}"); + } + if (response.IsSuccessStatusCode) { using (var result = await response.Content.ReadAsStreamAsync()) @@ -849,7 +855,7 @@ namespace GitHub.Runner.Worker else if (response.StatusCode == HttpStatusCode.NotFound) { // It doesn't make sense to retry in this case, so just stop - throw new ActionNotFoundException(new Uri(link)); + throw new ActionNotFoundException(new Uri(link), requestId); } else { diff --git a/src/Runner.Worker/ActionNotFoundException.cs b/src/Runner.Worker/ActionNotFoundException.cs index 41f899ef2..99ffdeded 100644 --- a/src/Runner.Worker/ActionNotFoundException.cs +++ b/src/Runner.Worker/ActionNotFoundException.cs @@ -5,8 +5,8 @@ namespace GitHub.Runner.Worker { public class ActionNotFoundException : Exception { - public ActionNotFoundException(Uri actionUri) - : base(FormatMessage(actionUri)) + public ActionNotFoundException(Uri actionUri, string requestId) + : base(FormatMessage(actionUri, requestId)) { } @@ -25,8 +25,13 @@ namespace GitHub.Runner.Worker { } - private static string FormatMessage(Uri actionUri) + private static string FormatMessage(Uri actionUri, string requestId) { + if (!string.IsNullOrEmpty(requestId)) + { + return $"An action could not be found at the URI '{actionUri}' ({requestId})"; + } + return $"An action could not be found at the URI '{actionUri}'"; } }