Commit 831b25c2 authored by Geoff Simmons's avatar Geoff Simmons

Add the sync_result_total counter vector.

parent 314c607e
...@@ -95,6 +95,8 @@ func (worker *NamespaceWorker) syncBcfg(key string) error { ...@@ -95,6 +95,8 @@ func (worker *NamespaceWorker) syncBcfg(key string) error {
// CRD validation should prevent this. // CRD validation should prevent this.
worker.log.Warnf("BackendConfig %s/%s: no services defined, "+ worker.log.Warnf("BackendConfig %s/%s: no services defined, "+
"ignoring", bcfg.Namespace, bcfg.Name) "ignoring", bcfg.Namespace, bcfg.Name)
syncCounters.WithLabelValues(worker.namespace, "BackendConfig",
"Ignore").Inc()
return nil return nil
} }
......
...@@ -256,9 +256,28 @@ func (ingc *IngressController) updateObj(old, new interface{}) { ...@@ -256,9 +256,28 @@ func (ingc *IngressController) updateObj(old, new interface{}) {
ingc.log.Infof("Update %s %s/%s: unchanged", ingc.log.Infof("Update %s %s/%s: unchanged",
t.GetKind(), oldMeta.GetNamespace(), t.GetKind(), oldMeta.GetNamespace(),
oldMeta.GetName()) oldMeta.GetName())
syncCounters.WithLabelValues(oldMeta.GetNamespace(),
t.GetKind(), "Ignore").Inc()
} else { } else {
ingc.log.Infof("Update %s/%s: unchanged", kind := "Unknown"
switch old.(type) {
case *extensions.Ingress:
kind = "Ingress"
case *api_v1.Service:
kind = "Service"
case *api_v1.Endpoints:
kind = "Endpoints"
case *api_v1.Secret:
kind = "Secret"
case *vcr_v1alpha1.VarnishConfig:
kind = "VarnishConfig"
case *vcr_v1alpha1.BackendConfig:
kind = "BackendConfig"
}
ingc.log.Infof("Update %s %s/%s: unchanged", kind,
oldMeta.GetNamespace(), oldMeta.GetName()) oldMeta.GetNamespace(), oldMeta.GetName())
syncCounters.WithLabelValues(oldMeta.GetNamespace(),
kind, "Ignore").Inc()
} }
return return
} }
...@@ -272,6 +291,8 @@ func (ingc *IngressController) updateObj(old, new interface{}) { ...@@ -272,6 +291,8 @@ func (ingc *IngressController) updateObj(old, new interface{}) {
ingc.log.Infof("Update endpoints %s/%s: empty Subsets, ignoring", ingc.log.Infof("Update endpoints %s/%s: empty Subsets, ignoring",
newEndp.Namespace, newEndp.Name) newEndp.Namespace, newEndp.Name)
syncCounters.WithLabelValues(oldMeta.GetNamespace(),
"Endpoints", "Ignore").Inc()
return return
} }
......
...@@ -36,6 +36,8 @@ func (worker *NamespaceWorker) syncEndp(key string) error { ...@@ -36,6 +36,8 @@ func (worker *NamespaceWorker) syncEndp(key string) error {
if err != nil { if err != nil {
worker.log.Warnf("Cannot get service for endpoints %s/%s, "+ worker.log.Warnf("Cannot get service for endpoints %s/%s, "+
"ignoring", worker.namespace, key) "ignoring", worker.namespace, key)
syncCounters.WithLabelValues(worker.namespace, "Endpoints",
"Ignore").Inc()
return nil return nil
} }
...@@ -56,6 +58,8 @@ func (worker *NamespaceWorker) syncEndp(key string) error { ...@@ -56,6 +58,8 @@ func (worker *NamespaceWorker) syncEndp(key string) error {
if len(ings) == 0 { if len(ings) == 0 {
worker.log.Debugf("No ingresses for endpoints: %s/%s", worker.log.Debugf("No ingresses for endpoints: %s/%s",
worker.namespace, key) worker.namespace, key)
syncCounters.WithLabelValues(worker.namespace, "Endpoints",
"Ignore").Inc()
return nil return nil
} }
......
...@@ -555,6 +555,8 @@ func (worker *NamespaceWorker) syncIng(key string) error { ...@@ -555,6 +555,8 @@ func (worker *NamespaceWorker) syncIng(key string) error {
worker.log.Infof("Ignoring Ingress %s/%s, Annotation '%v' "+ worker.log.Infof("Ignoring Ingress %s/%s, Annotation '%v' "+
"absent or is not 'varnish'", ing.Namespace, ing.Name, "absent or is not 'varnish'", ing.Namespace, ing.Name,
ingressClassKey) ingressClassKey)
syncCounters.WithLabelValues(worker.namespace, "Ingress",
"Ignore").Inc()
return nil return nil
} }
return worker.addOrUpdateIng(ing) return worker.addOrUpdateIng(ing)
......
...@@ -119,14 +119,22 @@ func (_ promProvider) NewRetriesMetric(name string) workqueue.CounterMetric { ...@@ -119,14 +119,22 @@ func (_ promProvider) NewRetriesMetric(name string) workqueue.CounterMetric {
return retries return retries
} }
var watchCounters map[string]map[SyncType]prometheus.Counter = map[string]map[SyncType]prometheus.Counter{ var (
"Ingress": make(map[SyncType]prometheus.Counter), watchCounters map[string]map[SyncType]prometheus.Counter = map[string]map[SyncType]prometheus.Counter{
"Service": make(map[SyncType]prometheus.Counter), "Ingress": make(map[SyncType]prometheus.Counter),
"Endpoints": make(map[SyncType]prometheus.Counter), "Service": make(map[SyncType]prometheus.Counter),
"Secret": make(map[SyncType]prometheus.Counter), "Endpoints": make(map[SyncType]prometheus.Counter),
"VarnishConfig": make(map[SyncType]prometheus.Counter), "Secret": make(map[SyncType]prometheus.Counter),
"BackendConfig": make(map[SyncType]prometheus.Counter), "VarnishConfig": make(map[SyncType]prometheus.Counter),
} "BackendConfig": make(map[SyncType]prometheus.Counter),
}
syncCounters = prometheus.NewCounterVec(prometheus.CounterOpts{
Namespace: namespace,
Subsystem: "sync",
Name: "result_total",
Help: "Total number of synchronization results",
}, []string{"namespace", "kind", "result"})
)
func InitMetrics() { func InitMetrics() {
workqueue.SetProvider(promProvider{}) workqueue.SetProvider(promProvider{})
...@@ -152,6 +160,7 @@ func InitMetrics() { ...@@ -152,6 +160,7 @@ func InitMetrics() {
prometheus.Register(m[syncType]) prometheus.Register(m[syncType])
} }
} }
prometheus.Register(syncCounters)
} }
func ServeMetrics(log *logrus.Logger, port uint16) { func ServeMetrics(log *logrus.Logger, port uint16) {
......
...@@ -128,6 +128,8 @@ func (worker *NamespaceWorker) syncSecret(key string) error { ...@@ -128,6 +128,8 @@ func (worker *NamespaceWorker) syncSecret(key string) error {
if !ok || app != labelVal { if !ok || app != labelVal {
worker.log.Infof("Not a Varnish secret: %s/%s", worker.log.Infof("Not a Varnish secret: %s/%s",
secret.Namespace, secret.Name) secret.Namespace, secret.Name)
syncCounters.WithLabelValues(worker.namespace, "Secret",
"Ignore").Inc()
return nil return nil
} }
......
...@@ -83,6 +83,8 @@ func (worker *NamespaceWorker) getIngsForSvc( ...@@ -83,6 +83,8 @@ func (worker *NamespaceWorker) getIngsForSvc(
if len(ings) == 0 { if len(ings) == 0 {
worker.log.Infof("No Varnish Ingresses defined for service %s/%s", worker.log.Infof("No Varnish Ingresses defined for service %s/%s",
svc.Namespace, svc.Name) svc.Namespace, svc.Name)
syncCounters.WithLabelValues(worker.namespace, "Service",
"Ignore").Inc()
} }
return ings, nil return ings, nil
} }
......
...@@ -110,6 +110,8 @@ func (worker *NamespaceWorker) syncVcfg(key string) error { ...@@ -110,6 +110,8 @@ func (worker *NamespaceWorker) syncVcfg(key string) error {
// CRD validation should prevent this. // CRD validation should prevent this.
worker.log.Infof("VarnishConfig %s/%s: no services defined, "+ worker.log.Infof("VarnishConfig %s/%s: no services defined, "+
"ignoring", vcfg.Namespace, vcfg.Name) "ignoring", vcfg.Namespace, vcfg.Name)
syncCounters.WithLabelValues(worker.namespace, "VarnishConfig",
"Ignore").Inc()
return nil return nil
} }
......
...@@ -84,29 +84,37 @@ func (worker *NamespaceWorker) event(obj interface{}, evtType, reason, ...@@ -84,29 +84,37 @@ func (worker *NamespaceWorker) event(obj interface{}, evtType, reason,
if syncObj, ok := obj.(*SyncObj); ok { if syncObj, ok := obj.(*SyncObj); ok {
eventObj = syncObj.Obj eventObj = syncObj.Obj
} }
kind := "Unknown"
switch eventObj.(type) { switch eventObj.(type) {
case *extensions.Ingress: case *extensions.Ingress:
ing, _ := eventObj.(*extensions.Ingress) ing, _ := eventObj.(*extensions.Ingress)
worker.recorder.Eventf(ing, evtType, reason, msgFmt, args...) worker.recorder.Eventf(ing, evtType, reason, msgFmt, args...)
kind = "Ingress"
case *api_v1.Service: case *api_v1.Service:
svc, _ := eventObj.(*api_v1.Service) svc, _ := eventObj.(*api_v1.Service)
worker.recorder.Eventf(svc, evtType, reason, msgFmt, args...) worker.recorder.Eventf(svc, evtType, reason, msgFmt, args...)
kind = "Service"
case *api_v1.Endpoints: case *api_v1.Endpoints:
endp, _ := eventObj.(*api_v1.Endpoints) endp, _ := eventObj.(*api_v1.Endpoints)
worker.recorder.Eventf(endp, evtType, reason, msgFmt, args...) worker.recorder.Eventf(endp, evtType, reason, msgFmt, args...)
kind = "Endpoints"
case *api_v1.Secret: case *api_v1.Secret:
secr, _ := eventObj.(*api_v1.Secret) secr, _ := eventObj.(*api_v1.Secret)
worker.recorder.Eventf(secr, evtType, reason, msgFmt, args...) worker.recorder.Eventf(secr, evtType, reason, msgFmt, args...)
kind = "Secret"
case *ving_v1alpha1.VarnishConfig: case *ving_v1alpha1.VarnishConfig:
vcfg, _ := eventObj.(*ving_v1alpha1.VarnishConfig) vcfg, _ := eventObj.(*ving_v1alpha1.VarnishConfig)
worker.recorder.Eventf(vcfg, evtType, reason, msgFmt, args...) worker.recorder.Eventf(vcfg, evtType, reason, msgFmt, args...)
kind = "VarnishConfig"
case *ving_v1alpha1.BackendConfig: case *ving_v1alpha1.BackendConfig:
bcfg, _ := eventObj.(*ving_v1alpha1.BackendConfig) bcfg, _ := eventObj.(*ving_v1alpha1.BackendConfig)
worker.recorder.Eventf(bcfg, evtType, reason, msgFmt, args...) worker.recorder.Eventf(bcfg, evtType, reason, msgFmt, args...)
kind = "BackendConfig"
default: default:
worker.log.Warnf("Unhandled type %T, no event generated", worker.log.Warnf("Unhandled type %T, no event generated",
eventObj) eventObj)
} }
syncCounters.WithLabelValues(worker.namespace, kind, reason).Inc()
} }
func (worker *NamespaceWorker) infoEvent(obj interface{}, reason, msgFmt string, func (worker *NamespaceWorker) infoEvent(obj interface{}, reason, msgFmt string,
......
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