Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(actionsmetrics): Add owner and workflow_name labels to workflow job metrics #2225

Merged
merged 1 commit into from
Mar 13, 2023

Conversation

hamishforbes
Copy link
Contributor

@hamishforbes hamishforbes commented Jan 30, 2023

Fixes #2176

@Link- Link- added the needs triage Requires review from the maintainers label Jan 31, 2023
)
githubWorkflowJobRunDurationSeconds = prometheus.NewHistogramVec(
prometheus.HistogramOpts{
Name: "github_workflow_job_run_duration_seconds",
Help: "Run times for workflow jobs in seconds",
Buckets: runtimeBuckets,
},
[]string{"runs_on", "job_name", "job_conclusion"},
append(commonLabels, "job_conclusion"),
Copy link
Collaborator

@mumoshu mumoshu Feb 21, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe this usage of append isn't safe in Go and can produce unexpected results for subsequent append(commonLabels, ...) calls, because append can mutate the slice.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah interesting, sounds like that's more of an issue when using the colon slice notation but yeah seems sketchy!
Would you prefer to just use a literal and duplicate the common labels for each metric or try and retain the re-usable common label definition?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do like the idea of explicitly extracting and defining commonLabels!
How about adding a function to create a new copy of commonLabels, add some extra labels, and return the resulting slice? That way, we can repeat the function calls in places we currently refer to commonLabels.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

something lile:

func metricLabels(extras ...string) {
    return append(append([[]string{}, commonLabels...), extras...)
}

so that we can rewrite this line to

Suggested change
append(commonLabels, "job_conclusion"),
metricLabels("job_conclusion"),

@mumoshu
Copy link
Collaborator

mumoshu commented Feb 26, 2023

I recently merged #2218, and apparently, it contained half of this pull request, resulting in a conflict. Let me try resolving it.

@@ -64,6 +64,9 @@ func (reader *EventReader) ProcessWorkflowJobEvent(ctx context.Context, event in
runsOn := strings.Join(e.WorkflowJob.Labels, `,`)
labels["runs_on"] = runsOn
labels["job_name"] = *e.WorkflowJob.Name
labels["organization"] = *e.Repo.Owner.Login
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@hamishforbes I realized #2218 added the organization label with another value of *e.Org.Name. If we call it "organization", that might be the correct value.

However, I do think it might be a good idea to be able to see *e.Repo.Owner.Login via labels when the workflow job event is coming from a runner associated with a repository owned by a user, not an organization.

That said, would you like to include *e.Repo.Owner.Login as another label, like "owner"?

@mumoshu
Copy link
Collaborator

mumoshu commented Mar 12, 2023

@hamishforbes Hey! I've addressed my own comments in the lastest commit. The label is now owner and we use metricLabels function to copy commonLabels and add some custom labels. WDYT?

@mumoshu mumoshu changed the title Feat/metrics labels feat(actionsmetrics): Add owner to workflow job metrics Mar 12, 2023
@hamishforbes
Copy link
Contributor Author

@hamishforbes Hey! I've addressed my own comments in the lastest commit. The label is now owner and we use metricLabels function to copy commonLabels and add some custom labels. WDYT?

Looks good to me!

I do think branch as an optional label would also be good, but that can be another PR/Issue.

@mumoshu
Copy link
Collaborator

mumoshu commented Mar 13, 2023

@hamishforbes Thanks for your review! Re branch, it turned out that github-go does not expose workflow job's "head_branch" which is what I believe needed for our use case.
I'll try to submit a tiny pull request to github-go. Once it gets merged, we are good to go!

@mumoshu
Copy link
Collaborator

mumoshu commented Mar 13, 2023

Fixed some panics related to the logger and the metrics labels for the case we feed workflow jobs from a repository instead of an org.

@mumoshu mumoshu changed the title feat(actionsmetrics): Add owner to workflow job metrics feat(actionsmetrics): Add owner and workflow_name labels to workflow job metrics Mar 13, 2023
Copy link
Collaborator

@mumoshu mumoshu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like it's working well for me! Let me merge this and keep testing locally.
Thank you so much for your effort @hamishforbes!

@mumoshu mumoshu merged commit bcaac39 into actions:master Mar 13, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs triage Requires review from the maintainers
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add more labels to metrics-server metrics
3 participants