From 6fb347add7f1e6ad6e070f08e5bc35e01820ce58 Mon Sep 17 00:00:00 2001 From: Jakub Semik Date: Tue, 7 Jan 2025 13:40:19 +0000 Subject: [PATCH] add exclude tags option --- README.md | 18 + src/client.ts | 1 + src/filter.ts | 13 +- src/main.ts | 1 + src/run.ts | 1 + tests/__snapshots__/run.test.ts.snap | 1489 ++++++++++++++++++++++++++ tests/run.test.ts | 39 + 7 files changed, 1561 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 5f8f94aa..d204798c 100644 --- a/README.md +++ b/README.md @@ -421,6 +421,7 @@ You can set the following inputs: | `datadog-site` | - | Datadog Server name such as `datadoghq.eu`, `ddog-gov.com`, `us3.datadoghq.com` | | `datadog-tags` | - | Additional tags in the form of `key:value` in a multiline string | | `metrics-patterns` | - | Filter the metrics by patterns in a multiline string | +| `tags-to-exclude` | - | Exclude specified tags by names in a multiline string | | `send-pull-request-labels` | `false` | Send pull request labels as Datadog tags | | `collect-job-metrics` | `false` | Collect job metrics | | `collect-step-metrics` | `false` | Collect step metrics | @@ -457,6 +458,23 @@ steps: If both include and exclude patterns are given, the later pattern has higher precedence. +### Exclude Tags + +The `tags-to-exclude` input allows you to specify tags that should be excluded from being sent to Datadog. You can provide this as a multiline string where each line contains a tag to be excluded. + +To exclude specific tags, include the `tags-to-exclude` option like this: + +```yaml +steps: + - uses: int128/datadog-actions-metrics@v1 + with: + tags-to-exclude: | + job_id + runs_on +``` + +Each tag listed in `tags-to-exclude` will not be sent to Datadog, helping you streamline the metrics data you wish to analyze. + ### Proxy To connect to Datadog API via a HTTPS proxy, set `https_proxy` environment variable. diff --git a/src/client.ts b/src/client.ts index 5a74908d..4014ef24 100644 --- a/src/client.ts +++ b/src/client.ts @@ -8,6 +8,7 @@ type Inputs = { datadogSite?: string datadogTags: string[] metricsPatterns: string[] + tagsToExclude: string[] } export type MetricsClient = { diff --git a/src/filter.ts b/src/filter.ts index 51f52263..d28e1dad 100644 --- a/src/filter.ts +++ b/src/filter.ts @@ -4,6 +4,7 @@ import { v1 } from '@datadog/datadog-api-client' type Inputs = { metricsPatterns: string[] datadogTags: string[] + tagsToExclude: string[] } export type MetricsFilter = (series: S[]) => S[] @@ -12,7 +13,7 @@ export const createMetricsFilter = (inputs: Inputs): MetricsFilter => { const matcher = createMatcher(inputs.metricsPatterns) return (series) => { series = series.filter((s) => matcher(s.metric)) - return injectTags(series, inputs.datadogTags) + return excludeTags(injectTags(series, inputs.datadogTags), inputs.tagsToExclude) } } @@ -39,3 +40,13 @@ export const injectTags = (series: S[], tags: str } return series.map((s) => ({ ...s, tags: [...(s.tags ?? []), ...tags] })) } + +export const excludeTags = (series: S[], tagsToExclude: string[]): S[] => { + if (tagsToExclude.length === 0) { + return series + } + return series.map((s) => ({ + ...s, + tags: (s.tags || []).filter((tag) => !tagsToExclude.some((exclude) => tag.startsWith(`${exclude}:`))), + })) +} diff --git a/src/main.ts b/src/main.ts index 08612b5c..eeedf8d7 100644 --- a/src/main.ts +++ b/src/main.ts @@ -16,6 +16,7 @@ const main = async (): Promise => { preferDistributionJobMetrics: core.getBooleanInput('prefer-distribution-job-metrics'), preferDistributionStepMetrics: core.getBooleanInput('prefer-distribution-step-metrics'), sendPullRequestLabels: core.getBooleanInput('send-pull-request-labels'), + tagsToExclude: core.getMultilineInput('tags-to-exclude'), }) } diff --git a/src/run.ts b/src/run.ts index 12b1f28d..3089dccf 100644 --- a/src/run.ts +++ b/src/run.ts @@ -22,6 +22,7 @@ type Inputs = { preferDistributionJobMetrics: boolean preferDistributionStepMetrics: boolean sendPullRequestLabels: boolean + tagsToExclude: string[] } export const run = async (context: GitHubContext, inputs: Inputs): Promise => { diff --git a/tests/__snapshots__/run.test.ts.snap b/tests/__snapshots__/run.test.ts.snap index 9147df15..c7d6f952 100644 --- a/tests/__snapshots__/run.test.ts.snap +++ b/tests/__snapshots__/run.test.ts.snap @@ -2258,3 +2258,1492 @@ exports[`workflow_run with collectJobMetrics 1`] = ` ], ] `; + +exports[`workflow_run with collectJobMetrics with tags to exclude 1`] = ` +[ + [ + { + "body": { + "series": [ + { + "host": "github.com", + "metric": "github.actions.workflow_run.total", + "points": [ + [ + 1639683442, + 1, + ], + ], + "tags": [ + "repository_owner:octo-org", + "repository_name:octo-repo", + "workflow_id:1589141559", + "workflow_name:Manually triggered workflow", + "run_attempt:1", + "event:workflow_dispatch", + "sender:Codertocat", + "sender_type:User", + "branch:main", + "default_branch:true", + "conclusion:null", + ], + "type": "count", + }, + { + "host": "github.com", + "metric": "github.actions.workflow_run.conclusion.null_total", + "points": [ + [ + 1639683442, + 1, + ], + ], + "tags": [ + "repository_owner:octo-org", + "repository_name:octo-repo", + "workflow_id:1589141559", + "workflow_name:Manually triggered workflow", + "run_attempt:1", + "event:workflow_dispatch", + "sender:Codertocat", + "sender_type:User", + "branch:main", + "default_branch:true", + "conclusion:null", + ], + "type": "count", + }, + { + "host": "github.com", + "metric": "github.actions.workflow_run.duration_second", + "points": [ + [ + 1639683442, + 0, + ], + ], + "tags": [ + "repository_owner:octo-org", + "repository_name:octo-repo", + "workflow_id:1589141559", + "workflow_name:Manually triggered workflow", + "run_attempt:1", + "event:workflow_dispatch", + "sender:Codertocat", + "sender_type:User", + "branch:main", + "default_branch:true", + "conclusion:null", + ], + "type": "gauge", + }, + ], + }, + }, + ], + [ + { + "body": { + "series": [ + { + "host": "github.com", + "metric": "github.actions.job.total", + "points": [ + [ + 1579542279, + 1, + ], + ], + "tags": [ + "repository_owner:octo-org", + "repository_name:octo-repo", + "workflow_id:1589141559", + "workflow_name:Manually triggered workflow", + "run_attempt:1", + "event:workflow_dispatch", + "sender:Codertocat", + "sender_type:User", + "branch:main", + "default_branch:true", + "job_name:build", + "conclusion:success", + "status:completed", + "runs_on:bar,foo,self-hosted", + ], + "type": "count", + }, + { + "host": "github.com", + "metric": "github.actions.job.conclusion.success_total", + "points": [ + [ + 1579542279, + 1, + ], + ], + "tags": [ + "repository_owner:octo-org", + "repository_name:octo-repo", + "workflow_id:1589141559", + "workflow_name:Manually triggered workflow", + "run_attempt:1", + "event:workflow_dispatch", + "sender:Codertocat", + "sender_type:User", + "branch:main", + "default_branch:true", + "job_name:build", + "conclusion:success", + "status:completed", + "runs_on:bar,foo,self-hosted", + ], + "type": "count", + }, + { + "host": "github.com", + "metric": "github.actions.job.queued_duration_second", + "points": [ + [ + 1579542279, + 29, + ], + ], + "tags": [ + "repository_owner:octo-org", + "repository_name:octo-repo", + "workflow_id:1589141559", + "workflow_name:Manually triggered workflow", + "run_attempt:1", + "event:workflow_dispatch", + "sender:Codertocat", + "sender_type:User", + "branch:main", + "default_branch:true", + "job_name:build", + "conclusion:success", + "status:completed", + "runs_on:bar,foo,self-hosted", + ], + "type": "gauge", + }, + { + "host": "github.com", + "metric": "github.actions.job.duration_second", + "points": [ + [ + 1579542279, + 119, + ], + ], + "tags": [ + "repository_owner:octo-org", + "repository_name:octo-repo", + "workflow_id:1589141559", + "workflow_name:Manually triggered workflow", + "run_attempt:1", + "event:workflow_dispatch", + "sender:Codertocat", + "sender_type:User", + "branch:main", + "default_branch:true", + "job_name:build", + "conclusion:success", + "status:completed", + "runs_on:bar,foo,self-hosted", + ], + "type": "gauge", + }, + { + "host": "github.com", + "metric": "github.actions.job.start_time_from_workflow_start_second", + "points": [ + [ + 1579542279, + -60141282, + ], + ], + "tags": [ + "repository_owner:octo-org", + "repository_name:octo-repo", + "workflow_id:1589141559", + "workflow_name:Manually triggered workflow", + "run_attempt:1", + "event:workflow_dispatch", + "sender:Codertocat", + "sender_type:User", + "branch:main", + "default_branch:true", + "job_name:build", + "conclusion:success", + "status:completed", + "runs_on:bar,foo,self-hosted", + ], + }, + ], + }, + }, + ], + [ + { + "body": { + "series": [ + { + "host": "github.com", + "metric": "github.actions.step.total", + "points": [ + [ + 1579542161, + 1, + ], + ], + "tags": [ + "repository_owner:octo-org", + "repository_name:octo-repo", + "workflow_id:1589141559", + "workflow_name:Manually triggered workflow", + "run_attempt:1", + "event:workflow_dispatch", + "sender:Codertocat", + "sender_type:User", + "branch:main", + "default_branch:true", + "job_name:build", + "runs_on:bar,foo,self-hosted", + "step_name:Set up job", + "step_number:1", + "conclusion:success", + "status:completed", + ], + "type": "count", + }, + { + "host": "github.com", + "metric": "github.actions.step.conclusion.success_total", + "points": [ + [ + 1579542161, + 1, + ], + ], + "tags": [ + "repository_owner:octo-org", + "repository_name:octo-repo", + "workflow_id:1589141559", + "workflow_name:Manually triggered workflow", + "run_attempt:1", + "event:workflow_dispatch", + "sender:Codertocat", + "sender_type:User", + "branch:main", + "default_branch:true", + "job_name:build", + "runs_on:bar,foo,self-hosted", + "step_name:Set up job", + "step_number:1", + "conclusion:success", + "status:completed", + ], + "type": "count", + }, + { + "host": "github.com", + "metric": "github.actions.step.duration_second", + "points": [ + [ + 1579542161, + 1, + ], + ], + "tags": [ + "repository_owner:octo-org", + "repository_name:octo-repo", + "workflow_id:1589141559", + "workflow_name:Manually triggered workflow", + "run_attempt:1", + "event:workflow_dispatch", + "sender:Codertocat", + "sender_type:User", + "branch:main", + "default_branch:true", + "job_name:build", + "runs_on:bar,foo,self-hosted", + "step_name:Set up job", + "step_number:1", + "conclusion:success", + "status:completed", + ], + "type": "gauge", + }, + { + "host": "github.com", + "metric": "github.actions.step.start_time_from_workflow_start_second", + "points": [ + [ + 1579542161, + -60141282, + ], + ], + "tags": [ + "repository_owner:octo-org", + "repository_name:octo-repo", + "workflow_id:1589141559", + "workflow_name:Manually triggered workflow", + "run_attempt:1", + "event:workflow_dispatch", + "sender:Codertocat", + "sender_type:User", + "branch:main", + "default_branch:true", + "job_name:build", + "runs_on:bar,foo,self-hosted", + "step_name:Set up job", + "step_number:1", + "conclusion:success", + "status:completed", + ], + }, + { + "host": "github.com", + "metric": "github.actions.step.total", + "points": [ + [ + 1579542165, + 1, + ], + ], + "tags": [ + "repository_owner:octo-org", + "repository_name:octo-repo", + "workflow_id:1589141559", + "workflow_name:Manually triggered workflow", + "run_attempt:1", + "event:workflow_dispatch", + "sender:Codertocat", + "sender_type:User", + "branch:main", + "default_branch:true", + "job_name:build", + "runs_on:bar,foo,self-hosted", + "step_name:Run actions/checkout@v2", + "step_number:2", + "conclusion:success", + "status:completed", + ], + "type": "count", + }, + { + "host": "github.com", + "metric": "github.actions.step.conclusion.success_total", + "points": [ + [ + 1579542165, + 1, + ], + ], + "tags": [ + "repository_owner:octo-org", + "repository_name:octo-repo", + "workflow_id:1589141559", + "workflow_name:Manually triggered workflow", + "run_attempt:1", + "event:workflow_dispatch", + "sender:Codertocat", + "sender_type:User", + "branch:main", + "default_branch:true", + "job_name:build", + "runs_on:bar,foo,self-hosted", + "step_name:Run actions/checkout@v2", + "step_number:2", + "conclusion:success", + "status:completed", + ], + "type": "count", + }, + { + "host": "github.com", + "metric": "github.actions.step.duration_second", + "points": [ + [ + 1579542165, + 4, + ], + ], + "tags": [ + "repository_owner:octo-org", + "repository_name:octo-repo", + "workflow_id:1589141559", + "workflow_name:Manually triggered workflow", + "run_attempt:1", + "event:workflow_dispatch", + "sender:Codertocat", + "sender_type:User", + "branch:main", + "default_branch:true", + "job_name:build", + "runs_on:bar,foo,self-hosted", + "step_name:Run actions/checkout@v2", + "step_number:2", + "conclusion:success", + "status:completed", + ], + "type": "gauge", + }, + { + "host": "github.com", + "metric": "github.actions.step.start_time_from_workflow_start_second", + "points": [ + [ + 1579542165, + -60141281, + ], + ], + "tags": [ + "repository_owner:octo-org", + "repository_name:octo-repo", + "workflow_id:1589141559", + "workflow_name:Manually triggered workflow", + "run_attempt:1", + "event:workflow_dispatch", + "sender:Codertocat", + "sender_type:User", + "branch:main", + "default_branch:true", + "job_name:build", + "runs_on:bar,foo,self-hosted", + "step_name:Run actions/checkout@v2", + "step_number:2", + "conclusion:success", + "status:completed", + ], + }, + { + "host": "github.com", + "metric": "github.actions.step.total", + "points": [ + [ + 1579542165, + 1, + ], + ], + "tags": [ + "repository_owner:octo-org", + "repository_name:octo-repo", + "workflow_id:1589141559", + "workflow_name:Manually triggered workflow", + "run_attempt:1", + "event:workflow_dispatch", + "sender:Codertocat", + "sender_type:User", + "branch:main", + "default_branch:true", + "job_name:build", + "runs_on:bar,foo,self-hosted", + "step_name:Set up Ruby", + "step_number:3", + "conclusion:success", + "status:completed", + ], + "type": "count", + }, + { + "host": "github.com", + "metric": "github.actions.step.conclusion.success_total", + "points": [ + [ + 1579542165, + 1, + ], + ], + "tags": [ + "repository_owner:octo-org", + "repository_name:octo-repo", + "workflow_id:1589141559", + "workflow_name:Manually triggered workflow", + "run_attempt:1", + "event:workflow_dispatch", + "sender:Codertocat", + "sender_type:User", + "branch:main", + "default_branch:true", + "job_name:build", + "runs_on:bar,foo,self-hosted", + "step_name:Set up Ruby", + "step_number:3", + "conclusion:success", + "status:completed", + ], + "type": "count", + }, + { + "host": "github.com", + "metric": "github.actions.step.duration_second", + "points": [ + [ + 1579542165, + 0, + ], + ], + "tags": [ + "repository_owner:octo-org", + "repository_name:octo-repo", + "workflow_id:1589141559", + "workflow_name:Manually triggered workflow", + "run_attempt:1", + "event:workflow_dispatch", + "sender:Codertocat", + "sender_type:User", + "branch:main", + "default_branch:true", + "job_name:build", + "runs_on:bar,foo,self-hosted", + "step_name:Set up Ruby", + "step_number:3", + "conclusion:success", + "status:completed", + ], + "type": "gauge", + }, + { + "host": "github.com", + "metric": "github.actions.step.start_time_from_workflow_start_second", + "points": [ + [ + 1579542165, + -60141277, + ], + ], + "tags": [ + "repository_owner:octo-org", + "repository_name:octo-repo", + "workflow_id:1589141559", + "workflow_name:Manually triggered workflow", + "run_attempt:1", + "event:workflow_dispatch", + "sender:Codertocat", + "sender_type:User", + "branch:main", + "default_branch:true", + "job_name:build", + "runs_on:bar,foo,self-hosted", + "step_name:Set up Ruby", + "step_number:3", + "conclusion:success", + "status:completed", + ], + }, + { + "host": "github.com", + "metric": "github.actions.step.total", + "points": [ + [ + 1579542168, + 1, + ], + ], + "tags": [ + "repository_owner:octo-org", + "repository_name:octo-repo", + "workflow_id:1589141559", + "workflow_name:Manually triggered workflow", + "run_attempt:1", + "event:workflow_dispatch", + "sender:Codertocat", + "sender_type:User", + "branch:main", + "default_branch:true", + "job_name:build", + "runs_on:bar,foo,self-hosted", + "step_name:Run actions/cache@v3", + "step_number:4", + "conclusion:success", + "status:completed", + ], + "type": "count", + }, + { + "host": "github.com", + "metric": "github.actions.step.conclusion.success_total", + "points": [ + [ + 1579542168, + 1, + ], + ], + "tags": [ + "repository_owner:octo-org", + "repository_name:octo-repo", + "workflow_id:1589141559", + "workflow_name:Manually triggered workflow", + "run_attempt:1", + "event:workflow_dispatch", + "sender:Codertocat", + "sender_type:User", + "branch:main", + "default_branch:true", + "job_name:build", + "runs_on:bar,foo,self-hosted", + "step_name:Run actions/cache@v3", + "step_number:4", + "conclusion:success", + "status:completed", + ], + "type": "count", + }, + { + "host": "github.com", + "metric": "github.actions.step.duration_second", + "points": [ + [ + 1579542168, + 3, + ], + ], + "tags": [ + "repository_owner:octo-org", + "repository_name:octo-repo", + "workflow_id:1589141559", + "workflow_name:Manually triggered workflow", + "run_attempt:1", + "event:workflow_dispatch", + "sender:Codertocat", + "sender_type:User", + "branch:main", + "default_branch:true", + "job_name:build", + "runs_on:bar,foo,self-hosted", + "step_name:Run actions/cache@v3", + "step_number:4", + "conclusion:success", + "status:completed", + ], + "type": "gauge", + }, + { + "host": "github.com", + "metric": "github.actions.step.start_time_from_workflow_start_second", + "points": [ + [ + 1579542168, + -60141277, + ], + ], + "tags": [ + "repository_owner:octo-org", + "repository_name:octo-repo", + "workflow_id:1589141559", + "workflow_name:Manually triggered workflow", + "run_attempt:1", + "event:workflow_dispatch", + "sender:Codertocat", + "sender_type:User", + "branch:main", + "default_branch:true", + "job_name:build", + "runs_on:bar,foo,self-hosted", + "step_name:Run actions/cache@v3", + "step_number:4", + "conclusion:success", + "status:completed", + ], + }, + { + "host": "github.com", + "metric": "github.actions.step.total", + "points": [ + [ + 1579542172, + 1, + ], + ], + "tags": [ + "repository_owner:octo-org", + "repository_name:octo-repo", + "workflow_id:1589141559", + "workflow_name:Manually triggered workflow", + "run_attempt:1", + "event:workflow_dispatch", + "sender:Codertocat", + "sender_type:User", + "branch:main", + "default_branch:true", + "job_name:build", + "runs_on:bar,foo,self-hosted", + "step_name:Install Bundler", + "step_number:5", + "conclusion:success", + "status:completed", + ], + "type": "count", + }, + { + "host": "github.com", + "metric": "github.actions.step.conclusion.success_total", + "points": [ + [ + 1579542172, + 1, + ], + ], + "tags": [ + "repository_owner:octo-org", + "repository_name:octo-repo", + "workflow_id:1589141559", + "workflow_name:Manually triggered workflow", + "run_attempt:1", + "event:workflow_dispatch", + "sender:Codertocat", + "sender_type:User", + "branch:main", + "default_branch:true", + "job_name:build", + "runs_on:bar,foo,self-hosted", + "step_name:Install Bundler", + "step_number:5", + "conclusion:success", + "status:completed", + ], + "type": "count", + }, + { + "host": "github.com", + "metric": "github.actions.step.duration_second", + "points": [ + [ + 1579542172, + 4, + ], + ], + "tags": [ + "repository_owner:octo-org", + "repository_name:octo-repo", + "workflow_id:1589141559", + "workflow_name:Manually triggered workflow", + "run_attempt:1", + "event:workflow_dispatch", + "sender:Codertocat", + "sender_type:User", + "branch:main", + "default_branch:true", + "job_name:build", + "runs_on:bar,foo,self-hosted", + "step_name:Install Bundler", + "step_number:5", + "conclusion:success", + "status:completed", + ], + "type": "gauge", + }, + { + "host": "github.com", + "metric": "github.actions.step.start_time_from_workflow_start_second", + "points": [ + [ + 1579542172, + -60141274, + ], + ], + "tags": [ + "repository_owner:octo-org", + "repository_name:octo-repo", + "workflow_id:1589141559", + "workflow_name:Manually triggered workflow", + "run_attempt:1", + "event:workflow_dispatch", + "sender:Codertocat", + "sender_type:User", + "branch:main", + "default_branch:true", + "job_name:build", + "runs_on:bar,foo,self-hosted", + "step_name:Install Bundler", + "step_number:5", + "conclusion:success", + "status:completed", + ], + }, + { + "host": "github.com", + "metric": "github.actions.step.total", + "points": [ + [ + 1579542173, + 1, + ], + ], + "tags": [ + "repository_owner:octo-org", + "repository_name:octo-repo", + "workflow_id:1589141559", + "workflow_name:Manually triggered workflow", + "run_attempt:1", + "event:workflow_dispatch", + "sender:Codertocat", + "sender_type:User", + "branch:main", + "default_branch:true", + "job_name:build", + "runs_on:bar,foo,self-hosted", + "step_name:Install Gems", + "step_number:6", + "conclusion:success", + "status:completed", + ], + "type": "count", + }, + { + "host": "github.com", + "metric": "github.actions.step.conclusion.success_total", + "points": [ + [ + 1579542173, + 1, + ], + ], + "tags": [ + "repository_owner:octo-org", + "repository_name:octo-repo", + "workflow_id:1589141559", + "workflow_name:Manually triggered workflow", + "run_attempt:1", + "event:workflow_dispatch", + "sender:Codertocat", + "sender_type:User", + "branch:main", + "default_branch:true", + "job_name:build", + "runs_on:bar,foo,self-hosted", + "step_name:Install Gems", + "step_number:6", + "conclusion:success", + "status:completed", + ], + "type": "count", + }, + { + "host": "github.com", + "metric": "github.actions.step.duration_second", + "points": [ + [ + 1579542173, + 1, + ], + ], + "tags": [ + "repository_owner:octo-org", + "repository_name:octo-repo", + "workflow_id:1589141559", + "workflow_name:Manually triggered workflow", + "run_attempt:1", + "event:workflow_dispatch", + "sender:Codertocat", + "sender_type:User", + "branch:main", + "default_branch:true", + "job_name:build", + "runs_on:bar,foo,self-hosted", + "step_name:Install Gems", + "step_number:6", + "conclusion:success", + "status:completed", + ], + "type": "gauge", + }, + { + "host": "github.com", + "metric": "github.actions.step.start_time_from_workflow_start_second", + "points": [ + [ + 1579542173, + -60141270, + ], + ], + "tags": [ + "repository_owner:octo-org", + "repository_name:octo-repo", + "workflow_id:1589141559", + "workflow_name:Manually triggered workflow", + "run_attempt:1", + "event:workflow_dispatch", + "sender:Codertocat", + "sender_type:User", + "branch:main", + "default_branch:true", + "job_name:build", + "runs_on:bar,foo,self-hosted", + "step_name:Install Gems", + "step_number:6", + "conclusion:success", + "status:completed", + ], + }, + { + "host": "github.com", + "metric": "github.actions.step.total", + "points": [ + [ + 1579542179, + 1, + ], + ], + "tags": [ + "repository_owner:octo-org", + "repository_name:octo-repo", + "workflow_id:1589141559", + "workflow_name:Manually triggered workflow", + "run_attempt:1", + "event:workflow_dispatch", + "sender:Codertocat", + "sender_type:User", + "branch:main", + "default_branch:true", + "job_name:build", + "runs_on:bar,foo,self-hosted", + "step_name:Run Tests", + "step_number:7", + "conclusion:success", + "status:completed", + ], + "type": "count", + }, + { + "host": "github.com", + "metric": "github.actions.step.conclusion.success_total", + "points": [ + [ + 1579542179, + 1, + ], + ], + "tags": [ + "repository_owner:octo-org", + "repository_name:octo-repo", + "workflow_id:1589141559", + "workflow_name:Manually triggered workflow", + "run_attempt:1", + "event:workflow_dispatch", + "sender:Codertocat", + "sender_type:User", + "branch:main", + "default_branch:true", + "job_name:build", + "runs_on:bar,foo,self-hosted", + "step_name:Run Tests", + "step_number:7", + "conclusion:success", + "status:completed", + ], + "type": "count", + }, + { + "host": "github.com", + "metric": "github.actions.step.duration_second", + "points": [ + [ + 1579542179, + 6, + ], + ], + "tags": [ + "repository_owner:octo-org", + "repository_name:octo-repo", + "workflow_id:1589141559", + "workflow_name:Manually triggered workflow", + "run_attempt:1", + "event:workflow_dispatch", + "sender:Codertocat", + "sender_type:User", + "branch:main", + "default_branch:true", + "job_name:build", + "runs_on:bar,foo,self-hosted", + "step_name:Run Tests", + "step_number:7", + "conclusion:success", + "status:completed", + ], + "type": "gauge", + }, + { + "host": "github.com", + "metric": "github.actions.step.start_time_from_workflow_start_second", + "points": [ + [ + 1579542179, + -60141269, + ], + ], + "tags": [ + "repository_owner:octo-org", + "repository_name:octo-repo", + "workflow_id:1589141559", + "workflow_name:Manually triggered workflow", + "run_attempt:1", + "event:workflow_dispatch", + "sender:Codertocat", + "sender_type:User", + "branch:main", + "default_branch:true", + "job_name:build", + "runs_on:bar,foo,self-hosted", + "step_name:Run Tests", + "step_number:7", + "conclusion:success", + "status:completed", + ], + }, + { + "host": "github.com", + "metric": "github.actions.step.total", + "points": [ + [ + 1579542279, + 1, + ], + ], + "tags": [ + "repository_owner:octo-org", + "repository_name:octo-repo", + "workflow_id:1589141559", + "workflow_name:Manually triggered workflow", + "run_attempt:1", + "event:workflow_dispatch", + "sender:Codertocat", + "sender_type:User", + "branch:main", + "default_branch:true", + "job_name:build", + "runs_on:bar,foo,self-hosted", + "step_name:Deploy to Heroku", + "step_number:8", + "conclusion:success", + "status:completed", + ], + "type": "count", + }, + { + "host": "github.com", + "metric": "github.actions.step.conclusion.success_total", + "points": [ + [ + 1579542279, + 1, + ], + ], + "tags": [ + "repository_owner:octo-org", + "repository_name:octo-repo", + "workflow_id:1589141559", + "workflow_name:Manually triggered workflow", + "run_attempt:1", + "event:workflow_dispatch", + "sender:Codertocat", + "sender_type:User", + "branch:main", + "default_branch:true", + "job_name:build", + "runs_on:bar,foo,self-hosted", + "step_name:Deploy to Heroku", + "step_number:8", + "conclusion:success", + "status:completed", + ], + "type": "count", + }, + { + "host": "github.com", + "metric": "github.actions.step.duration_second", + "points": [ + [ + 1579542279, + 100, + ], + ], + "tags": [ + "repository_owner:octo-org", + "repository_name:octo-repo", + "workflow_id:1589141559", + "workflow_name:Manually triggered workflow", + "run_attempt:1", + "event:workflow_dispatch", + "sender:Codertocat", + "sender_type:User", + "branch:main", + "default_branch:true", + "job_name:build", + "runs_on:bar,foo,self-hosted", + "step_name:Deploy to Heroku", + "step_number:8", + "conclusion:success", + "status:completed", + ], + "type": "gauge", + }, + { + "host": "github.com", + "metric": "github.actions.step.start_time_from_workflow_start_second", + "points": [ + [ + 1579542279, + -60141263, + ], + ], + "tags": [ + "repository_owner:octo-org", + "repository_name:octo-repo", + "workflow_id:1589141559", + "workflow_name:Manually triggered workflow", + "run_attempt:1", + "event:workflow_dispatch", + "sender:Codertocat", + "sender_type:User", + "branch:main", + "default_branch:true", + "job_name:build", + "runs_on:bar,foo,self-hosted", + "step_name:Deploy to Heroku", + "step_number:8", + "conclusion:success", + "status:completed", + ], + }, + { + "host": "github.com", + "metric": "github.actions.step.total", + "points": [ + [ + 1579542279, + 1, + ], + ], + "tags": [ + "repository_owner:octo-org", + "repository_name:octo-repo", + "workflow_id:1589141559", + "workflow_name:Manually triggered workflow", + "run_attempt:1", + "event:workflow_dispatch", + "sender:Codertocat", + "sender_type:User", + "branch:main", + "default_branch:true", + "job_name:build", + "runs_on:bar,foo,self-hosted", + "step_name:Post actions/cache@v3", + "step_number:16", + "conclusion:success", + "status:completed", + ], + "type": "count", + }, + { + "host": "github.com", + "metric": "github.actions.step.conclusion.success_total", + "points": [ + [ + 1579542279, + 1, + ], + ], + "tags": [ + "repository_owner:octo-org", + "repository_name:octo-repo", + "workflow_id:1589141559", + "workflow_name:Manually triggered workflow", + "run_attempt:1", + "event:workflow_dispatch", + "sender:Codertocat", + "sender_type:User", + "branch:main", + "default_branch:true", + "job_name:build", + "runs_on:bar,foo,self-hosted", + "step_name:Post actions/cache@v3", + "step_number:16", + "conclusion:success", + "status:completed", + ], + "type": "count", + }, + { + "host": "github.com", + "metric": "github.actions.step.duration_second", + "points": [ + [ + 1579542279, + 0, + ], + ], + "tags": [ + "repository_owner:octo-org", + "repository_name:octo-repo", + "workflow_id:1589141559", + "workflow_name:Manually triggered workflow", + "run_attempt:1", + "event:workflow_dispatch", + "sender:Codertocat", + "sender_type:User", + "branch:main", + "default_branch:true", + "job_name:build", + "runs_on:bar,foo,self-hosted", + "step_name:Post actions/cache@v3", + "step_number:16", + "conclusion:success", + "status:completed", + ], + "type": "gauge", + }, + { + "host": "github.com", + "metric": "github.actions.step.start_time_from_workflow_start_second", + "points": [ + [ + 1579542279, + -60141163, + ], + ], + "tags": [ + "repository_owner:octo-org", + "repository_name:octo-repo", + "workflow_id:1589141559", + "workflow_name:Manually triggered workflow", + "run_attempt:1", + "event:workflow_dispatch", + "sender:Codertocat", + "sender_type:User", + "branch:main", + "default_branch:true", + "job_name:build", + "runs_on:bar,foo,self-hosted", + "step_name:Post actions/cache@v3", + "step_number:16", + "conclusion:success", + "status:completed", + ], + }, + { + "host": "github.com", + "metric": "github.actions.step.total", + "points": [ + [ + 1579542279, + 1, + ], + ], + "tags": [ + "repository_owner:octo-org", + "repository_name:octo-repo", + "workflow_id:1589141559", + "workflow_name:Manually triggered workflow", + "run_attempt:1", + "event:workflow_dispatch", + "sender:Codertocat", + "sender_type:User", + "branch:main", + "default_branch:true", + "job_name:build", + "runs_on:bar,foo,self-hosted", + "step_name:Complete job", + "step_number:17", + "conclusion:success", + "status:completed", + ], + "type": "count", + }, + { + "host": "github.com", + "metric": "github.actions.step.conclusion.success_total", + "points": [ + [ + 1579542279, + 1, + ], + ], + "tags": [ + "repository_owner:octo-org", + "repository_name:octo-repo", + "workflow_id:1589141559", + "workflow_name:Manually triggered workflow", + "run_attempt:1", + "event:workflow_dispatch", + "sender:Codertocat", + "sender_type:User", + "branch:main", + "default_branch:true", + "job_name:build", + "runs_on:bar,foo,self-hosted", + "step_name:Complete job", + "step_number:17", + "conclusion:success", + "status:completed", + ], + "type": "count", + }, + { + "host": "github.com", + "metric": "github.actions.step.duration_second", + "points": [ + [ + 1579542279, + 0, + ], + ], + "tags": [ + "repository_owner:octo-org", + "repository_name:octo-repo", + "workflow_id:1589141559", + "workflow_name:Manually triggered workflow", + "run_attempt:1", + "event:workflow_dispatch", + "sender:Codertocat", + "sender_type:User", + "branch:main", + "default_branch:true", + "job_name:build", + "runs_on:bar,foo,self-hosted", + "step_name:Complete job", + "step_number:17", + "conclusion:success", + "status:completed", + ], + "type": "gauge", + }, + { + "host": "github.com", + "metric": "github.actions.step.start_time_from_workflow_start_second", + "points": [ + [ + 1579542279, + -60141163, + ], + ], + "tags": [ + "repository_owner:octo-org", + "repository_name:octo-repo", + "workflow_id:1589141559", + "workflow_name:Manually triggered workflow", + "run_attempt:1", + "event:workflow_dispatch", + "sender:Codertocat", + "sender_type:User", + "branch:main", + "default_branch:true", + "job_name:build", + "runs_on:bar,foo,self-hosted", + "step_name:Complete job", + "step_number:17", + "conclusion:success", + "status:completed", + ], + }, + ], + }, + }, + ], + [ + { + "body": { + "series": [ + { + "host": "github.com", + "metric": "github.actions.api_rate_limit.remaining", + "points": [ + [ + 1445412480, + 3999, + ], + ], + "tags": [ + "repository_owner:Codertocat", + "repository_name:Hello-World", + "resource:core", + ], + "type": "gauge", + }, + { + "host": "github.com", + "metric": "github.actions.api_rate_limit.limit", + "points": [ + [ + 1445412480, + 5000, + ], + ], + "tags": [ + "repository_owner:Codertocat", + "repository_name:Hello-World", + "resource:core", + ], + "type": "gauge", + }, + { + "host": "github.com", + "metric": "github.actions.api_rate_limit.remaining", + "points": [ + [ + 1445412480, + 999, + ], + ], + "tags": [ + "repository_owner:Codertocat", + "repository_name:Hello-World", + "resource:search", + ], + "type": "gauge", + }, + { + "host": "github.com", + "metric": "github.actions.api_rate_limit.limit", + "points": [ + [ + 1445412480, + 6000, + ], + ], + "tags": [ + "repository_owner:Codertocat", + "repository_name:Hello-World", + "resource:search", + ], + "type": "gauge", + }, + { + "host": "github.com", + "metric": "github.actions.api_rate_limit.remaining", + "points": [ + [ + 1445412480, + 4999, + ], + ], + "tags": [ + "repository_owner:Codertocat", + "repository_name:Hello-World", + "resource:graphql", + ], + "type": "gauge", + }, + { + "host": "github.com", + "metric": "github.actions.api_rate_limit.limit", + "points": [ + [ + 1445412480, + 7000, + ], + ], + "tags": [ + "repository_owner:Codertocat", + "repository_name:Hello-World", + "resource:graphql", + ], + "type": "gauge", + }, + ], + }, + }, + ], +] +`; diff --git a/tests/run.test.ts b/tests/run.test.ts index 88f6721d..40ced927 100644 --- a/tests/run.test.ts +++ b/tests/run.test.ts @@ -58,6 +58,42 @@ test('workflow_run with collectJobMetrics', async () => { preferDistributionJobMetrics: false, preferDistributionStepMetrics: false, sendPullRequestLabels: false, + tagsToExclude: [], + }, + ) + expect(getOctokit).toHaveBeenCalledWith('GITHUB_TOKEN') + expect(submitMetrics).toHaveBeenCalledTimes(4) + expect(submitMetrics.mock.calls).toMatchSnapshot() +}) + +test('workflow_run with collectJobMetrics with tags to exclude', async () => { + octokitMock.paginate.mockImplementation((f: unknown) => { + expect(f).toBe(octokitMock.rest.actions.listJobsForWorkflowRunAttempt) + return exampleWorkflowJobs + }) + octokitMock.graphql.mockResolvedValue(exampleCompletedCheckSuite) + octokitMock.rest.rateLimit.get.mockResolvedValue(exampleRateLimitResponse) + submitMetrics.mockResolvedValue({ status: 'ok' }) + + await run( + { + eventName: 'workflow_run', + payload: exampleWorkflowRunCompletedEvent, + repo: { owner: 'Codertocat', repo: 'Hello-World' }, + }, + { + githubToken: 'GITHUB_TOKEN', + githubTokenForRateLimitMetrics: 'GITHUB_TOKEN', + datadogApiKey: 'DATADOG_API_KEY', + datadogTags: [], + metricsPatterns: [], + collectJobMetrics: true, + collectStepMetrics: true, + preferDistributionWorkflowRunMetrics: false, + preferDistributionJobMetrics: false, + preferDistributionStepMetrics: false, + sendPullRequestLabels: false, + tagsToExclude: ['job_id'], }, ) expect(getOctokit).toHaveBeenCalledWith('GITHUB_TOKEN') @@ -87,6 +123,7 @@ test('workflow_run', async () => { preferDistributionJobMetrics: false, preferDistributionStepMetrics: false, sendPullRequestLabels: false, + tagsToExclude: [], }, ) expect(getOctokit).toHaveBeenCalledWith('GITHUB_TOKEN') @@ -116,6 +153,7 @@ test('pull_request_opened', async () => { preferDistributionJobMetrics: false, preferDistributionStepMetrics: false, sendPullRequestLabels: false, + tagsToExclude: [], }, ) expect(getOctokit).toHaveBeenCalledWith('GITHUB_TOKEN') @@ -146,6 +184,7 @@ test('pull_request_closed', async () => { preferDistributionJobMetrics: false, preferDistributionStepMetrics: false, sendPullRequestLabels: true, + tagsToExclude: [], }, ) expect(getOctokit).toHaveBeenCalledWith('GITHUB_TOKEN')