Skip to content

Commit

Permalink
feat: failure reason (#718)
Browse files Browse the repository at this point in the history
Co-authored-by: Maxime VISONNEAU <[email protected]>
  • Loading branch information
strpc and mvisonneau committed Oct 1, 2023
1 parent 6494609 commit cf54477
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 8 deletions.
14 changes: 7 additions & 7 deletions docs/metrics.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,13 @@
| `gitlab_ci_pipeline_coverage` | Coverage of the most recent pipeline | [project], [topics], [ref], [kind], [source], [variables] | *available by default* |
| `gitlab_ci_pipeline_duration_seconds` | Duration in seconds of the most recent pipeline | [project], [topics], [ref], [kind], [source], [variables] | *available by default* |
| `gitlab_ci_pipeline_id` | ID of the most recent pipeline | [project], [topics], [ref], [kind], [source], [variables] | *available by default* |
| `gitlab_ci_pipeline_job_artifact_size_bytes` | Artifact size in bytes (sum of all of them) of the most recent job | [project], [topics], [ref], [runner_description], [kind], [source], [variables], [stage], [job_name], [tag_list] | `project_defaults.pull.pipeline.jobs.enabled` |
| `gitlab_ci_pipeline_job_duration_seconds` | Duration in seconds of the most recent job | [project], [topics], [ref], [runner_description], [kind], [source], [variables], [stage], [job_name], [tag_list] | `project_defaults.pull.pipeline.jobs.enabled` |
| `gitlab_ci_pipeline_job_id` | ID of the most recent job | [project], [topics], [ref], [runner_description], [kind], [source], [variables], [stage], [job_name], [tag_list] | `project_defaults.pull.pipeline.jobs.enabled` |
| `gitlab_ci_pipeline_job_queued_duration_seconds` | Duration in seconds the most recent job has been queued before starting | [project], [topics], [ref], [runner_description], [kind], [source], [variables], [stage], [job_name], [tag_list] | `project_defaults.pull.pipeline.jobs.enabled` |
| `gitlab_ci_pipeline_job_run_count` | Number of executions of a job | [project], [topics], [ref], [runner_description], [kind], [source], [variables], [stage], [job_name], [tag_list] | `project_defaults.pull.pipeline.jobs.enabled` |
| `gitlab_ci_pipeline_job_status` | Status of the most recent job | [project], [topics], [ref], [runner_description], [kind], [source], [variables], [stage], [job_name], [tag_list], [status] | `project_defaults.pull.pipeline.jobs.enabled` |
| `gitlab_ci_pipeline_job_timestamp` | Creation date timestamp of the the most recent job | [project], [topics], [ref], [runner_description], [kind], [source], [variables], [stage], [job_name], [tag_list] | `project_defaults.pull.pipeline.jobs.enabled` |
| `gitlab_ci_pipeline_job_artifact_size_bytes` | Artifact size in bytes (sum of all of them) of the most recent job | [project], [topics], [ref], [runner_description], [kind], [source], [variables], [stage], [job_name], [tag_list], [failure_reason] | `project_defaults.pull.pipeline.jobs.enabled` |
| `gitlab_ci_pipeline_job_duration_seconds` | Duration in seconds of the most recent job | [project], [topics], [ref], [runner_description], [kind], [source], [variables], [stage], [job_name], [tag_list], [failure_reason] | `project_defaults.pull.pipeline.jobs.enabled` |
| `gitlab_ci_pipeline_job_id` | ID of the most recent job | [project], [topics], [ref], [runner_description], [kind], [source], [variables], [stage], [job_name], [tag_list], [failure_reason] | `project_defaults.pull.pipeline.jobs.enabled` |
| `gitlab_ci_pipeline_job_queued_duration_seconds` | Duration in seconds the most recent job has been queued before starting | [project], [topics], [ref], [runner_description], [kind], [source], [variables], [stage], [job_name], [tag_list], [failure_reason] | `project_defaults.pull.pipeline.jobs.enabled` |
| `gitlab_ci_pipeline_job_run_count` | Number of executions of a job | [project], [topics], [ref], [runner_description], [kind], [source], [variables], [stage], [job_name], [tag_list], [failure_reason] | `project_defaults.pull.pipeline.jobs.enabled` |
| `gitlab_ci_pipeline_job_status` | Status of the most recent job | [project], [topics], [ref], [runner_description], [kind], [source], [variables], [stage], [job_name], [tag_list], [status], [failure_reason] | `project_defaults.pull.pipeline.jobs.enabled` |
| `gitlab_ci_pipeline_job_timestamp` | Creation date timestamp of the the most recent job | [project], [topics], [ref], [runner_description], [kind], [source], [variables], [stage], [job_name], [tag_list], [failure_reason] | `project_defaults.pull.pipeline.jobs.enabled` |
| `gitlab_ci_pipeline_queued_duration_seconds` | Duration in seconds the most recent pipeline has been queued before starting | [project], [topics], [ref], [kind], [source], [variables] | *available by default* |
| `gitlab_ci_pipeline_run_count` | Number of executions of a pipeline | [project], [topics], [ref], [kind], [source], [variables] | *available by default* |
| `gitlab_ci_pipeline_status` | Status of the most recent pipeline | [project], [topics], [ref], [kind], [source], [variables], [status] | *available by default* |
Expand Down
2 changes: 1 addition & 1 deletion pkg/controller/collectors.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import "github.com/prometheus/client_golang/prometheus"

var (
defaultLabels = []string{"project", "topics", "kind", "ref", "source", "variables"}
jobLabels = []string{"stage", "job_name", "runner_description", "tag_list"}
jobLabels = []string{"stage", "job_name", "runner_description", "tag_list", "failure_reason"}
statusLabels = []string{"status"}
environmentLabels = []string{"project", "environment"}
environmentInformationLabels = []string{"environment_id", "external_url", "kind", "ref", "latest_commit_short_id", "current_commit_short_id", "available", "username"}
Expand Down
1 change: 1 addition & 0 deletions pkg/controller/jobs.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ func (c *Controller) ProcessJobMetrics(ctx context.Context, ref schemas.Ref, job
labels["stage"] = job.Stage
labels["job_name"] = job.Name
labels["tag_list"] = job.TagList
labels["failure_reason"] = job.FailureReason

if ref.Project.Pull.Pipeline.Jobs.RunnerDescription.Enabled {
re, err := regexp.Compile(ref.Project.Pull.Pipeline.Jobs.RunnerDescription.AggregationRegexp)
Expand Down
1 change: 1 addition & 0 deletions pkg/controller/jobs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ func TestProcessJobMetrics(t *testing.T) {
"source": ref.LatestPipeline.Source,
"stage": newJob.Stage,
"tag_list": newJob.TagList,
"failure_reason": newJob.FailureReason,
"job_name": newJob.Name,
"runner_description": ref.Project.Pull.Pipeline.Jobs.RunnerDescription.AggregationRegexp,
}
Expand Down
2 changes: 2 additions & 0 deletions pkg/schemas/jobs.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ type Job struct {
Status string
TagList string
ArtifactSize float64
FailureReason string
Runner Runner
}

Expand Down Expand Up @@ -53,6 +54,7 @@ func NewJob(gj goGitlab.Job) Job {
Status: gj.Status,
TagList: strings.Join(gj.TagList, ","),
ArtifactSize: artifactSize,
FailureReason: gj.FailureReason,

Runner: Runner{
Description: gj.Runner.Description,
Expand Down
1 change: 1 addition & 0 deletions pkg/schemas/metric.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ func (m Metric) Key() MetricKey {
m.Labels["stage"],
m.Labels["tag_list"],
m.Labels["job_name"],
m.Labels["failure_reason"],
})

case MetricKindEnvironmentBehindCommitsCount, MetricKindEnvironmentBehindDurationSeconds, MetricKindEnvironmentDeploymentCount, MetricKindEnvironmentDeploymentDurationSeconds, MetricKindEnvironmentDeploymentJobID, MetricKindEnvironmentDeploymentStatus, MetricKindEnvironmentDeploymentTimestamp, MetricKindEnvironmentInformation:
Expand Down

0 comments on commit cf54477

Please sign in to comment.