Skip to content

Commit

Permalink
Do not log health check endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
brycekahle committed Oct 10, 2017
1 parent d56dad0 commit 6589daa
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 4 deletions.
6 changes: 4 additions & 2 deletions api/api.go
Expand Up @@ -63,16 +63,17 @@ func NewAPIWithVersion(ctx context.Context, globalConfig *conf.GlobalConfigurati
}

xffmw, _ := xff.Default()
logger := newStructuredLogger(logrus.StandardLogger())

r := newRouter()
r.UseBypass(xffmw.Handler)
r.Use(withRequestID)
r.UseBypass(newStructuredLogger(logrus.StandardLogger()))
r.Use(recoverer)

r.Get("/health", api.HealthCheck)

r.Route("/", func(r *router) {
r.UseBypass(logger)
if globalConfig.MultiInstanceMode {
r.Use(api.loadInstanceConfig)
}
Expand Down Expand Up @@ -120,8 +121,9 @@ func NewAPIWithVersion(ctx context.Context, globalConfig *conf.GlobalConfigurati

if globalConfig.MultiInstanceMode {
// Operator microservice API
r.With(api.verifyOperatorRequest).Get("/", api.GetAppManifest)
r.WithBypass(logger).With(api.verifyOperatorRequest).Get("/", api.GetAppManifest)
r.Route("/instances", func(r *router) {
r.UseBypass(logger)
r.Use(api.verifyOperatorRequest)

r.Post("/", api.CreateInstance)
Expand Down
10 changes: 8 additions & 2 deletions api/api_test.go
Expand Up @@ -16,6 +16,9 @@ import (
func TestTraceWrapper(t *testing.T) {
hook := test.NewGlobal()
globalConfig := new(conf.GlobalConfiguration)
globalConfig.MultiInstanceMode = true
globalConfig.OperatorToken = "token"

config := new(conf.Configuration)
config.Payment.Stripe.Enabled = true
config.Payment.Stripe.SecretKey = "secret"
Expand All @@ -28,7 +31,10 @@ func TestTraceWrapper(t *testing.T) {
defer server.Close()

client := http.Client{}
rsp, err := client.Get(server.URL + "/health")
req, err := http.NewRequest(http.MethodGet, server.URL+"/", nil)
require.NoError(t, err)
req.Header.Add("Authorization", "Bearer token")
rsp, err := client.Do(req)
require.NoError(t, err)
assert.Equal(t, http.StatusOK, rsp.StatusCode)
assert.True(t, len(hook.Entries) > 0)
Expand All @@ -39,7 +45,7 @@ func TestTraceWrapper(t *testing.T) {
}
expected := map[string]string{
"method": "GET",
"path": "/health",
"path": "/",
}
for k, v := range expected {
if value, ok := entry.Data[k]; ok {
Expand Down
5 changes: 5 additions & 0 deletions api/router.go
Expand Up @@ -39,6 +39,11 @@ func (r *router) With(fn middlewareHandler) *router {
return &router{c}
}

func (r *router) WithBypass(fn func(next http.Handler) http.Handler) *router {
c := r.chi.With(fn)
return &router{c}
}

func (r *router) Use(fn middlewareHandler) {
r.chi.Use(middleware(fn))
}
Expand Down

0 comments on commit 6589daa

Please sign in to comment.