From 13c3489b6d405d585e9d0bd0ed5a819e66e15bc3 Mon Sep 17 00:00:00 2001 From: "dmitriy.krapivenko" Date: Sun, 29 Dec 2024 21:30:58 +0300 Subject: [PATCH 01/18] add workflow job and run even handlers --- .../inputs/webhooks/github/github_webhooks.go | 6 ++ .../webhooks/github/github_webhooks_models.go | 78 +++++++++++++++++++ 2 files changed, 84 insertions(+) diff --git a/plugins/inputs/webhooks/github/github_webhooks.go b/plugins/inputs/webhooks/github/github_webhooks.go index 069fe524ec388..677ae41e84e38 100644 --- a/plugins/inputs/webhooks/github/github_webhooks.go +++ b/plugins/inputs/webhooks/github/github_webhooks.go @@ -128,6 +128,12 @@ func (gh *GithubWebhook) NewEvent(data []byte, name string) (event, error) { case "watch": return generateEvent(data, &watchEvent{}) } + case "workflow_job": + return generateEvent(data, &workflowJobEvent{}) + } + case "workflow_run": + return generateEvent(data, &workflowRunEvent{}) + } return nil, &newEventError{"Not a recognized event type"} } diff --git a/plugins/inputs/webhooks/github/github_webhooks_models.go b/plugins/inputs/webhooks/github/github_webhooks_models.go index 18a5af9f0acd1..40c4f5d6c09e3 100644 --- a/plugins/inputs/webhooks/github/github_webhooks_models.go +++ b/plugins/inputs/webhooks/github/github_webhooks_models.go @@ -75,6 +75,24 @@ type pullRequestReviewComment struct { Comment string `json:"body"` } +type workflowJob struct { + RunAttempt int `json:"run_attempt"` + HeadBranch string `json:"head_branch"` + CreatedAt time `json:"created_at"` + StartedAt time `json:"started_at"` + CompletedAt time `json:"completed_at"` + Name string `json:"name"` +} + +type workflowRun struct { + HeadBranch string `json:"head_branch"` + CreatedAt time `json:"created_at"` + RunStartedAt time `json:"run_started_at"` + UpdatedAt time `json:"updated_at"` + RunAttempt int `json:"run_attempt"` + Name string `json:"name"` +} + type release struct { TagName string `json:"tag_name"` } @@ -646,3 +664,63 @@ func (s watchEvent) NewMetric() telegraf.Metric { m := metric.New(meas, t, f, time.Now()) return m } + +type workflowJobEvent struct { + Action string `json:"action"` + WorkflowJob workflowJob `json:"workflow_job"` + Repository repository `json:"repository"` + Sender sender `json:"sender"` +} + +func (s workflowJobEvent)NewMetric() telegraf.Metric { + event := "workflow_job" + t := map[string]string{ + "event": event, + "action": s.Action, + "repository": s.Repository.Repository, + "private": strconv.FormatBool(s.Repository.Private), + "user": s.Sender.User, + "admin": strconv.FormatBool(s.Sender.Admin), + "name": s.WorkflowJob.Name, + } + f := map[string]interface{}{ + "run_attempt": s.RunAttempt, + "queue_time": s.WorkflowJob.StartedAt.Sub(s.CreatedAt).Milliseconds(), + "run_time": s.WorkflowJob.CompletedAt.Sub(s.StartedAt).Milliseconds(), + "head_branch": s.WorkflowJob.HeadBranch, + } + m := metric.New(meas, t, f, time.Now()) + return m +} + +type workflowRunEvent struct { + Action string `json:"action"` + WorkflowJob workflowRun `json:"workflow_run"` + Repository repository `json:"repository"` + Sender sender `json:"sender"` +} + +func (s workflowRunEvent)NewMetric() telegraf.Metric { + event := "workflow_run" + t := map[string]string{ + "event": event, + "action": s.Action, + "repository": s.Repository.Repository, + "private": strconv.FormatBool(s.Repository.Private), + "user": s.Sender.User, + "admin": strconv.FormatBool(s.Sender.Admin), + "name": s.WorkflowRun.Name, + } + var run_time int := nil + if s.Action == "completed" { + run_time := s.WorkflowRun.UpdatedAt.Sub(s.RunStartedAt).Milliseconds() + } + f := map[string]interface{}{ + "run_attempt": s.RunAttempt, + "queue_time": s.WorkflowRun.Started_At.Sub(s.CreatedAt).Milliseconds(), + "run_time": run_time, + "head_branch": s.WorkflowRun.HeadBranch, + } + m := metric.New(meas, t, f, time.Now()) + return m +} \ No newline at end of file From f1192e0313a0c83347f01384e26ed676a220d0aa Mon Sep 17 00:00:00 2001 From: "dmitriy.krapivenko" Date: Sun, 29 Dec 2024 22:12:42 +0300 Subject: [PATCH 02/18] fix build --- .../inputs/webhooks/github/github_webhooks.go | 2 -- .../webhooks/github/github_webhooks_models.go | 35 +++++++++++-------- .../webhooks/github/github_webhooks_test.go | 8 +++++ 3 files changed, 29 insertions(+), 16 deletions(-) diff --git a/plugins/inputs/webhooks/github/github_webhooks.go b/plugins/inputs/webhooks/github/github_webhooks.go index 677ae41e84e38..cbc8700917b51 100644 --- a/plugins/inputs/webhooks/github/github_webhooks.go +++ b/plugins/inputs/webhooks/github/github_webhooks.go @@ -127,10 +127,8 @@ func (gh *GithubWebhook) NewEvent(data []byte, name string) (event, error) { return generateEvent(data, &teamAddEvent{}) case "watch": return generateEvent(data, &watchEvent{}) - } case "workflow_job": return generateEvent(data, &workflowJobEvent{}) - } case "workflow_run": return generateEvent(data, &workflowRunEvent{}) } diff --git a/plugins/inputs/webhooks/github/github_webhooks_models.go b/plugins/inputs/webhooks/github/github_webhooks_models.go index 40c4f5d6c09e3..9e4382bd4d6dd 100644 --- a/plugins/inputs/webhooks/github/github_webhooks_models.go +++ b/plugins/inputs/webhooks/github/github_webhooks_models.go @@ -78,17 +78,17 @@ type pullRequestReviewComment struct { type workflowJob struct { RunAttempt int `json:"run_attempt"` HeadBranch string `json:"head_branch"` - CreatedAt time `json:"created_at"` - StartedAt time `json:"started_at"` - CompletedAt time `json:"completed_at"` + CreatedAt string `json:"created_at"` + StartedAt string `json:"started_at"` + CompletedAt string `json:"completed_at"` Name string `json:"name"` } type workflowRun struct { HeadBranch string `json:"head_branch"` - CreatedAt time `json:"created_at"` - RunStartedAt time `json:"run_started_at"` - UpdatedAt time `json:"updated_at"` + CreatedAt string `json:"created_at"` + RunStartedAt string `json:"run_started_at"` + UpdatedAt string `json:"updated_at"` RunAttempt int `json:"run_attempt"` Name string `json:"name"` } @@ -683,10 +683,13 @@ func (s workflowJobEvent)NewMetric() telegraf.Metric { "admin": strconv.FormatBool(s.Sender.Admin), "name": s.WorkflowJob.Name, } + created_at, _ := time.Parse(time.RFC3339, s.WorkflowJob.CreatedAt) + started_at, _ := time.Parse(time.RFC3339, s.WorkflowJob.StartedAt) + completed_at, _ := time.Parse(time.RFC3339, s.WorkflowJob.CompletedAt) f := map[string]interface{}{ - "run_attempt": s.RunAttempt, - "queue_time": s.WorkflowJob.StartedAt.Sub(s.CreatedAt).Milliseconds(), - "run_time": s.WorkflowJob.CompletedAt.Sub(s.StartedAt).Milliseconds(), + "run_attempt": s.WorkflowJob.RunAttempt, + "queue_time": started_at.Sub(created_at).Milliseconds(), + "run_time": completed_at.Sub(started_at).Milliseconds(), "head_branch": s.WorkflowJob.HeadBranch, } m := metric.New(meas, t, f, time.Now()) @@ -695,7 +698,7 @@ func (s workflowJobEvent)NewMetric() telegraf.Metric { type workflowRunEvent struct { Action string `json:"action"` - WorkflowJob workflowRun `json:"workflow_run"` + WorkflowRun workflowRun `json:"workflow_run"` Repository repository `json:"repository"` Sender sender `json:"sender"` } @@ -711,13 +714,17 @@ func (s workflowRunEvent)NewMetric() telegraf.Metric { "admin": strconv.FormatBool(s.Sender.Admin), "name": s.WorkflowRun.Name, } - var run_time int := nil + var run_time int64 = 0 + created_at, _ := time.Parse(time.RFC3339, s.WorkflowRun.CreatedAt) + started_at, _ := time.Parse(time.RFC3339, s.WorkflowRun.RunStartedAt) + updated_at, _ := time.Parse(time.RFC3339, s.WorkflowRun.UpdatedAt) + if s.Action == "completed" { - run_time := s.WorkflowRun.UpdatedAt.Sub(s.RunStartedAt).Milliseconds() + run_time = updated_at.Sub(started_at).Milliseconds() } f := map[string]interface{}{ - "run_attempt": s.RunAttempt, - "queue_time": s.WorkflowRun.Started_At.Sub(s.CreatedAt).Milliseconds(), + "run_attempt": s.WorkflowRun.RunAttempt, + "queue_time": started_at.Sub(created_at).Milliseconds(), "run_time": run_time, "head_branch": s.WorkflowRun.HeadBranch, } diff --git a/plugins/inputs/webhooks/github/github_webhooks_test.go b/plugins/inputs/webhooks/github/github_webhooks_test.go index 94c912ef8d7d4..174345809f3cc 100644 --- a/plugins/inputs/webhooks/github/github_webhooks_test.go +++ b/plugins/inputs/webhooks/github/github_webhooks_test.go @@ -126,6 +126,14 @@ func TestEventWithSignatureSuccess(t *testing.T) { GithubWebhookRequestWithSignature(t, "watch", WatchEventJSON(), generateSignature("signature", []byte(WatchEventJSON())), http.StatusOK) } +func TestWorkflowJob(t *testing.T) { + GithubWebhookRequestWithSignature(t, "workflow_job", WatchEventJSON(), http.StatusOK) +} + +func TestWorkflowRun(t *testing.T) { + GithubWebhookRequestWithSignature(t, "workflow_run", WatchEventJSON(), http.StatusOK) +} + func TestCheckSignatureSuccess(t *testing.T) { if !checkSignature("my_little_secret", []byte("random-signature-body"), "sha1=3dca279e731c97c38e3019a075dee9ebbd0a99f0") { t.Errorf("check signature failed") From 03052a8a580563f874fac07300bc291003b56edf Mon Sep 17 00:00:00 2001 From: "dmitriy.krapivenko" Date: Sun, 29 Dec 2024 23:13:12 +0300 Subject: [PATCH 03/18] add job and run conclusion --- plugins/inputs/webhooks/github/github_webhooks_models.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/plugins/inputs/webhooks/github/github_webhooks_models.go b/plugins/inputs/webhooks/github/github_webhooks_models.go index 9e4382bd4d6dd..ddc4655302998 100644 --- a/plugins/inputs/webhooks/github/github_webhooks_models.go +++ b/plugins/inputs/webhooks/github/github_webhooks_models.go @@ -82,6 +82,7 @@ type workflowJob struct { StartedAt string `json:"started_at"` CompletedAt string `json:"completed_at"` Name string `json:"name"` + Conclusion string `json:"conclusion"` } type workflowRun struct { @@ -91,6 +92,7 @@ type workflowRun struct { UpdatedAt string `json:"updated_at"` RunAttempt int `json:"run_attempt"` Name string `json:"name"` + Conclusion string `json:"conclusion"` } type release struct { @@ -682,6 +684,7 @@ func (s workflowJobEvent)NewMetric() telegraf.Metric { "user": s.Sender.User, "admin": strconv.FormatBool(s.Sender.Admin), "name": s.WorkflowJob.Name, + "conclusion": s.WorkflowJob.Conclusion, } created_at, _ := time.Parse(time.RFC3339, s.WorkflowJob.CreatedAt) started_at, _ := time.Parse(time.RFC3339, s.WorkflowJob.StartedAt) @@ -713,6 +716,7 @@ func (s workflowRunEvent)NewMetric() telegraf.Metric { "user": s.Sender.User, "admin": strconv.FormatBool(s.Sender.Admin), "name": s.WorkflowRun.Name, + "conclusion": s.WorkflowRun.Conclusion, } var run_time int64 = 0 created_at, _ := time.Parse(time.RFC3339, s.WorkflowRun.CreatedAt) From 06e354536340061a77313554931489c498d7b031 Mon Sep 17 00:00:00 2001 From: "dmitriy.krapivenko" Date: Sun, 29 Dec 2024 23:19:18 +0300 Subject: [PATCH 04/18] fix tests json sample --- .../github/github_webhooks_mock_json.go | 544 ++++++++++++++++++ .../webhooks/github/github_webhooks_test.go | 4 +- 2 files changed, 546 insertions(+), 2 deletions(-) diff --git a/plugins/inputs/webhooks/github/github_webhooks_mock_json.go b/plugins/inputs/webhooks/github/github_webhooks_mock_json.go index 91af9a330576b..44083144c0e30 100644 --- a/plugins/inputs/webhooks/github/github_webhooks_mock_json.go +++ b/plugins/inputs/webhooks/github/github_webhooks_mock_json.go @@ -3557,3 +3557,547 @@ func WatchEventJSON() string { } }` } + +func WorkflowJobJSON() string { + return `{ + "action": "completed", + "workflow_job": { + "id": 34960636490, + "run_id": 12537003369, + "workflow_name": ".NET", + "head_branch": "feature/test", + "run_url": "https://api.github.com/repos/DeusDeorum1/yhome-controller/actions/runs/12537003369", + "run_attempt": 1, + "node_id": "CR_kwDONd0bVc8AAAAII9D6Sg", + "head_sha": "2c4f2526866d85e29bd7caea0791d861a0c713aa", + "url": "https://api.github.com/repos/DeusDeorum1/yhome-controller/actions/jobs/34960636490", + "html_url": "https://github.com/DeusDeorum1/yhome-controller/actions/runs/12537003369/job/34960636490", + "status": "completed", + "conclusion": "success", + "created_at": "2024-12-29T16:28:44Z", + "started_at": "2024-12-29T16:28:50Z", + "completed_at": "2024-12-29T16:29:17Z", + "name": "Run build", + "steps": [ + { + "name": "Set up job", + "status": "completed", + "conclusion": "success", + "number": 1, + "started_at": "2024-12-29T16:28:49Z", + "completed_at": "2024-12-29T16:28:50Z" + }, + { + "name": "Checkout", + "status": "completed", + "conclusion": "success", + "number": 2, + "started_at": "2024-12-29T16:28:50Z", + "completed_at": "2024-12-29T16:28:51Z" + } + ], + "check_run_url": "https://api.github.com/repos/DeusDeorum1/yhome-controller/check-runs/34960636490", + "labels": [ + "ubuntu-latest" + ], + "runner_id": 3, + "runner_name": "GitHub Actions 3", + "runner_group_id": 2, + "runner_group_name": "GitHub Actions" + }, + "repository": { + "id": 903682901, + "node_id": "R_kgDONd0bVQ", + "name": "yhome-controller", + "full_name": "DeusDeorum1/yhome-controller", + "private": true, + "owner": { + "login": "DeusDeorum1", + "id": 23059354, + "node_id": "MDQ6VXNlcjIzMDU5MzU0", + "avatar_url": "https://avatars.githubusercontent.com/u/23059354?v=4", + "gravatar_id": "", + "url": "https://api.github.com/users/DeusDeorum1", + "html_url": "https://github.com/DeusDeorum1", + "followers_url": "https://api.github.com/users/DeusDeorum1/followers", + "following_url": "https://api.github.com/users/DeusDeorum1/following{/other_user}", + "gists_url": "https://api.github.com/users/DeusDeorum1/gists{/gist_id}", + "starred_url": "https://api.github.com/users/DeusDeorum1/starred{/owner}{/repo}", + "subscriptions_url": "https://api.github.com/users/DeusDeorum1/subscriptions", + "organizations_url": "https://api.github.com/users/DeusDeorum1/orgs", + "repos_url": "https://api.github.com/users/DeusDeorum1/repos", + "events_url": "https://api.github.com/users/DeusDeorum1/events{/privacy}", + "received_events_url": "https://api.github.com/users/DeusDeorum1/received_events", + "type": "User", + "user_view_type": "public", + "site_admin": false + }, + "html_url": "https://github.com/DeusDeorum1/yhome-controller", + "description": null, + "fork": false, + "url": "https://api.github.com/repos/DeusDeorum1/yhome-controller", + "forks_url": "https://api.github.com/repos/DeusDeorum1/yhome-controller/forks", + "keys_url": "https://api.github.com/repos/DeusDeorum1/yhome-controller/keys{/key_id}", + "collaborators_url": "https://api.github.com/repos/DeusDeorum1/yhome-controller/collaborators{/collaborator}", + "teams_url": "https://api.github.com/repos/DeusDeorum1/yhome-controller/teams", + "hooks_url": "https://api.github.com/repos/DeusDeorum1/yhome-controller/hooks", + "issue_events_url": "https://api.github.com/repos/DeusDeorum1/yhome-controller/issues/events{/number}", + "events_url": "https://api.github.com/repos/DeusDeorum1/yhome-controller/events", + "assignees_url": "https://api.github.com/repos/DeusDeorum1/yhome-controller/assignees{/user}", + "branches_url": "https://api.github.com/repos/DeusDeorum1/yhome-controller/branches{/branch}", + "tags_url": "https://api.github.com/repos/DeusDeorum1/yhome-controller/tags", + "blobs_url": "https://api.github.com/repos/DeusDeorum1/yhome-controller/git/blobs{/sha}", + "git_tags_url": "https://api.github.com/repos/DeusDeorum1/yhome-controller/git/tags{/sha}", + "git_refs_url": "https://api.github.com/repos/DeusDeorum1/yhome-controller/git/refs{/sha}", + "trees_url": "https://api.github.com/repos/DeusDeorum1/yhome-controller/git/trees{/sha}", + "statuses_url": "https://api.github.com/repos/DeusDeorum1/yhome-controller/statuses/{sha}", + "languages_url": "https://api.github.com/repos/DeusDeorum1/yhome-controller/languages", + "stargazers_url": "https://api.github.com/repos/DeusDeorum1/yhome-controller/stargazers", + "contributors_url": "https://api.github.com/repos/DeusDeorum1/yhome-controller/contributors", + "subscribers_url": "https://api.github.com/repos/DeusDeorum1/yhome-controller/subscribers", + "subscription_url": "https://api.github.com/repos/DeusDeorum1/yhome-controller/subscription", + "commits_url": "https://api.github.com/repos/DeusDeorum1/yhome-controller/commits{/sha}", + "git_commits_url": "https://api.github.com/repos/DeusDeorum1/yhome-controller/git/commits{/sha}", + "comments_url": "https://api.github.com/repos/DeusDeorum1/yhome-controller/comments{/number}", + "issue_comment_url": "https://api.github.com/repos/DeusDeorum1/yhome-controller/issues/comments{/number}", + "contents_url": "https://api.github.com/repos/DeusDeorum1/yhome-controller/contents/{+path}", + "compare_url": "https://api.github.com/repos/DeusDeorum1/yhome-controller/compare/{base}...{head}", + "merges_url": "https://api.github.com/repos/DeusDeorum1/yhome-controller/merges", + "archive_url": "https://api.github.com/repos/DeusDeorum1/yhome-controller/{archive_format}{/ref}", + "downloads_url": "https://api.github.com/repos/DeusDeorum1/yhome-controller/downloads", + "issues_url": "https://api.github.com/repos/DeusDeorum1/yhome-controller/issues{/number}", + "pulls_url": "https://api.github.com/repos/DeusDeorum1/yhome-controller/pulls{/number}", + "milestones_url": "https://api.github.com/repos/DeusDeorum1/yhome-controller/milestones{/number}", + "notifications_url": "https://api.github.com/repos/DeusDeorum1/yhome-controller/notifications{?since,all,participating}", + "labels_url": "https://api.github.com/repos/DeusDeorum1/yhome-controller/labels{/name}", + "releases_url": "https://api.github.com/repos/DeusDeorum1/yhome-controller/releases{/id}", + "deployments_url": "https://api.github.com/repos/DeusDeorum1/yhome-controller/deployments", + "created_at": "2024-12-15T09:23:35Z", + "updated_at": "2024-12-22T14:25:20Z", + "pushed_at": "2024-12-29T16:28:40Z", + "git_url": "git://github.com/DeusDeorum1/yhome-controller.git", + "ssh_url": "git@github.com:DeusDeorum1/yhome-controller.git", + "clone_url": "https://github.com/DeusDeorum1/yhome-controller.git", + "svn_url": "https://github.com/DeusDeorum1/yhome-controller", + "homepage": null, + "size": 813, + "stargazers_count": 0, + "watchers_count": 0, + "language": "C#", + "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": "develop" + }, + "sender": { + "login": "DeusDeorum1", + "id": 23059354, + "node_id": "MDQ6VXNlcjIzMDU5MzU0", + "avatar_url": "https://avatars.githubusercontent.com/u/23059354?v=4", + "gravatar_id": "", + "url": "https://api.github.com/users/DeusDeorum1", + "html_url": "https://github.com/DeusDeorum1", + "followers_url": "https://api.github.com/users/DeusDeorum1/followers", + "following_url": "https://api.github.com/users/DeusDeorum1/following{/other_user}", + "gists_url": "https://api.github.com/users/DeusDeorum1/gists{/gist_id}", + "starred_url": "https://api.github.com/users/DeusDeorum1/starred{/owner}{/repo}", + "subscriptions_url": "https://api.github.com/users/DeusDeorum1/subscriptions", + "organizations_url": "https://api.github.com/users/DeusDeorum1/orgs", + "repos_url": "https://api.github.com/users/DeusDeorum1/repos", + "events_url": "https://api.github.com/users/DeusDeorum1/events{/privacy}", + "received_events_url": "https://api.github.com/users/DeusDeorum1/received_events", + "type": "User", + "user_view_type": "public", + "site_admin": false + } +}` +} + +func WorkflowRunJSON() string { + return `{ + "action": "completed", + "workflow_run": { + "id": 12537003369, + "name": ".NET", + "node_id": "WFR_kwLONd0bVc8AAAAC60N9aQ", + "head_branch": "feature/test", + "head_sha": "2c4f2526866d85e29bd7caea0791d861a0c713aa", + "path": ".github/workflows/dotnet.yml", + "display_title": "fix step name (#15)", + "run_number": 52, + "event": "push", + "status": "completed", + "conclusion": "success", + "workflow_id": 133367596, + "check_suite_id": 32519948712, + "check_suite_node_id": "CS_kwDONd0bVc8AAAAHklcJqA", + "url": "https://api.github.com/repos/DeusDeorum1/yhome-controller/actions/runs/12537003369", + "html_url": "https://github.com/DeusDeorum1/yhome-controller/actions/runs/12537003369", + "pull_requests": [ + + ], + "created_at": "2024-12-29T16:28:42Z", + "updated_at": "2024-12-29T16:30:08Z", + "actor": { + "login": "DeusDeorum1", + "id": 23059354, + "node_id": "MDQ6VXNlcjIzMDU5MzU0", + "avatar_url": "https://avatars.githubusercontent.com/u/23059354?v=4", + "gravatar_id": "", + "url": "https://api.github.com/users/DeusDeorum1", + "html_url": "https://github.com/DeusDeorum1", + "followers_url": "https://api.github.com/users/DeusDeorum1/followers", + "following_url": "https://api.github.com/users/DeusDeorum1/following{/other_user}", + "gists_url": "https://api.github.com/users/DeusDeorum1/gists{/gist_id}", + "starred_url": "https://api.github.com/users/DeusDeorum1/starred{/owner}{/repo}", + "subscriptions_url": "https://api.github.com/users/DeusDeorum1/subscriptions", + "organizations_url": "https://api.github.com/users/DeusDeorum1/orgs", + "repos_url": "https://api.github.com/users/DeusDeorum1/repos", + "events_url": "https://api.github.com/users/DeusDeorum1/events{/privacy}", + "received_events_url": "https://api.github.com/users/DeusDeorum1/received_events", + "type": "User", + "user_view_type": "public", + "site_admin": false + }, + "run_attempt": 1, + "referenced_workflows": [ + + ], + "run_started_at": "2024-12-29T16:28:42Z", + "triggering_actor": { + "login": "DeusDeorum1", + "id": 23059354, + "node_id": "MDQ6VXNlcjIzMDU5MzU0", + "avatar_url": "https://avatars.githubusercontent.com/u/23059354?v=4", + "gravatar_id": "", + "url": "https://api.github.com/users/DeusDeorum1", + "html_url": "https://github.com/DeusDeorum1", + "followers_url": "https://api.github.com/users/DeusDeorum1/followers", + "following_url": "https://api.github.com/users/DeusDeorum1/following{/other_user}", + "gists_url": "https://api.github.com/users/DeusDeorum1/gists{/gist_id}", + "starred_url": "https://api.github.com/users/DeusDeorum1/starred{/owner}{/repo}", + "subscriptions_url": "https://api.github.com/users/DeusDeorum1/subscriptions", + "organizations_url": "https://api.github.com/users/DeusDeorum1/orgs", + "repos_url": "https://api.github.com/users/DeusDeorum1/repos", + "events_url": "https://api.github.com/users/DeusDeorum1/events{/privacy}", + "received_events_url": "https://api.github.com/users/DeusDeorum1/received_events", + "type": "User", + "user_view_type": "public", + "site_admin": false + }, + "jobs_url": "https://api.github.com/repos/DeusDeorum1/yhome-controller/actions/runs/12537003369/jobs", + "logs_url": "https://api.github.com/repos/DeusDeorum1/yhome-controller/actions/runs/12537003369/logs", + "check_suite_url": "https://api.github.com/repos/DeusDeorum1/yhome-controller/check-suites/32519948712", + "artifacts_url": "https://api.github.com/repos/DeusDeorum1/yhome-controller/actions/runs/12537003369/artifacts", + "cancel_url": "https://api.github.com/repos/DeusDeorum1/yhome-controller/actions/runs/12537003369/cancel", + "rerun_url": "https://api.github.com/repos/DeusDeorum1/yhome-controller/actions/runs/12537003369/rerun", + "previous_attempt_url": null, + "workflow_url": "https://api.github.com/repos/DeusDeorum1/yhome-controller/actions/workflows/133367596", + "head_commit": { + "id": "2c4f2526866d85e29bd7caea0791d861a0c713aa", + "tree_id": "332883d5db0e30b010eac21edf512ba6f005eb92", + "message": "fix step name (#15)", + "timestamp": "2024-12-22T14:25:16Z", + "author": { + "name": "Arina2106", + "email": "77919706+Arina2106@users.noreply.github.com" + }, + "committer": { + "name": "GitHub", + "email": "noreply@github.com" + } + }, + "repository": { + "id": 903682901, + "node_id": "R_kgDONd0bVQ", + "name": "yhome-controller", + "full_name": "DeusDeorum1/yhome-controller", + "private": true, + "owner": { + "login": "DeusDeorum1", + "id": 23059354, + "node_id": "MDQ6VXNlcjIzMDU5MzU0", + "avatar_url": "https://avatars.githubusercontent.com/u/23059354?v=4", + "gravatar_id": "", + "url": "https://api.github.com/users/DeusDeorum1", + "html_url": "https://github.com/DeusDeorum1", + "followers_url": "https://api.github.com/users/DeusDeorum1/followers", + "following_url": "https://api.github.com/users/DeusDeorum1/following{/other_user}", + "gists_url": "https://api.github.com/users/DeusDeorum1/gists{/gist_id}", + "starred_url": "https://api.github.com/users/DeusDeorum1/starred{/owner}{/repo}", + "subscriptions_url": "https://api.github.com/users/DeusDeorum1/subscriptions", + "organizations_url": "https://api.github.com/users/DeusDeorum1/orgs", + "repos_url": "https://api.github.com/users/DeusDeorum1/repos", + "events_url": "https://api.github.com/users/DeusDeorum1/events{/privacy}", + "received_events_url": "https://api.github.com/users/DeusDeorum1/received_events", + "type": "User", + "user_view_type": "public", + "site_admin": false + }, + "html_url": "https://github.com/DeusDeorum1/yhome-controller", + "description": null, + "fork": false, + "url": "https://api.github.com/repos/DeusDeorum1/yhome-controller", + "forks_url": "https://api.github.com/repos/DeusDeorum1/yhome-controller/forks", + "keys_url": "https://api.github.com/repos/DeusDeorum1/yhome-controller/keys{/key_id}", + "collaborators_url": "https://api.github.com/repos/DeusDeorum1/yhome-controller/collaborators{/collaborator}", + "teams_url": "https://api.github.com/repos/DeusDeorum1/yhome-controller/teams", + "hooks_url": "https://api.github.com/repos/DeusDeorum1/yhome-controller/hooks", + "issue_events_url": "https://api.github.com/repos/DeusDeorum1/yhome-controller/issues/events{/number}", + "events_url": "https://api.github.com/repos/DeusDeorum1/yhome-controller/events", + "assignees_url": "https://api.github.com/repos/DeusDeorum1/yhome-controller/assignees{/user}", + "branches_url": "https://api.github.com/repos/DeusDeorum1/yhome-controller/branches{/branch}", + "tags_url": "https://api.github.com/repos/DeusDeorum1/yhome-controller/tags", + "blobs_url": "https://api.github.com/repos/DeusDeorum1/yhome-controller/git/blobs{/sha}", + "git_tags_url": "https://api.github.com/repos/DeusDeorum1/yhome-controller/git/tags{/sha}", + "git_refs_url": "https://api.github.com/repos/DeusDeorum1/yhome-controller/git/refs{/sha}", + "trees_url": "https://api.github.com/repos/DeusDeorum1/yhome-controller/git/trees{/sha}", + "statuses_url": "https://api.github.com/repos/DeusDeorum1/yhome-controller/statuses/{sha}", + "languages_url": "https://api.github.com/repos/DeusDeorum1/yhome-controller/languages", + "stargazers_url": "https://api.github.com/repos/DeusDeorum1/yhome-controller/stargazers", + "contributors_url": "https://api.github.com/repos/DeusDeorum1/yhome-controller/contributors", + "subscribers_url": "https://api.github.com/repos/DeusDeorum1/yhome-controller/subscribers", + "subscription_url": "https://api.github.com/repos/DeusDeorum1/yhome-controller/subscription", + "commits_url": "https://api.github.com/repos/DeusDeorum1/yhome-controller/commits{/sha}", + "git_commits_url": "https://api.github.com/repos/DeusDeorum1/yhome-controller/git/commits{/sha}", + "comments_url": "https://api.github.com/repos/DeusDeorum1/yhome-controller/comments{/number}", + "issue_comment_url": "https://api.github.com/repos/DeusDeorum1/yhome-controller/issues/comments{/number}", + "contents_url": "https://api.github.com/repos/DeusDeorum1/yhome-controller/contents/{+path}", + "compare_url": "https://api.github.com/repos/DeusDeorum1/yhome-controller/compare/{base}...{head}", + "merges_url": "https://api.github.com/repos/DeusDeorum1/yhome-controller/merges", + "archive_url": "https://api.github.com/repos/DeusDeorum1/yhome-controller/{archive_format}{/ref}", + "downloads_url": "https://api.github.com/repos/DeusDeorum1/yhome-controller/downloads", + "issues_url": "https://api.github.com/repos/DeusDeorum1/yhome-controller/issues{/number}", + "pulls_url": "https://api.github.com/repos/DeusDeorum1/yhome-controller/pulls{/number}", + "milestones_url": "https://api.github.com/repos/DeusDeorum1/yhome-controller/milestones{/number}", + "notifications_url": "https://api.github.com/repos/DeusDeorum1/yhome-controller/notifications{?since,all,participating}", + "labels_url": "https://api.github.com/repos/DeusDeorum1/yhome-controller/labels{/name}", + "releases_url": "https://api.github.com/repos/DeusDeorum1/yhome-controller/releases{/id}", + "deployments_url": "https://api.github.com/repos/DeusDeorum1/yhome-controller/deployments" + }, + "head_repository": { + "id": 903682901, + "node_id": "R_kgDONd0bVQ", + "name": "yhome-controller", + "full_name": "DeusDeorum1/yhome-controller", + "private": true, + "owner": { + "login": "DeusDeorum1", + "id": 23059354, + "node_id": "MDQ6VXNlcjIzMDU5MzU0", + "avatar_url": "https://avatars.githubusercontent.com/u/23059354?v=4", + "gravatar_id": "", + "url": "https://api.github.com/users/DeusDeorum1", + "html_url": "https://github.com/DeusDeorum1", + "followers_url": "https://api.github.com/users/DeusDeorum1/followers", + "following_url": "https://api.github.com/users/DeusDeorum1/following{/other_user}", + "gists_url": "https://api.github.com/users/DeusDeorum1/gists{/gist_id}", + "starred_url": "https://api.github.com/users/DeusDeorum1/starred{/owner}{/repo}", + "subscriptions_url": "https://api.github.com/users/DeusDeorum1/subscriptions", + "organizations_url": "https://api.github.com/users/DeusDeorum1/orgs", + "repos_url": "https://api.github.com/users/DeusDeorum1/repos", + "events_url": "https://api.github.com/users/DeusDeorum1/events{/privacy}", + "received_events_url": "https://api.github.com/users/DeusDeorum1/received_events", + "type": "User", + "user_view_type": "public", + "site_admin": false + }, + "html_url": "https://github.com/DeusDeorum1/yhome-controller", + "description": null, + "fork": false, + "url": "https://api.github.com/repos/DeusDeorum1/yhome-controller", + "forks_url": "https://api.github.com/repos/DeusDeorum1/yhome-controller/forks", + "keys_url": "https://api.github.com/repos/DeusDeorum1/yhome-controller/keys{/key_id}", + "collaborators_url": "https://api.github.com/repos/DeusDeorum1/yhome-controller/collaborators{/collaborator}", + "teams_url": "https://api.github.com/repos/DeusDeorum1/yhome-controller/teams", + "hooks_url": "https://api.github.com/repos/DeusDeorum1/yhome-controller/hooks", + "issue_events_url": "https://api.github.com/repos/DeusDeorum1/yhome-controller/issues/events{/number}", + "events_url": "https://api.github.com/repos/DeusDeorum1/yhome-controller/events", + "assignees_url": "https://api.github.com/repos/DeusDeorum1/yhome-controller/assignees{/user}", + "branches_url": "https://api.github.com/repos/DeusDeorum1/yhome-controller/branches{/branch}", + "tags_url": "https://api.github.com/repos/DeusDeorum1/yhome-controller/tags", + "blobs_url": "https://api.github.com/repos/DeusDeorum1/yhome-controller/git/blobs{/sha}", + "git_tags_url": "https://api.github.com/repos/DeusDeorum1/yhome-controller/git/tags{/sha}", + "git_refs_url": "https://api.github.com/repos/DeusDeorum1/yhome-controller/git/refs{/sha}", + "trees_url": "https://api.github.com/repos/DeusDeorum1/yhome-controller/git/trees{/sha}", + "statuses_url": "https://api.github.com/repos/DeusDeorum1/yhome-controller/statuses/{sha}", + "languages_url": "https://api.github.com/repos/DeusDeorum1/yhome-controller/languages", + "stargazers_url": "https://api.github.com/repos/DeusDeorum1/yhome-controller/stargazers", + "contributors_url": "https://api.github.com/repos/DeusDeorum1/yhome-controller/contributors", + "subscribers_url": "https://api.github.com/repos/DeusDeorum1/yhome-controller/subscribers", + "subscription_url": "https://api.github.com/repos/DeusDeorum1/yhome-controller/subscription", + "commits_url": "https://api.github.com/repos/DeusDeorum1/yhome-controller/commits{/sha}", + "git_commits_url": "https://api.github.com/repos/DeusDeorum1/yhome-controller/git/commits{/sha}", + "comments_url": "https://api.github.com/repos/DeusDeorum1/yhome-controller/comments{/number}", + "issue_comment_url": "https://api.github.com/repos/DeusDeorum1/yhome-controller/issues/comments{/number}", + "contents_url": "https://api.github.com/repos/DeusDeorum1/yhome-controller/contents/{+path}", + "compare_url": "https://api.github.com/repos/DeusDeorum1/yhome-controller/compare/{base}...{head}", + "merges_url": "https://api.github.com/repos/DeusDeorum1/yhome-controller/merges", + "archive_url": "https://api.github.com/repos/DeusDeorum1/yhome-controller/{archive_format}{/ref}", + "downloads_url": "https://api.github.com/repos/DeusDeorum1/yhome-controller/downloads", + "issues_url": "https://api.github.com/repos/DeusDeorum1/yhome-controller/issues{/number}", + "pulls_url": "https://api.github.com/repos/DeusDeorum1/yhome-controller/pulls{/number}", + "milestones_url": "https://api.github.com/repos/DeusDeorum1/yhome-controller/milestones{/number}", + "notifications_url": "https://api.github.com/repos/DeusDeorum1/yhome-controller/notifications{?since,all,participating}", + "labels_url": "https://api.github.com/repos/DeusDeorum1/yhome-controller/labels{/name}", + "releases_url": "https://api.github.com/repos/DeusDeorum1/yhome-controller/releases{/id}", + "deployments_url": "https://api.github.com/repos/DeusDeorum1/yhome-controller/deployments" + } + }, + "workflow": { + "id": 133367596, + "node_id": "W_kwDONd0bVc4H8wcs", + "name": ".NET", + "path": ".github/workflows/dotnet.yml", + "state": "active", + "created_at": "2024-12-15T09:57:52.000Z", + "updated_at": "2024-12-15T12:11:31.000Z", + "url": "https://api.github.com/repos/DeusDeorum1/yhome-controller/actions/workflows/133367596", + "html_url": "https://github.com/DeusDeorum1/yhome-controller/blob/develop/.github/workflows/dotnet.yml", + "badge_url": "https://github.com/DeusDeorum1/yhome-controller/workflows/.NET/badge.svg" + }, + "repository": { + "id": 903682901, + "node_id": "R_kgDONd0bVQ", + "name": "yhome-controller", + "full_name": "DeusDeorum1/yhome-controller", + "private": true, + "owner": { + "login": "DeusDeorum1", + "id": 23059354, + "node_id": "MDQ6VXNlcjIzMDU5MzU0", + "avatar_url": "https://avatars.githubusercontent.com/u/23059354?v=4", + "gravatar_id": "", + "url": "https://api.github.com/users/DeusDeorum1", + "html_url": "https://github.com/DeusDeorum1", + "followers_url": "https://api.github.com/users/DeusDeorum1/followers", + "following_url": "https://api.github.com/users/DeusDeorum1/following{/other_user}", + "gists_url": "https://api.github.com/users/DeusDeorum1/gists{/gist_id}", + "starred_url": "https://api.github.com/users/DeusDeorum1/starred{/owner}{/repo}", + "subscriptions_url": "https://api.github.com/users/DeusDeorum1/subscriptions", + "organizations_url": "https://api.github.com/users/DeusDeorum1/orgs", + "repos_url": "https://api.github.com/users/DeusDeorum1/repos", + "events_url": "https://api.github.com/users/DeusDeorum1/events{/privacy}", + "received_events_url": "https://api.github.com/users/DeusDeorum1/received_events", + "type": "User", + "user_view_type": "public", + "site_admin": false + }, + "html_url": "https://github.com/DeusDeorum1/yhome-controller", + "description": null, + "fork": false, + "url": "https://api.github.com/repos/DeusDeorum1/yhome-controller", + "forks_url": "https://api.github.com/repos/DeusDeorum1/yhome-controller/forks", + "keys_url": "https://api.github.com/repos/DeusDeorum1/yhome-controller/keys{/key_id}", + "collaborators_url": "https://api.github.com/repos/DeusDeorum1/yhome-controller/collaborators{/collaborator}", + "teams_url": "https://api.github.com/repos/DeusDeorum1/yhome-controller/teams", + "hooks_url": "https://api.github.com/repos/DeusDeorum1/yhome-controller/hooks", + "issue_events_url": "https://api.github.com/repos/DeusDeorum1/yhome-controller/issues/events{/number}", + "events_url": "https://api.github.com/repos/DeusDeorum1/yhome-controller/events", + "assignees_url": "https://api.github.com/repos/DeusDeorum1/yhome-controller/assignees{/user}", + "branches_url": "https://api.github.com/repos/DeusDeorum1/yhome-controller/branches{/branch}", + "tags_url": "https://api.github.com/repos/DeusDeorum1/yhome-controller/tags", + "blobs_url": "https://api.github.com/repos/DeusDeorum1/yhome-controller/git/blobs{/sha}", + "git_tags_url": "https://api.github.com/repos/DeusDeorum1/yhome-controller/git/tags{/sha}", + "git_refs_url": "https://api.github.com/repos/DeusDeorum1/yhome-controller/git/refs{/sha}", + "trees_url": "https://api.github.com/repos/DeusDeorum1/yhome-controller/git/trees{/sha}", + "statuses_url": "https://api.github.com/repos/DeusDeorum1/yhome-controller/statuses/{sha}", + "languages_url": "https://api.github.com/repos/DeusDeorum1/yhome-controller/languages", + "stargazers_url": "https://api.github.com/repos/DeusDeorum1/yhome-controller/stargazers", + "contributors_url": "https://api.github.com/repos/DeusDeorum1/yhome-controller/contributors", + "subscribers_url": "https://api.github.com/repos/DeusDeorum1/yhome-controller/subscribers", + "subscription_url": "https://api.github.com/repos/DeusDeorum1/yhome-controller/subscription", + "commits_url": "https://api.github.com/repos/DeusDeorum1/yhome-controller/commits{/sha}", + "git_commits_url": "https://api.github.com/repos/DeusDeorum1/yhome-controller/git/commits{/sha}", + "comments_url": "https://api.github.com/repos/DeusDeorum1/yhome-controller/comments{/number}", + "issue_comment_url": "https://api.github.com/repos/DeusDeorum1/yhome-controller/issues/comments{/number}", + "contents_url": "https://api.github.com/repos/DeusDeorum1/yhome-controller/contents/{+path}", + "compare_url": "https://api.github.com/repos/DeusDeorum1/yhome-controller/compare/{base}...{head}", + "merges_url": "https://api.github.com/repos/DeusDeorum1/yhome-controller/merges", + "archive_url": "https://api.github.com/repos/DeusDeorum1/yhome-controller/{archive_format}{/ref}", + "downloads_url": "https://api.github.com/repos/DeusDeorum1/yhome-controller/downloads", + "issues_url": "https://api.github.com/repos/DeusDeorum1/yhome-controller/issues{/number}", + "pulls_url": "https://api.github.com/repos/DeusDeorum1/yhome-controller/pulls{/number}", + "milestones_url": "https://api.github.com/repos/DeusDeorum1/yhome-controller/milestones{/number}", + "notifications_url": "https://api.github.com/repos/DeusDeorum1/yhome-controller/notifications{?since,all,participating}", + "labels_url": "https://api.github.com/repos/DeusDeorum1/yhome-controller/labels{/name}", + "releases_url": "https://api.github.com/repos/DeusDeorum1/yhome-controller/releases{/id}", + "deployments_url": "https://api.github.com/repos/DeusDeorum1/yhome-controller/deployments", + "created_at": "2024-12-15T09:23:35Z", + "updated_at": "2024-12-22T14:25:20Z", + "pushed_at": "2024-12-29T16:28:40Z", + "git_url": "git://github.com/DeusDeorum1/yhome-controller.git", + "ssh_url": "git@github.com:DeusDeorum1/yhome-controller.git", + "clone_url": "https://github.com/DeusDeorum1/yhome-controller.git", + "svn_url": "https://github.com/DeusDeorum1/yhome-controller", + "homepage": null, + "size": 813, + "stargazers_count": 0, + "watchers_count": 0, + "language": "C#", + "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": "develop" + }, + "sender": { + "login": "DeusDeorum1", + "id": 23059354, + "node_id": "MDQ6VXNlcjIzMDU5MzU0", + "avatar_url": "https://avatars.githubusercontent.com/u/23059354?v=4", + "gravatar_id": "", + "url": "https://api.github.com/users/DeusDeorum1", + "html_url": "https://github.com/DeusDeorum1", + "followers_url": "https://api.github.com/users/DeusDeorum1/followers", + "following_url": "https://api.github.com/users/DeusDeorum1/following{/other_user}", + "gists_url": "https://api.github.com/users/DeusDeorum1/gists{/gist_id}", + "starred_url": "https://api.github.com/users/DeusDeorum1/starred{/owner}{/repo}", + "subscriptions_url": "https://api.github.com/users/DeusDeorum1/subscriptions", + "organizations_url": "https://api.github.com/users/DeusDeorum1/orgs", + "repos_url": "https://api.github.com/users/DeusDeorum1/repos", + "events_url": "https://api.github.com/users/DeusDeorum1/events{/privacy}", + "received_events_url": "https://api.github.com/users/DeusDeorum1/received_events", + "type": "User", + "user_view_type": "public", + "site_admin": false + } +}` +} \ No newline at end of file diff --git a/plugins/inputs/webhooks/github/github_webhooks_test.go b/plugins/inputs/webhooks/github/github_webhooks_test.go index 174345809f3cc..a050c5e139ccb 100644 --- a/plugins/inputs/webhooks/github/github_webhooks_test.go +++ b/plugins/inputs/webhooks/github/github_webhooks_test.go @@ -127,11 +127,11 @@ func TestEventWithSignatureSuccess(t *testing.T) { } func TestWorkflowJob(t *testing.T) { - GithubWebhookRequestWithSignature(t, "workflow_job", WatchEventJSON(), http.StatusOK) + GithubWebhookRequestWithSignature(t, "workflow_job", WorkflowJobJSON(), http.StatusOK) } func TestWorkflowRun(t *testing.T) { - GithubWebhookRequestWithSignature(t, "workflow_run", WatchEventJSON(), http.StatusOK) + GithubWebhookRequestWithSignature(t, "workflow_run", WorkflowRunJSON(), http.StatusOK) } func TestCheckSignatureSuccess(t *testing.T) { From 2166c3c2c8329371f066b79fbd6b41564b54f8e7 Mon Sep 17 00:00:00 2001 From: "dmitriy.krapivenko" Date: Sun, 29 Dec 2024 23:20:15 +0300 Subject: [PATCH 05/18] fix tests --- plugins/inputs/webhooks/github/github_webhooks_test.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugins/inputs/webhooks/github/github_webhooks_test.go b/plugins/inputs/webhooks/github/github_webhooks_test.go index a050c5e139ccb..d09849e77ef81 100644 --- a/plugins/inputs/webhooks/github/github_webhooks_test.go +++ b/plugins/inputs/webhooks/github/github_webhooks_test.go @@ -127,11 +127,11 @@ func TestEventWithSignatureSuccess(t *testing.T) { } func TestWorkflowJob(t *testing.T) { - GithubWebhookRequestWithSignature(t, "workflow_job", WorkflowJobJSON(), http.StatusOK) + GithubWebhookRequest(t, "workflow_job", WorkflowJobJSON()) } func TestWorkflowRun(t *testing.T) { - GithubWebhookRequestWithSignature(t, "workflow_run", WorkflowRunJSON(), http.StatusOK) + GithubWebhookRequest(t, "workflow_run", WorkflowRunJSON()) } func TestCheckSignatureSuccess(t *testing.T) { From b9159ca6603d6ec2aeff30f699f875be29de711b Mon Sep 17 00:00:00 2001 From: "dmitriy.krapivenko" Date: Sun, 29 Dec 2024 23:32:23 +0300 Subject: [PATCH 06/18] fix lint --- .../github/github_webhooks_mock_json.go | 2 +- .../webhooks/github/github_webhooks_models.go | 98 +++++++++---------- 2 files changed, 50 insertions(+), 50 deletions(-) diff --git a/plugins/inputs/webhooks/github/github_webhooks_mock_json.go b/plugins/inputs/webhooks/github/github_webhooks_mock_json.go index 44083144c0e30..f3dd67399d66c 100644 --- a/plugins/inputs/webhooks/github/github_webhooks_mock_json.go +++ b/plugins/inputs/webhooks/github/github_webhooks_mock_json.go @@ -4100,4 +4100,4 @@ func WorkflowRunJSON() string { "site_admin": false } }` -} \ No newline at end of file +} diff --git a/plugins/inputs/webhooks/github/github_webhooks_models.go b/plugins/inputs/webhooks/github/github_webhooks_models.go index ddc4655302998..2e9938d6753ba 100644 --- a/plugins/inputs/webhooks/github/github_webhooks_models.go +++ b/plugins/inputs/webhooks/github/github_webhooks_models.go @@ -76,23 +76,23 @@ type pullRequestReviewComment struct { } type workflowJob struct { - RunAttempt int `json:"run_attempt"` - HeadBranch string `json:"head_branch"` - CreatedAt string `json:"created_at"` - StartedAt string `json:"started_at"` - CompletedAt string `json:"completed_at"` - Name string `json:"name"` - Conclusion string `json:"conclusion"` + RunAttempt int `json:"run_attempt"` + HeadBranch string `json:"head_branch"` + CreatedAt string `json:"created_at"` + StartedAt string `json:"started_at"` + CompletedAt string `json:"completed_at"` + Name string `json:"name"` + Conclusion string `json:"conclusion"` } type workflowRun struct { - HeadBranch string `json:"head_branch"` - CreatedAt string `json:"created_at"` - RunStartedAt string `json:"run_started_at"` - UpdatedAt string `json:"updated_at"` - RunAttempt int `json:"run_attempt"` - Name string `json:"name"` - Conclusion string `json:"conclusion"` + HeadBranch string `json:"head_branch"` + CreatedAt string `json:"created_at"` + RunStartedAt string `json:"run_started_at"` + UpdatedAt string `json:"updated_at"` + RunAttempt int `json:"run_attempt"` + Name string `json:"name"` + Conclusion string `json:"conclusion"` } type release struct { @@ -668,55 +668,55 @@ func (s watchEvent) NewMetric() telegraf.Metric { } type workflowJobEvent struct { - Action string `json:"action"` - WorkflowJob workflowJob `json:"workflow_job"` - Repository repository `json:"repository"` - Sender sender `json:"sender"` + Action string `json:"action"` + WorkflowJob workflowJob `json:"workflow_job"` + Repository repository `json:"repository"` + Sender sender `json:"sender"` } -func (s workflowJobEvent)NewMetric() telegraf.Metric { +func (s workflowJobEvent) NewMetric() telegraf.Metric { event := "workflow_job" t := map[string]string{ - "event": event, - "action": s.Action, - "repository": s.Repository.Repository, - "private": strconv.FormatBool(s.Repository.Private), - "user": s.Sender.User, - "admin": strconv.FormatBool(s.Sender.Admin), - "name": s.WorkflowJob.Name, - "conclusion": s.WorkflowJob.Conclusion, + "event": event, + "action": s.Action, + "repository": s.Repository.Repository, + "private": strconv.FormatBool(s.Repository.Private), + "user": s.Sender.User, + "admin": strconv.FormatBool(s.Sender.Admin), + "name": s.WorkflowJob.Name, + "conclusion": s.WorkflowJob.Conclusion, } created_at, _ := time.Parse(time.RFC3339, s.WorkflowJob.CreatedAt) started_at, _ := time.Parse(time.RFC3339, s.WorkflowJob.StartedAt) completed_at, _ := time.Parse(time.RFC3339, s.WorkflowJob.CompletedAt) f := map[string]interface{}{ - "run_attempt": s.WorkflowJob.RunAttempt, - "queue_time": started_at.Sub(created_at).Milliseconds(), - "run_time": completed_at.Sub(started_at).Milliseconds(), - "head_branch": s.WorkflowJob.HeadBranch, + "run_attempt": s.WorkflowJob.RunAttempt, + "queue_time": started_at.Sub(created_at).Milliseconds(), + "run_time": completed_at.Sub(started_at).Milliseconds(), + "head_branch": s.WorkflowJob.HeadBranch, } m := metric.New(meas, t, f, time.Now()) return m } type workflowRunEvent struct { - Action string `json:"action"` - WorkflowRun workflowRun `json:"workflow_run"` - Repository repository `json:"repository"` - Sender sender `json:"sender"` + Action string `json:"action"` + WorkflowRun workflowRun `json:"workflow_run"` + Repository repository `json:"repository"` + Sender sender `json:"sender"` } -func (s workflowRunEvent)NewMetric() telegraf.Metric { +func (s workflowRunEvent) NewMetric() telegraf.Metric { event := "workflow_run" t := map[string]string{ - "event": event, - "action": s.Action, - "repository": s.Repository.Repository, - "private": strconv.FormatBool(s.Repository.Private), - "user": s.Sender.User, - "admin": strconv.FormatBool(s.Sender.Admin), - "name": s.WorkflowRun.Name, - "conclusion": s.WorkflowRun.Conclusion, + "event": event, + "action": s.Action, + "repository": s.Repository.Repository, + "private": strconv.FormatBool(s.Repository.Private), + "user": s.Sender.User, + "admin": strconv.FormatBool(s.Sender.Admin), + "name": s.WorkflowRun.Name, + "conclusion": s.WorkflowRun.Conclusion, } var run_time int64 = 0 created_at, _ := time.Parse(time.RFC3339, s.WorkflowRun.CreatedAt) @@ -727,11 +727,11 @@ func (s workflowRunEvent)NewMetric() telegraf.Metric { run_time = updated_at.Sub(started_at).Milliseconds() } f := map[string]interface{}{ - "run_attempt": s.WorkflowRun.RunAttempt, - "queue_time": started_at.Sub(created_at).Milliseconds(), - "run_time": run_time, - "head_branch": s.WorkflowRun.HeadBranch, + "run_attempt": s.WorkflowRun.RunAttempt, + "queue_time": started_at.Sub(created_at).Milliseconds(), + "run_time": run_time, + "head_branch": s.WorkflowRun.HeadBranch, } m := metric.New(meas, t, f, time.Now()) return m -} \ No newline at end of file +} From da4efc69bb17b314d12edda042b115961f19292a Mon Sep 17 00:00:00 2001 From: "dmitriy.krapivenko" Date: Mon, 30 Dec 2024 14:13:29 +0300 Subject: [PATCH 07/18] fix lint errors and queue time counting --- .../webhooks/github/github_webhooks_models.go | 44 ++++++++++++++----- 1 file changed, 33 insertions(+), 11 deletions(-) diff --git a/plugins/inputs/webhooks/github/github_webhooks_models.go b/plugins/inputs/webhooks/github/github_webhooks_models.go index 2e9938d6753ba..dcf4d9175a8d5 100644 --- a/plugins/inputs/webhooks/github/github_webhooks_models.go +++ b/plugins/inputs/webhooks/github/github_webhooks_models.go @@ -3,6 +3,7 @@ package github import ( "strconv" "time" + "fmt" "github.com/influxdata/telegraf" "github.com/influxdata/telegraf/metric" @@ -686,13 +687,30 @@ func (s workflowJobEvent) NewMetric() telegraf.Metric { "name": s.WorkflowJob.Name, "conclusion": s.WorkflowJob.Conclusion, } - created_at, _ := time.Parse(time.RFC3339, s.WorkflowJob.CreatedAt) - started_at, _ := time.Parse(time.RFC3339, s.WorkflowJob.StartedAt) - completed_at, _ := time.Parse(time.RFC3339, s.WorkflowJob.CompletedAt) + createdAt, createdAtErr := time.Parse(time.RFC3339, s.WorkflowJob.CreatedAt) + if createdAtErr != nil { + fmt.Errorf("error parsing createdAt %q: %w", s.WorkflowJob.CreatedAt, createdAtErr) + } + startedAt, startedAtErr := time.Parse(time.RFC3339, s.WorkflowJob.StartedAt) + if startedAtErr != nil { + fmt.Errorf("error parsing createdAt %q: %w", s.WorkflowJob.StartedAt, startedAtErr) + } + completedAt, completedAtErr := time.Parse(time.RFC3339, s.WorkflowJob.CompletedAt) + if completedAtErr != nil { + fmt.Errorf("error parsing createdAt %q: %w", s.WorkflowJob.CompletedAt, completedAtErr) + } + var runTime int64 = 0 + var queueTime int64 = 0 + if s.Action == "in_progress" { + queueTime = startedAt.Sub(createdAt).Milliseconds() + } + if s.Action == "completed" { + runTime = completedAt.Sub(startedAt).Milliseconds() + } f := map[string]interface{}{ "run_attempt": s.WorkflowJob.RunAttempt, - "queue_time": started_at.Sub(created_at).Milliseconds(), - "run_time": completed_at.Sub(started_at).Milliseconds(), + "queue_time": queueTime, + "run_time": runTime, "head_branch": s.WorkflowJob.HeadBranch, } m := metric.New(meas, t, f, time.Now()) @@ -719,17 +737,21 @@ func (s workflowRunEvent) NewMetric() telegraf.Metric { "conclusion": s.WorkflowRun.Conclusion, } var run_time int64 = 0 - created_at, _ := time.Parse(time.RFC3339, s.WorkflowRun.CreatedAt) - started_at, _ := time.Parse(time.RFC3339, s.WorkflowRun.RunStartedAt) - updated_at, _ := time.Parse(time.RFC3339, s.WorkflowRun.UpdatedAt) + createdAt, createdAtErr := time.Parse(time.RFC3339, s.WorkflowRun.CreatedAt) + if createdAtErr != nil { + fmt.Errorf("error parsing createdAt %q: %w", s.WorkflowJob.CreatedAt, createdAtErr) + } + startedAt, startedAtErr := time.Parse(time.RFC3339, s.WorkflowRun.RunStartedAt) + if startedAtErr != nil { + fmt.Errorf("error parsing createdAt %q: %w", s.WorkflowJob.StartedAt, startedAtErr) + } if s.Action == "completed" { - run_time = updated_at.Sub(started_at).Milliseconds() + runTime = completedAt.Sub(startedAt).Milliseconds() } f := map[string]interface{}{ "run_attempt": s.WorkflowRun.RunAttempt, - "queue_time": started_at.Sub(created_at).Milliseconds(), - "run_time": run_time, + "run_time": runTime, "head_branch": s.WorkflowRun.HeadBranch, } m := metric.New(meas, t, f, time.Now()) From 3777099cf14ce3e40d9633996e886437e59c4743 Mon Sep 17 00:00:00 2001 From: "dmitriy.krapivenko" Date: Mon, 30 Dec 2024 14:35:20 +0300 Subject: [PATCH 08/18] add docs and fix gihub webhooks docs links --- plugins/inputs/webhooks/github/README.md | 81 ++++++++++++++++++------ 1 file changed, 60 insertions(+), 21 deletions(-) diff --git a/plugins/inputs/webhooks/github/README.md b/plugins/inputs/webhooks/github/README.md index 53adae92afadb..64986c8fc6670 100644 --- a/plugins/inputs/webhooks/github/README.md +++ b/plugins/inputs/webhooks/github/README.md @@ -28,7 +28,7 @@ The format is as follows: The tag values and field values show the place on the incoming JSON object where the data is sourced from. -### [`commit_comment` event](https://developer.github.com/v3/activity/events/types/#commitcommentevent) +### [`commit_comment` event](https://docs.github.com/en/webhooks/webhook-events-and-payloads#commit_comment) **Tags:** @@ -46,7 +46,7 @@ where the data is sourced from. * 'commit' = `event.comment.commit_id` string * 'comment' = `event.comment.body` string -### [`create` event](https://developer.github.com/v3/activity/events/types/#createevent) +### [`create` event](https://docs.github.com/en/webhooks/webhook-events-and-payloads#create) **Tags:** @@ -64,7 +64,7 @@ where the data is sourced from. * 'ref' = `event.ref` string * 'refType' = `event.ref_type` string -### [`delete` event](https://developer.github.com/v3/activity/events/types/#deleteevent) +### [`delete` event](https://docs.github.com/en/webhooks/webhook-events-and-payloads#delete) **Tags:** @@ -82,7 +82,7 @@ where the data is sourced from. * 'ref' = `event.ref` string * 'refType' = `event.ref_type` string -### [`deployment` event](https://developer.github.com/v3/activity/events/types/#deploymentevent) +### [`deployment` event](https://docs.github.com/en/webhooks/webhook-events-and-payloads#deployment) **Tags:** @@ -102,7 +102,7 @@ where the data is sourced from. * 'environment' = `event.deployment.environment` string * 'description' = `event.deployment.description` string -### [`deployment_status` event](https://developer.github.com/v3/activity/events/types/#deploymentstatusevent) +### [`deployment_status` event](https://docs.github.com/en/webhooks/webhook-events-and-payloads#deployment_status) **Tags:** @@ -124,7 +124,7 @@ where the data is sourced from. * 'depState' = `event.deployment_status.state` string * 'depDescription' = `event.deployment_status.description` string -### [`fork` event](https://developer.github.com/v3/activity/events/types/#forkevent) +### [`fork` event](https://docs.github.com/en/webhooks/webhook-events-and-payloads#fork) **Tags:** @@ -141,7 +141,7 @@ where the data is sourced from. * 'issues' = `event.repository.open_issues_count` int * 'forkee' = `event.forkee.repository` string -### [`gollum` event](https://developer.github.com/v3/activity/events/types/#gollumevent) +### [`gollum` event](https://docs.github.com/en/webhooks/webhook-events-and-payloads#gollum) **Tags:** @@ -157,7 +157,7 @@ where the data is sourced from. * 'forks' = `event.repository.forks_count` int * 'issues' = `event.repository.open_issues_count` int -### [`issue_comment` event](https://developer.github.com/v3/activity/events/types/#issuecommentevent) +### [`issue_comment` event](https://docs.github.com/en/webhooks/webhook-events-and-payloads#issue_comment) **Tags:** @@ -177,7 +177,7 @@ where the data is sourced from. * 'comments' = `event.issue.comments` int * 'body' = `event.comment.body` string -### [`issues` event](https://developer.github.com/v3/activity/events/types/#issuesevent) +### [`issues` event](https://docs.github.com/en/webhooks/webhook-events-and-payloads#issues) **Tags:** @@ -197,7 +197,7 @@ where the data is sourced from. * 'title' = `event.issue.title` string * 'comments' = `event.issue.comments` int -### [`member` event](https://developer.github.com/v3/activity/events/types/#memberevent) +### [`member` event](https://docs.github.com/en/webhooks/webhook-events-and-payloads#member) **Tags:** @@ -215,7 +215,7 @@ where the data is sourced from. * 'newMember' = `event.sender.login` string * 'newMemberStatus' = `event.sender.site_admin` bool -### [`membership` event](https://developer.github.com/v3/activity/events/types/#membershipevent) +### [`membership` event](https://docs.github.com/en/webhooks/webhook-events-and-payloads#membership) **Tags:** @@ -229,7 +229,7 @@ where the data is sourced from. * 'newMember' = `event.sender.login` string * 'newMemberStatus' = `event.sender.site_admin` bool -### [`page_build` event](https://developer.github.com/v3/activity/events/types/#pagebuildevent) +### [`page_build` event](https://docs.github.com/en/webhooks/webhook-events-and-payloads#page_build) **Tags:** @@ -245,7 +245,7 @@ where the data is sourced from. * 'forks' = `event.repository.forks_count` int * 'issues' = `event.repository.open_issues_count` int -### [`public` event](https://developer.github.com/v3/activity/events/types/#publicevent) +### [`public` event](https://docs.github.com/en/webhooks/webhook-events-and-payloads#public) **Tags:** @@ -261,7 +261,7 @@ where the data is sourced from. * 'forks' = `event.repository.forks_count` int * 'issues' = `event.repository.open_issues_count` int -### [`pull_request_review_comment` event](https://developer.github.com/v3/activity/events/types/#pullrequestreviewcommentevent) +### [`pull_request_review_comment` event](https://docs.github.com/en/webhooks/webhook-events-and-payloads#pull_request_review_comment) **Tags:** @@ -288,7 +288,7 @@ where the data is sourced from. * 'commentFile' = `event.comment.file` string * 'comment' = `event.comment.body` string -### [`pull_request` event](https://developer.github.com/v3/activity/events/types/#pullrequestevent) +### [`pull_request` event](https://docs.github.com/en/webhooks/webhook-events-and-payloads#pull_request) **Tags:** @@ -313,7 +313,7 @@ where the data is sourced from. * 'deletions' = `event.pull_request.deletions` int * 'changedFiles' = `event.pull_request.changed_files` int -### [`push` event](https://developer.github.com/v3/activity/events/types/#pushevent) +### [`push` event](https://docs.github.com/en/webhooks/webhook-events-and-payloads#push) **Tags:** @@ -332,7 +332,7 @@ where the data is sourced from. * 'before' = `event.before` string * 'after' = `event.after` string -### [`repository` event](https://developer.github.com/v3/activity/events/types/#repositoryevent) +### [`repository` event](https://docs.github.com/en/webhooks/webhook-events-and-payloads#repository) **Tags:** @@ -348,7 +348,7 @@ where the data is sourced from. * 'forks' = `event.repository.forks_count` int * 'issues' = `event.repository.open_issues_count` int -### [`release` event](https://developer.github.com/v3/activity/events/types/#releaseevent) +### [`release` event](https://docs.github.com/en/webhooks/webhook-events-and-payloads#release) **Tags:** @@ -365,7 +365,7 @@ where the data is sourced from. * 'issues' = `event.repository.open_issues_count` int * 'tagName' = `event.release.tag_name` string -### [`status` event](https://developer.github.com/v3/activity/events/types/#statusevent) +### [`status` event](https://docs.github.com/en/webhooks/webhook-events-and-payloads#status) **Tags:** @@ -383,7 +383,7 @@ where the data is sourced from. * 'commit' = `event.sha` string * 'state' = `event.state` string -### [`team_add` event](https://developer.github.com/v3/activity/events/types/#teamaddevent) +### [`team_add` event](https://docs.github.com/en/webhooks/webhook-events-and-payloads#team_add) **Tags:** @@ -400,7 +400,7 @@ where the data is sourced from. * 'issues' = `event.repository.open_issues_count` int * 'teamName' = `event.team.name` string -### [`watch` event](https://developer.github.com/v3/activity/events/types/#watchevent) +### [`watch` event](https://docs.github.com/en/webhooks/webhook-events-and-payloads#watch) **Tags:** @@ -415,3 +415,42 @@ where the data is sourced from. * 'stars' = `event.repository.stargazers_count` int * 'forks' = `event.repository.forks_count` int * 'issues' = `event.repository.open_issues_count` int + +### [`workflow_job` event](https://docs.github.com/en/webhooks/webhook-events-and-payloads#workflow_job) + +**Tags:** + +* 'event' = `headers[X-Github-Event]` string +* 'action' = `event.action` string +* 'repository' = `event.repository.full_name` string +* 'private' = `event.repository.private` bool +* 'user' = `event.sender.login` string +* 'admin' = `event.sender.site_admin` bool +* 'name' = `event.workflow_job.name` string +* 'conclusion' = `event.workflow_job.conclusion` string + +**Fields:** + +* 'run_attempt' = `event.workflow_job.run_attempt` int +* 'queue_time' = `event.workflow_job.started_at - event.workflow_job.created_at at event.action = in_progress in milliseconds` int +* 'run_time' = `event.workflow_job.completed_at - event.workflow_job.started_at at event.action = completed in milliseconds` int +* 'head_branch' = `event.workflow_job.head_branch` string + +### [`workflow_run` event](https://docs.github.com/en/webhooks/webhook-events-and-payloads#workflow_run) + +**Tags:** + +* 'event' = `headers[X-Github-Event]` string +* 'action' = `event.action` string +* 'repository' = `event.repository.full_name` string +* 'private' = `event.repository.private` bool +* 'user' = `event.sender.login` string +* 'admin' = `event.sender.site_admin` bool +* 'name' = `event.workflow_run.name` string +* 'conclusion' = `event.workflow_run.conclusion` string + +**Fields:** + +* 'run_attempt' = `event.workflow_run.run_attempt` int +* 'run_time' = `event.workflow_run.completed_at - event.workflow_run.run_started_at at event.action = completed in milliseconds` int +* 'head_branch' = `event.workflow_run.head_branch` string From 8fb0b31e5ff8ca12ce87de7128c7fc16cd7f575c Mon Sep 17 00:00:00 2001 From: "dmitriy.krapivenko" Date: Mon, 30 Dec 2024 14:37:40 +0300 Subject: [PATCH 09/18] fix go fmt --- plugins/inputs/webhooks/github/github_webhooks_models.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/inputs/webhooks/github/github_webhooks_models.go b/plugins/inputs/webhooks/github/github_webhooks_models.go index dcf4d9175a8d5..48583b4386e4e 100644 --- a/plugins/inputs/webhooks/github/github_webhooks_models.go +++ b/plugins/inputs/webhooks/github/github_webhooks_models.go @@ -1,9 +1,9 @@ package github import ( + "fmt" "strconv" "time" - "fmt" "github.com/influxdata/telegraf" "github.com/influxdata/telegraf/metric" From 0dd9d174c8b5ef13f5e2de871ef82f99b3679a24 Mon Sep 17 00:00:00 2001 From: "dmitriy.krapivenko" Date: Mon, 30 Dec 2024 14:44:04 +0300 Subject: [PATCH 10/18] fix copy-paste issue --- plugins/inputs/webhooks/github/github_webhooks_models.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugins/inputs/webhooks/github/github_webhooks_models.go b/plugins/inputs/webhooks/github/github_webhooks_models.go index 48583b4386e4e..3c142a6d74a60 100644 --- a/plugins/inputs/webhooks/github/github_webhooks_models.go +++ b/plugins/inputs/webhooks/github/github_webhooks_models.go @@ -739,11 +739,11 @@ func (s workflowRunEvent) NewMetric() telegraf.Metric { var run_time int64 = 0 createdAt, createdAtErr := time.Parse(time.RFC3339, s.WorkflowRun.CreatedAt) if createdAtErr != nil { - fmt.Errorf("error parsing createdAt %q: %w", s.WorkflowJob.CreatedAt, createdAtErr) + fmt.Errorf("error parsing createdAt %q: %w", s.WorkflowRun.CreatedAt, createdAtErr) } startedAt, startedAtErr := time.Parse(time.RFC3339, s.WorkflowRun.RunStartedAt) if startedAtErr != nil { - fmt.Errorf("error parsing createdAt %q: %w", s.WorkflowJob.StartedAt, startedAtErr) + fmt.Errorf("error parsing createdAt %q: %w", s.WorkflowRun.StartedAt, startedAtErr) } if s.Action == "completed" { From 8456d6e83863aaf529e0862267e253730c2020d1 Mon Sep 17 00:00:00 2001 From: "dmitriy.krapivenko" Date: Mon, 30 Dec 2024 14:44:58 +0300 Subject: [PATCH 11/18] fix runTime var name --- plugins/inputs/webhooks/github/github_webhooks_models.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/inputs/webhooks/github/github_webhooks_models.go b/plugins/inputs/webhooks/github/github_webhooks_models.go index 3c142a6d74a60..16c6e440e709f 100644 --- a/plugins/inputs/webhooks/github/github_webhooks_models.go +++ b/plugins/inputs/webhooks/github/github_webhooks_models.go @@ -736,7 +736,7 @@ func (s workflowRunEvent) NewMetric() telegraf.Metric { "name": s.WorkflowRun.Name, "conclusion": s.WorkflowRun.Conclusion, } - var run_time int64 = 0 + var runTime int64 = 0 createdAt, createdAtErr := time.Parse(time.RFC3339, s.WorkflowRun.CreatedAt) if createdAtErr != nil { fmt.Errorf("error parsing createdAt %q: %w", s.WorkflowRun.CreatedAt, createdAtErr) From be91d6512e1d2bfbb5e40b6efd725dadf0125d16 Mon Sep 17 00:00:00 2001 From: "dmitriy.krapivenko" Date: Mon, 30 Dec 2024 14:53:38 +0300 Subject: [PATCH 12/18] fix field names --- .../inputs/webhooks/github/github_webhooks_models.go | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/plugins/inputs/webhooks/github/github_webhooks_models.go b/plugins/inputs/webhooks/github/github_webhooks_models.go index 16c6e440e709f..4aa41f501372a 100644 --- a/plugins/inputs/webhooks/github/github_webhooks_models.go +++ b/plugins/inputs/webhooks/github/github_webhooks_models.go @@ -737,17 +737,17 @@ func (s workflowRunEvent) NewMetric() telegraf.Metric { "conclusion": s.WorkflowRun.Conclusion, } var runTime int64 = 0 - createdAt, createdAtErr := time.Parse(time.RFC3339, s.WorkflowRun.CreatedAt) - if createdAtErr != nil { - fmt.Errorf("error parsing createdAt %q: %w", s.WorkflowRun.CreatedAt, createdAtErr) - } startedAt, startedAtErr := time.Parse(time.RFC3339, s.WorkflowRun.RunStartedAt) if startedAtErr != nil { - fmt.Errorf("error parsing createdAt %q: %w", s.WorkflowRun.StartedAt, startedAtErr) + fmt.Errorf("error parsing startedAt %q: %w", s.WorkflowRun.RunStartedAt, startedAtErr) + } + updatedAt, updatedAtErr := time.Parse(time.RFC3339, s.WorkflowRun.UpdatedAt) + if updatedAtErr != nil { + fmt.Errorf("error parsing updatedAt %q: %w", s.WorkflowRun.UpdatedAt, updatedAtErr) } if s.Action == "completed" { - runTime = completedAt.Sub(startedAt).Milliseconds() + runTime = updatedAt.Sub(startedAt).Milliseconds() } f := map[string]interface{}{ "run_attempt": s.WorkflowRun.RunAttempt, From 72efe2ea96a19ea95a50252017721cfbcc27c606 Mon Sep 17 00:00:00 2001 From: "dmitriy.krapivenko" Date: Sat, 18 Jan 2025 12:18:10 +0300 Subject: [PATCH 13/18] add error log for unknown event and fix linter errors --- .../inputs/webhooks/github/github_webhooks.go | 1 + .../webhooks/github/github_webhooks_models.go | 34 +++++++------------ 2 files changed, 14 insertions(+), 21 deletions(-) diff --git a/plugins/inputs/webhooks/github/github_webhooks.go b/plugins/inputs/webhooks/github/github_webhooks.go index cbc8700917b51..38b7f73ef01cf 100644 --- a/plugins/inputs/webhooks/github/github_webhooks.go +++ b/plugins/inputs/webhooks/github/github_webhooks.go @@ -54,6 +54,7 @@ func (gh *GithubWebhook) eventHandler(w http.ResponseWriter, r *http.Request) { e, err := gh.NewEvent(data, eventType) if err != nil { w.WriteHeader(http.StatusBadRequest) + w.Write([]byte(err.Error())) return } if e != nil { diff --git a/plugins/inputs/webhooks/github/github_webhooks_models.go b/plugins/inputs/webhooks/github/github_webhooks_models.go index 4aa41f501372a..2f9f55628b9f1 100644 --- a/plugins/inputs/webhooks/github/github_webhooks_models.go +++ b/plugins/inputs/webhooks/github/github_webhooks_models.go @@ -1,7 +1,6 @@ package github import ( - "fmt" "strconv" "time" @@ -687,32 +686,28 @@ func (s workflowJobEvent) NewMetric() telegraf.Metric { "name": s.WorkflowJob.Name, "conclusion": s.WorkflowJob.Conclusion, } - createdAt, createdAtErr := time.Parse(time.RFC3339, s.WorkflowJob.CreatedAt) - if createdAtErr != nil { - fmt.Errorf("error parsing createdAt %q: %w", s.WorkflowJob.CreatedAt, createdAtErr) - } - startedAt, startedAtErr := time.Parse(time.RFC3339, s.WorkflowJob.StartedAt) - if startedAtErr != nil { - fmt.Errorf("error parsing createdAt %q: %w", s.WorkflowJob.StartedAt, startedAtErr) - } - completedAt, completedAtErr := time.Parse(time.RFC3339, s.WorkflowJob.CompletedAt) - if completedAtErr != nil { - fmt.Errorf("error parsing createdAt %q: %w", s.WorkflowJob.CompletedAt, completedAtErr) - } + createdAt, _ := time.Parse(time.RFC3339, s.WorkflowJob.CreatedAt) + startedAt, _ := time.Parse(time.RFC3339, s.WorkflowJob.StartedAt) + completedAt, _ := time.Parse(time.RFC3339, s.WorkflowJob.CompletedAt) + var runTime int64 = 0 var queueTime int64 = 0 + if s.Action == "in_progress" { queueTime = startedAt.Sub(createdAt).Milliseconds() } + if s.Action == "completed" { runTime = completedAt.Sub(startedAt).Milliseconds() } + f := map[string]interface{}{ "run_attempt": s.WorkflowJob.RunAttempt, "queue_time": queueTime, "run_time": runTime, "head_branch": s.WorkflowJob.HeadBranch, } + m := metric.New(meas, t, f, time.Now()) return m } @@ -736,24 +731,21 @@ func (s workflowRunEvent) NewMetric() telegraf.Metric { "name": s.WorkflowRun.Name, "conclusion": s.WorkflowRun.Conclusion, } + var runTime int64 = 0 - startedAt, startedAtErr := time.Parse(time.RFC3339, s.WorkflowRun.RunStartedAt) - if startedAtErr != nil { - fmt.Errorf("error parsing startedAt %q: %w", s.WorkflowRun.RunStartedAt, startedAtErr) - } - updatedAt, updatedAtErr := time.Parse(time.RFC3339, s.WorkflowRun.UpdatedAt) - if updatedAtErr != nil { - fmt.Errorf("error parsing updatedAt %q: %w", s.WorkflowRun.UpdatedAt, updatedAtErr) - } + startedAt, _ := time.Parse(time.RFC3339, s.WorkflowRun.RunStartedAt) + updatedAt, _ := time.Parse(time.RFC3339, s.WorkflowRun.UpdatedAt) if s.Action == "completed" { runTime = updatedAt.Sub(startedAt).Milliseconds() } + f := map[string]interface{}{ "run_attempt": s.WorkflowRun.RunAttempt, "run_time": runTime, "head_branch": s.WorkflowRun.HeadBranch, } + m := metric.New(meas, t, f, time.Now()) return m } From 1cd755b42fe09ecd116d14d2dce23e0e79b6a3d7 Mon Sep 17 00:00:00 2001 From: "dmitriy.krapivenko" Date: Fri, 24 Jan 2025 17:01:59 +0300 Subject: [PATCH 14/18] use time.Time to unmarshal time fields --- .../webhooks/github/github_webhooks_models.go | 62 ++++++++----------- 1 file changed, 25 insertions(+), 37 deletions(-) diff --git a/plugins/inputs/webhooks/github/github_webhooks_models.go b/plugins/inputs/webhooks/github/github_webhooks_models.go index 2f9f55628b9f1..8603d433669ec 100644 --- a/plugins/inputs/webhooks/github/github_webhooks_models.go +++ b/plugins/inputs/webhooks/github/github_webhooks_models.go @@ -76,23 +76,23 @@ type pullRequestReviewComment struct { } type workflowJob struct { - RunAttempt int `json:"run_attempt"` - HeadBranch string `json:"head_branch"` - CreatedAt string `json:"created_at"` - StartedAt string `json:"started_at"` - CompletedAt string `json:"completed_at"` - Name string `json:"name"` - Conclusion string `json:"conclusion"` + RunAttempt int `json:"run_attempt"` + HeadBranch string `json:"head_branch"` + CreatedAt time.Time `json:"created_at"` + StartedAt time.Time `json:"started_at"` + CompletedAt time.Time `json:"completed_at"` + Name string `json:"name"` + Conclusion string `json:"conclusion"` } type workflowRun struct { - HeadBranch string `json:"head_branch"` - CreatedAt string `json:"created_at"` - RunStartedAt string `json:"run_started_at"` - UpdatedAt string `json:"updated_at"` - RunAttempt int `json:"run_attempt"` - Name string `json:"name"` - Conclusion string `json:"conclusion"` + HeadBranch string `json:"head_branch"` + CreatedAt time.Time `json:"created_at"` + RunStartedAt time.Time `json:"run_started_at"` + UpdatedAt time.Time `json:"updated_at"` + RunAttempt int `json:"run_attempt"` + Name string `json:"name"` + Conclusion string `json:"conclusion"` } type release struct { @@ -686,28 +686,21 @@ func (s workflowJobEvent) NewMetric() telegraf.Metric { "name": s.WorkflowJob.Name, "conclusion": s.WorkflowJob.Conclusion, } - createdAt, _ := time.Parse(time.RFC3339, s.WorkflowJob.CreatedAt) - startedAt, _ := time.Parse(time.RFC3339, s.WorkflowJob.StartedAt) - completedAt, _ := time.Parse(time.RFC3339, s.WorkflowJob.CompletedAt) - - var runTime int64 = 0 - var queueTime int64 = 0 - + + var runTimeMs int64 + var queueTimeMs int64 if s.Action == "in_progress" { - queueTime = startedAt.Sub(createdAt).Milliseconds() + queueTimeMs = s.WorkflowJob.StartedAt.Sub(s.WorkflowJob.CreatedAt).Milliseconds() } - if s.Action == "completed" { - runTime = completedAt.Sub(startedAt).Milliseconds() + runTimeMs = s.WorkflowJob.CompletedAt.Sub(s.WorkflowJob.StartedAt).Milliseconds() } - f := map[string]interface{}{ "run_attempt": s.WorkflowJob.RunAttempt, - "queue_time": queueTime, - "run_time": runTime, + "queue_time": queueTimeMs, + "run_time": runTimeMs, "head_branch": s.WorkflowJob.HeadBranch, } - m := metric.New(meas, t, f, time.Now()) return m } @@ -731,21 +724,16 @@ func (s workflowRunEvent) NewMetric() telegraf.Metric { "name": s.WorkflowRun.Name, "conclusion": s.WorkflowRun.Conclusion, } - - var runTime int64 = 0 - startedAt, _ := time.Parse(time.RFC3339, s.WorkflowRun.RunStartedAt) - updatedAt, _ := time.Parse(time.RFC3339, s.WorkflowRun.UpdatedAt) - + var runTimeMs int64 + if s.Action == "completed" { - runTime = updatedAt.Sub(startedAt).Milliseconds() + runTimeMs = s.WorkflowRun.UpdatedAt.Sub(s.WorkflowRun.RunStartedAt).Milliseconds() } - f := map[string]interface{}{ "run_attempt": s.WorkflowRun.RunAttempt, - "run_time": runTime, + "run_time": runTimeMs, "head_branch": s.WorkflowRun.HeadBranch, } - m := metric.New(meas, t, f, time.Now()) return m } From a17281148a14cedff9ecf76ac569062d9c6aeedb Mon Sep 17 00:00:00 2001 From: "dmitriy.krapivenko" Date: Fri, 24 Jan 2025 17:06:45 +0300 Subject: [PATCH 15/18] fix formatting issue --- .../webhooks/github/github_webhooks_models.go | 32 +++++++++---------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/plugins/inputs/webhooks/github/github_webhooks_models.go b/plugins/inputs/webhooks/github/github_webhooks_models.go index 8603d433669ec..1f74686830ff8 100644 --- a/plugins/inputs/webhooks/github/github_webhooks_models.go +++ b/plugins/inputs/webhooks/github/github_webhooks_models.go @@ -76,23 +76,23 @@ type pullRequestReviewComment struct { } type workflowJob struct { - RunAttempt int `json:"run_attempt"` - HeadBranch string `json:"head_branch"` - CreatedAt time.Time `json:"created_at"` - StartedAt time.Time `json:"started_at"` - CompletedAt time.Time `json:"completed_at"` - Name string `json:"name"` - Conclusion string `json:"conclusion"` + RunAttempt int `json:"run_attempt"` + HeadBranch string `json:"head_branch"` + CreatedAt time.Time `json:"created_at"` + StartedAt time.Time `json:"started_at"` + CompletedAt time.Time `json:"completed_at"` + Name string `json:"name"` + Conclusion string `json:"conclusion"` } type workflowRun struct { - HeadBranch string `json:"head_branch"` - CreatedAt time.Time `json:"created_at"` - RunStartedAt time.Time `json:"run_started_at"` - UpdatedAt time.Time `json:"updated_at"` - RunAttempt int `json:"run_attempt"` - Name string `json:"name"` - Conclusion string `json:"conclusion"` + HeadBranch string `json:"head_branch"` + CreatedAt time.Time `json:"created_at"` + RunStartedAt time.Time `json:"run_started_at"` + UpdatedAt time.Time `json:"updated_at"` + RunAttempt int `json:"run_attempt"` + Name string `json:"name"` + Conclusion string `json:"conclusion"` } type release struct { @@ -686,7 +686,7 @@ func (s workflowJobEvent) NewMetric() telegraf.Metric { "name": s.WorkflowJob.Name, "conclusion": s.WorkflowJob.Conclusion, } - + var runTimeMs int64 var queueTimeMs int64 if s.Action == "in_progress" { @@ -725,7 +725,7 @@ func (s workflowRunEvent) NewMetric() telegraf.Metric { "conclusion": s.WorkflowRun.Conclusion, } var runTimeMs int64 - + if s.Action == "completed" { runTimeMs = s.WorkflowRun.UpdatedAt.Sub(s.WorkflowRun.RunStartedAt).Milliseconds() } From 3330bcc3af7a0f074d623bd948f55441b0199ba1 Mon Sep 17 00:00:00 2001 From: "dmitriy.krapivenko" Date: Fri, 24 Jan 2025 17:15:46 +0300 Subject: [PATCH 16/18] fix func name case after merge --- plugins/inputs/webhooks/github/github_webhooks_models.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugins/inputs/webhooks/github/github_webhooks_models.go b/plugins/inputs/webhooks/github/github_webhooks_models.go index 76dbc4b113322..8bc989a3f0b54 100644 --- a/plugins/inputs/webhooks/github/github_webhooks_models.go +++ b/plugins/inputs/webhooks/github/github_webhooks_models.go @@ -674,7 +674,7 @@ type workflowJobEvent struct { Sender sender `json:"sender"` } -func (s workflowJobEvent) NewMetric() telegraf.Metric { +func (s workflowJobEvent) newMetric() telegraf.Metric { event := "workflow_job" t := map[string]string{ "event": event, @@ -712,7 +712,7 @@ type workflowRunEvent struct { Sender sender `json:"sender"` } -func (s workflowRunEvent) NewMetric() telegraf.Metric { +func (s workflowRunEvent) newMetric() telegraf.Metric { event := "workflow_run" t := map[string]string{ "event": event, From cf0a48ca6e437d334e8a9a18173dbfcb32456a40 Mon Sep 17 00:00:00 2001 From: "dmitriy.krapivenko" Date: Fri, 24 Jan 2025 17:21:59 +0300 Subject: [PATCH 17/18] yet another func name case fix after merge --- plugins/inputs/webhooks/github/github_webhooks_test.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugins/inputs/webhooks/github/github_webhooks_test.go b/plugins/inputs/webhooks/github/github_webhooks_test.go index 51322032d7284..d25a12679ef48 100644 --- a/plugins/inputs/webhooks/github/github_webhooks_test.go +++ b/plugins/inputs/webhooks/github/github_webhooks_test.go @@ -127,11 +127,11 @@ func TestEventWithSignatureSuccess(t *testing.T) { } func TestWorkflowJob(t *testing.T) { - GithubWebhookRequest(t, "workflow_job", WorkflowJobJSON()) + githubWebhookRequest(t, "workflow_job", WorkflowJobJSON()) } func TestWorkflowRun(t *testing.T) { - GithubWebhookRequest(t, "workflow_run", WorkflowRunJSON()) + githubWebhookRequest(t, "workflow_run", WorkflowRunJSON()) } func TestCheckSignatureSuccess(t *testing.T) { From c383b82a61afbb59af763ad9883fa68cd47cba63 Mon Sep 17 00:00:00 2001 From: "dmitriy.krapivenko" Date: Fri, 24 Jan 2025 19:38:59 +0300 Subject: [PATCH 18/18] remove unnecessary method call --- plugins/inputs/webhooks/github/github_webhooks.go | 1 - 1 file changed, 1 deletion(-) diff --git a/plugins/inputs/webhooks/github/github_webhooks.go b/plugins/inputs/webhooks/github/github_webhooks.go index f07bcea399614..a23d77baa4223 100644 --- a/plugins/inputs/webhooks/github/github_webhooks.go +++ b/plugins/inputs/webhooks/github/github_webhooks.go @@ -55,7 +55,6 @@ func (gh *Webhook) eventHandler(w http.ResponseWriter, r *http.Request) { e, err := gh.newEvent(data, eventType) if err != nil { w.WriteHeader(http.StatusBadRequest) - w.Write([]byte(err.Error())) return } if e != nil {