Skip to content

Commit 3f27114

Browse files
committed
stop send duration metric if workflow failed
1 parent 252646b commit 3f27114

File tree

3 files changed

+35
-26
lines changed

3 files changed

+35
-26
lines changed

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

Lines changed: 31 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -15,19 +15,19 @@ runs:
1515
run: |
1616
# Check if WORKFLOW_START_TIME is set
1717
if [ -z "$WORKFLOW_START_TIME" ]; then
18-
echo "Warning: WORKFLOW_START_TIME not set, skipping metrics upload"
19-
exit 0
18+
echo "Warning: WORKFLOW_START_TIME not set, skipping metrics upload"
19+
exit 0
2020
fi
2121
2222
duration=$(($(date +%s) - $WORKFLOW_START_TIME))
2323
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 }})"
3131
fi
3232
3333
# Determine success/failure (1 for success, 0 for failure)
@@ -40,25 +40,6 @@ runs:
4040
aws cloudwatch put-metric-data \
4141
--namespace "GitHub/Workflows" \
4242
--metric-data '[{
43-
"MetricName": "Duration",
44-
"Value": '$duration',
45-
"Unit": "Seconds",
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-
},
61-
{
6243
"MetricName": "Success",
6344
"Value": '$success_value',
6445
"Unit": "Count",
@@ -72,9 +53,33 @@ runs:
7253
"Value": "'$job_name'"
7354
},
7455
{
75-
"Name": "Repository",
56+
"Name": "Repository",
7657
"Value": "${{ github.repository }}"
7758
}
7859
]
79-
}
80-
]'
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/codebuild-ci.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ jobs:
7373
aws codebuild stop-build --id $BUILD_ID
7474
fi
7575
- name: Upload metrics
76+
if: always()
7677
uses: ./.github/actions/workflow-metrics
7778

7879
service-check-batch-and-artifact-size-metrics:
@@ -164,6 +165,7 @@ jobs:
164165
exit 1
165166
}
166167
- name: Upload metrics
168+
if: always()
167169
uses: ./.github/actions/workflow-metrics
168170

169171
release-artifact-size-metrics:

.github/workflows/continuous-integration.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ jobs:
5151
ls -lsa
5252
./gradlew -Ptest.java.version=${{ matrix.java-version }} jvmTest --stacktrace
5353
- name: Upload metrics
54+
if: always()
5455
uses: ./aws-sdk-kotlin/.github/actions/workflow-metrics
5556
- name: Save Test Reports
5657
if: failure()
@@ -109,6 +110,7 @@ jobs:
109110
./gradlew test jvmTest
110111
./gradlew testAllProtocols
111112
- name: Upload metrics
113+
if: always()
112114
uses: ./aws-sdk-kotlin/.github/actions/workflow-metrics
113115
- name: Save Test Reports
114116
if: failure()

0 commit comments

Comments
 (0)