shell-operator icon indicating copy to clipboard operation
shell-operator copied to clipboard

Lost metrics/wrong labels when same metric name has different labels

Open redbaron opened this issue 1 year ago • 0 comments

Expected behavior (what you expected to happen):

Each metric producced by a hook should have exactly same labels as reported by the script

Actual behavior (what actually happened):

Looks like shell-operator expects all metrics with the same name has common set of labels. When it differs between metric instances, wrong labels are reported and some metrics can be completely omitted.

Steps to reproduce:

#!/usr/bin/env bash

if [[ ${1:-} == "--config" ]] ; then
  cat <<EOF
configVersion: v1
onStartup: 1
EOF
else
jq -nc '{group:"g",name: "m1", action:"set", value: 1, labels: {a: "A"}}' >>"$METRICS_PATH"
jq -nc '{group:"g",name: "m1", action:"set", value: 2, labels: {c: "C"}}' >>"$METRICS_PATH"
jq -nc '{group:"g",name: "m1", action:"set", value: 3, labels: {a: "A", b:"B"}}' >>"$METRICS_PATH"
jq -nc '{group:"g",name: "m2", action:"set", value: 1, labels: {a: "A1"}}' >>"$METRICS_PATH"
jq -nc '{group:"g",name: "m2", action:"set", value: 2, labels: {c: "C2"}}' >>"$METRICS_PATH"
jq -nc '{group:"g",name: "m2", action:"set", value: 3, labels: {a: "A3", b:"B3"}}' >>"$METRICS_PATH"
fi

produces:

# HELP m1 m1
# TYPE m1 gauge
m1{a="",hook="metrics.sh"} 2
m1{a="A",hook="metrics.sh"} 3
# HELP m2 m2
# TYPE m2 gauge
m2{a="",hook="metrics.sh"} 2
m2{a="A1",hook="metrics.sh"} 1
m2{a="A3",hook="metrics.sh"} 3

Environment:

  • Shell-operator version: v1.4.7

redbaron avatar May 27 '24 08:05 redbaron