Commit 1ff7b034 authored by Geoff Simmons's avatar Geoff Simmons

Use a counter vector for the watcher event counters.

parent 831b25c2
......@@ -211,42 +211,40 @@ func (ingc *IngressController) logObj(action string, obj interface{}) {
}
}
func incWatchCounter(obj interface{}, syncType SyncType) {
func incWatchCounter(obj interface{}, sync string) {
switch obj.(type) {
case *extensions.Ingress:
watchCounters["Ingress"][syncType].Inc()
watchCounters.WithLabelValues("Ingress", sync).Inc()
case *api_v1.Service:
watchCounters["Service"][syncType].Inc()
watchCounters.WithLabelValues("Service", sync).Inc()
case *api_v1.Endpoints:
watchCounters["Endpoints"][syncType].Inc()
watchCounters.WithLabelValues("Endpoints", sync).Inc()
case *api_v1.Secret:
watchCounters["Secret"][syncType].Inc()
watchCounters.WithLabelValues("Secret", sync).Inc()
case *vcr_v1alpha1.VarnishConfig:
watchCounters["VarnishConfig"][syncType].Inc()
watchCounters.WithLabelValues("VarnishConfig", sync).Inc()
case *vcr_v1alpha1.BackendConfig:
watchCounters["BackendConfig"][syncType].Inc()
watchCounters.WithLabelValues("BackendConfig", sync).Inc()
default:
err := fmt.Errorf("Unhandled type %T, watcher counter not "+
"incremented", obj)
utilruntime.HandleError(err)
watchCounters.WithLabelValues("Unknown", sync).Inc()
}
}
func (ingc *IngressController) addObj(obj interface{}) {
ingc.logObj("Add", obj)
incWatchCounter(obj, Add)
incWatchCounter(obj, "Add")
ingc.nsQs.Queue.Add(&SyncObj{Type: Add, Obj: obj})
}
func (ingc *IngressController) deleteObj(obj interface{}) {
ingc.logObj("Delete", obj)
incWatchCounter(obj, Delete)
incWatchCounter(obj, "Delete")
ingc.nsQs.Queue.Add(&SyncObj{Type: Delete, Obj: obj})
}
func (ingc *IngressController) updateObj(old, new interface{}) {
ingc.log.Debug("Update:", old, new)
incWatchCounter(new, Update)
incWatchCounter(new, "Update")
oldMeta, oldErr := meta.Accessor(old)
newMeta, newErr := meta.Accessor(new)
t, tErr := meta.TypeAccessor(old)
......
......@@ -120,14 +120,13 @@ func (_ promProvider) NewRetriesMetric(name string) workqueue.CounterMetric {
}
var (
watchCounters map[string]map[SyncType]prometheus.Counter = map[string]map[SyncType]prometheus.Counter{
"Ingress": make(map[SyncType]prometheus.Counter),
"Service": make(map[SyncType]prometheus.Counter),
"Endpoints": make(map[SyncType]prometheus.Counter),
"Secret": make(map[SyncType]prometheus.Counter),
"VarnishConfig": make(map[SyncType]prometheus.Counter),
"BackendConfig": make(map[SyncType]prometheus.Counter),
}
watchCounters = prometheus.NewCounterVec(prometheus.CounterOpts{
Subsystem: "watcher",
Namespace: namespace,
Name: "events_total",
Help: "Total number of watcher API events",
}, []string{"kind", "event"})
syncCounters = prometheus.NewCounterVec(prometheus.CounterOpts{
Namespace: namespace,
Subsystem: "sync",
......@@ -138,28 +137,7 @@ var (
func InitMetrics() {
workqueue.SetProvider(promProvider{})
syncLabels := map[SyncType]string{
Add: "add",
Update: "update",
Delete: "delete",
}
for kind, m := range watchCounters {
for syncType, typeLabel := range syncLabels {
labels := make(map[string]string)
labels["kind"] = kind
labels["event"] = typeLabel
m[syncType] = prometheus.NewCounter(
prometheus.CounterOpts{
Subsystem: "watcher",
Namespace: namespace,
Name: "events_total",
Help: "Total number of watcher " +
"API events",
ConstLabels: labels,
})
prometheus.Register(m[syncType])
}
}
prometheus.Register(watchCounters)
prometheus.Register(syncCounters)
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment