|
| 1 | +name: bootstrap-alarms |
| 2 | + |
| 3 | +permissions: |
| 4 | + id-token: write |
| 5 | + contents: read |
| 6 | + |
| 7 | +on: |
| 8 | + schedule: |
| 9 | + - cron: '0 8 * * 1' # Every Monday at 08:00 UTC |
| 10 | + workflow_dispatch: |
| 11 | + |
| 12 | +env: |
| 13 | + AWS_REGION: ${{ secrets.AWS_REGION }} |
| 14 | + ALARM_NAMESPACE: GitHubActions |
| 15 | + |
| 16 | +jobs: |
| 17 | + bootstrap: |
| 18 | + runs-on: ubuntu-latest |
| 19 | + env: |
| 20 | + COMPOSITE_ALARM_NAME: GitHubActions-${{ github.repository_owner }}-${{ github.event.repository.name }}-integration-tests-aggregate |
| 21 | + |
| 22 | + steps: |
| 23 | + - name: Debug OIDC token |
| 24 | + run: | |
| 25 | + echo "GitHub ref: ${{ github.ref }}" |
| 26 | + echo "GitHub event name: ${{ github.event_name }}" |
| 27 | +
|
| 28 | + - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 |
| 29 | + |
| 30 | + - name: Configure AWS credentials (OIDC) |
| 31 | + uses: aws-actions/configure-aws-credentials@ec61189d14ec14c8efccab744f656cffd0e33f37 # v6.1.0 |
| 32 | + with: |
| 33 | + role-to-assume: ${{ secrets.AWS_OIDC_ROLE_ARN }} |
| 34 | + aws-region: ${{ secrets.AWS_REGION }} |
| 35 | + |
| 36 | + - name: Create individual metric alarms |
| 37 | + run: | |
| 38 | + set -euo pipefail |
| 39 | +
|
| 40 | + MATRIX_FILE=".github/test-matrix.json" |
| 41 | + ALARM_NAMES=() |
| 42 | +
|
| 43 | + # Iterate over every arch × distro_config permutation from the shared matrix |
| 44 | + for row in $(jq -c ' |
| 45 | + .arch[] as $a | |
| 46 | + .distro_config[] as $d | |
| 47 | + { arch: $a.label, distro: $d.distro, distro_version: $d.distro_version, runtime_version: $d.runtime_version } |
| 48 | + ' "$MATRIX_FILE"); do |
| 49 | +
|
| 50 | + arch=$(echo "$row" | jq -r '.arch') |
| 51 | + distro=$(echo "$row" | jq -r '.distro') |
| 52 | + distro_version=$(echo "$row" | jq -r '.distro_version') |
| 53 | + runtime_version=$(echo "$row" | jq -r '.runtime_version') |
| 54 | +
|
| 55 | + ALARM_NAME="GitHubActions-ruby-ric-${distro}-${distro_version}-ruby${runtime_version}-${arch}" |
| 56 | +
|
| 57 | + echo "Creating alarm: ${ALARM_NAME}" |
| 58 | +
|
| 59 | + # Alarms if no success metric is received within 3 days |
| 60 | + # Uses 1-day periods with 3 evaluation periods for faster state transitions |
| 61 | + aws cloudwatch put-metric-alarm \ |
| 62 | + --alarm-name "${ALARM_NAME}" \ |
| 63 | + --alarm-description "Integration test: ${distro} ${distro_version} / ruby ${runtime_version} (${arch})" \ |
| 64 | + --namespace "${ALARM_NAMESPACE}" \ |
| 65 | + --metric-name "TestResult" \ |
| 66 | + --dimensions "Name=Distro,Value=${distro}" "Name=DistroVersion,Value=${distro_version}" "Name=RuntimeVersion,Value=${runtime_version}" "Name=Arch,Value=${arch}" \ |
| 67 | + --statistic Sum \ |
| 68 | + --period 86400 \ |
| 69 | + --evaluation-periods 3 \ |
| 70 | + --datapoints-to-alarm 3 \ |
| 71 | + --threshold 1 \ |
| 72 | + --comparison-operator LessThanThreshold \ |
| 73 | + --treat-missing-data breaching |
| 74 | +
|
| 75 | + ALARM_NAMES+=("${ALARM_NAME}") |
| 76 | + done |
| 77 | +
|
| 78 | + # Save alarm names for the composite alarm step |
| 79 | + printf '%s\n' "${ALARM_NAMES[@]}" > /tmp/alarm_names.txt |
| 80 | +
|
| 81 | + - name: Create composite aggregate alarm |
| 82 | + run: | |
| 83 | + set -euo pipefail |
| 84 | +
|
| 85 | + mapfile -t ALARM_NAMES < /tmp/alarm_names.txt |
| 86 | +
|
| 87 | + # Build the composite alarm rule: triggers if ANY sub-alarm is in ALARM or INSUFFICIENT_DATA |
| 88 | + RULE="" |
| 89 | + for name in "${ALARM_NAMES[@]}"; do |
| 90 | + if [ -n "$RULE" ]; then |
| 91 | + RULE="${RULE} OR " |
| 92 | + fi |
| 93 | + RULE="${RULE}(ALARM(\"${name}\") OR INSUFFICIENT_DATA(\"${name}\"))" |
| 94 | + done |
| 95 | +
|
| 96 | + echo "Composite alarm rule:" |
| 97 | + echo "${RULE}" |
| 98 | +
|
| 99 | + aws cloudwatch put-composite-alarm \ |
| 100 | + --alarm-name "${COMPOSITE_ALARM_NAME}" \ |
| 101 | + --alarm-description "Aggregate alarm for all Ruby RIC integration test permutations" \ |
| 102 | + --alarm-rule "${RULE}" \ |
| 103 | + --actions-enabled \ |
| 104 | + --alarm-actions "${{ secrets.AWS_ALARM_TARGET_ARN }}" \ |
| 105 | + --insufficient-data-actions "${{ secrets.AWS_ALARM_TARGET_ARN }}" |
| 106 | +
|
| 107 | + echo "Composite alarm '${COMPOSITE_ALARM_NAME}' created successfully." |
0 commit comments