Skip to content

Commit

Permalink
Merge pull request #491 from alphagov/add-source-labels
Browse files Browse the repository at this point in the history
Add source label for router reload metrics
  • Loading branch information
theseanything authored Nov 4, 2024
2 parents 3597f55 + 9f1422c commit ea5fc42
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
5 changes: 3 additions & 2 deletions lib/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,15 @@ var (
0.99: 0.005,
},
},
[]string{"success"},
[]string{"success", "source"},
)

routesCountMetric = prometheus.NewGauge(
routesCountMetric = prometheus.NewGaugeVec(
prometheus.GaugeOpts{
Name: "router_routes_loaded",
Help: "Number of routes currently loaded",
},
[]string{"source"},
)
)

Expand Down
4 changes: 2 additions & 2 deletions lib/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ type mongoDatabase interface {
func (rt *Router) reloadRoutes(db *mgo.Database, currentOptime bson.MongoTimestamp) {
var success bool
timer := prometheus.NewTimer(prometheus.ObserverFunc(func(v float64) {
labels := prometheus.Labels{"success": strconv.FormatBool(success)}
labels := prometheus.Labels{"success": strconv.FormatBool(success), "source": "mongo"}
routeReloadDurationMetric.With(labels).Observe(v)
}))
defer func() {
Expand Down Expand Up @@ -246,7 +246,7 @@ func (rt *Router) reloadRoutes(db *mgo.Database, currentOptime bson.MongoTimesta
rt.lock.Unlock()

logInfo(fmt.Sprintf("router: reloaded %d routes", routeCount))
routesCountMetric.Set(float64(routeCount))
routesCountMetric.WithLabelValues("mongo").Set(float64(routeCount))
}

func (rt *Router) getCurrentMongoInstance(db mongoDatabase) (MongoReplicaSetMember, error) {
Expand Down

0 comments on commit ea5fc42

Please sign in to comment.