prometheus: Initialize mgmt_checkapply_total metrics
It is recommended by Prometheus to initialize metrics: https://prometheus.io/docs/practices/instrumentation/#avoid-missing-metrics This commits initialize the mgmt_checkapply_total metric for each registered resource. Signed-off-by: Julien Pivotto <roidelapluie@inuits.eu>
This commit is contained in:
@@ -269,6 +269,10 @@ func (obj *Main) Run() error {
|
|||||||
if err := prom.Start(); err != nil {
|
if err := prom.Start(); err != nil {
|
||||||
return errwrap.Wrapf(err, "can't start initiate Prometheus instance")
|
return errwrap.Wrapf(err, "can't start initiate Prometheus instance")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if err := prom.InitKindMetrics(resources.RegisteredResourcesNames()); err != nil {
|
||||||
|
return errwrap.Wrapf(err, "can't initialize kind-specific prometheus metrics")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if !obj.NoPgp {
|
if !obj.NoPgp {
|
||||||
|
|||||||
@@ -149,6 +149,31 @@ func (obj *Prometheus) Stop() error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// InitKindMetrics initialized prometheus counters. For each kind of
|
||||||
|
// resource checkApply counters are initialized with all the possible value.
|
||||||
|
func (obj *Prometheus) InitKindMetrics(kinds []string) error {
|
||||||
|
if obj == nil {
|
||||||
|
return nil // happens when mgmt is launched without --prometheus
|
||||||
|
}
|
||||||
|
bools := []bool{true, false}
|
||||||
|
for _, kind := range kinds {
|
||||||
|
for _, apply := range bools {
|
||||||
|
for _, eventful := range bools {
|
||||||
|
for _, errorful := range bools {
|
||||||
|
labels := prometheus.Labels{
|
||||||
|
"kind": kind,
|
||||||
|
"apply": strconv.FormatBool(apply),
|
||||||
|
"eventful": strconv.FormatBool(eventful),
|
||||||
|
"errorful": strconv.FormatBool(errorful),
|
||||||
|
}
|
||||||
|
obj.checkApplyTotal.With(labels)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
// UpdateCheckApplyTotal refreshes the failing gauge by parsing the internal
|
// UpdateCheckApplyTotal refreshes the failing gauge by parsing the internal
|
||||||
// state map.
|
// state map.
|
||||||
func (obj *Prometheus) UpdateCheckApplyTotal(kind string, apply, eventful, errorful bool) error {
|
func (obj *Prometheus) UpdateCheckApplyTotal(kind string, apply, eventful, errorful bool) error {
|
||||||
|
|||||||
@@ -52,6 +52,15 @@ func RegisterResource(kind string, fn func() Res) {
|
|||||||
registeredResources[kind] = fn
|
registeredResources[kind] = fn
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// RegisteredResourcesNames returns the kind of the registered resources.
|
||||||
|
func RegisteredResourcesNames() []string {
|
||||||
|
kinds := []string{}
|
||||||
|
for k := range registeredResources {
|
||||||
|
kinds = append(kinds, k)
|
||||||
|
}
|
||||||
|
return kinds
|
||||||
|
}
|
||||||
|
|
||||||
// NewResource returns an empty resource object from a registered kind. It
|
// NewResource returns an empty resource object from a registered kind. It
|
||||||
// errors if the resource kind doesn't exist.
|
// errors if the resource kind doesn't exist.
|
||||||
func NewResource(kind string) (Res, error) {
|
func NewResource(kind string) (Res, error) {
|
||||||
|
|||||||
@@ -78,6 +78,18 @@ func TestIFF(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestRegisteredResourcesNames(t *testing.T) {
|
||||||
|
kinds := RegisteredResourcesNames()
|
||||||
|
for _, kind := range kinds {
|
||||||
|
if kind == "" {
|
||||||
|
t.Error("Empty kind found")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if len(kinds) == 0 {
|
||||||
|
t.Error("No registered resources")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func TestReadEvent(t *testing.T) {
|
func TestReadEvent(t *testing.T) {
|
||||||
//res := FileRes{}
|
//res := FileRes{}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user