Skip to content

Commit

Permalink
Implement /healthz resource (#945)
Browse files Browse the repository at this point in the history
  • Loading branch information
mazay authored Oct 16, 2024
1 parent 80bb864 commit 0c48b52
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 8 deletions.
4 changes: 2 additions & 2 deletions charts/s3sync-service/templates/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ spec:
livenessProbe:
failureThreshold: 3
httpGet:
path: /info
path: /healthz
port: {{ .Values.httpServer.port }}
scheme: HTTP
initialDelaySeconds: 20
Expand All @@ -88,7 +88,7 @@ spec:
readinessProbe:
failureThreshold: 3
httpGet:
path: /info
path: /healthz
port: {{ .Values.httpServer.port }}
scheme: HTTP
initialDelaySeconds: 20
Expand Down
7 changes: 5 additions & 2 deletions service/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,10 @@ func (rh *ReloadHandler) handler(res http.ResponseWriter, req *http.Request) {
// HTTP handler wrapper function
func handlerWrapper(fn http.HandlerFunc) http.HandlerFunc {
return func(res http.ResponseWriter, req *http.Request) {
logger.Infof("%s - \"%s %s %s\" %s", req.RemoteAddr, req.Method,
req.URL.Path, req.Proto, strconv.FormatInt(req.ContentLength, 10))
if req.URL.Path != "/healthz" {
logger.Infof("%s - \"%s %s %s\" %s", req.RemoteAddr, req.Method,
req.URL.Path, req.Proto, strconv.FormatInt(req.ContentLength, 10))
}

res.Header().Set("Server", "s3sync-service"+"/"+version)
res.Header().Set("Content-Type", "application/json")
Expand All @@ -102,6 +104,7 @@ func prometheusExporter(metricsPort string, metricsPath string) {
func httpServer(httpPort string, reloaderChan chan<- bool) {
logger.Infof("starting http server on port %s", httpPort)
reloadHandler := ReloadHandler{Chan: reloaderChan}
http.HandleFunc("/healthz", handlerWrapper(infoHandler))
http.HandleFunc("/info", handlerWrapper(infoHandler))
http.HandleFunc("/reload", handlerWrapper(reloadHandler.handler))
logger.Fatalln(http.ListenAndServe(":"+httpPort, nil))
Expand Down
4 changes: 0 additions & 4 deletions service/http_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ func TestInfoHandler(t *testing.T) {
config.ChecksumWorkers,
config.LogLevel,
})

if err != nil {
t.Error(err.Error())
}
Expand Down Expand Up @@ -99,7 +98,6 @@ func TestReloadHandler(t *testing.T) {
startupTime,
status,
})

if err != nil {
t.Error(err.Error())
}
Expand All @@ -119,7 +117,6 @@ func TestPrometheusExporter(t *testing.T) {
time.Sleep(time.Second * 5)

resp, err := http.Get("http://127.0.0.1:9350/metrics")

if err != nil {
t.Error(err.Error())
}
Expand All @@ -141,7 +138,6 @@ func TestHttpServerr(t *testing.T) {
time.Sleep(time.Second * 5)

resp, err := http.Get("http://127.0.0.1:8090/info")

if err != nil {
t.Error(err.Error())
}
Expand Down

0 comments on commit 0c48b52

Please sign in to comment.