From 14812d84a9b86650573f4b3af254d4579ee805ee Mon Sep 17 00:00:00 2001 From: ChristopherHX Date: Sat, 2 Sep 2023 20:39:30 +0200 Subject: [PATCH] Fix upload results logs (#159) * fix UploadResults*LogAsync logic * fix results api requests --- protocol/logger/job_logger.go | 4 ++-- protocol/results/contracts.go | 4 ++-- protocol/results/service.go | 8 ++++---- protocol/results/timestamp_test.go | 2 +- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/protocol/logger/job_logger.go b/protocol/logger/job_logger.go index 268389f..ece3403 100644 --- a/protocol/logger/job_logger.go +++ b/protocol/logger/job_logger.go @@ -360,8 +360,8 @@ func (logger *JobLogger) update() error { logger.ChangeId++ updatereq := &results.StepsUpdateRequest{} updatereq.ChangeOrder = logger.ChangeId - updatereq.WorkflowJobRunBackendID = logger.JobRequest.Plan.PlanID - updatereq.WorkflowRunBackendID = logger.TimelineRecords.Value[0].ID + updatereq.WorkflowRunBackendID = logger.JobRequest.Plan.PlanID + updatereq.WorkflowJobRunBackendID = logger.TimelineRecords.Value[0].ID updatereq.Steps = make([]results.Step, len(logger.TimelineRecords.Value)-1) for i, rec := range logger.TimelineRecords.Value[1:] { updatereq.Steps[i] = results.ConvertTimelineRecordToStep(*rec) diff --git a/protocol/results/contracts.go b/protocol/results/contracts.go index 94b63e5..2be3711 100644 --- a/protocol/results/contracts.go +++ b/protocol/results/contracts.go @@ -45,7 +45,7 @@ type GetSignedStepLogsURLRequest struct { type GetSignedStepLogsURLResponse struct { LogsUrl string `json:"logs_url,omitempty"` BlobStorageType string `json:"blob_storage_type,omitempty"` - SoftSizeLimit int64 `json:"soft_size_limit,omitempty"` + // SoftSizeLimit int64 `json:"soft_size_limit,omitempty"` // a string in the backend? } type JobLogsMetadataCreate struct { @@ -119,7 +119,7 @@ func ConvertTimestamp(s *string) string { if s == nil || *s == "" { return "" } - if t, err := time.Parse(protocol.TimestampInputFormat, *s); err != nil { + if t, err := time.Parse(protocol.TimestampInputFormat, *s); err == nil { return t.Format(TimestampOutputFormat) } return "" diff --git a/protocol/results/service.go b/protocol/results/service.go index d301094..333ecc2 100644 --- a/protocol/results/service.go +++ b/protocol/results/service.go @@ -79,7 +79,7 @@ func (rs *ResultsService) UploadResultsStepSummaryAsync(ctx context.Context, pla req := &GetSignedStepSummaryURLRequest{ WorkflowRunBackendId: planId, WorkflowJobRunBackendId: jobId, - StepBackendId: jobId, + StepBackendId: stepId, } uploadUrlResponse := &GetSignedStepSummaryURLResponse{} url, err := rs.Connection.BuildURL(GetStepSummarySignedBlobURL, nil, nil) @@ -120,7 +120,7 @@ func (rs *ResultsService) UploadResultsStepLogAsync(ctx context.Context, planId req := &GetSignedStepLogsURLRequest{ WorkflowRunBackendId: planId, WorkflowJobRunBackendId: jobId, - StepBackendId: jobId, + StepBackendId: stepId, } uploadUrlResponse := &GetSignedStepLogsURLResponse{} url, err := rs.Connection.BuildURL(GetStepLogsSignedBlobURL, nil, nil) @@ -133,7 +133,7 @@ func (rs *ResultsService) UploadResultsStepLogAsync(ctx context.Context, planId if uploadUrlResponse.LogsUrl == "" { return fmt.Errorf("failed to get step log upload url") } - if !firstBlock { + if firstBlock { err := rs.CreateAppendFileAsync(ctx, uploadUrlResponse.LogsUrl, uploadUrlResponse.BlobStorageType) if err != nil { return err @@ -179,7 +179,7 @@ func (rs *ResultsService) UploadResultsJobLogAsync(ctx context.Context, planId s if uploadUrlResponse.LogsUrl == "" { return fmt.Errorf("failed to get step log upload url") } - if !firstBlock { + if firstBlock { err := rs.CreateAppendFileAsync(ctx, uploadUrlResponse.LogsUrl, uploadUrlResponse.BlobStorageType) if err != nil { return err diff --git a/protocol/results/timestamp_test.go b/protocol/results/timestamp_test.go index 85a9d29..28d901b 100644 --- a/protocol/results/timestamp_test.go +++ b/protocol/results/timestamp_test.go @@ -54,6 +54,6 @@ func TestConvertTimestamp(t *testing.T) { } for _, i := range table { - assert.Equal(t, i.Output, ConvertTimestamp(i.Input)) + assert.Equal(t, i.Output, ConvertTimestamp(&i.Input)) } }