mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-23 11:50:44 +00:00
Provides register apis for custom collector
This commit is contained in:
parent
6f8595b2ef
commit
c75ec1a244
@ -85,3 +85,22 @@ func RawRegister(c prometheus.Collector) error {
|
|||||||
prometheus.Register(c)
|
prometheus.Register(c)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// CustomRegister registers a custom collector but uses the global registry.
|
||||||
|
func CustomRegister(c metrics.StableCollector) error {
|
||||||
|
err := defaultRegistry.CustomRegister(c)
|
||||||
|
|
||||||
|
//TODO(RainbowMango): Maybe we can wrap this error by error wrapping.(Golang 1.13)
|
||||||
|
_ = prometheus.Register(c)
|
||||||
|
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// CustomMustRegister registers custom collectors but uses the global registry.
|
||||||
|
func CustomMustRegister(cs ...metrics.StableCollector) {
|
||||||
|
defaultRegistry.CustomMustRegister(cs...)
|
||||||
|
|
||||||
|
for _, c := range cs {
|
||||||
|
prometheus.MustRegister(c)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -78,6 +78,8 @@ type KubeRegistry interface {
|
|||||||
RawRegister(prometheus.Collector) error
|
RawRegister(prometheus.Collector) error
|
||||||
// Deprecated
|
// Deprecated
|
||||||
RawMustRegister(...prometheus.Collector)
|
RawMustRegister(...prometheus.Collector)
|
||||||
|
CustomRegister(c StableCollector) error
|
||||||
|
CustomMustRegister(cs ...StableCollector)
|
||||||
Register(Registerable) error
|
Register(Registerable) error
|
||||||
MustRegister(...Registerable)
|
MustRegister(...Registerable)
|
||||||
Unregister(Registerable) bool
|
Unregister(Registerable) bool
|
||||||
@ -117,6 +119,29 @@ func (kr *kubeRegistry) MustRegister(cs ...Registerable) {
|
|||||||
kr.PromRegistry.MustRegister(metrics...)
|
kr.PromRegistry.MustRegister(metrics...)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// CustomRegister registers a new custom collector.
|
||||||
|
func (kr *kubeRegistry) CustomRegister(c StableCollector) error {
|
||||||
|
if c.Create(&kr.version, c) {
|
||||||
|
return kr.PromRegistry.Register(c)
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// CustomMustRegister works like CustomRegister but registers any number of
|
||||||
|
// StableCollectors and panics upon the first registration that causes an
|
||||||
|
// error.
|
||||||
|
func (kr *kubeRegistry) CustomMustRegister(cs ...StableCollector) {
|
||||||
|
collectors := make([]prometheus.Collector, 0, len(cs))
|
||||||
|
for _, c := range cs {
|
||||||
|
if c.Create(&kr.version, c) {
|
||||||
|
collectors = append(collectors, c)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
kr.PromRegistry.MustRegister(collectors...)
|
||||||
|
}
|
||||||
|
|
||||||
// RawRegister takes a native prometheus.Collector and registers the collector
|
// RawRegister takes a native prometheus.Collector and registers the collector
|
||||||
// to the registry. This bypasses metrics safety checks, so should only be used
|
// to the registry. This bypasses metrics safety checks, so should only be used
|
||||||
// to register custom prometheus collectors.
|
// to register custom prometheus collectors.
|
||||||
|
Loading…
Reference in New Issue
Block a user