Commit b913502c authored by Geoff Simmons's avatar Geoff Simmons

Add counter metrics for watcher API events.

parent 8a57bcf8
......@@ -211,18 +211,42 @@ func (ingc *IngressController) logObj(action string, obj interface{}) {
}
}
func incWatchCounter(obj interface{}, syncType SyncType) {
switch obj.(type) {
case *extensions.Ingress:
watchCounters["Ingress"][syncType].Inc()
case *api_v1.Service:
watchCounters["Service"][syncType].Inc()
case *api_v1.Endpoints:
watchCounters["Endpoints"][syncType].Inc()
case *api_v1.Secret:
watchCounters["Secret"][syncType].Inc()
case *vcr_v1alpha1.VarnishConfig:
watchCounters["VarnishConfig"][syncType].Inc()
case *vcr_v1alpha1.BackendConfig:
watchCounters["BackendConfig"][syncType].Inc()
default:
err := fmt.Errorf("Unhandled type %T, watcher counter not "+
"incremented", obj)
utilruntime.HandleError(err)
}
}
func (ingc *IngressController) addObj(obj interface{}) {
ingc.logObj("Add", obj)
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)
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)
oldMeta, oldErr := meta.Accessor(old)
newMeta, newErr := meta.Accessor(new)
t, tErr := meta.TypeAccessor(old)
......
......@@ -119,8 +119,39 @@ func (_ promProvider) NewRetriesMetric(name string) workqueue.CounterMetric {
return retries
}
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),
}
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])
}
}
}
func ServeMetrics(log *logrus.Logger, port uint16) {
......
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