Skip to content

Commit 264f91b

Browse files
committed
initial action/test for emitting metrics via kat
1 parent 5e545cd commit 264f91b

File tree

2 files changed

+100
-0
lines changed

2 files changed

+100
-0
lines changed
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
name: Emit Metrics
2+
description: Emit metrics from another workflow/action using the kat tool
3+
inputs:
4+
namespace:
5+
description: The CloudWatch namespace in which to emit metrics
6+
required: true
7+
dimensions:
8+
description: |-
9+
The dimensions to include with emitted metrics, as a collection of `name=value` pairs. Multiple dimensions are
10+
delimited by newlines (`\n`) and whitespace is trimmed from before/after each `name=value` pair. When passing
11+
multiple dimensions, make sure to use YAML's block literal syntax (`|` or `|-`).
12+
13+
For example:
14+
```
15+
dimensions: |
16+
Artifact=foo-artifact
17+
Platform=Kotlin/JVM
18+
Variant=External
19+
```
20+
required: true
21+
metrics:
22+
description: |-
23+
The metrics to emit into the given namespace and using the specified dimensions. Individual metrics are written in
24+
the form of `<name>:<value>[:<unit>]` where:
25+
* <name> is the metric name and may include spaces but not colons (`:`)
26+
* <value> is the numeric value of the metric
27+
* <unit> is the CloudWatch unit name (if omitted, `None` is assumed)
28+
29+
Multiple metrics are delimited by newlines (`\n`) and whitespace is trimmed from before/after each metric
30+
specification. When passing multiple metrics, make sure to use YAML's block literal syntax (`|` or `|-`).
31+
32+
For example:
33+
```
34+
metrics: |
35+
BuildTime:4.532:Seconds
36+
BuildSucceeded:1:Count
37+
```
38+
required: true
39+
40+
runs:
41+
using: composite
42+
steps:
43+
- name: Emit Metrics
44+
shell: bash
45+
run: |
46+
# Trim a string and echo the result
47+
trim() {
48+
# args:
49+
# $1 the string to trim
50+
51+
echo -n "$1" | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//'
52+
}
53+
54+
# Convert a newline-delimited string into a single-line string delimited by spaces with each element prefixed
55+
format() {
56+
# args:
57+
# $1 the prefix for each element
58+
# $2 the newline-delimited string
59+
60+
PROCESSED=""
61+
IFS=$'\n'; ARR=($2); unset IFS
62+
for ITEM in "${ARR[@]}"; do
63+
PROCESSED="$PROCESSED $1 $(trim "$INPUT")"
64+
done
65+
echo -n "$(trim "$PROCESSED")"
66+
}
67+
68+
NAMESPACE="--namespace "${{ inputs.namespace }}""
69+
DIMENSIONS="$(format "--dimension" "${{ inputs.dimensions }}")"
70+
METRICS="$(format "--metric" "${{ inputs.metrics }}")"
71+
CMD="kat $NAMESPACE $DIMENSIONS $METRICS"
72+
73+
echo "Executing command \"$CMD\""
74+
eval "$CMD"
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
name: Test the emit-metrics action
2+
on:
3+
workflow_dispatch:
4+
5+
jobs:
6+
emit-a-metric:
7+
runs-on: ubuntu-latest
8+
steps:
9+
- name: Set up kat tool
10+
uses: ./.github/actions/setup-kat
11+
- name: Configure AWS Credentials
12+
uses: aws-actions/configure-aws-credentials@v4
13+
with:
14+
role-to-assume: ${{ secrets.TEST_CI_AWS_ROLE_ARN }}
15+
aws-region: us-west-2
16+
- name: Emit some test metrics
17+
uses: ./.github/actions/emit-metrics
18+
with:
19+
namespace: Test Namespace (ignore me)
20+
dimensions: |
21+
Artifact=foo-artifact
22+
Platform=Kotlin/JVM
23+
Variant=External
24+
metrics: |
25+
BuildTime:4.532:Seconds
26+
BuildSucceeded:1:Count

0 commit comments

Comments
 (0)