Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Include HealthCheck in server pkg #44

Merged
merged 7 commits into from
Dec 2, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ require (
github.com/prometheus/client_golang v1.11.0
github.com/prometheus/common v0.26.0
github.com/sirupsen/logrus v1.8.1
google.golang.org/grpc v1.41.0
google.golang.org/protobuf v1.27.1
k8s.io/api v0.22.2
k8s.io/apimachinery v0.22.2
k8s.io/utils v0.0.0-20210930125809-cb0fa318a74b
Expand Down Expand Up @@ -90,6 +88,8 @@ require (
gomodules.xyz/jsonpatch/v2 v2.2.0 // indirect
google.golang.org/appengine v1.6.7 // indirect
google.golang.org/genproto v0.0.0-20210602131652-f16073e35f0c // indirect
google.golang.org/grpc v1.41.0 // indirect
google.golang.org/protobuf v1.27.1 // indirect
gopkg.in/inf.v0 v0.9.1 // indirect
gopkg.in/square/go-jose.v2 v2.5.1 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
Expand Down
6 changes: 6 additions & 0 deletions pkg/common/server/middlewares.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,9 @@ func (s Server) setUserID() gin.HandlerFunc {
c.Next()
}
}

func (s Server) healthz() gin.HandlerFunc {
return func(ctx *gin.Context) {
ctx.Status(http.StatusNoContent)
}
}
5 changes: 5 additions & 0 deletions pkg/common/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,3 +85,8 @@ func (s *Server) RunSecurely(ctx context.Context) {
s.log.Infof("Server exiting")
}()
}

// UseHealthCheck creates a new HealthCheck route
func (s *Server) UseHealthCheck() {
wsalles marked this conversation as resolved.
Show resolved Hide resolved
s.Router.GET(s.configuration.HealthCheckEndpoint, s.healthz())
}
13 changes: 7 additions & 6 deletions pkg/common/server/server_configuration.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,13 @@ import (

// HTTPServerConfiguration is a struct that holds all the environment variables required to the HTTP server
type HTTPServerConfiguration struct {
Host string `envconfig:"HTTP_HOST" default:""`
Port int `envconfig:"HTTP_PORT" default:"80"`
RequestTimeout time.Duration `envconfig:"HTTP_REQUEST_TIMEOUT" default:"30s"`
UserID string `envconfig:"USER_ID" required:"true"`
CertificateFile string `envconfig:"CERTIFICATE_FILE" default:"/etc/tls/tls.crt"`
CertificateKeyFile string `envconfig:"CERTIFICATE_KEY_FILE" default:"/etc/tls/tls.key"`
Host string `envconfig:"HTTP_HOST" default:""`
Port int `envconfig:"HTTP_PORT" default:"80"`
RequestTimeout time.Duration `envconfig:"HTTP_REQUEST_TIMEOUT" default:"30s"`
UserID string `envconfig:"USER_ID" default:""`
CertificateFile string `envconfig:"CERTIFICATE_FILE" default:"/etc/tls/tls.crt"`
CertificateKeyFile string `envconfig:"CERTIFICATE_KEY_FILE" default:"/etc/tls/tls.key"`
HealthCheckEndpoint string `envconfig:"HEALTH_CHECK_ENDPOINT" default:"/healthz"`
}

// LoadFromEnvVars reads all env vars required for the server package
Expand Down