Skip to content

Commit cfe175a

Browse files
authored
audit: count workflow failure when telemetry is unavailable (#42046)
1 parent ebe5b8e commit cfe175a

3 files changed

Lines changed: 32 additions & 0 deletions

File tree

pkg/cli/audit.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -747,6 +747,9 @@ func applyAuditMetrics(run WorkflowRun, results auditAnalysisResults) WorkflowRu
747747
run.TokenUsage = results.metrics.TokenUsage
748748
run.Turns = results.metrics.Turns
749749
run.ErrorCount = results.failedJobCount
750+
if run.Conclusion == "failure" && run.ErrorCount == 0 {
751+
run.ErrorCount = 1
752+
}
750753
run.WarningCount = 0
751754
run.SafeItemsCount = results.safeItemsCount
752755
return run

pkg/cli/audit_report.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -299,6 +299,9 @@ func buildAuditData(processedRun ProcessedRun, metrics LogMetrics, mcpToolUsage
299299
ErrorCount: run.ErrorCount,
300300
WarningCount: run.WarningCount,
301301
}
302+
if run.Conclusion == "failure" && metricsData.ErrorCount == 0 {
303+
metricsData.ErrorCount = 1
304+
}
302305

303306
needsFallbackMetrics := metricsData.TokenUsage == 0 || metricsData.Turns == 0
304307
needsFallbackEngineConfig := run.LogsPath != "" && findAwInfoPath(run.LogsPath) == ""

pkg/cli/audit_test.go

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,32 @@ func TestBuildAuditData(t *testing.T) {
263263
}
264264
}
265265

266+
func TestBuildAuditDataCountsFailedWorkflowWithoutTelemetryAsError(t *testing.T) {
267+
processedRun := ProcessedRun{
268+
Run: WorkflowRun{
269+
DatabaseID: 123456,
270+
WorkflowName: "Failed Workflow",
271+
Status: "completed",
272+
Conclusion: "failure",
273+
LogsPath: testutil.TempDir(t, "test-*"),
274+
},
275+
}
276+
277+
auditData := buildAuditData(processedRun, LogMetrics{}, nil)
278+
279+
assert.Equal(t, 1, auditData.Metrics.ErrorCount, "failed workflow should contribute at least one error")
280+
}
281+
282+
func TestApplyAuditMetricsCountsWorkflowFailureWithoutTelemetry(t *testing.T) {
283+
run := WorkflowRun{
284+
Conclusion: "failure",
285+
}
286+
287+
updated := applyAuditMetrics(run, auditAnalysisResults{})
288+
289+
assert.Equal(t, 1, updated.ErrorCount, "failed workflow should contribute at least one error")
290+
}
291+
266292
func TestDescribeFile(t *testing.T) {
267293
tests := []struct {
268294
filename string

0 commit comments

Comments
 (0)