Skip to content

Commit

Permalink
Silence health route by default
Browse files Browse the repository at this point in the history
Signed-off-by: Josh Dolitsky <jdolitsky@gmail.com>
  • Loading branch information
jdolitsky committed Nov 4, 2018
1 parent d9a698c commit 49e9b0e
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 7 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,7 @@ The contents of index.yaml will be printed to stdout and the program will exit.

#### Other CLI options
- `--log-json` - output structured logs as json
- `--log-health` - log incoming /health requests
- `--disable-api` - disable all routes prefixed with /api
- `--disable-statefiles` - disable use of index-cache.yaml
- `--allow-overwrite` - allow chart versions to be re-uploaded without ?force querystring
Expand Down
3 changes: 2 additions & 1 deletion cmd/chartmuseum/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ func cliHandler(c *cli.Context) {
ProvPostFormFieldName: conf.GetString("provpostformfieldname"),
ContextPath: conf.GetString("contextpath"),
LogJSON: conf.GetBool("logjson"),
LogHealth: conf.GetBool("loghealth"),
Debug: conf.GetBool("debug"),
EnableAPI: !conf.GetBool("disableapi"),
UseStatefiles: !conf.GetBool("disablestatefiles"),
Expand Down Expand Up @@ -116,7 +117,7 @@ func backendFromConfig(conf *config.Config) storage.Backend {
case "google":
backend = googleBackendFromConfig(conf)
case "oracle":
backend = oracleBackendFromConfig(conf)
backend = oracleBackendFromConfig(conf)
case "microsoft":
backend = microsoftBackendFromConfig(conf)
case "alibaba":
Expand Down
12 changes: 9 additions & 3 deletions pkg/chartmuseum/router/middleware.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package router
import (
"fmt"
"strconv"
"strings"
"sync/atomic"
"time"

Expand All @@ -33,12 +34,15 @@ var (
requestServedMessage = "Request served"
)

func requestWrapper(logger *cm_logger.Logger) func(c *gin.Context) {
func requestWrapper(logger *cm_logger.Logger, logHealth bool) func(c *gin.Context) {
return func(c *gin.Context) {
setupContext(c)

reqPath := c.Request.URL.Path
logger.Debugc(c, fmt.Sprintf("Incoming request: %s", reqPath))
logRequest := !strings.HasSuffix(reqPath, "/health") || logHealth
if logRequest {
logger.Debugc(c, fmt.Sprintf("Incoming request: %s", reqPath))
}
start := time.Now()

c.Next()
Expand All @@ -56,7 +60,9 @@ func requestWrapper(logger *cm_logger.Logger) func(c *gin.Context) {

switch {
case status == 200 || status == 201:
logger.Infoc(c, requestServedMessage, meta...)
if logRequest {
logger.Infoc(c, requestServedMessage, meta...)
}
case status == 404:
logger.Warnc(c, requestServedMessage, meta...)
default:
Expand Down
7 changes: 4 additions & 3 deletions pkg/chartmuseum/router/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ type (
TlsCert string
TlsKey string
PathPrefix string
LogHealth bool
EnableMetrics bool
AnonymousGet bool
Depth int
Expand Down Expand Up @@ -90,7 +91,7 @@ func NewRouter(options RouterOptions) *Router {
gin.SetMode(gin.ReleaseMode)
engine := gin.New()
engine.Use(gin.Recovery())
engine.Use(requestWrapper(options.Logger))
engine.Use(requestWrapper(options.Logger, options.LogHealth))
engine.Use(limits.RequestSizeLimiter(int64(options.MaxUploadSize)))

if options.EnableMetrics {
Expand All @@ -113,8 +114,8 @@ func NewRouter(options RouterOptions) *Router {
// if BearerAuth is true, looks for required inputs.
// example input:
// --bearer-auth=true
// --auth-realm="https://127.0.0.1:5001/auth"
// --auth-service="chartmuseum"
// --auth-realm="https://127.0.0.1:5001/auth"
// --auth-service="chartmuseum"
// --auth-issuer="Acme auth server"
// --auth-cert-path="./certs/authorization-server-cert.pem"
if options.BearerAuth {
Expand Down
2 changes: 2 additions & 0 deletions pkg/chartmuseum/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ type (
ProvPostFormFieldName string
ContextPath string
LogJSON bool
LogHealth bool
Debug bool
EnableAPI bool
UseStatefiles bool
Expand Down Expand Up @@ -88,6 +89,7 @@ func NewServer(options ServerOptions) (Server, error) {
ContextPath: contextPath,
TlsCert: options.TlsCert,
TlsKey: options.TlsKey,
LogHealth: options.LogHealth,
EnableMetrics: options.EnableMetrics,
AnonymousGet: options.AnonymousGet,
Depth: options.Depth,
Expand Down
9 changes: 9 additions & 0 deletions pkg/config/vars.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,15 @@ var configVars = map[string]configVar{
EnvVar: "LOG_JSON",
},
},
"loghealth": {
Type: boolType,
Default: false,
CLIFlag: cli.BoolFlag{
Name: "log-health",
Usage: "log inbound /health requests",
EnvVar: "LOG_HEALTH",
},
},
"disablemetrics": {
Type: boolType,
Default: false,
Expand Down

0 comments on commit 49e9b0e

Please sign in to comment.