Skip to content

Commit

Permalink
fix: .*/healthz and .*/readyz endpoints for HTTP server
Browse files Browse the repository at this point in the history
  • Loading branch information
DrPsychick committed Apr 8, 2023
1 parent a0517d3 commit cb34fcf
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
3 changes: 2 additions & 1 deletion server.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"fmt"
"io"
"net/http"
"strings"
"sync"

"github.com/aws/aws-lambda-go/lambda"
Expand Down Expand Up @@ -197,7 +198,7 @@ func (m *ServeMux) Serve(b *ResponseBuilder, r *RequestEnvelope) {
// ServeHTTP dispatches the request to the handler whose
// alexa intent matches the request URL.
func (m *ServeMux) ServeHTTP(w http.ResponseWriter, r *http.Request) {
if r.URL != nil && (r.URL.Path == "/healthz" || r.URL.Path == "/readyz") {
if r.URL != nil && (strings.HasSuffix(r.URL.Path, "/livez") || strings.HasSuffix(r.URL.Path, "/readyz")) {
if _, err := w.Write([]byte("ok")); err != nil {
m.logger.Debug("failed to write response")
}
Expand Down
4 changes: 2 additions & 2 deletions server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ func TestServer(t *testing.T) {
func TestMuxServeHTTPProbes(t *testing.T) {
mux := NewServerMux(log.New(nil, log.ConsoleFormat(), log.Info))
rw := httptest.NewRecorder()
u, _ := url.Parse("http://anything/healthz")
u, _ := url.Parse("http://anything.net/livez")
r := &http.Request{Method: http.MethodGet, URL: u}

mux.ServeHTTP(rw, r)
Expand All @@ -46,7 +46,7 @@ func TestMuxServeHTTPProbes(t *testing.T) {
assert.Contains(t, string(res), "ok")

rw = httptest.NewRecorder()
u, _ = url.Parse("http://anything/readyz")
u, _ = url.Parse("http://anything.com/somethingelse/readyz")
r = &http.Request{Method: http.MethodGet, URL: u}

mux.ServeHTTP(rw, r)
Expand Down

0 comments on commit cb34fcf

Please sign in to comment.