Skip to content

Commit

Permalink
fix: skip check runs when generating runners metrics (#151)
Browse files Browse the repository at this point in the history
* fix: skip check runs when generating runners metrics

* remove log, add explainer comment
  • Loading branch information
Elfo404 authored Oct 4, 2024
1 parent 606c074 commit 74a0e4d
Show file tree
Hide file tree
Showing 4 changed files with 176 additions and 10 deletions.
9 changes: 9 additions & 0 deletions receiver/githubactionsreceiver/metric_event_handling.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,15 @@ func newMetricsHandler(settings receiver.Settings, cfg *Config, logger *zap.Logg
}

func (m *metricsHandler) eventToMetrics(event *github.WorkflowJobEvent) pmetric.Metrics {
if event.GetWorkflowJob().GetConclusion() == "skipped" ||
// Check runs are also reported via WorkflowJobEvent, we want to skip them when generating metrics.
// We do so by checking if the runner ID is 0, which is the zero value for the field.
// see https://github.com/actions/actions-runner-controller/issues/2118.
// NOTE: This also applies to cancelled jobs which have not been started.
(event.GetAction() == "completed" && event.GetWorkflowJob().GetRunnerID() == 0) {
return m.mb.Emit()
}

repo := event.GetRepo().GetFullName()

labels := ""
Expand Down
2 changes: 1 addition & 1 deletion receiver/githubactionsreceiver/receiver.go
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ func (gar *githubActionsReceiver) ServeHTTP(w http.ResponseWriter, r *http.Reque
// Handle events based on specific types and completion status
switch e := event.(type) {
case *github.WorkflowJobEvent:
if gar.metricsConsumer != nil && e.GetWorkflowJob().GetConclusion() != "skipped" {
if gar.metricsConsumer != nil {
err := gar.metricsConsumer.ConsumeMetrics(ctx, gar.metricsHandler.eventToMetrics(e))

if err != nil {
Expand Down
27 changes: 18 additions & 9 deletions receiver/githubactionsreceiver/receiver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,16 +111,25 @@ func TestEventToTracesTraces(t *testing.T) {

func TestEventToMetrics(t *testing.T) {
tests := []struct {
desc string
payloadFilePath string
eventType string
expectedMetrics int
desc string
payloadFilePath string
eventType string
expectedMetrics int
expectedDataPoints int
}{
{
desc: "WorkflowJobEvent processing",
payloadFilePath: "./testdata/queued/1_workflow_job_queued.json",
eventType: "workflow_job",
expectedMetrics: 1,
desc: "WorkflowJobEvent processing",
payloadFilePath: "./testdata/queued/1_workflow_job_queued.json",
eventType: "workflow_job",
expectedMetrics: 1,
expectedDataPoints: len(metadata.MapAttributeCiGithubWorkflowJobStatus),
},
{
desc: "WorkflowJobEvent (check run) processing",
payloadFilePath: "./testdata/completed/5_workflow_job_check-run_completed.json",
eventType: "workflow_job",
expectedMetrics: 0,
expectedDataPoints: 0,
},
}

Expand All @@ -146,7 +155,7 @@ func TestEventToMetrics(t *testing.T) {
metrics := mh.eventToMetrics(event.(*github.WorkflowJobEvent))

require.Equalf(t, test.expectedMetrics, metrics.MetricCount(), "%s: unexpected number of metrics", test.desc)
require.Equalf(t, len(metadata.MapAttributeCiGithubWorkflowJobStatus), metrics.DataPointCount(), "%s: unexpected number of datapoints", test.desc)
require.Equalf(t, test.expectedDataPoints, metrics.DataPointCount(), "%s: unexpected number of datapoints", test.desc)
})
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,148 @@
{
"action": "completed",
"workflow_job": {
"id": 17556730984,
"run_id": 6454805877,
"workflow_name": "Tests",
"head_branch": "main",
"run_url": "https://api.github.com/repos/foo/webhook-testing/actions/runs/6454805877",
"run_attempt": 10,
"node_id": "CR_kwDOKdcZe88AAAAEFnZ0aA",
"head_sha": "4d6ee57193c29fc3b23723c386f462287b60bf87",
"url": "https://api.github.com/repos/foo/webhook-testing/actions/jobs/17556730984",
"html_url": "https://github.com/foo/webhook-testing/actions/runs/6454805877/job/17556730984",
"status": "completed",
"conclusion": "success",
"created_at": "2023-10-13T10:11:27Z",
"started_at": "2023-10-13T10:11:34Z",
"completed_at": "2023-10-13T10:11:44Z",
"name": "check-run-eslint",
"steps": [],
"check_run_url": "https://api.github.com/repos/foo/webhook-testing/check-runs/17556730984",
"labels": [],
"runner_id": null,
"runner_name": null,
"runner_group_id": null,
"runner_group_name": null
},
"repository": {
"id": 701962619,
"node_id": "R_kgDOKdcZew",
"name": "webhook-testing",
"full_name": "foo/webhook-testing",
"private": true,
"owner": {
"login": "foo",
"id": 1499932,
"node_id": "MDQ6VXNlcjE0OTk5MzI=",
"avatar_url": "https://avatars.githubusercontent.com/u/1499932?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/foo",
"html_url": "https://github.com/foo",
"followers_url": "https://api.github.com/users/foo/followers",
"following_url": "https://api.github.com/users/foo/following{/other_user}",
"gists_url": "https://api.github.com/users/foo/gists{/gist_id}",
"starred_url": "https://api.github.com/users/foo/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/foo/subscriptions",
"organizations_url": "https://api.github.com/users/foo/orgs",
"repos_url": "https://api.github.com/users/foo/repos",
"events_url": "https://api.github.com/users/foo/events{/privacy}",
"received_events_url": "https://api.github.com/users/foo/received_events",
"type": "User",
"site_admin": false
},
"html_url": "https://github.com/foo/webhook-testing",
"description": null,
"fork": false,
"url": "https://api.github.com/repos/foo/webhook-testing",
"forks_url": "https://api.github.com/repos/foo/webhook-testing/forks",
"keys_url": "https://api.github.com/repos/foo/webhook-testing/keys{/key_id}",
"collaborators_url": "https://api.github.com/repos/foo/webhook-testing/collaborators{/collaborator}",
"teams_url": "https://api.github.com/repos/foo/webhook-testing/teams",
"hooks_url": "https://api.github.com/repos/foo/webhook-testing/hooks",
"issue_events_url": "https://api.github.com/repos/foo/webhook-testing/issues/events{/number}",
"events_url": "https://api.github.com/repos/foo/webhook-testing/events",
"assignees_url": "https://api.github.com/repos/foo/webhook-testing/assignees{/user}",
"branches_url": "https://api.github.com/repos/foo/webhook-testing/branches{/branch}",
"tags_url": "https://api.github.com/repos/foo/webhook-testing/tags",
"blobs_url": "https://api.github.com/repos/foo/webhook-testing/git/blobs{/sha}",
"git_tags_url": "https://api.github.com/repos/foo/webhook-testing/git/tags{/sha}",
"git_refs_url": "https://api.github.com/repos/foo/webhook-testing/git/refs{/sha}",
"trees_url": "https://api.github.com/repos/foo/webhook-testing/git/trees{/sha}",
"statuses_url": "https://api.github.com/repos/foo/webhook-testing/statuses/{sha}",
"languages_url": "https://api.github.com/repos/foo/webhook-testing/languages",
"stargazers_url": "https://api.github.com/repos/foo/webhook-testing/stargazers",
"contributors_url": "https://api.github.com/repos/foo/webhook-testing/contributors",
"subscribers_url": "https://api.github.com/repos/foo/webhook-testing/subscribers",
"subscription_url": "https://api.github.com/repos/foo/webhook-testing/subscription",
"commits_url": "https://api.github.com/repos/foo/webhook-testing/commits{/sha}",
"git_commits_url": "https://api.github.com/repos/foo/webhook-testing/git/commits{/sha}",
"comments_url": "https://api.github.com/repos/foo/webhook-testing/comments{/number}",
"issue_comment_url": "https://api.github.com/repos/foo/webhook-testing/issues/comments{/number}",
"contents_url": "https://api.github.com/repos/foo/webhook-testing/contents/{+path}",
"compare_url": "https://api.github.com/repos/foo/webhook-testing/compare/{base}...{head}",
"merges_url": "https://api.github.com/repos/foo/webhook-testing/merges",
"archive_url": "https://api.github.com/repos/foo/webhook-testing/{archive_format}{/ref}",
"downloads_url": "https://api.github.com/repos/foo/webhook-testing/downloads",
"issues_url": "https://api.github.com/repos/foo/webhook-testing/issues{/number}",
"pulls_url": "https://api.github.com/repos/foo/webhook-testing/pulls{/number}",
"milestones_url": "https://api.github.com/repos/foo/webhook-testing/milestones{/number}",
"notifications_url": "https://api.github.com/repos/foo/webhook-testing/notifications{?since,all,participating}",
"labels_url": "https://api.github.com/repos/foo/webhook-testing/labels{/name}",
"releases_url": "https://api.github.com/repos/foo/webhook-testing/releases{/id}",
"deployments_url": "https://api.github.com/repos/foo/webhook-testing/deployments",
"created_at": "2023-10-13T04:54:00Z",
"updated_at": "2023-10-13T05:26:13Z",
"pushed_at": "2023-10-13T09:30:39Z",
"git_url": "git://github.com/foo/webhook-testing.git",
"ssh_url": "[email protected]:foo/webhook-testing.git",
"clone_url": "https://github.com/foo/webhook-testing.git",
"svn_url": "https://github.com/foo/webhook-testing",
"homepage": null,
"size": 27,
"stargazers_count": 0,
"watchers_count": 0,
"language": "Python",
"has_issues": true,
"has_projects": true,
"has_downloads": true,
"has_wiki": false,
"has_pages": false,
"has_discussions": false,
"forks_count": 0,
"mirror_url": null,
"archived": false,
"disabled": false,
"open_issues_count": 0,
"license": null,
"allow_forking": true,
"is_template": false,
"web_commit_signoff_required": false,
"topics": [],
"visibility": "private",
"forks": 0,
"open_issues": 0,
"watchers": 0,
"default_branch": "main"
},
"sender": {
"login": "foo",
"id": 1499932,
"node_id": "MDQ6VXNlcjE0OTk5MzI=",
"avatar_url": "https://avatars.githubusercontent.com/u/1499932?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/foo",
"html_url": "https://github.com/foo",
"followers_url": "https://api.github.com/users/foo/followers",
"following_url": "https://api.github.com/users/foo/following{/other_user}",
"gists_url": "https://api.github.com/users/foo/gists{/gist_id}",
"starred_url": "https://api.github.com/users/foo/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/foo/subscriptions",
"organizations_url": "https://api.github.com/users/foo/orgs",
"repos_url": "https://api.github.com/users/foo/repos",
"events_url": "https://api.github.com/users/foo/events{/privacy}",
"received_events_url": "https://api.github.com/users/foo/received_events",
"type": "User",
"site_admin": false
}
}

0 comments on commit 74a0e4d

Please sign in to comment.