Skip to content

Commit e6417c7

Browse files
authored
feat: detect pipeline & jobs allowed to fail (#990)
* fix: missing new status success_with_warnings * feat: detect jobs allowed to fail
1 parent 1a9ff4b commit e6417c7

File tree

7 files changed

+16
-5
lines changed

7 files changed

+16
-5
lines changed

pkg/controller/collectors.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ var (
1010
environmentInformationLabels = []string{"environment_id", "external_url", "kind", "ref", "latest_commit_short_id", "current_commit_short_id", "available", "username"}
1111
testSuiteLabels = []string{"test_suite_name"}
1212
testCaseLabels = []string{"test_case_name", "test_case_classname"}
13-
statusesList = [...]string{"created", "waiting_for_resource", "preparing", "pending", "running", "success", "failed", "canceled", "skipped", "manual", "scheduled", "error"}
13+
statusesList = [...]string{"created", "waiting_for_resource", "preparing", "pending", "running", "success", "failed", "canceled", "skipped", "manual", "scheduled", "error", "success_with_warnings"}
1414
)
1515

1616
// NewInternalCollectorCurrentlyQueuedTasksCount returns a new collector for the gcpe_currently_queued_tasks_count metric.

pkg/controller/jobs.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,13 +173,18 @@ func (c *Controller) ProcessJobMetrics(ctx context.Context, ref schemas.Ref, job
173173
Value: job.ArtifactSize,
174174
})
175175

176+
jobStatus := job.Status
177+
if jobStatus == "failed" && job.AllowFailure {
178+
jobStatus = "success_with_warnings"
179+
}
180+
176181
emitStatusMetric(
177182
ctx,
178183
c.Store,
179184
schemas.MetricKindJobStatus,
180185
labels,
181186
statusesList[:],
182-
job.Status,
187+
jobStatus,
183188
ref.Project.OutputSparseStatusMetrics,
184189
)
185190
}

pkg/controller/jobs_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ func TestProcessJobMetrics(t *testing.T) {
8080
Stage: "🚀",
8181
TagList: "",
8282
ArtifactSize: 150,
83+
AllowFailure: true,
8384
Runner: schemas.Runner{
8485
Description: "foo-123-bar",
8586
},
@@ -163,7 +164,7 @@ func TestProcessJobMetrics(t *testing.T) {
163164
}
164165
assert.Equal(t, artifactSize, metrics[artifactSize.Key()])
165166

166-
labels["status"] = newJob.Status
167+
labels["status"] = "success_with_warnings"
167168
status := schemas.Metric{
168169
Kind: schemas.MetricKindJobStatus,
169170
Labels: labels,

pkg/schemas/jobs.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ type Job struct {
1717
Status string
1818
TagList string
1919
ArtifactSize float64
20+
AllowFailure bool
2021
FailureReason string
2122
Runner Runner
2223
}
@@ -54,6 +55,7 @@ func NewJob(gj goGitlab.Job) Job {
5455
Status: gj.Status,
5556
TagList: strings.Join(gj.TagList, ","),
5657
ArtifactSize: artifactSize,
58+
AllowFailure: gj.AllowFailure,
5759
FailureReason: gj.FailureReason,
5860

5961
Runner: Runner{

pkg/schemas/jobs_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ func TestNewJob(t *testing.T) {
1919
StartedAt: &startedAt,
2020
Duration: 15,
2121
QueuedDuration: 10,
22+
AllowFailure: true,
2223
Status: "failed",
2324
Stage: "🚀",
2425
TagList: []string{"test-tag"},
@@ -56,6 +57,7 @@ func TestNewJob(t *testing.T) {
5657
Status: "failed",
5758
TagList: "test-tag",
5859
ArtifactSize: 150,
60+
AllowFailure: true,
5961

6062
Runner: Runner{
6163
Description: "xxx",

pkg/schemas/pipelines.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package schemas
33
import (
44
"context"
55
"strconv"
6+
"strings"
67

78
log "github.com/sirupsen/logrus"
89
goGitlab "gitlab.com/gitlab-org/api/client-go"
@@ -83,7 +84,7 @@ func NewPipeline(ctx context.Context, gp goGitlab.Pipeline) Pipeline {
8384
}
8485

8586
if gp.DetailedStatus != nil {
86-
pipeline.Status = gp.DetailedStatus.Group
87+
pipeline.Status = strings.ReplaceAll(gp.DetailedStatus.Group, "-", "_")
8788
} else {
8889
pipeline.Status = gp.Status
8990
}

pkg/schemas/pipelines_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ func TestNewPipeline(t *testing.T) {
5353
Label: "passed with warnings",
5454
Group: "success-with-warnings",
5555
},
56-
"success-with-warnings",
56+
"success_with_warnings",
5757
},
5858
}
5959

0 commit comments

Comments
 (0)