Skip to content

Commit

Permalink
allow to namespace the metric
Browse files Browse the repository at this point in the history
  • Loading branch information
matteosuppo committed Mar 5, 2020
1 parent 439d92a commit 8dd011a
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions metrics/collection.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,20 @@ import (
// MetricsCollection allows you to query multiple introspector
type MetricsCollection struct {
Collection []introspector.Introspector
namespace string
counter *prometheus.CounterVec
}

func NewMetricsCollection(collection ...introspector.Introspector) MetricsCollection {
func NewMetricsCollection(namespace string, collection ...introspector.Introspector) MetricsCollection {
counter := prometheus.NewCounterVec(prometheus.CounterOpts{
Name: "introspector_counts",
Help: "The requests to introspect a token and which introspector responds",
}, []string{"introspector"})
}, []string{"namespace", "introspector"})
prometheus.MustRegister(counter)

return MetricsCollection{
Collection: collection,
namespace: namespace,
counter: counter,
}
}
Expand All @@ -35,12 +37,12 @@ func (c MetricsCollection) Introspect(token string) (introspector.Introspection,
for i := range c.Collection {
intro, err := c.Collection[i].Introspect(token)
if err == nil {
c.counter.WithLabelValues(fmt.Sprintf("%T", c.Collection[i])).Inc()
c.counter.WithLabelValues(c.namespace, fmt.Sprintf("%T", c.Collection[i])).Inc()
return intro, nil
}
errs = append(errs, err)
}

c.counter.WithLabelValues("none").Inc()
c.counter.WithLabelValues(c.namespace, "none").Inc()
return introspector.Introspection{}, errs.Err()
}

0 comments on commit 8dd011a

Please sign in to comment.