Browse Source

Set up labels for counters in advance

Signed-off-by: Paulin Todev <paulin.todev@gmail.com>
pull/13023/head
Paulin Todev 12 months ago
parent
commit
108a749a45
No known key found for this signature in database
GPG Key ID: 9A127C7452ED9879
  1. 21
      discovery/kubernetes/endpoints.go
  2. 21
      discovery/kubernetes/endpointslice.go
  3. 19
      discovery/kubernetes/ingress.go
  4. 19
      discovery/kubernetes/node.go
  5. 10
      discovery/kubernetes/pod.go
  6. 19
      discovery/kubernetes/service.go

21
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)
},
})

21
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)
},
})

19
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)
},
})

19
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)
},
})

10
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)
},
})

19
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)
},
})

Loading…
Cancel
Save