Skip to content

Commit

Permalink
Support to set name label for each github_workflow_status metrics
Browse files Browse the repository at this point in the history
  • Loading branch information
zealgt committed Jan 4, 2023
1 parent 685b516 commit 09e42fe
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 13 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ node_modules/

.DS_Store

config/config.yml
configs/config.yml

# Logs
logs
Expand Down
17 changes: 10 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ Docker image : https://hub.docker.com/repository/docker/zealgt/github-actions-pr
- Monitor API rate limit remaining
- Support both Personal access tokens (classic) and Fine-grained personal access tokens
- Require only necessary permissions
- Easy to setup!!

## Getting started

Expand Down Expand Up @@ -45,11 +46,14 @@ runner: # optional
org: organization_name
workflow: # optional
enabled: true
owner: owner_name # apply to all list (optional)
owner: owner_name # optional, apply to all list
list:
- owner: owner_name # override workflow.owner (optional)
- owner: owner_name # optional, override workflow.owner
name: custom_name # optional, name for github_workflow_status
repo: repo_name_1
- repo: repo_name_2
- repo: repo_name_3
- repo: repo_name_4
```
## Example metrics
Expand All @@ -67,9 +71,8 @@ github_runner_status{id="145",name="Runner 3",os="Linux"} 1

# HELP github_workflow_status Latest workflow status for each repository (0=unknown, 1=queued, 2=in_progress, 3=cancelled, 4=failure, 5=success)
# TYPE github_workflow_status gauge
github_workflow_status{repo_name="repo-1",workflow_name="Development"} 5
github_workflow_status{repo_name="repo-2",workflow_name="Development"} 2
github_workflow_status{repo_name="repo-3",workflow_name="Production"} 1
github_workflow_status{repo_name="repo-4",workflow_name="Production"} 5
github_workflow_status{repo_name="repo-5",workflow_name="Production"} 5
github_workflow_status{name="custom_name",repo_name="repo_name_1",workflow_name="Development"} 5
github_workflow_status{name="repo_name_2",repo_name="repo_name_2",workflow_name="Development"} 2
github_workflow_status{name="repo_name_3",repo_name="repo_name_3",workflow_name="Production"} 1
github_workflow_status{name="repo_name_4",repo_name="repo_name_4",workflow_name="Production"} 1
```
5 changes: 3 additions & 2 deletions configs/config.example.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@ runner: # optional
org: organization_name
workflow: # optional
enabled: true
owner: owner_name # apply to all list (optional)
owner: owner_name # optional, apply to all list
list:
- owner: owner_name # override workflow.owner (optional)
- owner: owner_name # optional, override workflow.owner
name: custom_name # optional, name for github_workflow_status
repo: repo_name_1
- repo: repo_name_2
11 changes: 8 additions & 3 deletions src/metrics/fetchWorkflows.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const mapStatus = {
const workflowGauge = new Gauge({
name: 'github_workflow_status',
help: 'Latest workflow status for each repository (0=unknown, 1=queued, 2=in_progress, 3=cancelled, 4=failure, 5=success)',
labelNames: ['repo_name', 'workflow_name'],
labelNames: ['name', 'repo_name', 'workflow_name'],
})

const getWorkflowStatus = (status, conclusion) => {
Expand All @@ -41,14 +41,19 @@ const fetchWorkflows = async () => {
.map((v, i) => {
if (v.status === 'fulfilled') return v.value?.data?.workflow_runs?.[0]
console.log(
`Error while fetch workflow for repository name ${repoList[i]} - ${v.reason.toString()}`
`Error while fetch workflow for repository name ${list[i].repo} - ${v.reason.toString()}`
)
})
.filter((v) => v)

workflowList.forEach(({ repository, name, status, conclusion }) => {
const { name: displayName } = list.find((v) => v.repo === repository.name) || {}
workflowGauge.set(
{ repo_name: repository.name, workflow_name: name },
{
name: displayName || repository.name,
repo_name: repository.name,
workflow_name: name,
},
getWorkflowStatus(status, conclusion)
)
})
Expand Down

0 comments on commit 09e42fe

Please sign in to comment.