Skip to content

Commit

Permalink
Add github.actions.workflow_run.duration_second.distribution (#982)
Browse files Browse the repository at this point in the history
  • Loading branch information
int128 authored Jan 21, 2024
1 parent 66e68e5 commit 9c5bb0a
Show file tree
Hide file tree
Showing 4 changed files with 123 additions and 79 deletions.
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,10 @@ This action sends the following metrics.
- e.g. `github.actions.workflow_run.conclusion.success_total`
- e.g. `github.actions.workflow_run.conclusion.failure_total`
- See [the official document](https://docs.github.com/en/rest/reference/checks#create-a-check-run) for the possible values of `CONCLUSION` field
- `github.actions.workflow_run.duration_second`
- Time from a workflow is started until it is updated
- `github.actions.workflow_run.duration_second` (gauge)
- Time from a workflow run is started until it is updated
- `github.actions.workflow_run.duration_second.distribution` (distribution)
- Time from a workflow run is started until it is updated

It has the following tags:

Expand Down
3 changes: 2 additions & 1 deletion src/workflowRun/handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,8 @@ const handleWorkflowRunCompleted = async (

const metrics = computeWorkflowRunJobStepMetrics(e, checkSuite, workflowJobs?.data)

await metricsClient.submitMetrics(metrics.workflowRunMetrics, 'workflow run')
await metricsClient.submitMetrics(metrics.workflowRunMetrics.series, 'workflow run')
await metricsClient.submitDistributionPoints(metrics.workflowRunMetrics.distributionPointsSeries, 'workflow run')
if (inputs.collectJobMetrics) {
await metricsClient.submitMetrics(metrics.jobMetrics.series, 'job')
await metricsClient.submitDistributionPoints(metrics.jobMetrics.distributionPointsSeries, 'job')
Expand Down
23 changes: 18 additions & 5 deletions src/workflowRun/metrics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,10 @@ const getCommonDistibutionPointsTags = (e: WorkflowRunCompletedEvent): string[]
]

export type WorkflowRunJobStepMetrics = {
workflowRunMetrics: v1.Series[]
workflowRunMetrics: {
series: v1.Series[]
distributionPointsSeries: v1.DistributionPointsSeries[]
}
jobMetrics: {
series: v1.Series[]
distributionPointsSeries: v1.DistributionPointsSeries[]
Expand Down Expand Up @@ -62,10 +65,14 @@ export const computeWorkflowRunJobStepMetrics = (
}
}

export const computeWorkflowRunMetrics = (e: WorkflowRunCompletedEvent): v1.Series[] => {
export const computeWorkflowRunMetrics = (e: WorkflowRunCompletedEvent) => {
const series: v1.Series[] = []
const distributionPointsSeries: v1.DistributionPointsSeries[] = []
const tags = [...getCommonMetricsTags(e), `conclusion:${e.workflow_run.conclusion}`]
const distributionPointsTags = [...getCommonDistibutionPointsTags(e), `conclusion:${e.workflow_run.conclusion}`]
const updatedAt = unixTime(e.workflow_run.updated_at)
const series: v1.Series[] = [

series.push(
{
host: 'github.com',
tags,
Expand All @@ -80,7 +87,7 @@ export const computeWorkflowRunMetrics = (e: WorkflowRunCompletedEvent): v1.Seri
type: 'count',
points: [[updatedAt, 1]],
},
]
)

const runStartedAt = unixTime(e.workflow_run.run_started_at)
const duration = updatedAt - runStartedAt
Expand All @@ -91,7 +98,13 @@ export const computeWorkflowRunMetrics = (e: WorkflowRunCompletedEvent): v1.Seri
type: 'gauge',
points: [[updatedAt, duration]],
})
return series
distributionPointsSeries.push({
host: 'github.com',
tags: distributionPointsTags,
metric: 'github.actions.workflow_run.duration_second.distribution',
points: [[updatedAt, [duration]]],
})
return { series, distributionPointsSeries }
}

const joinRunsOn = (labels: string[]): string => labels.sort().join(',')
Expand Down
170 changes: 99 additions & 71 deletions tests/workflowRun/__snapshots__/metrics.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -1055,78 +1055,106 @@ exports[`computeStepMetrics 1`] = `
`;

exports[`computeWorkflowRunMetrics 1`] = `
[
{
"host": "github.com",
"metric": "github.actions.workflow_run.total",
"points": [
[
1639683442,
1,
{
"distributionPointsSeries": [
{
"host": "github.com",
"metric": "github.actions.workflow_run.duration_second.distribution",
"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": "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_name:Manually triggered workflow",
"run_attempt:1",
"event:workflow_dispatch",
"sender:Codertocat",
"sender_type:User",
"branch:main",
"default_branch:true",
"conclusion:null",
],
],
"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,
},
],
"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": "gauge",
},
]
"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",
},
],
}
`;

0 comments on commit 9c5bb0a

Please sign in to comment.