mirror of
https://github.com/prometheus/prometheus.git
synced 2025-03-05 20:59:13 -08: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()
|
||||
}
|
||||
|
||||
epAddCount := eventCount.WithLabelValues("endpoints", "add")
|
||||
epUpdateCount := eventCount.WithLabelValues("endpoints", "update")
|
||||
epDeleteCount := eventCount.WithLabelValues("endpoints", "delete")
|
||||
epAddCount := eventCount.WithLabelValues(RoleEndpoint.String(), MetricLabelRoleAdd)
|
||||
epUpdateCount := eventCount.WithLabelValues(RoleEndpoint.String(), MetricLabelRoleUpdate)
|
||||
epDeleteCount := eventCount.WithLabelValues(RoleEndpoint.String(), MetricLabelRoleDelete)
|
||||
|
||||
svcAddCount := eventCount.WithLabelValues("service", "add")
|
||||
svcUpdateCount := eventCount.WithLabelValues("service", "update")
|
||||
svcDeleteCount := eventCount.WithLabelValues("service", "delete")
|
||||
svcAddCount := eventCount.WithLabelValues(RoleService.String(), MetricLabelRoleAdd)
|
||||
svcUpdateCount := eventCount.WithLabelValues(RoleService.String(), MetricLabelRoleUpdate)
|
||||
svcDeleteCount := eventCount.WithLabelValues(RoleService.String(), MetricLabelRoleDelete)
|
||||
|
||||
e := &Endpoints{
|
||||
logger: l,
|
||||
|
@ -72,7 +72,7 @@ func NewEndpoints(l log.Logger, eps cache.SharedIndexInformer, svc, pod, node ca
|
|||
podStore: pod.GetStore(),
|
||||
nodeInf: node,
|
||||
withNodeMetadata: node != nil,
|
||||
queue: workqueue.NewNamed("endpoints"),
|
||||
queue: workqueue.NewNamed(RoleEndpoint.String()),
|
||||
}
|
||||
|
||||
_, err := e.endpointsInf.AddEventHandler(cache.ResourceEventHandlerFuncs{
|
||||
|
|
|
@ -57,13 +57,13 @@ func NewEndpointSlice(l log.Logger, eps cache.SharedIndexInformer, svc, pod, nod
|
|||
l = log.NewNopLogger()
|
||||
}
|
||||
|
||||
epslAddCount := eventCount.WithLabelValues("endpointslice", "add")
|
||||
epslUpdateCount := eventCount.WithLabelValues("endpointslice", "update")
|
||||
epslDeleteCount := eventCount.WithLabelValues("endpointslice", "delete")
|
||||
epslAddCount := eventCount.WithLabelValues(RoleEndpointSlice.String(), MetricLabelRoleAdd)
|
||||
epslUpdateCount := eventCount.WithLabelValues(RoleEndpointSlice.String(), MetricLabelRoleUpdate)
|
||||
epslDeleteCount := eventCount.WithLabelValues(RoleEndpointSlice.String(), MetricLabelRoleDelete)
|
||||
|
||||
svcAddCount := eventCount.WithLabelValues("service", "add")
|
||||
svcUpdateCount := eventCount.WithLabelValues("service", "update")
|
||||
svcDeleteCount := eventCount.WithLabelValues("service", "delete")
|
||||
svcAddCount := eventCount.WithLabelValues(RoleService.String(), MetricLabelRoleAdd)
|
||||
svcUpdateCount := eventCount.WithLabelValues(RoleService.String(), MetricLabelRoleUpdate)
|
||||
svcDeleteCount := eventCount.WithLabelValues(RoleService.String(), MetricLabelRoleDelete)
|
||||
|
||||
e := &EndpointSlice{
|
||||
logger: l,
|
||||
|
@ -75,7 +75,7 @@ func NewEndpointSlice(l log.Logger, eps cache.SharedIndexInformer, svc, pod, nod
|
|||
podStore: pod.GetStore(),
|
||||
nodeInf: node,
|
||||
withNodeMetadata: node != nil,
|
||||
queue: workqueue.NewNamed("endpointSlice"),
|
||||
queue: workqueue.NewNamed(RoleEndpointSlice.String()),
|
||||
}
|
||||
|
||||
_, err := e.endpointSliceInf.AddEventHandler(cache.ResourceEventHandlerFuncs{
|
||||
|
|
|
@ -42,15 +42,15 @@ type Ingress struct {
|
|||
// NewIngress returns a new ingress discovery.
|
||||
func NewIngress(l log.Logger, inf cache.SharedInformer, eventCount *prometheus.CounterVec) *Ingress {
|
||||
|
||||
ingressAddCount := eventCount.WithLabelValues("ingress", "add")
|
||||
ingressUpdateCount := eventCount.WithLabelValues("ingress", "update")
|
||||
ingressDeleteCount := eventCount.WithLabelValues("ingress", "delete")
|
||||
ingressAddCount := eventCount.WithLabelValues(RoleIngress.String(), MetricLabelRoleAdd)
|
||||
ingressUpdateCount := eventCount.WithLabelValues(RoleIngress.String(), MetricLabelRoleUpdate)
|
||||
ingressDeleteCount := eventCount.WithLabelValues(RoleIngress.String(), MetricLabelRoleDelete)
|
||||
|
||||
s := &Ingress{
|
||||
logger: l,
|
||||
informer: inf,
|
||||
store: inf.GetStore(),
|
||||
queue: workqueue.NewNamed("ingress"),
|
||||
queue: workqueue.NewNamed(RoleIngress.String()),
|
||||
}
|
||||
|
||||
_, 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.
|
||||
type SDConfig struct {
|
||||
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})
|
||||
|
||||
// Initialize metric vectors.
|
||||
for _, role := range []string{"endpointslice", "endpoints", "node", "pod", "service", "ingress"} {
|
||||
for _, evt := range []string{"add", "delete", "update"} {
|
||||
for _, role := range []string{
|
||||
RoleEndpointSlice.String(),
|
||||
RoleEndpoint.String(),
|
||||
RoleNode.String(),
|
||||
RolePod.String(),
|
||||
RoleService.String(),
|
||||
RoleIngress.String()} {
|
||||
for _, evt := range []string{
|
||||
MetricLabelRoleAdd,
|
||||
MetricLabelRoleDelete,
|
||||
MetricLabelRoleUpdate,
|
||||
} {
|
||||
d.eventCount.WithLabelValues(role, evt)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -50,15 +50,15 @@ func NewNode(l log.Logger, inf cache.SharedInformer, eventCount *prometheus.Coun
|
|||
l = log.NewNopLogger()
|
||||
}
|
||||
|
||||
nodeAddCount := eventCount.WithLabelValues("node", "add")
|
||||
nodeUpdateCount := eventCount.WithLabelValues("node", "update")
|
||||
nodeDeleteCount := eventCount.WithLabelValues("node", "delete")
|
||||
nodeAddCount := eventCount.WithLabelValues(RoleNode.String(), MetricLabelRoleAdd)
|
||||
nodeUpdateCount := eventCount.WithLabelValues(RoleNode.String(), MetricLabelRoleUpdate)
|
||||
nodeDeleteCount := eventCount.WithLabelValues(RoleNode.String(), MetricLabelRoleDelete)
|
||||
|
||||
n := &Node{
|
||||
logger: l,
|
||||
informer: inf,
|
||||
store: inf.GetStore(),
|
||||
queue: workqueue.NewNamed("node"),
|
||||
queue: workqueue.NewNamed(RoleNode.String()),
|
||||
}
|
||||
|
||||
_, err := n.informer.AddEventHandler(cache.ResourceEventHandlerFuncs{
|
||||
|
|
|
@ -51,9 +51,9 @@ 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")
|
||||
podAddCount := eventCount.WithLabelValues(RolePod.String(), MetricLabelRoleAdd)
|
||||
podDeleteCount := eventCount.WithLabelValues(RolePod.String(), MetricLabelRoleDelete)
|
||||
podUpdateCount := eventCount.WithLabelValues(RolePod.String(), MetricLabelRoleUpdate)
|
||||
|
||||
p := &Pod{
|
||||
podInf: pods,
|
||||
|
@ -61,7 +61,7 @@ func NewPod(l log.Logger, pods cache.SharedIndexInformer, nodes cache.SharedInfo
|
|||
withNodeMetadata: nodes != nil,
|
||||
store: pods.GetStore(),
|
||||
logger: l,
|
||||
queue: workqueue.NewNamed("pod"),
|
||||
queue: workqueue.NewNamed(RolePod.String()),
|
||||
}
|
||||
_, err := p.podInf.AddEventHandler(cache.ResourceEventHandlerFuncs{
|
||||
AddFunc: func(o interface{}) {
|
||||
|
|
|
@ -45,15 +45,15 @@ func NewService(l log.Logger, inf cache.SharedInformer, eventCount *prometheus.C
|
|||
l = log.NewNopLogger()
|
||||
}
|
||||
|
||||
svcAddCount := eventCount.WithLabelValues("service", "add")
|
||||
svcUpdateCount := eventCount.WithLabelValues("service", "update")
|
||||
svcDeleteCount := eventCount.WithLabelValues("service", "delete")
|
||||
svcAddCount := eventCount.WithLabelValues(RoleService.String(), MetricLabelRoleAdd)
|
||||
svcUpdateCount := eventCount.WithLabelValues(RoleService.String(), MetricLabelRoleUpdate)
|
||||
svcDeleteCount := eventCount.WithLabelValues(RoleService.String(), MetricLabelRoleDelete)
|
||||
|
||||
s := &Service{
|
||||
logger: l,
|
||||
informer: inf,
|
||||
store: inf.GetStore(),
|
||||
queue: workqueue.NewNamed("service"),
|
||||
queue: workqueue.NewNamed(RoleService.String()),
|
||||
}
|
||||
|
||||
_, err := s.informer.AddEventHandler(cache.ResourceEventHandlerFuncs{
|
||||
|
|
Loading…
Reference in a new issue