Skip to content
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

Upload the diagnostic logs to the Results Service #3114

Merged
15 changes: 15 additions & 0 deletions src/Runner.Common/JobServerQueue.cs
Original file line number Diff line number Diff line change
Expand Up @@ -551,6 +551,10 @@ private async Task ProcessResultsUploadQueueAsync(bool runOnce = false)
{
await UploadSummaryFile(file);
}
if (string.Equals(file.Type, CoreAttachmentType.DiagnosticLog, StringComparison.OrdinalIgnoreCase))
jtamsut marked this conversation as resolved.
Show resolved Hide resolved
jtamsut marked this conversation as resolved.
Show resolved Hide resolved
{
await UploadResultsDiagnosticLogsFile(file);
}
else if (String.Equals(file.Type, CoreAttachmentType.ResultsLog, StringComparison.OrdinalIgnoreCase))
{
if (file.RecordId != _jobTimelineRecordId)
Expand Down Expand Up @@ -922,6 +926,17 @@ private async Task UploadSummaryFile(ResultsUploadFileInfo file)
await UploadResultsFile(file, summaryHandler);
}

private async Task UploadResultsDiagnosticLogsFile(ResultsUploadFileInfo file)
{
Trace.Info($"Starting to upload diagnostic logs file to results service {file.Name}, {file.Path}");
ResultsFileUploadHandler diagnosticLogsHandler = async (file) =>
{
await _resultsServer.CreateResultsDiagnosticLogsAsync(file.PlanId, file.JobId, file.Path, CancellationToken.None);
};

await UploadResultsFile(file, diagnosticLogsHandler);
}

