Skip to content

Commit 1eb15f2

Browse files
authored
Report job has infra failure to run-service (#4073)
1 parent afe4fc8 commit 1eb15f2

File tree

9 files changed

+23
-10
lines changed

9 files changed

+23
-10
lines changed

src/Runner.Common/RunServer.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ Task CompleteJobAsync(
3030
string environmentUrl,
3131
IList<Telemetry> telemetry,
3232
string billingOwnerId,
33+
string infrastructureFailureCategory,
3334
CancellationToken token);
3435

3536
Task<RenewJobResponse> RenewJobAsync(Guid planId, Guid jobId, CancellationToken token);
@@ -80,11 +81,12 @@ public Task CompleteJobAsync(
8081
string environmentUrl,
8182
IList<Telemetry> telemetry,
8283
string billingOwnerId,
84+
string infrastructureFailureCategory,
8385
CancellationToken cancellationToken)
8486
{
8587
CheckConnection();
8688
return RetryRequest(
87-
async () => await _runServiceHttpClient.CompleteJobAsync(requestUri, planId, jobId, result, outputs, stepResults, jobAnnotations, environmentUrl, telemetry, billingOwnerId, cancellationToken), cancellationToken,
89+
async () => await _runServiceHttpClient.CompleteJobAsync(requestUri, planId, jobId, result, outputs, stepResults, jobAnnotations, environmentUrl, telemetry, billingOwnerId, infrastructureFailureCategory, cancellationToken), cancellationToken,
8890
shouldRetry: ex =>
8991
ex is not VssUnauthorizedException && // HTTP status 401
9092
ex is not TaskOrchestrationJobNotFoundException); // HTTP status 404

src/Runner.Listener/JobDispatcher.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1211,7 +1211,7 @@ private async Task ForceFailJob(IRunServer runServer, Pipelines.AgentJobRequestM
12111211
jobAnnotations.Add(annotation.Value);
12121212
}
12131213

1214-
await runServer.CompleteJobAsync(message.Plan.PlanId, message.JobId, TaskResult.Failed, outputs: null, stepResults: null, jobAnnotations: jobAnnotations, environmentUrl: null, telemetry: null, billingOwnerId: message.BillingOwnerId, CancellationToken.None);
1214+
await runServer.CompleteJobAsync(message.Plan.PlanId, message.JobId, TaskResult.Failed, outputs: null, stepResults: null, jobAnnotations: jobAnnotations, environmentUrl: null, telemetry: null, billingOwnerId: message.BillingOwnerId, infrastructureFailureCategory: null, CancellationToken.None);
12151215
}
12161216
catch (Exception ex)
12171217
{

src/Runner.Worker/ActionManager.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -111,15 +111,15 @@ public sealed class ActionManager : RunnerService, IActionManager
111111
{
112112
// Log the error and fail the PrepareActionsAsync Initialization.
113113
Trace.Error($"Caught exception from PrepareActionsAsync Initialization: {ex}");
114-
executionContext.InfrastructureError(ex.Message);
114+
executionContext.InfrastructureError(ex.Message, category: "resolve_action");
115115
executionContext.Result = TaskResult.Failed;
116116
throw;
117117
}
118118
catch (InvalidActionArchiveException ex)
119119
{
120120
// Log the error and fail the PrepareActionsAsync Initialization.
121121
Trace.Error($"Caught exception from PrepareActionsAsync Initialization: {ex}");
122-
executionContext.InfrastructureError(ex.Message);
122+
executionContext.InfrastructureError(ex.Message, category: "invalid_action_download");
123123
executionContext.Result = TaskResult.Failed;
124124
throw;
125125
}
@@ -777,15 +777,15 @@ private async Task DownloadRepositoryActionAsync(IExecutionContext executionCont
777777
IOUtil.DeleteDirectory(destDirectory, executionContext.CancellationToken);
778778
Directory.CreateDirectory(destDirectory);
779779

780-
if (downloadInfo.PackageDetails != null)
780+
if (downloadInfo.PackageDetails != null)
781781
{
782782
executionContext.Output($"##[group]Download immutable action package '{downloadInfo.NameWithOwner}@{downloadInfo.Ref}'");
783783
executionContext.Output($"Version: {downloadInfo.PackageDetails.Version}");
784784
executionContext.Output($"Digest: {downloadInfo.PackageDetails.ManifestDigest}");
785785
executionContext.Output($"Source commit SHA: {downloadInfo.ResolvedSha}");
786786
executionContext.Output("##[endgroup]");
787-
}
788-
else
787+
}
788+
else
789789
{
790790
executionContext.Output($"Download action repository '{downloadInfo.NameWithOwner}@{downloadInfo.Ref}' (SHA:{downloadInfo.ResolvedSha})");
791791
}

src/Runner.Worker/ExecutionContext.cs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -522,6 +522,10 @@ public TaskResult Complete(TaskResult? result = null, string currentOperation =
522522
if (annotation != null)
523523
{
524524
stepResult.Annotations.Add(annotation.Value);
525+
if (annotation.Value.IsInfrastructureIssue && string.IsNullOrEmpty(Global.InfrastructureFailureCategory))
526+
{
527+
Global.InfrastructureFailureCategory = issue.Category;
528+
}
525529
}
526530
});
527531

@@ -1335,9 +1339,9 @@ public static void Error(this IExecutionContext context, string message)
13351339
}
13361340

