Skip to content

Commit 80c1467

Browse files
committed
collect success rate metric
1 parent 019d8e4 commit 80c1467

File tree

2 files changed

+45
-8
lines changed

2 files changed

+45
-8
lines changed

.github/actions/workflow-metrics/action.yml

Lines changed: 39 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,18 +24,25 @@ runs:
2424
# Build job name with matrix values
2525
job_name="${{ github.job }}"
2626
if [ ! -z "${{ matrix.java-version || '' }}" ]; then
27-
job_name="${job_name}(${{ matrix.java-version }})"
27+
job_name="${job_name}(${{ matrix.java-version }})"
2828
fi
2929
if [ ! -z "${{ matrix.os || '' }}" ]; then
30-
job_name="${job_name}(${{ matrix.os }})"
30+
job_name="${job_name}(${{ matrix.os }})"
31+
fi
32+
33+
# Determine success/failure (1 for success, 0 for failure)
34+
if [ "${{ job.status }}" == "success" ]; then
35+
success_value=1
36+
else
37+
success_value=0
3138
fi
3239
3340
aws cloudwatch put-metric-data \
3441
--namespace "GitHub/Workflows" \
3542
--metric-data '[{
36-
"MetricName": "Duration",
37-
"Value": '$duration',
38-
"Unit": "Seconds",
43+
"MetricName": "Success",
44+
"Value": '$success_value',
45+
"Unit": "Count",
3946
"Dimensions": [
4047
{
4148
"Name": "WorkflowName",
@@ -46,8 +53,33 @@ runs:
4653
"Value": "'$job_name'"
4754
},
4855
{
49-
"Name": "Repository",
56+
"Name": "Repository",
5057
"Value": "${{ github.repository }}"
5158
}
5259
]
53-
}]'
60+
}]'
61+
62+
# Send Duration metric only if workflow successful
63+
if [ "$success_value" -eq 1 ]; then
64+
aws cloudwatch put-metric-data \
65+
--namespace "GitHub/Workflows" \
66+
--metric-data '[{
67+
"MetricName": "Duration",
68+
"Value": '$duration',
69+
"Unit": "Seconds",
70+
"Dimensions": [
71+
{
72+
"Name": "WorkflowName",
73+
"Value": "${{ github.workflow }}"
74+
},
75+
{
76+
"Name": "JobName",
77+
"Value": "'$job_name'"
78+
},
79+
{
80+
"Name": "Repository",
81+
"Value": "${{ github.repository }}"
82+
}
83+
]
84+
}]'
85+
fi

.github/workflows/continuous-integration.yml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ jobs:
5252
run: |
5353
./gradlew -Ptest.java.version=${{ matrix.java-version }} jvmTest --stacktrace
5454
- name: Upload metrics
55+
if: always()
5556
uses: ./.github/actions/workflow-metrics
5657

5758
all-platforms:
@@ -88,7 +89,9 @@ jobs:
8889
with:
8990
name: test-reports-${{ matrix.os }}
9091
path: '**/build/reports'
91-
92+
- name: Upload metrics
93+
if: always()
94+
uses: ./.github/actions/workflow-metrics
9295
protocol-tests:
9396
runs-on: ubuntu-latest
9497
steps:
@@ -111,6 +114,7 @@ jobs:
111114
./gradlew publishToMavenLocal
112115
./gradlew testAllProtocols
113116
- name: Upload metrics
117+
if: always()
114118
uses: ./.github/actions/workflow-metrics
115119
downstream:
116120
runs-on: ubuntu-latest
@@ -169,4 +173,5 @@ jobs:
169173
./gradlew test jvmTest
170174
./gradlew testAllProtocols
171175
- name: Upload metrics
176+
if: always()
172177
uses: ./smithy-kotlin/.github/actions/workflow-metrics

0 commit comments

Comments
 (0)