Skip to content

Commit d19c1ea

Browse files
authored
bugs, add sentry handler, add diagnostic logging (#2482)
* bugs, add sentry handler, add diagnostic logging * missed
1 parent 79cfe88 commit d19c1ea

File tree

7 files changed

+457
-81
lines changed

7 files changed

+457
-81
lines changed

backend/controllers/projects.go

Lines changed: 70 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -647,18 +647,27 @@ func (d DiggerController) SetJobStatusForProject(c *gin.Context) {
647647
return
648648
}
649649

650+
slog.Debug("Fetching job for status update", "jobId", jobId, "orgId", orgId)
650651
job, err := models.DB.GetDiggerJob(jobId)
651652
if err != nil {
652-
slog.Error("Error fetching job", "jobId", jobId, "error", err)
653+
slog.Error("DIAGNOSTIC #1: Failed to fetch job from database",
654+
"jobId", jobId,
655+
"error", err,
656+
"errorType", fmt.Sprintf("%T", err))
653657
c.JSON(http.StatusInternalServerError, gin.H{"error": "Error fetching job"})
654658
return
655659
}
656660

657661
batchId := *job.BatchID
658662

663+
slog.Debug("Fetching organization", "orgId", orgId, "jobId", jobId)
659664
org, err := models.DB.GetOrganisationById(orgId)
660665
if err != nil || org == nil {
661-
slog.Error("Error getting organisation", "jobId", jobId, "error", err)
666+
slog.Error("DIAGNOSTIC #2: Failed to fetch organization",
667+
"orgId", orgId,
668+
"jobId", jobId,
669+
"error", err,
670+
"orgIsNil", org == nil)
662671
c.JSON(http.StatusInternalServerError, gin.H{"error": "Error fetching organisation"})
663672
return
664673
}
@@ -674,13 +683,14 @@ func (d DiggerController) SetJobStatusForProject(c *gin.Context) {
674683
switch request.Status {
675684
case "created":
676685
job.Status = orchestrator_scheduler.DiggerJobCreated
686+
slog.Debug("Updating job status to created", "jobId", jobId)
677687
err := models.DB.UpdateDiggerJob(job)
678688
if err != nil {
679-
slog.Error("Error updating job status",
689+
slog.Error("DIAGNOSTIC #3: Failed to update job status (created)",
680690
"jobId", jobId,
681691
"status", request.Status,
682692
"error", err,
683-
)
693+
"errorType", fmt.Sprintf("%T", err))
684694
c.JSON(http.StatusInternalServerError, gin.H{"error": "Error updating job status"})
685695
return
686696
}
@@ -695,13 +705,14 @@ func (d DiggerController) SetJobStatusForProject(c *gin.Context) {
695705

696706
case "triggered":
697707
job.Status = orchestrator_scheduler.DiggerJobTriggered
708+
slog.Debug("Updating job status to triggered", "jobId", jobId)
698709
err := models.DB.UpdateDiggerJob(job)
699710
if err != nil {
700-
slog.Error("Error updating job status",
711+
slog.Error("DIAGNOSTIC #3: Failed to update job status (triggered)",
701712
"jobId", jobId,
702713
"status", request.Status,
703714
"error", err,
704-
)
715+
"errorType", fmt.Sprintf("%T", err))
705716
c.JSON(http.StatusInternalServerError, gin.H{"error": "Error updating job status"})
706717
return
707718
}
@@ -720,13 +731,14 @@ func (d DiggerController) SetJobStatusForProject(c *gin.Context) {
720731
slog.Debug("Adding workflow url to job", "jobId", jobId, "workflowUrl", request.WorkflowUrl)
721732
job.WorkflowRunUrl = &request.WorkflowUrl
722733
}
734+
slog.Debug("Updating job status to started", "jobId", jobId)
723735
err := models.DB.UpdateDiggerJob(job)
724736
if err != nil {
725-
slog.Error("Error updating job status",
737+
slog.Error("DIAGNOSTIC #3: Failed to update job status (started)",
726738
"jobId", jobId,
727739
"status", request.Status,
728740
"error", err,
729-
)
741+
"errorType", fmt.Sprintf("%T", err))
730742
c.JSON(http.StatusInternalServerError, gin.H{"error": "Error updating job status"})
731743
return
732744
}
@@ -745,12 +757,14 @@ func (d DiggerController) SetJobStatusForProject(c *gin.Context) {
745757
job.Status = orchestrator_scheduler.DiggerJobSucceeded
746758
job.TerraformOutput = request.TerraformOutput
747759
if request.Footprint != nil {
760+
slog.Debug("Marshalling plan footprint", "jobId", jobId)
748761
job.PlanFootprint, err = json.Marshal(request.Footprint)
749762
if err != nil {
750-
slog.Error("Error marshalling plan footprint",
763+
slog.Error("DIAGNOSTIC #4: Failed to marshal plan footprint",
751764
"jobId", jobId,
752765
"error", err,
753-
)
766+
"errorType", fmt.Sprintf("%T", err),
767+
"footprintSize", len(fmt.Sprintf("%v", request.Footprint)))
754768
c.JSON(http.StatusInternalServerError, gin.H{"error": "Error marshalling plan footprint"})
755769
return
756770
}
@@ -790,13 +804,14 @@ func (d DiggerController) SetJobStatusForProject(c *gin.Context) {
790804
job.PRCommentUrl = request.PrCommentUrl
791805
job.PRCommentId = prCommentId
792806

807+
slog.Debug("Updating job to succeeded", "jobId", jobId)
793808
err = models.DB.UpdateDiggerJob(job)
794809
if err != nil {
795-
slog.Error("Error updating job",
810+
slog.Error("DIAGNOSTIC #3: Failed to update job status (succeeded)",
796811
"jobId", jobId,
797812
"status", request.Status,
798813
"error", err,
799-
)
814+
"errorType", fmt.Sprintf("%T", err))
800815
c.JSON(http.StatusInternalServerError, gin.H{"error": "Error saving job"})
801816
return
802817
}
@@ -925,13 +940,14 @@ func (d DiggerController) SetJobStatusForProject(c *gin.Context) {
925940
segment.Track(*org, "", "", "github", "ci_job_failed", nil)
926941
job.Status = orchestrator_scheduler.DiggerJobFailed
927942
job.TerraformOutput = request.TerraformOutput
943+
slog.Debug("Updating job status to failed", "jobId", jobId)
928944
err := models.DB.UpdateDiggerJob(job)
929945
if err != nil {
930-
slog.Error("Error updating job status",
946+
slog.Error("DIAGNOSTIC #3: Failed to update job status (failed)",
931947
"jobId", jobId,
932948
"status", request.Status,
933949
"error", err,
934-
)
950+
"errorType", fmt.Sprintf("%T", err))
935951
c.JSON(http.StatusInternalServerError, gin.H{"error": "Error saving job"})
936952
return
937953
}
@@ -987,57 +1003,77 @@ func (d DiggerController) SetJobStatusForProject(c *gin.Context) {
9871003
"jobId", jobId,
9881004
)
9891005

1006+
slog.Debug("Updating batch status", "batchId", batch.ID, "jobId", jobId)
9901007
err = models.DB.UpdateBatchStatus(batch)
9911008
if err != nil {
992-
slog.Error("Error updating batch status",
1009+
slog.Error("DIAGNOSTIC #5: Failed to update batch status",
9931010
"batchId", batch.ID,
1011+
"jobId", jobId,
9941012
"error", err,
995-
)
1013+
"errorType", fmt.Sprintf("%T", err))
9961014
c.JSON(http.StatusInternalServerError, gin.H{"error": "Error updating batch status"})
9971015
return
9981016
}
9991017

1018+
slog.Debug("Fetching refreshed batch", "batchId", batch.ID, "jobId", jobId)
10001019
refreshedBatch, err := models.DB.GetDiggerBatch(&batch.ID)
10011020
if err != nil {
1002-
slog.Error("Error getting refreshed batch",
1021+
slog.Error("DIAGNOSTIC #6: Failed to fetch refreshed batch",
10031022
"batchId", batch.ID,
1023+
"jobId", jobId,
10041024
"error", err,
1005-
)
1025+
"errorType", fmt.Sprintf("%T", err))
10061026
c.JSON(http.StatusInternalServerError, gin.H{"error": "Error getting refreshed batch"})
10071027
return
10081028
}
10091029
//err = UpdateCheckStatusForBatch(d.GithubClientProvider, refreshedBatch)
1030+
slog.Debug("Attempting to update GitHub Check Run for batch",
1031+
"batchId", batch.ID,
1032+
"checkRunId", refreshedBatch.CheckRunId,
1033+
"vcs", refreshedBatch.VCS,
1034+
"jobId", jobId)
10101035
err = UpdateCheckRunForBatch(d.GithubClientProvider, refreshedBatch)
10111036
if err != nil {
1012-
slog.Error("Error updating check status",
1013-
"batchId", batch.ID,
1037+
slog.Warn("DIAGNOSTIC #7: Failed to update GitHub Check Run for batch (non-fatal)",
10141038
"batchId", batch.ID,
1039+
"checkRunId", refreshedBatch.CheckRunId,
1040+
"vcs", refreshedBatch.VCS,
10151041
"error", err,
1016-
)
1017-
c.JSON(http.StatusInternalServerError, gin.H{"error": "Error updating aggregate status check"})
1018-
return
1042+
"errorType", fmt.Sprintf("%T", err))
1043+
// Continue processing - Check Run update is best-effort, not critical
1044+
} else {
1045+
slog.Debug("Successfully updated GitHub Check Run for batch", "batchId", batch.ID)
10191046
}
10201047

1048+
slog.Debug("Fetching refreshed job", "jobId", jobId, "batchId", batch.ID)
10211049
refreshedJob, err := models.DB.GetDiggerJob(jobId)
10221050
if err != nil {
1023-
slog.Error("Error getting refreshed job",
1051+
slog.Error("DIAGNOSTIC #8: Failed to fetch refreshed job",
10241052
"jobId", jobId,
1053+
"batchId", batch.ID,
10251054
"error", err,
1026-
)
1055+
"errorType", fmt.Sprintf("%T", err))
10271056
c.JSON(http.StatusInternalServerError, gin.H{"error": "Error getting refreshed job"})
10281057
return
10291058
}
10301059
//err = UpdateCommitStatusForJob(d.GithubClientProvider, refreshedJob)
1060+
slog.Debug("Attempting to update GitHub Check Run for job",
1061+
"jobId", jobId,
1062+
"checkRunId", refreshedJob.CheckRunId,
1063+
"vcs", refreshedJob.Batch.VCS,
1064+
"batchId", batch.ID)
10311065
err = UpdateCheckRunForJob(d.GithubClientProvider, refreshedJob)
10321066
if err != nil {
1033-
slog.Error("Error updating check status",
1067+
slog.Warn("DIAGNOSTIC #9: Failed to update GitHub Check Run for job (non-fatal)",
10341068
"jobId", jobId,
1069+
"checkRunId", refreshedJob.CheckRunId,
10351070
"batchId", batch.ID,
1036-
"jobId", jobId,
1071+
"vcs", refreshedJob.Batch.VCS,
10371072
"error", err,
1038-
)
1039-
c.JSON(http.StatusInternalServerError, gin.H{"error": "Error updating aggregate status check"})
1040-
return
1073+
"errorType", fmt.Sprintf("%T", err))
1074+
// Continue processing - Check Run update is best-effort, not critical
1075+
} else {
1076+
slog.Debug("Successfully updated GitHub Check Run for job", "jobId", jobId)
10411077
}
10421078

10431079
if batch.ReportTerraformOutputs {
@@ -1075,12 +1111,14 @@ func (d DiggerController) SetJobStatusForProject(c *gin.Context) {
10751111
}
10761112

10771113
// return batch summary to client
1114+
slog.Debug("Marshalling batch to JSON", "batchId", batch.ID, "jobId", jobId)
10781115
res, err := batch.MapToJsonStruct()
10791116
if err != nil {
1080-
slog.Error("Error getting batch details",
1117+
slog.Error("DIAGNOSTIC #10: Failed to marshal batch to JSON",
10811118
"batchId", batch.ID,
1119+
"jobId", jobId,
10821120
"error", err,
1083-
)
1121+
"errorType", fmt.Sprintf("%T", err))
10841122
c.JSON(http.StatusInternalServerError, gin.H{"error": "Error getting batch details"})
10851123
return
10861124
}

0 commit comments

Comments
 (0)