private async Task UploadResultsStepLogFile(ResultsUploadFileInfo file)
{
Trace.Info($"Starting upload of step log file to results service {file.Name}, {file.Path}");
Expand Down
14 changes: 14 additions & 0 deletions src/Runner.Common/ResultsServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ Task CreateResultsJobLogAsync(string planId, string jobId, string file, bool fin

Task UpdateResultsWorkflowStepsAsync(Guid scopeIdentifier, string hubName, Guid planId, Guid timelineId,
IEnumerable<TimelineRecord> records, CancellationToken cancellationToken);

Task CreateResultsDiagnosticLogsAsync(string planId, string jobId, string file, CancellationToken cancellationToken);
}

public sealed class ResultServer : RunnerService, IResultsServer
Expand Down Expand Up @@ -141,6 +143,18 @@ public Task UpdateResultsWorkflowStepsAsync(Guid scopeIdentifier, string hubName
throw new InvalidOperationException("Results client is not initialized.");
}

public Task CreateResultsDiagnosticLogsAsync(string planId, string jobId, string file,
CancellationToken cancellationToken)
{
if (_resultsClient != null)
{
return _resultsClient.UploadResultsDiagnosticLogsAsync(planId, jobId, file,
cancellationToken: cancellationToken);
}

throw new InvalidOperationException("Results client is not initialized.");
}

public ValueTask DisposeAsync()
{
CloseWebSocket(WebSocketCloseStatus.NormalClosure, CancellationToken.None);
Expand Down
2 changes: 2 additions & 0 deletions src/Runner.Worker/DiagnosticLogManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,8 @@ public void UploadDiagnosticLogs(IExecutionContext executionContext,

parentContext.QueueAttachFile(type: CoreAttachmentType.DiagnosticLog, name: diagnosticsZipFileName, filePath: diagnosticsZipFilePath);

parentContext.QueueDiagnosticLogFile(name: diagnosticsZipFileName, filePath: diagnosticsZipFilePath);

executionContext.Debug("Diagnostic file upload complete.");
}

Expand Down
14 changes: 14 additions & 0 deletions src/Runner.Worker/ExecutionContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ public interface IExecutionContext : IRunnerService
long Write(string tag, string message);
void QueueAttachFile(string type, string name, string filePath);
void QueueSummaryFile(string name, string filePath, Guid stepRecordId);
void QueueDiagnosticLogFile(string name, string filePath);

// timeline record update methods
void Start(string currentOperation = null);
Expand Down Expand Up @@ -982,6 +983,19 @@ public void QueueSummaryFile(string name, string filePath, Guid stepRecordId)
_jobServerQueue.QueueResultsUpload(stepRecordId, name, filePath, ChecksAttachmentType.StepSummary, deleteSource: false, finalize: true, firstBlock: true, totalLines: 0);
}

public void QueueDiagnosticLogFile(string name, string filePath)
{
ArgUtil.NotNullOrEmpty(name, nameof(name));
ArgUtil.NotNullOrEmpty(filePath, nameof(filePath));

jtamsut marked this conversation as resolved.
Show resolved Hide resolved

if (!File.Exists(filePath))
{
throw new FileNotFoundException($"Can't upload diagnostic log file: {filePath}. File does not exist.");
}
_jobServerQueue.QueueResultsUpload(_record.Id, name, filePath, CoreAttachmentType.DiagnosticLog, deleteSource: false, finalize: true, firstBlock: true, totalLines: 0);
jtamsut marked this conversation as resolved.
Show resolved Hide resolved
}

// Add OnMatcherChanged
public void Add(OnMatcherChanged handler)
{
Expand Down
20 changes: 20 additions & 0 deletions src/Sdk/WebApi/WebApi/Contracts.cs
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,26 @@ public class GetSignedStepLogsURLResponse
public long SoftSizeLimit;
}

[DataContract]
[JsonObject(NamingStrategyType = typeof(SnakeCaseNamingStrategy))]
public class GetSignedDiagnosticLogsURLRequest
{
[DataMember]
public string WorkflowJobRunBackendId;
[DataMember]
public string WorkflowRunBackendId;
}

[DataContract]
[JsonObject(NamingStrategyType = typeof(SnakeCaseNamingStrategy))]
public class GetSignedDiagnosticLogsURLResponse
{
[DataMember]
public string DiagLogsURL;
[DataMember]
public string BlobStorageType;
}

[DataContract]
[JsonObject(NamingStrategyType = typeof(SnakeCaseNamingStrategy))]
public class JobLogsMetadataCreate
Expand Down
39 changes: 39 additions & 0 deletions src/Sdk/WebApi/WebApi/ResultsHttpClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,32 @@ private async Task<GetSignedStepLogsURLResponse> GetStepLogUploadUrlAsync(string
return await GetResultsSignedURLResponse<GetSignedStepLogsURLRequest, GetSignedStepLogsURLResponse>(getStepLogsSignedBlobURLEndpoint, cancellationToken, request);
}

private async Task<GetSignedDiagnosticLogsURLResponse> GetSignedDiagnosticLogsURL(string planId, string jobId, CancellationToken cancellationToken)
jtamsut marked this conversation as resolved.
Show resolved Hide resolved
{
var request = new GetSignedDiagnosticLogsURLRequest()
{
WorkflowJobRunBackendId = jobId,
WorkflowRunBackendId = planId,
};

var getDiagnosticLogsSignedBlobURLEndpoint = new Uri(m_resultsServiceUrl, Constants.GetJobDiagLogsSignedBlobURL);

return await GetResultsSignedURLResponse<GetSignedDiagnosticLogsURLRequest, GetSignedDiagnosticLogsURLResponse>(getDiagnosticLogsSignedBlobURLEndpoint, cancellationToken, request);
}

private async Task<GetSignedDiagnosticLogsURLResponse> GetDiagnosticLogsUploadUrlAsync(string planId, string jobId, CancellationToken cancellationToken)
{
var request = new GetSignedDiagnosticLogsURLRequest()
{
WorkflowJobRunBackendId = jobId,
WorkflowRunBackendId = planId,
};

var getDiagnosticLogsSignedBlobURLEndpoint = new Uri(m_resultsServiceUrl, Constants.GetJobDiagLogsSignedBlobURL);

return await GetResultsSignedURLResponse<GetSignedDiagnosticLogsURLRequest, GetSignedDiagnosticLogsURLResponse>(getDiagnosticLogsSignedBlobURLEndpoint, cancellationToken, request);
}

private async Task<GetSignedJobLogsURLResponse> GetJobLogUploadUrlAsync(string planId, string jobId, CancellationToken cancellationToken)
{
var request = new GetSignedJobLogsURLRequest()
Expand Down Expand Up @@ -421,6 +447,18 @@ public async Task UploadResultsJobLogAsync(string planId, string jobId, string f
}
}

public async Task UploadResultsDiagnosticLogsAsync(string planId, string jobId, string file, CancellationToken cancellationToken)
{
// Get the upload url
var uploadUrlResponse = await GetDiagnosticLogsUploadUrlAsync(planId, jobId, cancellationToken);
if (uploadUrlResponse == null || uploadUrlResponse.DiagLogsURL == null)
{
throw new Exception("Failed to get diagnostic logs upload url");
}

await UploadLogFile(file, true, true, uploadUrlResponse.DiagLogsURL, uploadUrlResponse.BlobStorageType, cancellationToken);
}

private Step ConvertTimelineRecordToStep(TimelineRecord r)
{
return new Step()
Expand Down Expand Up @@ -511,6 +549,7 @@ public static class Constants
public static readonly string CreateStepLogsMetadata = ResultsReceiverTwirpEndpoint + "CreateStepLogsMetadata";
public static readonly string GetJobLogsSignedBlobURL = ResultsReceiverTwirpEndpoint + "GetJobLogsSignedBlobURL";
public static readonly string CreateJobLogsMetadata = ResultsReceiverTwirpEndpoint + "CreateJobLogsMetadata";
public static readonly string GetJobDiagLogsSignedBlobURL = ResultsReceiverTwirpEndpoint + "GetJobDiagLogsSignedBlobURL";
public static readonly string ResultsProtoApiV1Endpoint = "twirp/github.actions.results.api.v1.WorkflowStepUpdateService/";
public static readonly string WorkflowStepsUpdate = ResultsProtoApiV1Endpoint + "WorkflowStepsUpdate";

Expand Down
Loading