Update gather-prom-metrics service selection

This change updates how the gather-prom-metrics playbook role
chooses which services and ports to scrape when gathering metrics
at the end of a zuul build.

We can hit more metric endpoints by finding services with a "metrics"
port, as not all applications have a service labeled "component=exporter"

Change-Id: Ib8db7ea2e7034063eefadad74828d0396407275b
This commit is contained in:
Steven Fitzpatrick 2020-03-20 15:05:04 -05:00
parent 4f30b1361e
commit 510f55a48b

View File

@ -20,9 +20,9 @@
set -e
NAMESPACES=$(kubectl get namespaces -o json | jq -r '.items[].metadata.name')
for NS in $NAMESPACES; do
SERVICES=$(kubectl get svc -l component=metrics -n $NS -o json | jq -r '.items[].metadata.name')
SERVICES=$(kubectl get svc -n $NS -o json | jq -r '.items[] | select(.spec.ports[].name=="metrics") | .metadata.name')
for SVC in $SERVICES; do
PORT=$(kubectl get svc $SVC -n $NS -o json | jq -r '.spec.ports[].port')
PORT=$(kubectl get svc $SVC -n $NS -o json | jq -r '.spec.ports[] | select(.name=="metrics") | .port')
curl "$SVC.$NS:$PORT/metrics" >> "{{ logs_dir }}"/prometheus/$NS-$SVC.txt || true
done
done