Skip to content

BUILD-11298 Add CI metrics job-completed hook for WarpBuild runners#270

Draft
matemoln wants to merge 1 commit into
masterfrom
BUILD-11298-ci-metrics-hook
Draft

BUILD-11298 Add CI metrics job-completed hook for WarpBuild runners#270
matemoln wants to merge 1 commit into
masterfrom
BUILD-11298-ci-metrics-hook

Conversation

@matemoln
Copy link
Copy Markdown
Contributor

Summary

Publish job-completed.sh for WarpBuild CI metrics (BUILD-11298). The script is copied verbatim from github-runners-infra (infra/applications/github-runners/hooks/job-completed.sh).

This is not a GitHub Action — it lives under ci-metrics/ and is downloaded at job start by WarpBuild runner AMIs built in SonarSource/ci-ami-images#369.

Contents

  • ci-metrics/job-completed.sh — cgroup/network metrics hook (fail-open)
  • README section documenting usage, feature flag, and raw URL

Consumer pin

ci-ami-images downloads from:

https://raw.githubusercontent.com/SonarSource/ci-github-actions/BUILD-11298-ci-metrics-hook/ci-metrics/job-completed.sh

This branch is intentionally long-lived until the hook is promoted to a release tag; update the consumer URL when merging to master / cutting a tag.

Feature flag

Set CI_METRICS_ENABLED=true to collect metrics. Output: ${CI_METRICS_DIR}/job-metrics.json and a ## CI Metrics step summary table.

Out of scope

  • ACTIONS_RUNNER_HOOK_JOB_COMPLETED wiring (BUILD-11299)
  • Removing the duplicate copy in github-runners-infra (ARC still uses it)

Test plan

  • Raw URL returns 200 after merge to branch
  • Validated via ci-ami-images ci-metrics-test.yml on WarpBuild PoC runner

Publish runner-side job-completed.sh for download by ci-ami-images AMIs.
Branch BUILD-11298-ci-metrics-hook is pinned by the consumer until a tag is cut.
@matemoln matemoln requested a review from a team as a code owner May 22, 2026 11:04
Copilot AI review requested due to automatic review settings May 22, 2026 11:04
@matemoln matemoln deployed to sca-checking May 22, 2026 11:04 — with GitHub Actions Active
@sonarqubecloud
Copy link
Copy Markdown

Agentic Analysis: Early Results

Agentic Analysis and Context Augmentation are available on your project. Here are some issues that could have been prevented. Follow the links to learn how to put them into action.

15 issue(s) found across 1 file(s):

Rule File Line Message
shelldre:S7682 ci-metrics/job-completed.sh 30 Add an explicit return statement at the end of the function.
shelldre:S7682 ci-metrics/job-completed.sh 71 Add an explicit return statement at the end of the function.
shelldre:S7679 ci-metrics/job-completed.sh 71 Assign this positional parameter to a local variable.
shelldre:S7679 ci-metrics/job-completed.sh 71 Assign this positional parameter to a local variable.
shelldre:S7682 ci-metrics/job-completed.sh 74 Add an explicit return statement at the end of the function.
shelldre:S7682 ci-metrics/job-completed.sh 81 Add an explicit return statement at the end of the function.
shelldre:S7682 ci-metrics/job-completed.sh 87 Add an explicit return statement at the end of the function.
shelldre:S7682 ci-metrics/job-completed.sh 97 Add an explicit return statement at the end of the function.
shelldre:S7682 ci-metrics/job-completed.sh 109 Add an explicit return statement at the end of the function.
shelldre:S7682 ci-metrics/job-completed.sh 111 Add an explicit return statement at the end of the function.
shelldre:S7682 ci-metrics/job-completed.sh 116 Add an explicit return statement at the end of the function.
shelldre:S7682 ci-metrics/job-completed.sh 118 Add an explicit return statement at the end of the function.
shelldre:S7682 ci-metrics/job-completed.sh 190 Add an explicit return statement at the end of the function.
shelldre:S7679 ci-metrics/job-completed.sh 191 Assign this positional parameter to a local variable.
shelldre:S7679 ci-metrics/job-completed.sh 191 Assign this positional parameter to a local variable.

Analyzed by SonarQube Agentic Analysis in 3.1 s

@hashicorp-vault-sonar-prod
Copy link
Copy Markdown

hashicorp-vault-sonar-prod Bot commented May 22, 2026

