Skip to content

Commit 15169f8

Browse files
committed
collect CI metric
1 parent 6a7c47b commit 15169f8

File tree

3 files changed

+126
-1
lines changed

3 files changed

+126
-1
lines changed
Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
name: Workflow Metrics
2+
description: >
3+
Track and upload workflow metrics to CloudWatch
4+
5+
runs:
6+
using: composite
7+
steps:
8+
- name: Configure AWS Credentials
9+
uses: aws-actions/configure-aws-credentials@v4
10+
with:
11+
# will change this to AWS CI role before merging
12+
role-to-assume: arn:aws:iam::886436966712:role/Admin
13+
aws-region: us-west-2
14+
- name: Upload workflow metrics
15+
shell: bash
16+
run: |
17+
# Determine build job name with matrix values
18+
job_name="${{ github.job }}"
19+
if [ ! -z "${{ matrix.java-version || '' }}" ]; then
20+
job_name="${job_name}(${{ matrix.java-version }})"
21+
fi
22+
if [ ! -z "${{ matrix.os || '' }}" ]; then
23+
job_name="${job_name}(${{ matrix.os }})"
24+
fi
25+
26+
# Determine success/failure (1 for success, 0 for failure)
27+
if [ "${{ job.status }}" == "success" ]; then
28+
success_value=1
29+
else
30+
success_value=0
31+
fi
32+
33+
# Determine branch (PR target branch or current branch)
34+
if [ ! -z "${{ github.base_ref }}" ]; then
35+
branch_name="${{ github.base_ref }}"
36+
else
37+
branch_name="${{ github.ref_name }}"
38+
fi
39+
40+
aws cloudwatch put-metric-data \
41+
--namespace "GitHub/Workflows" \
42+
--metric-data '[{
43+
"MetricName": "Success",
44+
"Value": '$success_value',
45+
"Unit": "Count",
46+
"Dimensions": [
47+
{
48+
"Name": "WorkflowName",
49+
"Value": "${{ github.workflow }}"
50+
},
51+
{
52+
"Name": "JobName",
53+
"Value": "'$job_name'"
54+
},
55+
{
56+
"Name": "Repository",
57+
"Value": "${{ github.repository }}"
58+
},
59+
{
60+
"Name": "Branch",
61+
"Value": "'$branch_name'"
62+
}
63+
]
64+
}]'
65+
66+
if [ -z "$WORKFLOW_START_TIME" ]; then
67+
echo "Warning: WORKFLOW_START_TIME not set, skipping metrics upload"
68+
exit 0
69+
fi
70+
71+
duration=$(($(date +%s) - $WORKFLOW_START_TIME))
72+
73+
# Only track duration for successful workflows
74+
if [ "$success_value" -eq 1 ]; then
75+
aws cloudwatch put-metric-data \
76+
--namespace "GitHub/Workflows" \
77+
--metric-data '[{
78+
"MetricName": "Duration",
79+
"Value": '$duration',
80+
"Unit": "Seconds",
81+
"Dimensions": [
82+
{
83+
"Name": "WorkflowName",
84+
"Value": "${{ github.workflow }}"
85+
},
86+
{
87+
"Name": "JobName",
88+
"Value": "'$job_name'"
89+
},
90+
{
91+
"Name": "Repository",
92+
"Value": "${{ github.repository }}"
93+
},
94+
{
95+
"Name": "Branch",
96+
"Value": "'$branch_name'"
97+
}
98+
]
99+
}]'
100+
fi

.github/workflows/codebuild-ci.yml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,10 @@ jobs:
4343
if: github.event_name == 'pull_request' || github.event_name == 'workflow_dispatch'
4444
runs-on: ubuntu-latest
4545
steps:
46+
- name: Checkout sources
47+
uses: actions/checkout@v2
48+
- name: Set start time
49+
run: echo "WORKFLOW_START_TIME=$(date +%s)" >> $GITHUB_ENV
4650
- name: Verify PRs are not running malicious code
4751
if: ${{ (inputs.aws-sdk-kotlin-pr != '' || inputs.smithy-kotlin-pr != '') && inputs.check-pr == false }}
4852
run: |
@@ -68,11 +72,16 @@ jobs:
6872
echo "cancelling in-progress build: id=$BUILD_ID"
6973
aws codebuild stop-build --id $BUILD_ID
7074
fi
75+
- name: Upload metrics
76+
if: always()
77+
uses: ./.github/actions/workflow-metrics
7178

7279
service-check-batch-and-artifact-size-metrics:
7380
if: github.event_name == 'pull_request' || github.event_name == 'workflow_dispatch'
7481
runs-on: ubuntu-latest
7582
steps:
83+
- name: Set start time
84+
run: echo "WORKFLOW_START_TIME=$(date +%s)" >> $GITHUB_ENV
7685
- name: Verify PRs are not running malicious code
7786
if: ${{ (inputs.aws-sdk-kotlin-pr != '' || inputs.smithy-kotlin-pr != '') && inputs.check-pr == false }}
7887
run: |
@@ -155,6 +164,9 @@ jobs:
155164
echo If this is expected please add the 'acknowledge-artifact-size-increase' label to this pull request.
156165
exit 1
157166
}
167+
- name: Upload metrics
168+
if: always()
169+
uses: ./.github/actions/workflow-metrics
158170

159171
release-artifact-size-metrics:
160172
if: github.event_name == 'release'

.github/workflows/continuous-integration.yml

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@ on:
44
pull_request:
55
workflow_dispatch:
66

7-
permissions: { }
7+
permissions:
8+
id-token: write
9+
contents: read
810

911
# Allow one instance of this workflow per pull request, and cancel older runs when new changes are pushed
1012
concurrency:
@@ -29,6 +31,8 @@ jobs:
2931
- 17
3032
- 21
3133
steps:
34+
- name: Set start time
35+
run: echo "WORKFLOW_START_TIME=$(date +%s)" >> $GITHUB_ENV
3236
- name: Checkout sources
3337
uses: actions/checkout@v4
3438
with:
@@ -46,6 +50,9 @@ jobs:
4650
pwd
4751
ls -lsa
4852
./gradlew -Ptest.java.version=${{ matrix.java-version }} jvmTest --stacktrace
53+
- name: Upload metrics
54+
if: always()
55+
uses: ./aws-sdk-kotlin/.github/actions/workflow-metrics
4956
- name: Save Test Reports
5057
if: failure()
5158
uses: actions/upload-artifact@v4
@@ -60,6 +67,9 @@ jobs:
6067
matrix:
6168
os: [ ubuntu-latest, macos-latest, windows-latest ]
6269
steps:
70+
- name: Set start time
71+
shell: bash
72+
run: echo "WORKFLOW_START_TIME=$(date +%s)" >> $GITHUB_ENV
6373
- name: Checkout sources
6474
uses: actions/checkout@v4
6575
with:
@@ -99,6 +109,9 @@ jobs:
99109
./gradlew apiCheck
100110
./gradlew test jvmTest
101111
./gradlew testAllProtocols
112+
- name: Upload metrics
113+
if: always()
114+
uses: ./aws-sdk-kotlin/.github/actions/workflow-metrics
102115
- name: Save Test Reports
103116
if: failure()
104117
uses: actions/upload-artifact@v4

0 commit comments

Comments
 (0)