mirror of
https://github.com/prometheus/prometheus
synced 2025-04-08 10:32:00 +00:00
Define metric label values in one place
Signed-off-by: Paulin Todev <paulin.todev@gmail.com>
This commit is contained in:
parent
108a749a45
commit
27bb57a37b
@ -54,13 +54,13 @@ func NewEndpoints(l log.Logger, eps cache.SharedIndexInformer, svc, pod, node ca
|
|||||||
l = log.NewNopLogger()
|
l = log.NewNopLogger()
|
||||||
}
|
}
|
||||||
|
|
||||||
epAddCount := eventCount.WithLabelValues("endpoints", "add")
|
epAddCount := eventCount.WithLabelValues(RoleEndpoint.String(), MetricLabelRoleAdd)
|
||||||
epUpdateCount := eventCount.WithLabelValues("endpoints", "update")
|
epUpdateCount := eventCount.WithLabelValues(RoleEndpoint.String(), MetricLabelRoleUpdate)
|
||||||
epDeleteCount := eventCount.WithLabelValues("endpoints", "delete")
|
epDeleteCount := eventCount.WithLabelValues(RoleEndpoint.String(), MetricLabelRoleDelete)
|
||||||
|
|
||||||
svcAddCount := eventCount.WithLabelValues("service", "add")
|
svcAddCount := eventCount.WithLabelValues(RoleService.String(), MetricLabelRoleAdd)
|
||||||
svcUpdateCount := eventCount.WithLabelValues("service", "update")
|
svcUpdateCount := eventCount.WithLabelValues(RoleService.String(), MetricLabelRoleUpdate)
|
||||||
svcDeleteCount := eventCount.WithLabelValues("service", "delete")
|
svcDeleteCount := eventCount.WithLabelValues(RoleService.String(), MetricLabelRoleDelete)
|
||||||
|
|
||||||
e := &Endpoints{
|
e := &Endpoints{
|
||||||
logger: l,
|
logger: l,
|
||||||
@ -72,7 +72,7 @@ func NewEndpoints(l log.Logger, eps cache.SharedIndexInformer, svc, pod, node ca
|
|||||||
podStore: pod.GetStore(),
|
podStore: pod.GetStore(),
|
||||||
nodeInf: node,
|
nodeInf: node,
|
||||||
withNodeMetadata: node != nil,
|
withNodeMetadata: node != nil,
|
||||||
queue: workqueue.NewNamed("endpoints"),
|
queue: workqueue.NewNamed(RoleEndpoint.String()),
|
||||||
}
|
}
|
||||||
|
|
||||||
_, err := e.endpointsInf.AddEventHandler(cache.ResourceEventHandlerFuncs{
|
_, err := e.endpointsInf.AddEventHandler(cache.ResourceEventHandlerFuncs{
|
||||||
|
@ -57,13 +57,13 @@ func NewEndpointSlice(l log.Logger, eps cache.SharedIndexInformer, svc, pod, nod
|
|||||||
l = log.NewNopLogger()
|
l = log.NewNopLogger()
|
||||||
}
|
}
|
||||||
|
|
||||||
epslAddCount := eventCount.WithLabelValues("endpointslice", "add")
|
epslAddCount := eventCount.WithLabelValues(RoleEndpointSlice.String(), MetricLabelRoleAdd)
|
||||||
epslUpdateCount := eventCount.WithLabelValues("endpointslice", "update")
|
epslUpdateCount := eventCount.WithLabelValues(RoleEndpointSlice.String(), MetricLabelRoleUpdate)
|
||||||
epslDeleteCount := eventCount.WithLabelValues("endpointslice", "delete")
|
epslDeleteCount := eventCount.WithLabelValues(RoleEndpointSlice.String(), MetricLabelRoleDelete)
|
||||||
|
|
||||||
svcAddCount := eventCount.WithLabelValues("service", "add")
|
svcAddCount := eventCount.WithLabelValues(RoleService.String(), MetricLabelRoleAdd)
|
||||||
svcUpdateCount := eventCount.WithLabelValues("service", "update")
|
svcUpdateCount := eventCount.WithLabelValues(RoleService.String(), MetricLabelRoleUpdate)
|
||||||
svcDeleteCount := eventCount.WithLabelValues("service", "delete")
|
svcDeleteCount := eventCount.WithLabelValues(RoleService.String(), MetricLabelRoleDelete)
|
||||||
|
|
||||||
e := &EndpointSlice{
|
e := &EndpointSlice{
|
||||||
logger: l,
|
logger: l,
|
||||||
@ -75,7 +75,7 @@ func NewEndpointSlice(l log.Logger, eps cache.SharedIndexInformer, svc, pod, nod
|
|||||||
podStore: pod.GetStore(),
|
podStore: pod.GetStore(),
|
||||||
nodeInf: node,
|
nodeInf: node,
|
||||||
withNodeMetadata: node != nil,
|
withNodeMetadata: node != nil,
|
||||||
queue: workqueue.NewNamed("endpointSlice"),
|
queue: workqueue.NewNamed(RoleEndpointSlice.String()),
|
||||||
}
|
}
|
||||||
|
|
||||||
_, err := e.endpointSliceInf.AddEventHandler(cache.ResourceEventHandlerFuncs{
|
_, err := e.endpointSliceInf.AddEventHandler(cache.ResourceEventHandlerFuncs{
|
||||||
|
@ -42,15 +42,15 @@ 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 {
|
||||||
|
|
||||||
ingressAddCount := eventCount.WithLabelValues("ingress", "add")
|
ingressAddCount := eventCount.WithLabelValues(RoleIngress.String(), MetricLabelRoleAdd)
|
||||||
ingressUpdateCount := eventCount.WithLabelValues("ingress", "update")
|
ingressUpdateCount := eventCount.WithLabelValues(RoleIngress.String(), MetricLabelRoleUpdate)
|
||||||
ingressDeleteCount := eventCount.WithLabelValues("ingress", "delete")
|
ingressDeleteCount := eventCount.WithLabelValues(RoleIngress.String(), MetricLabelRoleDelete)
|
||||||
|
|
||||||
s := &Ingress{
|
s := &Ingress{
|
||||||
logger: l,
|
logger: l,
|
||||||
informer: inf,
|
informer: inf,
|
||||||
store: inf.GetStore(),
|
store: inf.GetStore(),
|
||||||
queue: workqueue.NewNamed("ingress"),
|
queue: workqueue.NewNamed(RoleIngress.String()),
|
||||||
}
|
}
|
||||||
|
|
||||||
_, err := s.informer.AddEventHandler(cache.ResourceEventHandlerFuncs{
|
_, err := s.informer.AddEventHandler(cache.ResourceEventHandlerFuncs{
|
||||||
|
@ -102,6 +102,16 @@ func (c *Role) UnmarshalYAML(unmarshal func(interface{}) error) error {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (c Role) String() string {
|
||||||
|
return string(c)
|
||||||
|
}
|
||||||
|
|
||||||
|
const (
|
||||||
|
MetricLabelRoleAdd = "add"
|
||||||
|
MetricLabelRoleDelete = "delete"
|
||||||
|
MetricLabelRoleUpdate = "update"
|
||||||
|
)
|
||||||
|
|
||||||
// SDConfig is the configuration for Kubernetes service discovery.
|
// SDConfig is the configuration for Kubernetes service discovery.
|
||||||
type SDConfig struct {
|
type SDConfig struct {
|
||||||
APIServer config.URL `yaml:"api_server,omitempty"`
|
APIServer config.URL `yaml:"api_server,omitempty"`
|
||||||
@ -351,8 +361,18 @@ func New(l log.Logger, reg prometheus.Registerer, conf *SDConfig) (*Discovery, e
|
|||||||
d.metricRegisterer = discovery.NewMetricRegisterer(reg, []prometheus.Collector{d.eventCount})
|
d.metricRegisterer = discovery.NewMetricRegisterer(reg, []prometheus.Collector{d.eventCount})
|
||||||
|
|
||||||
// Initialize metric vectors.
|
// Initialize metric vectors.
|
||||||
for _, role := range []string{"endpointslice", "endpoints", "node", "pod", "service", "ingress"} {
|
for _, role := range []string{
|
||||||
for _, evt := range []string{"add", "delete", "update"} {
|
RoleEndpointSlice.String(),
|
||||||
|
RoleEndpoint.String(),
|
||||||
|
RoleNode.String(),
|
||||||
|
RolePod.String(),
|
||||||
|
RoleService.String(),
|
||||||
|
RoleIngress.String()} {
|
||||||
|
for _, evt := range []string{
|
||||||
|
MetricLabelRoleAdd,
|
||||||
|
MetricLabelRoleDelete,
|
||||||
|
MetricLabelRoleUpdate,
|
||||||
|
} {
|
||||||
d.eventCount.WithLabelValues(role, evt)
|
d.eventCount.WithLabelValues(role, evt)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -50,15 +50,15 @@ func NewNode(l log.Logger, inf cache.SharedInformer, eventCount *prometheus.Coun
|
|||||||
l = log.NewNopLogger()
|
l = log.NewNopLogger()
|
||||||
}
|
}
|
||||||
|
|
||||||
nodeAddCount := eventCount.WithLabelValues("node", "add")
|
nodeAddCount := eventCount.WithLabelValues(RoleNode.String(), MetricLabelRoleAdd)
|
||||||
nodeUpdateCount := eventCount.WithLabelValues("node", "update")
|
nodeUpdateCount := eventCount.WithLabelValues(RoleNode.String(), MetricLabelRoleUpdate)
|
||||||
nodeDeleteCount := eventCount.WithLabelValues("node", "delete")
|
nodeDeleteCount := eventCount.WithLabelValues(RoleNode.String(), MetricLabelRoleDelete)
|
||||||
|
|
||||||
n := &Node{
|
n := &Node{
|
||||||
logger: l,
|
logger: l,
|
||||||
informer: inf,
|
informer: inf,
|
||||||
store: inf.GetStore(),
|
store: inf.GetStore(),
|
||||||
queue: workqueue.NewNamed("node"),
|
queue: workqueue.NewNamed(RoleNode.String()),
|
||||||
}
|
}
|
||||||
|
|
||||||
_, err := n.informer.AddEventHandler(cache.ResourceEventHandlerFuncs{
|
_, err := n.informer.AddEventHandler(cache.ResourceEventHandlerFuncs{
|
||||||
|
@ -51,9 +51,9 @@ func NewPod(l log.Logger, pods cache.SharedIndexInformer, nodes cache.SharedInfo
|
|||||||
l = log.NewNopLogger()
|
l = log.NewNopLogger()
|
||||||
}
|
}
|
||||||
|
|
||||||
podAddCount := eventCount.WithLabelValues("pod", "add")
|
podAddCount := eventCount.WithLabelValues(RolePod.String(), MetricLabelRoleAdd)
|
||||||
podDeleteCount := eventCount.WithLabelValues("pod", "delete")
|
podDeleteCount := eventCount.WithLabelValues(RolePod.String(), MetricLabelRoleDelete)
|
||||||
podUpdateCount := eventCount.WithLabelValues("pod", "update")
|
podUpdateCount := eventCount.WithLabelValues(RolePod.String(), MetricLabelRoleUpdate)
|
||||||
|
|
||||||
p := &Pod{
|
p := &Pod{
|
||||||
podInf: pods,
|
podInf: pods,
|
||||||
@ -61,7 +61,7 @@ func NewPod(l log.Logger, pods cache.SharedIndexInformer, nodes cache.SharedInfo
|
|||||||
withNodeMetadata: nodes != nil,
|
withNodeMetadata: nodes != nil,
|
||||||
store: pods.GetStore(),
|
store: pods.GetStore(),
|
||||||
logger: l,
|
logger: l,
|
||||||
queue: workqueue.NewNamed("pod"),
|
queue: workqueue.NewNamed(RolePod.String()),
|
||||||
}
|
}
|
||||||
_, err := p.podInf.AddEventHandler(cache.ResourceEventHandlerFuncs{
|
_, err := p.podInf.AddEventHandler(cache.ResourceEventHandlerFuncs{
|
||||||
AddFunc: func(o interface{}) {
|
AddFunc: func(o interface{}) {
|
||||||
|
@ -45,15 +45,15 @@ func NewService(l log.Logger, inf cache.SharedInformer, eventCount *prometheus.C
|
|||||||
l = log.NewNopLogger()
|
l = log.NewNopLogger()
|
||||||
}
|
}
|
||||||
|
|
||||||
svcAddCount := eventCount.WithLabelValues("service", "add")
|
svcAddCount := eventCount.WithLabelValues(RoleService.String(), MetricLabelRoleAdd)
|
||||||
svcUpdateCount := eventCount.WithLabelValues("service", "update")
|
svcUpdateCount := eventCount.WithLabelValues(RoleService.String(), MetricLabelRoleUpdate)
|
||||||
svcDeleteCount := eventCount.WithLabelValues("service", "delete")
|
svcDeleteCount := eventCount.WithLabelValues(RoleService.String(), MetricLabelRoleDelete)
|
||||||
|
|
||||||
s := &Service{
|
s := &Service{
|
||||||
logger: l,
|
logger: l,
|
||||||
informer: inf,
|
informer: inf,
|
||||||
store: inf.GetStore(),
|
store: inf.GetStore(),
|
||||||
queue: workqueue.NewNamed("service"),
|
queue: workqueue.NewNamed(RoleService.String()),
|
||||||
}
|
}
|
||||||
|
|
||||||
_, err := s.informer.AddEventHandler(cache.ResourceEventHandlerFuncs{
|
_, err := s.informer.AddEventHandler(cache.ResourceEventHandlerFuncs{
|
||||||
|
Loading…
Reference in New Issue
Block a user