prometheus: Move the prometheus nil check inside the prometheus function
That pattern will be reused in future metrics. Signed-off-by: Julien Pivotto <roidelapluie@inuits.eu>
This commit is contained in:
@@ -224,11 +224,9 @@ func (g *Graph) Process(v *Vertex) error {
|
|||||||
// if this fails, don't UpdateTimestamp()
|
// if this fails, don't UpdateTimestamp()
|
||||||
checkOK, err = obj.CheckApply(!noop)
|
checkOK, err = obj.CheckApply(!noop)
|
||||||
|
|
||||||
if obj.Prometheus() != nil {
|
if promErr := obj.Prometheus().UpdateCheckApplyTotal(obj.Kind(), !noop, !checkOK, err != nil); promErr != nil {
|
||||||
if promErr := obj.Prometheus().UpdateCheckApplyTotal(obj.Kind(), !noop, !checkOK, err != nil); promErr != nil {
|
// TODO: how to error correctly
|
||||||
// TODO: how to error correctly
|
log.Printf("%s[%s]: Prometheus.UpdateCheckApplyTotal() errored: %v", v.Kind(), v.GetName(), err)
|
||||||
log.Printf("%s[%s]: Prometheus.UpdateCheckApplyTotal() errored: %v", v.Kind(), v.GetName(), err)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
// TODO: Can the `Poll` converged timeout tracking be a
|
// TODO: Can the `Poll` converged timeout tracking be a
|
||||||
// more general method for all converged timeouts? this
|
// more general method for all converged timeouts? this
|
||||||
|
|||||||
@@ -80,6 +80,9 @@ func (obj *Prometheus) Stop() error {
|
|||||||
// 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 {
|
||||||
|
if obj == nil {
|
||||||
|
return nil // happens when mgmt is launched without --prometheus
|
||||||
|
}
|
||||||
labels := prometheus.Labels{"kind": kind, "apply": strconv.FormatBool(apply), "eventful": strconv.FormatBool(eventful), "errorful": strconv.FormatBool(errorful)}
|
labels := prometheus.Labels{"kind": kind, "apply": strconv.FormatBool(apply), "eventful": strconv.FormatBool(eventful), "errorful": strconv.FormatBool(errorful)}
|
||||||
metric := obj.checkApplyTotal.With(labels)
|
metric := obj.checkApplyTotal.With(labels)
|
||||||
metric.Inc()
|
metric.Inc()
|
||||||
|
|||||||
Reference in New Issue
Block a user