Skip to content

Commit e3fba54

Browse files
committed
collect CI metrics
1 parent f557442 commit e3fba54

File tree

2 files changed

+77
-2
lines changed

2 files changed

+77
-2
lines changed
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
name: Workflow Metrics
2+
description: >
3+
Track and upload workflow execution time 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+
role-to-assume: arn:aws:iam::886436966712:role/Admin
12+
aws-region: us-west-2
13+
- name: Upload workflow metrics
14+
shell: bash
15+
run: |
16+
# Check if WORKFLOW_START_TIME is set
17+
if [ -z "$WORKFLOW_START_TIME" ]; then
18+
echo "Warning: WORKFLOW_START_TIME not set, skipping metrics upload"
19+
exit 0
20+
fi
21+
22+
duration=$(($(date +%s) - $WORKFLOW_START_TIME))
23+
24+
# Build job name with matrix values
25+
job_name="${{ github.job }}"
26+
if [ ! -z "${{ matrix.java-version || '' }}" ]; then
27+
job_name="${job_name} (${{ matrix.java-version }})"
28+
fi
29+
if [ ! -z "${{ matrix.os || '' }}" ]; then
30+
job_name="${job_name} (${{ matrix.os }})"
31+
fi
32+
33+
aws cloudwatch put-metric-data \
34+
--namespace "GitHub/Workflows" \
35+
--metric-data '[{
36+
"MetricName": "Duration",
37+
"Value": '$duration',
38+
"Unit": "Seconds",
39+
"Dimensions": [
40+
{
41+
"Name": "WorkflowName",
42+
"Value": "${{ github.workflow }}"
43+
},
44+
{
45+
"Name": "JobName",
46+
"Value": "'$job_name'"
47+
},
48+
{
49+
"Name": "Repository",
50+
"Value": "${{ github.repository }}"
51+
}
52+
]
53+
}]'

.github/workflows/continuous-integration.yml

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@ on:
88
pull_request:
99
workflow_dispatch:
1010

11+
permissions:
12+
id-token: write
13+
contents: read
14+
1115
# Allow one instance of this workflow per pull request, and cancel older runs when new changes are pushed
1216
concurrency:
1317
group: ci-pr-${{ github.ref }}
@@ -31,6 +35,8 @@ jobs:
3135
- 17
3236
- 21
3337
steps:
38+
- name: Set start time
39+
run: echo "WORKFLOW_START_TIME=$(date +%s)" >> $GITHUB_ENV
3440
- name: Checkout sources
3541
uses: actions/checkout@v4
3642
- name: Configure JDK
@@ -45,6 +51,8 @@ jobs:
4551
shell: bash
4652
run: |
4753
./gradlew -Ptest.java.version=${{ matrix.java-version }} jvmTest --stacktrace
54+
- name: Upload metrics
55+
uses: ./aws-sdk-kotlin/.github/actions/workflow-metrics
4856

4957
all-platforms:
5058
runs-on: ${{ matrix.os }}
@@ -53,6 +61,9 @@ jobs:
5361
matrix:
5462
os: [ ubuntu-latest, macos-latest, windows-latest ]
5563
steps:
64+
- name: Set start time
65+
shell: bash
66+
run: echo "WORKFLOW_START_TIME=$(date +%s)" >> $GITHUB_ENV
5667
- name: Checkout sources
5768
uses: actions/checkout@v4
5869
- name: Configure JDK
@@ -69,6 +80,8 @@ jobs:
6980
echo "kotlinWarningsAsErrors=true" >> $GITHUB_WORKSPACE/local.properties
7081
./gradlew apiCheck
7182
./gradlew test jvmTest
83+
- name: Upload metrics
84+
uses: ./aws-sdk-kotlin/.github/actions/workflow-metrics
7285
- name: Save Test Reports
7386
if: failure()
7487
uses: actions/upload-artifact@v4
@@ -79,6 +92,9 @@ jobs:
7992
protocol-tests:
8093
runs-on: ubuntu-latest
8194
steps:
95+
- name: Set start time
96+
shell: bash
97+
run: echo "WORKFLOW_START_TIME=$(date +%s)" >> $GITHUB_ENV
8298
- name: Checkout sources
8399
uses: actions/checkout@v4
84100
- name: Configure JDK
@@ -94,10 +110,14 @@ jobs:
94110
run: |
95111
./gradlew publishToMavenLocal
96112
./gradlew testAllProtocols
97-
113+
- name: Upload metrics
114+
uses: ./aws-sdk-kotlin/.github/actions/workflow-metrics
98115
downstream:
99116
runs-on: ubuntu-latest
100117
steps:
118+
- name: Set start time
119+
shell: bash
120+
run: echo "WORKFLOW_START_TIME=$(date +%s)" >> $GITHUB_ENV
101121
- name: Checkout sources
102122
uses: actions/checkout@v4
103123
with:
@@ -147,4 +167,6 @@ jobs:
147167
sed -i "s/smithy-kotlin-codegen-version = .*$/smithy-kotlin-codegen-version = \"$SMITHY_KOTLIN_CODEGEN_VERSION\"/" gradle/libs.versions.toml
148168
./gradlew --parallel publishToMavenLocal
149169
./gradlew test jvmTest
150-
./gradlew testAllProtocols
170+
./gradlew testAllProtocols
171+
- name: Upload metrics
172+
uses: ./aws-sdk-kotlin/.github/actions/workflow-metrics

0 commit comments

Comments
 (0)