package observability import ( "slices" "github.com/prometheus/client_golang/prometheus" "go.etcd.io/etcd/api/v3/etcdserverpb" ) const ( Corrupt = "CORRUPT" NoSpace = "NOSPACE" ) // ReportAlarmMetrics reports the status of the alarms for each member in the etcd cluster func ReportAlarmMetrics(alarms []*etcdserverpb.AlarmMember) { reportAlarm(EtcdAlarmStateCorrupt, alarms, Corrupt) reportAlarm(EtcdAlarmStateNospace, alarms, NoSpace) } // Checks if the slice contains any alarms of the target alarm type // Records the result on the corresponding metric func reportAlarm(metric *prometheus.GaugeVec, alarms []*etcdserverpb.AlarmMember, target string) { checkAlarmFunc := func(alarmMember *etcdserverpb.AlarmMember) bool { return alarmMember.Alarm.String() == target } if slices.ContainsFunc(alarms, checkAlarmFunc) { metric.WithLabelValues().Set(1) } else { metric.WithLabelValues().Set(0) } }