From 46260749c18bc566a522e727ac133060e57c74e3 Mon Sep 17 00:00:00 2001 From: Julien Pivotto Date: Sun, 26 Feb 2017 08:46:21 +0100 Subject: [PATCH] prometheus: Move the prometheus nil check inside the prometheus function That pattern will be reused in future metrics. Signed-off-by: Julien Pivotto --- pgraph/actions.go | 8 +++----- prometheus/prometheus.go | 3 +++ 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/pgraph/actions.go b/pgraph/actions.go index f2f9b3e9..cedfe3d1 100644 --- a/pgraph/actions.go +++ b/pgraph/actions.go @@ -224,11 +224,9 @@ func (g *Graph) Process(v *Vertex) error { // if this fails, don't UpdateTimestamp() checkOK, err = obj.CheckApply(!noop) - if obj.Prometheus() != nil { - if promErr := obj.Prometheus().UpdateCheckApplyTotal(obj.Kind(), !noop, !checkOK, err != nil); promErr != nil { - // TODO: how to error correctly - log.Printf("%s[%s]: Prometheus.UpdateCheckApplyTotal() errored: %v", v.Kind(), v.GetName(), err) - } + if promErr := obj.Prometheus().UpdateCheckApplyTotal(obj.Kind(), !noop, !checkOK, err != nil); promErr != nil { + // TODO: how to error correctly + log.Printf("%s[%s]: Prometheus.UpdateCheckApplyTotal() errored: %v", v.Kind(), v.GetName(), err) } // TODO: Can the `Poll` converged timeout tracking be a // more general method for all converged timeouts? this diff --git a/prometheus/prometheus.go b/prometheus/prometheus.go index 3a3cfbf5..d3c9c25a 100644 --- a/prometheus/prometheus.go +++ b/prometheus/prometheus.go @@ -80,6 +80,9 @@ func (obj *Prometheus) Stop() error { // UpdateCheckApplyTotal refreshes the failing gauge by parsing the internal // state map. 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)} metric := obj.checkApplyTotal.With(labels) metric.Inc()