diff --git a/discovery/kubernetes/endpoints.go b/discovery/kubernetes/endpoints.go index 801a45f7c..f97f1ee56 100644 --- a/discovery/kubernetes/endpoints.go +++ b/discovery/kubernetes/endpoints.go @@ -53,6 +53,15 @@ func NewEndpoints(l log.Logger, eps cache.SharedIndexInformer, svc, pod, node ca if l == nil { l = log.NewNopLogger() } + + epAddCount := eventCount.WithLabelValues("endpoints", "add") + epUpdateCount := eventCount.WithLabelValues("endpoints", "update") + epDeleteCount := eventCount.WithLabelValues("endpoints", "delete") + + svcAddCount := eventCount.WithLabelValues("service", "add") + svcUpdateCount := eventCount.WithLabelValues("service", "update") + svcDeleteCount := eventCount.WithLabelValues("service", "delete") + e := &Endpoints{ logger: l, endpointsInf: eps, @@ -68,15 +77,15 @@ func NewEndpoints(l log.Logger, eps cache.SharedIndexInformer, svc, pod, node ca _, err := e.endpointsInf.AddEventHandler(cache.ResourceEventHandlerFuncs{ AddFunc: func(o interface{}) { - eventCount.WithLabelValues("endpoints", "add").Inc() + epAddCount.Inc() e.enqueue(o) }, UpdateFunc: func(_, o interface{}) { - eventCount.WithLabelValues("endpoints", "update").Inc() + epUpdateCount.Inc() e.enqueue(o) }, DeleteFunc: func(o interface{}) { - eventCount.WithLabelValues("endpoints", "delete").Inc() + epDeleteCount.Inc() e.enqueue(o) }, }) @@ -107,15 +116,15 @@ func NewEndpoints(l log.Logger, eps cache.SharedIndexInformer, svc, pod, node ca // TODO(fabxc): potentially remove add and delete event handlers. Those should // be triggered via the endpoint handlers already. AddFunc: func(o interface{}) { - eventCount.WithLabelValues("service", "add").Inc() + svcAddCount.Inc() serviceUpdate(o) }, UpdateFunc: func(_, o interface{}) { - eventCount.WithLabelValues("service", "update").Inc() + svcUpdateCount.Inc() serviceUpdate(o) }, DeleteFunc: func(o interface{}) { - eventCount.WithLabelValues("service", "delete").Inc() + svcDeleteCount.Inc() serviceUpdate(o) }, }) diff --git a/discovery/kubernetes/endpointslice.go b/discovery/kubernetes/endpointslice.go index e2ac1de42..a7e0ea98c 100644 --- a/discovery/kubernetes/endpointslice.go +++ b/discovery/kubernetes/endpointslice.go @@ -56,6 +56,15 @@ func NewEndpointSlice(l log.Logger, eps cache.SharedIndexInformer, svc, pod, nod if l == nil { l = log.NewNopLogger() } + + epslAddCount := eventCount.WithLabelValues("endpointslice", "add") + epslUpdateCount := eventCount.WithLabelValues("endpointslice", "update") + epslDeleteCount := eventCount.WithLabelValues("endpointslice", "delete") + + svcAddCount := eventCount.WithLabelValues("service", "add") + svcUpdateCount := eventCount.WithLabelValues("service", "update") + svcDeleteCount := eventCount.WithLabelValues("service", "delete") + e := &EndpointSlice{ logger: l, endpointSliceInf: eps, @@ -71,15 +80,15 @@ func NewEndpointSlice(l log.Logger, eps cache.SharedIndexInformer, svc, pod, nod _, err := e.endpointSliceInf.AddEventHandler(cache.ResourceEventHandlerFuncs{ AddFunc: func(o interface{}) { - eventCount.WithLabelValues("endpointslice", "add").Inc() + epslAddCount.Inc() e.enqueue(o) }, UpdateFunc: func(_, o interface{}) { - eventCount.WithLabelValues("endpointslice", "update").Inc() + epslUpdateCount.Inc() e.enqueue(o) }, DeleteFunc: func(o interface{}) { - eventCount.WithLabelValues("endpointslice", "delete").Inc() + epslDeleteCount.Inc() e.enqueue(o) }, }) @@ -110,15 +119,15 @@ func NewEndpointSlice(l log.Logger, eps cache.SharedIndexInformer, svc, pod, nod } _, err = e.serviceInf.AddEventHandler(cache.ResourceEventHandlerFuncs{ AddFunc: func(o interface{}) { - eventCount.WithLabelValues("service", "add").Inc() + svcAddCount.Inc() serviceUpdate(o) }, UpdateFunc: func(_, o interface{}) { - eventCount.WithLabelValues("service", "update").Inc() + svcUpdateCount.Inc() serviceUpdate(o) }, DeleteFunc: func(o interface{}) { - eventCount.WithLabelValues("service", "delete").Inc() + svcDeleteCount.Inc() serviceUpdate(o) }, }) diff --git a/discovery/kubernetes/ingress.go b/discovery/kubernetes/ingress.go index 91b1fb0ee..72712245a 100644 --- a/discovery/kubernetes/ingress.go +++ b/discovery/kubernetes/ingress.go @@ -41,18 +41,29 @@ type Ingress struct { // NewIngress returns a new ingress discovery. func NewIngress(l log.Logger, inf cache.SharedInformer, eventCount *prometheus.CounterVec) *Ingress { - s := &Ingress{logger: l, informer: inf, store: inf.GetStore(), queue: workqueue.NewNamed("ingress")} + + ingressAddCount := eventCount.WithLabelValues("ingress", "add") + ingressUpdateCount := eventCount.WithLabelValues("ingress", "update") + ingressDeleteCount := eventCount.WithLabelValues("ingress", "delete") + + s := &Ingress{ + logger: l, + informer: inf, + store: inf.GetStore(), + queue: workqueue.NewNamed("ingress"), + } + _, err := s.informer.AddEventHandler(cache.ResourceEventHandlerFuncs{ AddFunc: func(o interface{}) { - eventCount.WithLabelValues("ingress", "add").Inc() + ingressAddCount.Inc() s.enqueue(o) }, DeleteFunc: func(o interface{}) { - eventCount.WithLabelValues("ingress", "delete").Inc() + ingressDeleteCount.Inc() s.enqueue(o) }, UpdateFunc: func(_, o interface{}) { - eventCount.WithLabelValues("ingress", "update").Inc() + ingressUpdateCount.Inc() s.enqueue(o) }, }) diff --git a/discovery/kubernetes/node.go b/discovery/kubernetes/node.go index f1e37e6fa..f9a318336 100644 --- a/discovery/kubernetes/node.go +++ b/discovery/kubernetes/node.go @@ -49,18 +49,29 @@ func NewNode(l log.Logger, inf cache.SharedInformer, eventCount *prometheus.Coun if l == nil { l = log.NewNopLogger() } - n := &Node{logger: l, informer: inf, store: inf.GetStore(), queue: workqueue.NewNamed("node")} + + nodeAddCount := eventCount.WithLabelValues("node", "add") + nodeUpdateCount := eventCount.WithLabelValues("node", "update") + nodeDeleteCount := eventCount.WithLabelValues("node", "delete") + + n := &Node{ + logger: l, + informer: inf, + store: inf.GetStore(), + queue: workqueue.NewNamed("node"), + } + _, err := n.informer.AddEventHandler(cache.ResourceEventHandlerFuncs{ AddFunc: func(o interface{}) { - eventCount.WithLabelValues("node", "add").Inc() + nodeAddCount.Inc() n.enqueue(o) }, DeleteFunc: func(o interface{}) { - eventCount.WithLabelValues("node", "delete").Inc() + nodeDeleteCount.Inc() n.enqueue(o) }, UpdateFunc: func(_, o interface{}) { - eventCount.WithLabelValues("node", "update").Inc() + nodeUpdateCount.Inc() n.enqueue(o) }, }) diff --git a/discovery/kubernetes/pod.go b/discovery/kubernetes/pod.go index cc809b29c..31936f9c0 100644 --- a/discovery/kubernetes/pod.go +++ b/discovery/kubernetes/pod.go @@ -51,6 +51,10 @@ func NewPod(l log.Logger, pods cache.SharedIndexInformer, nodes cache.SharedInfo l = log.NewNopLogger() } + podAddCount := eventCount.WithLabelValues("pod", "add") + podDeleteCount := eventCount.WithLabelValues("pod", "delete") + podUpdateCount := eventCount.WithLabelValues("pod", "update") + p := &Pod{ podInf: pods, nodeInf: nodes, @@ -61,15 +65,15 @@ func NewPod(l log.Logger, pods cache.SharedIndexInformer, nodes cache.SharedInfo } _, err := p.podInf.AddEventHandler(cache.ResourceEventHandlerFuncs{ AddFunc: func(o interface{}) { - eventCount.WithLabelValues("pod", "add").Inc() + podAddCount.Inc() p.enqueue(o) }, DeleteFunc: func(o interface{}) { - eventCount.WithLabelValues("pod", "delete").Inc() + podDeleteCount.Inc() p.enqueue(o) }, UpdateFunc: func(_, o interface{}) { - eventCount.WithLabelValues("pod", "update").Inc() + podUpdateCount.Inc() p.enqueue(o) }, }) diff --git a/discovery/kubernetes/service.go b/discovery/kubernetes/service.go index a680ebee8..02158b124 100644 --- a/discovery/kubernetes/service.go +++ b/discovery/kubernetes/service.go @@ -44,18 +44,29 @@ func NewService(l log.Logger, inf cache.SharedInformer, eventCount *prometheus.C if l == nil { l = log.NewNopLogger() } - s := &Service{logger: l, informer: inf, store: inf.GetStore(), queue: workqueue.NewNamed("service")} + + svcAddCount := eventCount.WithLabelValues("service", "add") + svcUpdateCount := eventCount.WithLabelValues("service", "update") + svcDeleteCount := eventCount.WithLabelValues("service", "delete") + + s := &Service{ + logger: l, + informer: inf, + store: inf.GetStore(), + queue: workqueue.NewNamed("service"), + } + _, err := s.informer.AddEventHandler(cache.ResourceEventHandlerFuncs{ AddFunc: func(o interface{}) { - eventCount.WithLabelValues("service", "add").Inc() + svcAddCount.Inc() s.enqueue(o) }, DeleteFunc: func(o interface{}) { - eventCount.WithLabelValues("service", "delete").Inc() + svcDeleteCount.Inc() s.enqueue(o) }, UpdateFunc: func(_, o interface{}) { - eventCount.WithLabelValues("service", "update").Inc() + svcUpdateCount.Inc() s.enqueue(o) }, })