-
Notifications
You must be signed in to change notification settings - Fork 995
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
Publish job telemetry to run-service. #3545
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 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 |
---|---|---|
|
@@ -15,6 +15,7 @@ | |
using GitHub.Runner.Sdk; | ||
using GitHub.Services.Common; | ||
using GitHub.Services.WebApi; | ||
using Sdk.RSWebApi.Contracts; | ||
using Pipelines = GitHub.DistributedTask.Pipelines; | ||
|
||
namespace GitHub.Runner.Worker | ||
|
@@ -279,7 +280,12 @@ private async Task<TaskResult> CompleteJobAsync(IRunServer runServer, IExecution | |
jobContext.Debug($"Finishing: {message.JobDisplayName}"); | ||
TaskResult result = jobContext.Complete(taskResult); | ||
|
||
await ShutdownQueue(throwOnFailure: false); | ||
var jobQueueTelemetry = await ShutdownQueue(throwOnFailure: false); | ||
// include any job telemetry from the background upload process. | ||
if (jobQueueTelemetry?.Count > 0) | ||
{ | ||
jobContext.Global.JobTelemetry.AddRange(jobQueueTelemetry); | ||
} | ||
|
||
// Make sure to clean temp after file upload since they may be pending fileupload still use the TEMP dir. | ||
_tempDirectoryManager?.CleanupTempDirectory(); | ||
|
@@ -297,14 +303,21 @@ private async Task<TaskResult> CompleteJobAsync(IRunServer runServer, IExecution | |
environmentUrl = urlStringToken.Value; | ||
} | ||
|
||
// Get telemetry | ||
IList<Telemetry> telemetry = null; | ||
if (jobContext.Global.JobTelemetry.Count > 0) | ||
{ | ||
telemetry = jobContext.Global.JobTelemetry.Select(x => new Telemetry { Type = x.Type.ToString(), Message = x.Message, }).ToList(); | ||
} | ||
|
||
Trace.Info($"Raising job completed against run service"); | ||
var completeJobRetryLimit = 5; | ||
var exceptions = new List<Exception>(); | ||
while (completeJobRetryLimit-- > 0) | ||
{ | ||
try | ||
{ | ||
await runServer.CompleteJobAsync(message.Plan.PlanId, message.JobId, result, jobContext.JobOutputs, jobContext.Global.StepsResult, jobContext.Global.JobAnnotations, environmentUrl, default); | ||
await runServer.CompleteJobAsync(message.Plan.PlanId, message.JobId, result, jobContext.JobOutputs, jobContext.Global.StepsResult, jobContext.Global.JobAnnotations, environmentUrl, telemetry, default); | ||
return result; | ||
} | ||
catch (Exception ex) | ||
|
@@ -329,56 +342,14 @@ private async Task<TaskResult> CompleteJobAsync(IJobServer jobServer, IExecution | |
|
||
if (_runnerSettings.DisableUpdate == true) | ||
{ | ||
try | ||
{ | ||
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. i moved this to its own method in the bottom of the file, so i can easily diff the different between send job completion to run-service vs. actions-service. |
||
var currentVersion = new PackageVersion(BuildConstants.RunnerPackage.Version); | ||
ServiceEndpoint systemConnection = message.Resources.Endpoints.Single(x => string.Equals(x.Name, WellKnownServiceEndpointNames.SystemVssConnection, StringComparison.OrdinalIgnoreCase)); | ||
VssCredentials serverCredential = VssUtil.GetVssCredential(systemConnection); | ||
|
||
var runnerServer = HostContext.GetService<IRunnerServer>(); | ||
await runnerServer.ConnectAsync(systemConnection.Url, serverCredential); | ||
var serverPackages = await runnerServer.GetPackagesAsync("agent", BuildConstants.RunnerPackage.PackageName, 5, includeToken: false, cancellationToken: CancellationToken.None); | ||
if (serverPackages.Count > 0) | ||
{ | ||
serverPackages = serverPackages.OrderByDescending(x => x.Version).ToList(); | ||
Trace.Info($"Newer packages {StringUtil.ConvertToJson(serverPackages.Select(x => x.Version.ToString()))}"); | ||
|
||
var warnOnFailedJob = false; // any minor/patch version behind. | ||
var warnOnOldRunnerVersion = false; // >= 2 minor version behind | ||
if (serverPackages.Any(x => x.Version.CompareTo(currentVersion) > 0)) | ||
{ | ||
Trace.Info($"Current runner version {currentVersion} is behind the latest runner version {serverPackages[0].Version}."); | ||
warnOnFailedJob = true; | ||
} | ||
|
||
if (serverPackages.Where(x => x.Version.Major == currentVersion.Major && x.Version.Minor > currentVersion.Minor).Count() > 1) | ||
{ | ||
Trace.Info($"Current runner version {currentVersion} is way behind the latest runner version {serverPackages[0].Version}."); | ||
warnOnOldRunnerVersion = true; | ||
} | ||
|
||
if (result == TaskResult.Failed && warnOnFailedJob) | ||
{ | ||
jobContext.Warning($"This job failure may be caused by using an out of date self-hosted runner. You are currently using runner version {currentVersion}. Please update to the latest version {serverPackages[0].Version}"); | ||
} | ||
else if (warnOnOldRunnerVersion) | ||
{ | ||
jobContext.Warning($"This self-hosted runner is currently using runner version {currentVersion}. This version is out of date. Please update to the latest version {serverPackages[0].Version}"); | ||
} | ||
} | ||
} | ||
catch (Exception ex) | ||
{ | ||
// Ignore any error since suggest runner update is best effort. | ||
Trace.Error($"Caught exception during runner version check: {ex}"); | ||
} | ||
await WarningOutdatedRunnerAsync(jobContext, message, result); | ||
} | ||
|
||
try | ||
{ | ||
var jobQueueTelemetry = await ShutdownQueue(throwOnFailure: true); | ||
// include any job telemetry from the background upload process. | ||
if (jobQueueTelemetry.Count > 0) | ||
if (jobQueueTelemetry?.Count > 0) | ||
{ | ||
jobContext.Global.JobTelemetry.AddRange(jobQueueTelemetry); | ||
} | ||
|
@@ -506,5 +477,52 @@ private async Task<IList<JobTelemetry>> ShutdownQueue(bool throwOnFailure) | |
|
||
return Array.Empty<JobTelemetry>(); | ||
} | ||
|
||
private async Task WarningOutdatedRunnerAsync(IExecutionContext jobContext, Pipelines.AgentJobRequestMessage message, TaskResult result) | ||
{ | ||
try | ||
{ | ||
var currentVersion = new PackageVersion(BuildConstants.RunnerPackage.Version); | ||
ServiceEndpoint systemConnection = message.Resources.Endpoints.Single(x => string.Equals(x.Name, WellKnownServiceEndpointNames.SystemVssConnection, StringComparison.OrdinalIgnoreCase)); | ||
VssCredentials serverCredential = VssUtil.GetVssCredential(systemConnection); | ||
|
||
var runnerServer = HostContext.GetService<IRunnerServer>(); | ||
await runnerServer.ConnectAsync(systemConnection.Url, serverCredential); | ||
var serverPackages = await runnerServer.GetPackagesAsync("agent", BuildConstants.RunnerPackage.PackageName, 5, includeToken: false, cancellationToken: CancellationToken.None); | ||
if (serverPackages.Count > 0) | ||
{ | ||
serverPackages = serverPackages.OrderByDescending(x => x.Version).ToList(); | ||
Trace.Info($"Newer packages {StringUtil.ConvertToJson(serverPackages.Select(x => x.Version.ToString()))}"); | ||
|
||
var warnOnFailedJob = false; // any minor/patch version behind. | ||
var warnOnOldRunnerVersion = false; // >= 2 minor version behind | ||
if (serverPackages.Any(x => x.Version.CompareTo(currentVersion) > 0)) | ||
{ | ||
Trace.Info($"Current runner version {currentVersion} is behind the latest runner version {serverPackages[0].Version}."); | ||
warnOnFailedJob = true; | ||
} | ||
|
||
if (serverPackages.Where(x => x.Version.Major == currentVersion.Major && x.Version.Minor > currentVersion.Minor).Count() > 1) | ||
{ | ||
Trace.Info($"Current runner version {currentVersion} is way behind the latest runner version {serverPackages[0].Version}."); | ||
warnOnOldRunnerVersion = true; | ||
} | ||
|
||
if (result == TaskResult.Failed && warnOnFailedJob) | ||
{ | ||
jobContext.Warning($"This job failure may be caused by using an out of date self-hosted runner. You are currently using runner version {currentVersion}. Please update to the latest version {serverPackages[0].Version}"); | ||
} | ||
else if (warnOnOldRunnerVersion) | ||
{ | ||
jobContext.Warning($"This self-hosted runner is currently using runner version {currentVersion}. This version is out of date. Please update to the latest version {serverPackages[0].Version}"); | ||
} | ||
} | ||
} | ||
catch (Exception ex) | ||
{ | ||
// Ignore any error since suggest runner update is best effort. | ||
Trace.Error($"Caught exception during runner version check: {ex}"); | ||
} | ||
} | ||
} | ||
} |
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,20 @@ | ||
using System.Runtime.Serialization; | ||
|
||
namespace Sdk.RSWebApi.Contracts | ||
{ | ||
[DataContract] | ||
public struct Telemetry | ||
{ | ||
public Telemetry(string message, string type) | ||
{ | ||
Message = message; | ||
Type = type; | ||
} | ||
|
||
[DataMember(Name = "message", EmitDefaultValue = false)] | ||
public string Message { get; set; } | ||
|
||
[DataMember(Name = "type", EmitDefaultValue = false)] | ||
public string Type { get; set; } | ||
} | ||
} |
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
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.
match the behavior for sending job complete to actions service.