Skip to content

Commit

Permalink
fix(): refactoring metric factory to accept prefix for the metrics (#27)
Browse files Browse the repository at this point in the history
* fix(): refactoring metric factory to accept prefix for the metrics

Signed-off-by: Puran Adhikari <puran.adhikari@aveshasystems.com>

* fix(): moving prefix set to NewMetricFactory method

Signed-off-by: Puran Adhikari <puran.adhikari@aveshasystems.com>

---------

Signed-off-by: Puran Adhikari <puran.adhikari@aveshasystems.com>
  • Loading branch information
PuranAdhikari authored May 3, 2023
1 parent c583470 commit edd2613
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions pkg/metrics/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ type MetricsFactoryOptions struct {
Cluster string
Namespace string
ReportingController string
Prefix string
}

type metricsFactory struct {
Expand All @@ -26,6 +27,9 @@ type metricsFactory struct {
}

func NewMetricsFactory(r prometheus.Registerer, o MetricsFactoryOptions) (MetricsFactory, error) {
if o.Prefix == "" {
o.Prefix = "kubeslice"
}
mf := &metricsFactory{
Registerer: r,
Options: o,
Expand Down Expand Up @@ -58,7 +62,7 @@ func (m *metricsFactory) getCurryLabels(labels []string) ([]string, prometheus.L
func (m *metricsFactory) NewCounter(name string, help string, labels []string) *prometheus.CounterVec {
labels, cl := m.getCurryLabels(labels)
return promauto.With(m.Registerer).NewCounterVec(prometheus.CounterOpts{
Namespace: "kubeslice",
Namespace: m.Options.Prefix,
Name: name,
Help: help,
}, labels).MustCurryWith(cl)
Expand All @@ -67,7 +71,7 @@ func (m *metricsFactory) NewCounter(name string, help string, labels []string) *
func (m *metricsFactory) NewGauge(name string, help string, labels []string) *prometheus.GaugeVec {
labels, cl := m.getCurryLabels(labels)
return promauto.With(m.Registerer).NewGaugeVec(prometheus.GaugeOpts{
Namespace: "kubeslice",
Namespace: m.Options.Prefix,
Name: name,
Help: help,
}, labels).MustCurryWith(cl)
Expand All @@ -76,7 +80,7 @@ func (m *metricsFactory) NewGauge(name string, help string, labels []string) *pr
func (m *metricsFactory) NewHistogram(name string, help string, labels []string) prometheus.ObserverVec {
labels, cl := m.getCurryLabels(labels)
return promauto.With(m.Registerer).NewHistogramVec(prometheus.HistogramOpts{
Namespace: "kubeslice",
Namespace: m.Options.Prefix,
Name: name,
Help: help,
}, labels).MustCurryWith(cl)
Expand Down

0 comments on commit edd2613

Please sign in to comment.