13371341
// Do not add a format string overload. See comment on ExecutionContext.Write().
1338-
public static void InfrastructureError(this IExecutionContext context, string message)
1342+
public static void InfrastructureError(this IExecutionContext context, string message, string category = null)
13391343
{
1340-
var issue = new Issue() { Type = IssueType.Error, Message = message, IsInfrastructureIssue = true };
1344+
var issue = new Issue() { Type = IssueType.Error, Message = message, IsInfrastructureIssue = true, Category = category };
13411345
context.AddIssue(issue, ExecutionContextLogOptions.Default);
13421346
}
13431347

src/Runner.Worker/GlobalContext.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ public sealed class GlobalContext
2727
public StepsContext StepsContext { get; set; }
2828
public Variables Variables { get; set; }
2929
public bool WriteDebug { get; set; }
30+
public string InfrastructureFailureCategory { get; set; }
3031
public JObject ContainerHookState { get; set; }
3132
}
3233
}

src/Runner.Worker/JobRunner.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -321,7 +321,7 @@ private async Task<TaskResult> CompleteJobAsync(IRunServer runServer, IExecution
321321
{
322322
try
323323
{
324-
await runServer.CompleteJobAsync(message.Plan.PlanId, message.JobId, result, jobContext.JobOutputs, jobContext.Global.StepsResult, jobContext.Global.JobAnnotations, environmentUrl, telemetry, billingOwnerId: message.BillingOwnerId, default);
324+
await runServer.CompleteJobAsync(message.Plan.PlanId, message.JobId, result, jobContext.JobOutputs, jobContext.Global.StepsResult, jobContext.Global.JobAnnotations, environmentUrl, telemetry, billingOwnerId: message.BillingOwnerId, infrastructureFailureCategory: jobContext.Global.InfrastructureFailureCategory, default);
325325
return result;
326326
}
327327
catch (VssUnauthorizedException ex)

src/Sdk/RSWebApi/Contracts/CompleteJobRequest.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,5 +35,8 @@ public class CompleteJobRequest
3535

3636
[DataMember(Name = "billingOwnerId", EmitDefaultValue = false)]
3737
public string BillingOwnerId { get; set; }
38+
39+
[DataMember(Name = "infrastructureFailureCategory", EmitDefaultValue = false)]
40+
public string InfrastructureFailureCategory { get; set; }
3841
}
3942
}

src/Sdk/RSWebApi/Contracts/IssueExtensions.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ public static class IssueExtensions
4242
StartColumn = columnNumber,
4343
EndColumn = endColumnNumber,
4444
StepNumber = stepNumber,
45+
IsInfrastructureIssue = issue.IsInfrastructureIssue ?? false
4546
};
4647
}
4748

src/Sdk/RSWebApi/RunServiceHttpClient.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@ public async Task CompleteJobAsync(
131131
string environmentUrl,
132132
IList<Telemetry> telemetry,
133133
string billingOwnerId,
134+
string infrastructureFailureCategory,
134135
CancellationToken cancellationToken = default)
135136
{
136137
HttpMethod httpMethod = new HttpMethod("POST");
@@ -145,6 +146,7 @@ public async Task CompleteJobAsync(
145146
EnvironmentUrl = environmentUrl,
146147
Telemetry = telemetry,
147148
BillingOwnerId = billingOwnerId,
149+
InfrastructureFailureCategory = infrastructureFailureCategory
148150
};
149151

150152
requestUri = new Uri(requestUri, "completejob");

0 commit comments

Comments
 (0)