Skip to content

Commit 4163eee

Browse files
06180618reesscot
authored
feat: add CloudWatch metric when publishLatest fails (#2311)
* feat: add cloudwatch metric when publishLatest failes * chore: name and comment change * refactor: create reusable workflow folder * refactor: use reusable workflow metric * Update .github/workflows/publish-latest.yml Co-authored-by: Scott Rees <[email protected]> * refactor: remove reusable folder * refactor: use log-metric compose action to replace reusable workflow Co-authored-by: 0618 <[email protected]> Co-authored-by: Scott Rees <[email protected]>
1 parent f21a12e commit 4163eee

File tree

4 files changed

+82
-32
lines changed

4 files changed

+82
-32
lines changed
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
name: 'Log Metric'
2+
description: 'Log data point to a metric with the provided value. If the metric is not there, it will create one.'
3+
inputs:
4+
metric-name:
5+
description: 'target metric name'
6+
required: true
7+
value:
8+
description: 'the value to log to the metric'
9+
required: true
10+
AWS_ACCESS_KEY_ID:
11+
description: 'target AWS account credentials'
12+
required: true
13+
AWS_SECRET_ACCESS_KEY:
14+
description: 'target AWS account credentials'
15+
required: true
16+
runs:
17+
using: 'composite'
18+
steps:
19+
- name: Configure AWS credentials
20+
uses: aws-actions/configure-aws-credentials@v1
21+
with:
22+
aws-access-key-id: ${{ inputs.AWS_ACCESS_KEY_ID }}
23+
aws-secret-access-key: ${{ inputs.AWS_SECRET_ACCESS_KEY }}
24+
aws-region: us-east-1
25+
- shell: bash
26+
run: aws cloudwatch put-metric-data --metric-name ${{ inputs.metric-name }} --namespace GithubCanaryApps --value ${{ inputs.value }}

.github/workflows/publish-latest.yml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,3 +87,31 @@ jobs:
8787
env:
8888
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
8989
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
90+
91+
log-failure-metric:
92+
# Send data point 1 to metric PublishNPMFailure, if it's a failure
93+
runs-on: ubuntu-latest
94+
environment: ci
95+
if: ${{ failure() }}
96+
steps:
97+
- name: Log failure data point to metric PublishNPMFailure
98+
uses: ./.github/actions/log-metric
99+
with:
100+
metric-name: PublishNPMFailure
101+
value: 1
102+
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
103+
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
104+
105+
log-success-metric:
106+
# Send data point 0 to metric PublishNPMFailure, if it's a success
107+
runs-on: ubuntu-latest
108+
environment: ci
109+
if: ${{ success() }}
110+
steps:
111+
- name: Log success data point to metric PublishNPMFailure
112+
uses: ./.github/actions/log-metric
113+
with:
114+
metric-name: PublishNPMFailure
115+
value: 0
116+
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
117+
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}

.github/workflows/run-and-test-builds.yml

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -97,31 +97,29 @@ jobs:
9797
VALID_PASSWORD: ${{ secrets.VALID_PASSWORD }}
9898

9999
log-failure-metric:
100-
# Send data point 1 to metric RunTimeTestsFailure, if failure
100+
# Send data point 1 to metricRunTimeTestsFailure, if it's a failure
101101
runs-on: ubuntu-latest
102102
environment: ci
103-
needs: build
104103
if: ${{ failure() }}
105104
steps:
106-
- name: Configure AWS credentials
107-
uses: aws-actions/configure-aws-credentials@v1
105+
- name: Log failure data point to metric RunTimeTestsFailure
106+
uses: ./.github/actions/log-metric
108107
with:
109-
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
110-
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
111-
aws-region: us-east-1
112-
- run: aws cloudwatch put-metric-data --metric-name RunTimeTestsFailure --namespace GithubCanaryApps --value 1
108+
metric-name: RunTimeTestsFailure
109+
value: 1
110+
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
111+
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
113112

114113
log-success-metric:
115-
# Send data point 0 to metric RunTimeTestsFailure, if success
114+
# Send data point 0 to metric RunTimeTestsFailure, if it's a success
116115
runs-on: ubuntu-latest
117116
environment: ci
118-
needs: build
119117
if: ${{ success() }}
120118
steps:
121-
- name: Configure AWS credentials
122-
uses: aws-actions/configure-aws-credentials@v1
119+
- name: Log success data point to metric RunTimeTestsFailure
120+
uses: ./.github/actions/log-metric
123121
with:
124-
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
125-
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
126-
aws-region: us-east-1
127-
- run: aws cloudwatch put-metric-data --metric-name RunTimeTestsFailure --namespace GithubCanaryApps --value 0
122+
metric-name: RunTimeTestsFailure
123+
value: 0
124+
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
125+
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}

.github/workflows/test-deploy-main.yml

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -169,31 +169,29 @@ jobs:
169169
working-directory: ./canary
170170

171171
log-failure-metric:
172-
# Send data point 1 to metric RunTimeTestsFailure, if success
172+
# Send data point 1 to metric PublishNextFailure, if it's a failure
173173
runs-on: ubuntu-latest
174174
environment: ci
175-
needs: build-test
176175
if: ${{ failure() }}
177176
steps:
178-
- name: Configure AWS credentials
179-
uses: aws-actions/configure-aws-credentials@v1
177+
- name: Log failure data point to metric PublishNextFailure
178+
uses: ./.github/actions/log-metric
180179
with:
181-
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
182-
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
183-
aws-region: us-east-1
184-
- run: aws cloudwatch put-metric-data --metric-name publishFailure --namespace GithubCanaryApps --value 1
180+
metric-name: PublishNextFailure
181+
value: 1
182+
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
183+
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
185184

186185
log-success-metric:
187-
# Send data point 0 to metric RunTimeTestsFailure, if success
186+
# Send data point 0 to metric PublishNextFailure, if it's a success
188187
runs-on: ubuntu-latest
189188
environment: ci
190-
needs: build-test
191189
if: ${{ success() }}
192190
steps:
193-
- name: Configure AWS credentials
194-
uses: aws-actions/configure-aws-credentials@v1
191+
- name: Log success data point to metric PublishNextFailure
192+
uses: ./.github/actions/log-metric
195193
with:
196-
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
197-
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
198-
aws-region: us-east-1
199-
- run: aws cloudwatch put-metric-data --metric-name publishFailure --namespace GithubCanaryApps --value 0
194+
metric-name: PublishNextFailure
195+
value: 0
196+
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
197+
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}

0 commit comments

Comments
 (0)