Skip to content

Commit

Permalink
Disable metrics endpoint access logs by default
Browse files Browse the repository at this point in the history
Switch off the metrics endpoint access logs as it's unlikely they're
going to be of significant value, but allow them to be re-enabled by the
command-line or configuration file.
  • Loading branch information
jonathanio committed Aug 15, 2024
1 parent fa9d48d commit d7aa62e
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 7 deletions.
1 change: 1 addition & 0 deletions config/serve.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@ endpoints:

logging:
json: true
metrics: false
level: debug
4 changes: 4 additions & 0 deletions internal/cmd/serve.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,10 @@ func init() {
flags.Int("shutdown-timeout", shutdownTimeout, "Timeout (in seconds) to wait for requests to finish")
_ = viper.BindPFlag("endpoints.timeouts.shutdown", flags.Lookup("shutdown-timeout"))

viper.SetDefault("logging.metrics", false)
flags.Bool("log-metrics", false, "Set whether to log metrics port requests")
_ = viper.BindPFlag("logging.metrics", flags.Lookup("log-metrics"))

rootCmd.AddCommand(serveCmd)
}

Expand Down
5 changes: 4 additions & 1 deletion internal/serve/metrics/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,10 @@ type Service struct {
func NewService() *Service {
router := gin.New()

router.Use(middleware.Logger())
if viper.GetBool("logging.metrics") {
router.Use(middleware.Logger())
}

router.Use(middleware.Prometheus("metrics"))
router.Use(gin.Recovery())

Expand Down
5 changes: 0 additions & 5 deletions internal/serve/middleware/logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,6 @@ func Logger() gin.HandlerFunc {
http.StatusUnauthorized,
http.StatusNotFound,
),
// slogg.IgnorePath(
// "/alive",
// "/healthz",
// "/metrics",
// ),
},
},
)
Expand Down
11 changes: 10 additions & 1 deletion schemas/serve.json
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,9 @@
"level": {
"$ref": "#/$defs/logging-level"
},
"metrics": {
"$ref": "#/$defs/logging-metrics"
},
"json": {
"$ref": "#/$defs/logging-json"
}
Expand All @@ -181,9 +184,15 @@
"type": "string",
"enum": ["debug", "info", "warning", "error"]
},
"logging-metrics": {
"description": "Set whether or not to log requests to the metrics port",
"type": "boolean",
"default": false
},
"logging-json": {
"description": "Set whether or not to use JSON-based structured logging",
"type": "boolean"
"type": "boolean",
"default": false
}
},
"type": "object",
Expand Down

0 comments on commit d7aa62e

Please sign in to comment.