mirror of
https://github.com/prometheus/prometheus.git
synced 2024-11-09 23:24:05 -08:00
keep kubernetes metrics in global vars (#6765)
Signed-off-by: yeya24 <yb532204897@gmail.com>
This commit is contained in:
parent
641676b397
commit
1a18594176
|
@ -29,6 +29,12 @@ import (
|
||||||
"github.com/prometheus/prometheus/discovery/targetgroup"
|
"github.com/prometheus/prometheus/discovery/targetgroup"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
epAddCount = eventCount.WithLabelValues("endpoints", "add")
|
||||||
|
epUpdateCount = eventCount.WithLabelValues("endpoints", "update")
|
||||||
|
epDeleteCount = eventCount.WithLabelValues("endpoints", "delete")
|
||||||
|
)
|
||||||
|
|
||||||
// Endpoints discovers new endpoint targets.
|
// Endpoints discovers new endpoint targets.
|
||||||
type Endpoints struct {
|
type Endpoints struct {
|
||||||
logger log.Logger
|
logger log.Logger
|
||||||
|
@ -62,15 +68,15 @@ func NewEndpoints(l log.Logger, svc, eps, pod cache.SharedInformer) *Endpoints {
|
||||||
|
|
||||||
e.endpointsInf.AddEventHandler(cache.ResourceEventHandlerFuncs{
|
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)
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
@ -98,15 +104,15 @@ func NewEndpoints(l log.Logger, svc, eps, pod cache.SharedInformer) *Endpoints {
|
||||||
// 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)
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
|
@ -28,6 +28,12 @@ import (
|
||||||
"github.com/prometheus/prometheus/util/strutil"
|
"github.com/prometheus/prometheus/util/strutil"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
ingressAddCount = eventCount.WithLabelValues("ingress", "add")
|
||||||
|
ingressUpdateCount = eventCount.WithLabelValues("ingress", "update")
|
||||||
|
ingressDeleteCount = eventCount.WithLabelValues("ingress", "delete")
|
||||||
|
)
|
||||||
|
|
||||||
// Ingress implements discovery of Kubernetes ingress.
|
// Ingress implements discovery of Kubernetes ingress.
|
||||||
type Ingress struct {
|
type Ingress struct {
|
||||||
logger log.Logger
|
logger log.Logger
|
||||||
|
@ -41,15 +47,15 @@ func NewIngress(l log.Logger, inf cache.SharedInformer) *Ingress {
|
||||||
s := &Ingress{logger: l, informer: inf, store: inf.GetStore(), queue: workqueue.NewNamed("ingress")}
|
s := &Ingress{logger: l, informer: inf, store: inf.GetStore(), queue: workqueue.NewNamed("ingress")}
|
||||||
s.informer.AddEventHandler(cache.ResourceEventHandlerFuncs{
|
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)
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
|
@ -34,6 +34,12 @@ const (
|
||||||
NodeLegacyHostIP = "LegacyHostIP"
|
NodeLegacyHostIP = "LegacyHostIP"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
nodeAddCount = eventCount.WithLabelValues("node", "add")
|
||||||
|
nodeUpdateCount = eventCount.WithLabelValues("node", "update")
|
||||||
|
nodeDeleteCount = eventCount.WithLabelValues("node", "delete")
|
||||||
|
)
|
||||||
|
|
||||||
// Node discovers Kubernetes nodes.
|
// Node discovers Kubernetes nodes.
|
||||||
type Node struct {
|
type Node struct {
|
||||||
logger log.Logger
|
logger log.Logger
|
||||||
|
@ -50,15 +56,15 @@ func NewNode(l log.Logger, inf cache.SharedInformer) *Node {
|
||||||
n := &Node{logger: l, informer: inf, store: inf.GetStore(), queue: workqueue.NewNamed("node")}
|
n := &Node{logger: l, informer: inf, store: inf.GetStore(), queue: workqueue.NewNamed("node")}
|
||||||
n.informer.AddEventHandler(cache.ResourceEventHandlerFuncs{
|
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)
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
|
@ -32,6 +32,12 @@ import (
|
||||||
"github.com/prometheus/prometheus/util/strutil"
|
"github.com/prometheus/prometheus/util/strutil"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
podAddCount = eventCount.WithLabelValues("pod", "add")
|
||||||
|
podUpdateCount = eventCount.WithLabelValues("pod", "update")
|
||||||
|
podDeleteCount = eventCount.WithLabelValues("pod", "delete")
|
||||||
|
)
|
||||||
|
|
||||||
// Pod discovers new pod targets.
|
// Pod discovers new pod targets.
|
||||||
type Pod struct {
|
type Pod struct {
|
||||||
informer cache.SharedInformer
|
informer cache.SharedInformer
|
||||||
|
@ -53,15 +59,15 @@ func NewPod(l log.Logger, pods cache.SharedInformer) *Pod {
|
||||||
}
|
}
|
||||||
p.informer.AddEventHandler(cache.ResourceEventHandlerFuncs{
|
p.informer.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)
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
|
@ -30,6 +30,12 @@ import (
|
||||||
"github.com/prometheus/prometheus/util/strutil"
|
"github.com/prometheus/prometheus/util/strutil"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
svcAddCount = eventCount.WithLabelValues("service", "add")
|
||||||
|
svcUpdateCount = eventCount.WithLabelValues("service", "update")
|
||||||
|
svcDeleteCount = eventCount.WithLabelValues("service", "delete")
|
||||||
|
)
|
||||||
|
|
||||||
// Service implements discovery of Kubernetes services.
|
// Service implements discovery of Kubernetes services.
|
||||||
type Service struct {
|
type Service struct {
|
||||||
logger log.Logger
|
logger log.Logger
|
||||||
|
@ -46,15 +52,15 @@ func NewService(l log.Logger, inf cache.SharedInformer) *Service {
|
||||||
s := &Service{logger: l, informer: inf, store: inf.GetStore(), queue: workqueue.NewNamed("service")}
|
s := &Service{logger: l, informer: inf, store: inf.GetStore(), queue: workqueue.NewNamed("service")}
|
||||||
s.informer.AddEventHandler(cache.ResourceEventHandlerFuncs{
|
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