Fixed metrics on/off setting

This commit is contained in:
kolaente 2019-09-01 18:39:03 +02:00
parent 43676f045c
commit 1d98e4cabe
No known key found for this signature in database
GPG key ID: F40E70337AB24C9B
2 changed files with 65 additions and 62 deletions

View file

@ -211,7 +211,7 @@ func GetUserFromClaims(claims jwt.MapClaims) (user *User, err error) {
func UpdateActiveUsersFromContext(c echo.Context) (err error) { func UpdateActiveUsersFromContext(c echo.Context) (err error) {
user, err := GetCurrentUser(c) user, err := GetCurrentUser(c)
if err != nil { if err != nil {
return err return
} }
allActiveUsers, err := metrics.GetActiveUsers() allActiveUsers, err := metrics.GetActiveUsers()

View file

@ -27,7 +27,9 @@ import (
) )
func setupMetrics(a *echo.Group) { func setupMetrics(a *echo.Group) {
if config.ServiceEnableMetrics.GetBool() { if !config.ServiceEnableMetrics.GetBool() {
return
}
if !config.RedisEnabled.GetBool() { if !config.RedisEnabled.GetBool() {
log.Fatal("You have to enable redis in order to use metrics") log.Fatal("You have to enable redis in order to use metrics")
@ -65,7 +67,7 @@ func setupMetrics(a *echo.Group) {
// Set initial totals // Set initial totals
total, err := models.GetTotalCount(c.Type) total, err := models.GetTotalCount(c.Type)
if err != nil { if err != nil {
log.Fatalf("Could not set initial count for %v, error was %s", c.Type, err) log.Fatalf("Could not get initial count for %v, error was %s", c.Type, err)
} }
if err := metrics.SetCount(total, c.Rediskey); err != nil { if err := metrics.SetCount(total, c.Rediskey); err != nil {
log.Fatalf("Could not set initial count for %v, error was %s", c.Type, err) log.Fatalf("Could not set initial count for %v, error was %s", c.Type, err)
@ -78,11 +80,13 @@ func setupMetrics(a *echo.Group) {
} }
a.GET("/metrics", echo.WrapHandler(promhttp.Handler())) a.GET("/metrics", echo.WrapHandler(promhttp.Handler()))
}
} }
func setupMetricsMiddleware(a *echo.Group) { func setupMetricsMiddleware(a *echo.Group) {
if config.ServiceJWTSecret.GetBool() { if !config.ServiceEnableMetrics.GetBool() {
return
}
a.Use(func(next echo.HandlerFunc) echo.HandlerFunc { a.Use(func(next echo.HandlerFunc) echo.HandlerFunc {
return func(c echo.Context) error { return func(c echo.Context) error {
@ -94,5 +98,4 @@ func setupMetricsMiddleware(a *echo.Group) {
return next(c) return next(c)
} }
}) })
}
} }