mirror of
https://github.com/prometheus/prometheus.git
synced 2025-03-05 20:59:13 -08:00
Set up labels for counters in advance
Signed-off-by: Paulin Todev <paulin.todev@gmail.com>
This commit is contained in:
parent
6279497124
commit
108a749a45
|
@ -53,6 +53,15 @@ func NewEndpoints(l log.Logger, eps cache.SharedIndexInformer, svc, pod, node ca
|
||||||
if l == nil {
|
if l == nil {
|
||||||
l = log.NewNopLogger()
|
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{
|
e := &Endpoints{
|
||||||
logger: l,
|
logger: l,
|
||||||
endpointsInf: eps,
|
endpointsInf: eps,
|
||||||
|
@ -68,15 +77,15 @@ func NewEndpoints(l log.Logger, eps cache.SharedIndexInformer, svc, pod, node ca
|
||||||
|
|
||||||
_, err := e.endpointsInf.AddEventHandler(cache.ResourceEventHandlerFuncs{
|
_, err := e.endpointsInf.AddEventHandler(cache.ResourceEventHandlerFuncs{
|
||||||
AddFunc: func(o interface{}) {
|
AddFunc: func(o interface{}) {
|
||||||
eventCount.WithLabelValues("endpoints", "add").Inc()
|
epAddCount.Inc()
|
||||||
e.enqueue(o)
|
e.enqueue(o)
|
||||||
},
|
},
|
||||||
UpdateFunc: func(_, o interface{}) {
|
UpdateFunc: func(_, o interface{}) {
|
||||||
eventCount.WithLabelValues("endpoints", "update").Inc()
|
epUpdateCount.Inc()
|
||||||
e.enqueue(o)
|
e.enqueue(o)
|
||||||
},
|
},
|
||||||
DeleteFunc: func(o interface{}) {
|
DeleteFunc: func(o interface{}) {
|
||||||
eventCount.WithLabelValues("endpoints", "delete").Inc()
|
epDeleteCount.Inc()
|
||||||
e.enqueue(o)
|
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
|
// TODO(fabxc): potentially remove add and delete event handlers. Those should
|
||||||
// be triggered via the endpoint handlers already.
|
// be triggered via the endpoint handlers already.
|
||||||
AddFunc: func(o interface{}) {
|
AddFunc: func(o interface{}) {
|
||||||
eventCount.WithLabelValues("service", "add").Inc()
|
svcAddCount.Inc()
|
||||||
serviceUpdate(o)
|
serviceUpdate(o)
|
||||||
},
|
},
|
||||||
UpdateFunc: func(_, o interface{}) {
|
UpdateFunc: func(_, o interface{}) {
|
||||||
eventCount.WithLabelValues("service", "update").Inc()
|
svcUpdateCount.Inc()
|
||||||
serviceUpdate(o)
|
serviceUpdate(o)
|
||||||
},
|
},
|
||||||
DeleteFunc: func(o interface{}) {
|
DeleteFunc: func(o interface{}) {
|
||||||
eventCount.WithLabelValues("service", "delete").Inc()
|
svcDeleteCount.Inc()
|
||||||
serviceUpdate(o)
|
serviceUpdate(o)
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
|
@ -56,6 +56,15 @@ func NewEndpointSlice(l log.Logger, eps cache.SharedIndexInformer, svc, pod, nod
|
||||||
if l == nil {
|
if l == nil {
|
||||||
l = log.NewNopLogger()
|
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{
|
e := &EndpointSlice{
|
||||||
logger: l,
|
logger: l,
|
||||||
endpointSliceInf: eps,
|
endpointSliceInf: eps,
|
||||||
|
@ -71,15 +80,15 @@ func NewEndpointSlice(l log.Logger, eps cache.SharedIndexInformer, svc, pod, nod
|
||||||
|
|
||||||
_, err := e.endpointSliceInf.AddEventHandler(cache.ResourceEventHandlerFuncs{
|
_, err := e.endpointSliceInf.AddEventHandler(cache.ResourceEventHandlerFuncs{
|
||||||
AddFunc: func(o interface{}) {
|
AddFunc: func(o interface{}) {
|
||||||
eventCount.WithLabelValues("endpointslice", "add").Inc()
|
epslAddCount.Inc()
|
||||||
e.enqueue(o)
|
e.enqueue(o)
|
||||||
},
|
},
|
||||||
UpdateFunc: func(_, o interface{}) {
|
UpdateFunc: func(_, o interface{}) {
|
||||||
eventCount.WithLabelValues("endpointslice", "update").Inc()
|
epslUpdateCount.Inc()
|
||||||
e.enqueue(o)
|
e.enqueue(o)
|
||||||
},
|
},
|
||||||
DeleteFunc: func(o interface{}) {
|
DeleteFunc: func(o interface{}) {
|
||||||
eventCount.WithLabelValues("endpointslice", "delete").Inc()
|
epslDeleteCount.Inc()
|
||||||
e.enqueue(o)
|
e.enqueue(o)
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
@ -110,15 +119,15 @@ func NewEndpointSlice(l log.Logger, eps cache.SharedIndexInformer, svc, pod, nod
|
||||||
}
|
}
|
||||||
_, err = e.serviceInf.AddEventHandler(cache.ResourceEventHandlerFuncs{
|
_, err = e.serviceInf.AddEventHandler(cache.ResourceEventHandlerFuncs{
|
||||||
AddFunc: func(o interface{}) {
|
AddFunc: func(o interface{}) {
|
||||||
eventCount.WithLabelValues("service", "add").Inc()
|
svcAddCount.Inc()
|
||||||
serviceUpdate(o)
|
serviceUpdate(o)
|
||||||
},
|
},
|
||||||
UpdateFunc: func(_, o interface{}) {
|
UpdateFunc: func(_, o interface{}) {
|
||||||
eventCount.WithLabelValues("service", "update").Inc()
|
svcUpdateCount.Inc()
|
||||||
serviceUpdate(o)
|
serviceUpdate(o)
|
||||||
},
|
},
|
||||||
DeleteFunc: func(o interface{}) {
|
DeleteFunc: func(o interface{}) {
|
||||||
eventCount.WithLabelValues("service", "delete").Inc()
|
svcDeleteCount.Inc()
|
||||||
serviceUpdate(o)
|
serviceUpdate(o)
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
|
@ -41,18 +41,29 @@ type Ingress struct {
|
||||||
|
|
||||||
// NewIngress returns a new ingress discovery.
|
// NewIngress returns a new ingress discovery.
|
||||||
func NewIngress(l log.Logger, inf cache.SharedInformer, eventCount *prometheus.CounterVec) *Ingress {
|
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{
|
_, err := s.informer.AddEventHandler(cache.ResourceEventHandlerFuncs{
|
||||||
AddFunc: func(o interface{}) {
|
AddFunc: func(o interface{}) {
|
||||||
eventCount.WithLabelValues("ingress", "add").Inc()
|
ingressAddCount.Inc()
|
||||||
s.enqueue(o)
|
s.enqueue(o)
|
||||||
},
|
},
|
||||||
DeleteFunc: func(o interface{}) {
|
DeleteFunc: func(o interface{}) {
|
||||||
eventCount.WithLabelValues("ingress", "delete").Inc()
|
ingressDeleteCount.Inc()
|
||||||
s.enqueue(o)
|
s.enqueue(o)
|
||||||
},
|
},
|
||||||
UpdateFunc: func(_, o interface{}) {
|
UpdateFunc: func(_, o interface{}) {
|
||||||
eventCount.WithLabelValues("ingress", "update").Inc()
|
ingressUpdateCount.Inc()
|
||||||
s.enqueue(o)
|
s.enqueue(o)
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
|
@ -49,18 +49,29 @@ func NewNode(l log.Logger, inf cache.SharedInformer, eventCount *prometheus.Coun
|
||||||
if l == nil {
|
if l == nil {
|
||||||
l = log.NewNopLogger()
|
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{
|
_, err := n.informer.AddEventHandler(cache.ResourceEventHandlerFuncs{
|
||||||
AddFunc: func(o interface{}) {
|
AddFunc: func(o interface{}) {
|
||||||
eventCount.WithLabelValues("node", "add").Inc()
|
nodeAddCount.Inc()
|
||||||
n.enqueue(o)
|
n.enqueue(o)
|
||||||
},
|
},
|
||||||
DeleteFunc: func(o interface{}) {
|
DeleteFunc: func(o interface{}) {
|
||||||
eventCount.WithLabelValues("node", "delete").Inc()
|
nodeDeleteCount.Inc()
|
||||||
n.enqueue(o)
|
n.enqueue(o)
|
||||||
},
|
},
|
||||||
UpdateFunc: func(_, o interface{}) {
|
UpdateFunc: func(_, o interface{}) {
|
||||||
eventCount.WithLabelValues("node", "update").Inc()
|
nodeUpdateCount.Inc()
|
||||||
n.enqueue(o)
|
n.enqueue(o)
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
|
@ -51,6 +51,10 @@ func NewPod(l log.Logger, pods cache.SharedIndexInformer, nodes cache.SharedInfo
|
||||||
l = log.NewNopLogger()
|
l = log.NewNopLogger()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
podAddCount := eventCount.WithLabelValues("pod", "add")
|
||||||
|
podDeleteCount := eventCount.WithLabelValues("pod", "delete")
|
||||||
|
podUpdateCount := eventCount.WithLabelValues("pod", "update")
|
||||||
|
|
||||||
p := &Pod{
|
p := &Pod{
|
||||||
podInf: pods,
|
podInf: pods,
|
||||||
nodeInf: nodes,
|
nodeInf: nodes,
|
||||||
|
@ -61,15 +65,15 @@ func NewPod(l log.Logger, pods cache.SharedIndexInformer, nodes cache.SharedInfo
|
||||||
}
|
}
|
||||||
_, err := p.podInf.AddEventHandler(cache.ResourceEventHandlerFuncs{
|
_, err := p.podInf.AddEventHandler(cache.ResourceEventHandlerFuncs{
|
||||||
AddFunc: func(o interface{}) {
|
AddFunc: func(o interface{}) {
|
||||||
eventCount.WithLabelValues("pod", "add").Inc()
|
podAddCount.Inc()
|
||||||
p.enqueue(o)
|
p.enqueue(o)
|
||||||
},
|
},
|
||||||
DeleteFunc: func(o interface{}) {
|
DeleteFunc: func(o interface{}) {
|
||||||
eventCount.WithLabelValues("pod", "delete").Inc()
|
podDeleteCount.Inc()
|
||||||
p.enqueue(o)
|
p.enqueue(o)
|
||||||
},
|
},
|
||||||
UpdateFunc: func(_, o interface{}) {
|
UpdateFunc: func(_, o interface{}) {
|
||||||
eventCount.WithLabelValues("pod", "update").Inc()
|
podUpdateCount.Inc()
|
||||||
p.enqueue(o)
|
p.enqueue(o)
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
|
@ -44,18 +44,29 @@ func NewService(l log.Logger, inf cache.SharedInformer, eventCount *prometheus.C
|
||||||
if l == nil {
|
if l == nil {
|
||||||
l = log.NewNopLogger()
|
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{
|
_, err := s.informer.AddEventHandler(cache.ResourceEventHandlerFuncs{
|
||||||
AddFunc: func(o interface{}) {
|
AddFunc: func(o interface{}) {
|
||||||
eventCount.WithLabelValues("service", "add").Inc()
|
svcAddCount.Inc()
|
||||||
s.enqueue(o)
|
s.enqueue(o)
|
||||||
},
|
},
|
||||||
DeleteFunc: func(o interface{}) {
|
DeleteFunc: func(o interface{}) {
|
||||||
eventCount.WithLabelValues("service", "delete").Inc()
|
svcDeleteCount.Inc()
|
||||||
s.enqueue(o)
|
s.enqueue(o)
|
||||||
},
|
},
|
||||||
UpdateFunc: func(_, o interface{}) {
|
UpdateFunc: func(_, o interface{}) {
|
||||||
eventCount.WithLabelValues("service", "update").Inc()
|
svcUpdateCount.Inc()
|
||||||
s.enqueue(o)
|
s.enqueue(o)
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
Loading…
Reference in a new issue