Skip to content

Commit 76b6034

Browse files
authored
feat: add new emit-metrics action (#65)
1 parent 86e1555 commit 76b6034

File tree

1 file changed

+77
-0
lines changed

1 file changed

+77
-0
lines changed
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
name: Emit Metrics
2+
description: Emit metrics 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: Verify kat exists
44+
shell: bash
45+
run: which kat || ( echo "Cannot find kat installation. Did you forget to run setup-kat first?" && exit 1 )
46+
- name: Emit Metrics
47+
shell: bash
48+
run: |
49+
# Trim a string and echo the result
50+
trim() {
51+
# args:
52+
# $1 the string to trim
53+
54+
echo -n "$1" | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//'
55+
}
56+
57+
# Convert a newline-delimited string into a single-line string delimited by spaces with each element prefixed
58+
format() {
59+
# args:
60+
# $1 the prefix for each element
61+
# $2 the newline-delimited string
62+
63+
PROCESSED=""
64+
IFS=$'\n'; ARR=($2); unset IFS
65+
for ITEM in "${ARR[@]}"; do
66+
PROCESSED="$PROCESSED $1 \"$(trim "$ITEM")\""
67+
done
68+
echo -n "$(trim "$PROCESSED")"
69+
}
70+
71+
NAMESPACE="--namespace \"${{ inputs.namespace }}\""
72+
DIMENSIONS="$(format "--dimension" "${{ inputs.dimensions }}")"
73+
METRICS="$(format "--metric" "${{ inputs.metrics }}")"
74+
CMD="kat metrics emit $NAMESPACE $DIMENSIONS $METRICS"
75+
76+
echo "Executing command \"$CMD\""
77+
eval "$CMD"

0 commit comments

Comments
 (0)