From 38628e5f3d42ad4c5477a22f402e6fd9b8ea28d0 Mon Sep 17 00:00:00 2001 From: Shourie Ganguly Date: Wed, 17 Jul 2024 16:13:05 +0530 Subject: [PATCH] added health check to mock-service container --- .../_dev/deploy/docker/docker-compose.yml | 4 ++++ .../docker/websocket-mock-service/main.go | 19 ++++++++++++------- 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/packages/websocket/_dev/deploy/docker/docker-compose.yml b/packages/websocket/_dev/deploy/docker/docker-compose.yml index a5a1ed54ba2..3f6c4a1e898 100644 --- a/packages/websocket/_dev/deploy/docker/docker-compose.yml +++ b/packages/websocket/_dev/deploy/docker/docker-compose.yml @@ -8,4 +8,8 @@ services: - ./websocket-mock-service:/app ports: - "3000:3000" + healthcheck: + test: "wget --no-verbose --tries=1 --spider http://localhost:3000/health || exit 1" + interval: 10s + timeout: 5s command: ["go", "run", "main.go"] diff --git a/packages/websocket/_dev/deploy/docker/websocket-mock-service/main.go b/packages/websocket/_dev/deploy/docker/websocket-mock-service/main.go index 4e22471f7a6..393e7afd03e 100644 --- a/packages/websocket/_dev/deploy/docker/websocket-mock-service/main.go +++ b/packages/websocket/_dev/deploy/docker/websocket-mock-service/main.go @@ -17,15 +17,10 @@ func main() { } func handleWebSocket(w http.ResponseWriter, r *http.Request) { - upgrader := websocket.Upgrader{ - CheckOrigin: func(r *http.Request) bool { return true }, - } - conn, err := upgrader.Upgrade(w, r, nil) - if err != nil { - log.Println(err) + + if r.URL.Path == "/health" { return } - defer conn.Close() if r.URL.Path == "/testbasicauth" { // Check if the 'Authorization' header is set for basic authentication @@ -38,6 +33,16 @@ func handleWebSocket(w http.ResponseWriter, r *http.Request) { } } + upgrader := websocket.Upgrader{ + CheckOrigin: func(r *http.Request) bool { return true }, + } + conn, err := upgrader.Upgrade(w, r, nil) + if err != nil { + log.Println(err) + return + } + defer conn.Close() + var responseMessage []map[string]string if r.URL.Path == "/testbasicauth" {