BUILD-11298

@matemoln matemoln marked this pull request as draft May 22, 2026 11:06
@sonarqubecloud
Copy link
Copy Markdown

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds a runner-side “job completed” metrics hook script under ci-metrics/ intended to be downloaded and executed by WarpBuild runner images, and documents how consumers should enable and fetch it.

Changes:

  • Added ci-metrics/job-completed.sh to collect cgroup v2 + network totals, write job-metrics.json, and append a step-summary table (fail-open).
  • Documented the hook’s purpose, feature flag, and the pinned raw URL in README.md.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 4 comments.

File Description
README.md Documents the new ci-metrics/ hook, usage, feature flag, and consumer raw URL.
ci-metrics/job-completed.sh Introduces the job-completed hook script that collects and emits CI metrics + optional cache aggregation.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +4 to +5
# Reads cgroup v2 + /proc/net/dev as totals (no baseline; ephemeral runners), writes ${CI_METRICS_DIR}/job-metrics.json, and appends a
# metrics table to $GITHUB_STEP_SUMMARY.
Comment on lines +24 to +27
# Fail-open: any unexpected error returns rc=0.
# The script also has an explicit `exit 0` at the bottom, so the trap only fires on errors.
# No EXIT trap: it would suppress non-zero returns if the hook is sourced.
trap 'exit 0' ERR
Comment on lines +264 to +267
for iface in "${!net_rx[@]}"; do
json_by_interface+="${sep}\"${iface}\":{\"rx_bytes\":${net_rx[$iface]},\"tx_bytes\":${net_tx[$iface]}}"
sep=","
done
Comment on lines +1 to +6
#!/usr/bin/env bash
# CI metrics completion hook.
#
# Reads cgroup v2 + /proc/net/dev as totals (no baseline; ephemeral runners), writes ${CI_METRICS_DIR}/job-metrics.json, and appends a
# metrics table to $GITHUB_STEP_SUMMARY.
# Fail-open: any error → exit 0 without breaking the job.
@gitar-bot
Copy link
Copy Markdown

gitar-bot Bot commented May 22, 2026

CI failed: Pre-commit checks failed: shellcheck found an unused function in the new job-completed.sh script (SC2329), and markdownlint flagged 3 lines in README.md exceeding the 140-character limit.

Overview

Analyzed 1 CI log from the pre-commit job. The PR introduces a new CI metrics job-completed hook for WarpBuild runners, but the pre-commit validation detected code quality issues in both the new bash script and the updated documentation.

Failures

ShellCheck violation in job-completed.sh (confidence: high)

  • Type: test
  • Affected jobs: 77367353298 (pre-commit)
  • Related to change: yes
  • Root cause: The new file ci-metrics/job-completed.sh contains a shellcheck warning SC2329 indicating a function that is never invoked.
  • Suggested fix: Review the function definitions in job-completed.sh and either remove unused functions or invoke them appropriately in the script logic.

Markdown line length violations in README.md (confidence: high)

  • Type: test
  • Affected jobs: 77367353298 (pre-commit)
  • Related to change: yes
  • Root cause: Documentation added for the job-completed hook feature in README.md has 3 lines that exceed the configured 140-character limit: line 69 (233 chars), line 76 (216 chars), and line 80 (236 chars).
  • Suggested fix: Reformat the affected lines in README.md to stay within the 140-character limit by breaking long lines or rewording the documentation.

Summary

  • Change-related failures: 2 (shellcheck SC2329 unused function; markdownlint line length violations)
  • Infrastructure/flaky failures: None
  • Recommended action: Fix the shellcheck warning by reviewing function usage in job-completed.sh, and reformat the 3 offending lines in README.md to comply with the 140-character line length limit. Re-run pre-commit validation after fixes.
Code Review ✅ Approved

Publishes job-completed.sh hook for WarpBuild CI metrics collection, copied from github-runners-infra. Script enables fail-open cgroup/network metrics gathering when CI_METRICS_ENABLED=true, with no issues found.

Tip

Comment Gitar fix CI or enable auto-apply: gitar auto-apply:on

Options

Auto-apply is off → Gitar will not commit updates to this branch.
Display: compact → Showing less information.

Comment with these commands to change:

Auto-apply Compact
gitar auto-apply:on         
gitar display:verbose         

Was this helpful? React with 👍 / 👎 | Gitar

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants