Skip to content

Commit

Permalink
Merge pull request #917 from xmidt-org/metrics-update
Browse files Browse the repository at this point in the history
Updated Metrics for Caduceus
  • Loading branch information
maurafortino authored Jun 14, 2023
2 parents b5f4dee + 2b2b89f commit 15c37f7
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 1 deletion.
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ require (
github.com/miekg/dns v1.1.54
github.com/mitchellh/mapstructure v1.5.0
github.com/prometheus/client_golang v1.15.1
github.com/prometheus/client_model v0.4.0 // indirect
github.com/segmentio/ksuid v1.0.4
github.com/spaolacci/murmur3 v1.1.0 // indirect
github.com/spf13/cast v1.5.1
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -1463,6 +1463,8 @@ github.com/prometheus/client_model v0.1.0/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6T
github.com/prometheus/client_model v0.2.0/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA=
github.com/prometheus/client_model v0.3.0 h1:UBgGFHqYdG/TPFD1B1ogZywDqEkwp3fBMvqdiQ7Xew4=
github.com/prometheus/client_model v0.3.0/go.mod h1:LDGWKZIo7rky3hgvBe+caln+Dr3dPggB5dvjtD7w9+w=
github.com/prometheus/client_model v0.4.0 h1:5lQXD3cAg1OXBf4Wq03gTrXHeaV0TQvGfUooCfx1yqY=
github.com/prometheus/client_model v0.4.0/go.mod h1:oMQmHW1/JoDwqLtg57MGgP/Fb1CJEYF2imWWhWtMkYU=
github.com/prometheus/common v0.0.0-20181113130724-41aa239b4cce/go.mod h1:daVV7qP5qjZbuso7PdcryaAu0sAZbrN9i7WWcTMWvro=
github.com/prometheus/common v0.0.0-20181126121408-4724e9255275/go.mod h1:daVV7qP5qjZbuso7PdcryaAu0sAZbrN9i7WWcTMWvro=
github.com/prometheus/common v0.2.0/go.mod h1:TNfzLD0ON7rHzMJeJkieUDPYmFC7Snx/y86RQel1bk4=
Expand Down
29 changes: 28 additions & 1 deletion xmetrics/registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ type Registry interface {
PrometheusProvider
provider.Provider
prometheus.Gatherer

NewPrometheusGaugeEx(namespace, subsystem, name string) prometheus.Gauge
NewPrometheusGauge(name string) prometheus.Gauge
}

// registry is the internal Registry implementation
Expand Down Expand Up @@ -97,7 +100,7 @@ func (r *registry) NewGaugeVecEx(namespace, subsystem, name string) *prometheus.
return gaugeVec
}

panic(fmt.Errorf("The preregistered metric %s is not a gauge", key))
panic(fmt.Errorf("the preregistered metric %s is not a gauge", key))
}

gaugeVec := prometheus.NewGaugeVec(
Expand Down Expand Up @@ -125,6 +128,30 @@ func (r *registry) NewGauge(name string) metrics.Gauge {
return gokitprometheus.NewGauge(r.NewGaugeVec(name))
}

func (r *registry) NewPrometheusGauge(name string) prometheus.Gauge {
return r.NewPrometheusGaugeEx(r.namespace, r.subsystem, name)
}

func (r *registry) NewPrometheusGaugeEx(namespace, subsystem, name string) prometheus.Gauge {

gauge := prometheus.NewGauge(prometheus.GaugeOpts{
Namespace: namespace,
Subsystem: subsystem,
Name: name,
Help: name,
})

if err := r.Register(gauge); err != nil {
if already, ok := err.(prometheus.AlreadyRegisteredError); ok {
return already.ExistingCollector.(prometheus.Gauge)
} else {
panic(err)
}
}

return gauge
}

func (r *registry) NewHistogramVec(name string) *prometheus.HistogramVec {
return r.NewHistogramVecEx(r.namespace, r.subsystem, name)
}
Expand Down

0 comments on commit 15c37f7

Please sign in to comment.