Skip to content

Commit 7e79c24

Browse files
Revert instance related commits
instead let the proxy handle different types of stats This reverts commit 895a1a1. This reverts commit 6d417d0. This reverts commit b31d02d. This reverts commit f41d8e8.
1 parent 947a53d commit 7e79c24

File tree

1 file changed

+21
-31
lines changed

1 file changed

+21
-31
lines changed

.github/actions/pushLoggedMetrics/action.yml

Lines changed: 21 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -15,50 +15,40 @@ runs:
1515
# send some stats whilst we're at it
1616
echo Metrics file found.
1717
nl .sfpowerscripts/logs/metrics.log
18-
countmetrics=$(jq --slurp --raw-output '
18+
metrics=$(jq --slurp --raw-output '
1919
# just keep the last value
2020
reverse | unique_by(.metric, .tags) | reverse | .[] |
21-
select(.type == "count") |
21+
(
22+
if .type == "count" then "counter"
23+
# note the spelling
24+
elif .type == "guage" then "gauge"
25+
# statsd-timers are always in ms. prometheus has no such type, so just
26+
# use a gauge
27+
elif .type == "timers" then "gauge"
28+
# anything else, handle it when the time comes
29+
else "unknown" end
30+
) as $type |
2231
# assume counters with no value given are 1
2332
(
24-
if .value == null then 1
25-
else .value
33+
if .value == null and $type == "counter" then 1
34+
elif $type == "gauge" then .value
35+
else null
2636
end
2737
) as $value |
28-
# only allow alpha, _, and : in metrics name
29-
(.metric | gsub("[^a-z_]"; ":")) as $metric |
30-
# transform tags into prometheus
31-
(.tags // {} | to_entries | map(.key + "=\"" + (.value | tostring) + "\"") | join(",")) as $tags |
32-
# put it all together. one line with description, one line with metric.
33-
"# TYPE \($metric) counter\n\($metric){\($tags)} \($value)"
34-
' .sfpowerscripts/logs/metrics.log | awk '/^# TYPE / && a[$3]++ {next}; 1')
35-
gaugemetrics=$(jq --slurp --raw-output '
36-
# just keep the last value
37-
reverse | unique_by(.metric, .tags) | reverse | .[] |
38-
select(.type == "guage" or .type == "timers") |
39-
# only allow alpha, _, and : in metrics name
40-
(.metric | gsub("[^a-z_]"; ":")) as $metric |
38+
select($value != null) |
39+
# only allow alpha and _ in metrics name
40+
(.metric | gsub("[^a-z]"; "_")) as $metric |
4141
# transform tags into prometheus
42-
(.tags // {} | to_entries | map(.key + "=\"" + (.value | tostring) + "\"") | join(",")) as $tags |
42+
(.tags // {} | to_entries | map(.key + "=\"" + .value + "\"") | join(",")) as $tags |
4343
# put it all together. one line with description, one line with metric.
44-
"# TYPE \($metric) gauge\n\($metric){\($tags)} \(.value)"
44+
"# TYPE \($metric) \($type)\n\($metric){\($tags)} \($value)"
4545
' .sfpowerscripts/logs/metrics.log | awk '/^# TYPE / && a[$3]++ {next}; 1')
4646
echo "METRICSKEY len: ${#METRICSKEY}"
4747
keyfile=$(mktemp) || exit 1
4848
cat > "$keyfile" <<< "$METRICSKEY"
49-
# send count metrics. accumulate by specifying instance per run.
50-
sig=$(printf %s "$countmetrics" | openssl dgst -sha256 -sign "$keyfile" -out - | base64 -w0)
51-
jq --compact-output --null-input \
52-
--arg metrics "$countmetrics" \
53-
--arg runner sf-platform \
54-
--arg sig "$sig" \
55-
'{"runner":$runner,"metrics":$metrics,"signature":$sig}' |
56-
tee >(curl -D- -H 'Content-Type: application/json' --data-binary @- \
57-
"https://sf-github-metrics.ekstern.dev.nav.no/measures/job/sfplatform/instance/${{github.run_id}}")
58-
# send gauge metrics. no instance means metrics sent get overwritten.
59-
sig=$(printf %s "$gaugemetrics" | openssl dgst -sha256 -sign "$keyfile" -out - | base64 -w0)
49+
sig=$(printf %s "$metrics" | openssl dgst -sha256 -sign "$keyfile" -out - | base64 -w0)
6050
jq --compact-output --null-input \
61-
--arg metrics "$gaugemetrics" \
51+
--arg metrics "$metrics" \
6252
--arg runner sf-platform \
6353
--arg sig "$sig" \
6454
'{"runner":$runner,"metrics":$metrics,"signature":$sig}' |

0 commit comments

Comments
 (0)