Skip to content

Commit

Permalink
Merge pull request #209 from sgreene570/bz-1892338
Browse files Browse the repository at this point in the history
Bug 1892338: metrics: Rework template_router_reload_failure metric
  • Loading branch information
openshift-merge-robot committed Nov 9, 2020
2 parents 1785a68 + 839d822 commit d72b687
Showing 1 changed file with 14 additions and 11 deletions.
25 changes: 14 additions & 11 deletions pkg/router/template/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,8 @@ type templateRouter struct {
stateChanged bool
// metricReload tracks reloads
metricReload prometheus.Summary
// metricReloadFails tracks reload failures
metricReloadFails prometheus.Counter
// metricReloadFailure tracks reload failures
metricReloadFailure prometheus.Gauge
// metricWriteConfig tracks writing config
metricWriteConfig prometheus.Summary
// dynamicConfigManager configures route changes dynamically on the
Expand Down Expand Up @@ -201,12 +201,12 @@ func newTemplateRouter(cfg templateRouterCfg) (*templateRouter, error) {
Help: "Measures the time spent reloading the router in seconds.",
})
prometheus.MustRegister(metricsReload)
metricReloadFails := prometheus.NewCounter(prometheus.CounterOpts{
metricReloadFailure := prometheus.NewGauge(prometheus.GaugeOpts{
Namespace: "template_router",
Name: "reload_fails",
Help: "Tracks the number of failed router reloads",
Name: "reload_failure",
Help: "Metric to track the status of the most recent HAProxy reload",
})
prometheus.MustRegister(metricReloadFails)
prometheus.MustRegister(metricReloadFailure)
metricWriteConfig := prometheus.NewSummary(prometheus.SummaryOpts{
Namespace: "template_router",
Name: "write_config_seconds",
Expand Down Expand Up @@ -238,9 +238,9 @@ func newTemplateRouter(cfg templateRouterCfg) (*templateRouter, error) {
captureHTTPResponseHeaders: cfg.captureHTTPResponseHeaders,
captureHTTPCookie: cfg.captureHTTPCookie,

metricReload: metricsReload,
metricReloadFails: metricReloadFails,
metricWriteConfig: metricWriteConfig,
metricReload: metricsReload,
metricReloadFailure: metricReloadFailure,
metricWriteConfig: metricWriteConfig,

rateLimitedCommitFunction: nil,
}
Expand Down Expand Up @@ -464,11 +464,14 @@ func (r *templateRouter) commitAndReload() error {
if r.dynamicConfigManager != nil {
r.dynamicConfigManager.Notify(RouterEventReloadError)
}
// Increment the failed reload counter when a reload fails
r.metricReloadFails.Inc()
// Set the metricReloadFailure metric to true when a reload fails.
r.metricReloadFailure.Set(float64(1))
return err
}

// Set the metricReloadFailure metric to false when a reload succeeds.
r.metricReloadFailure.Set(float64(0))

if r.dynamicConfigManager != nil {
r.dynamicConfigManager.Notify(RouterEventReloadEnd)
}
Expand Down

0 comments on commit d72b687

Please sign in to comment.