44 "context"
55 "fmt"
66 "net/http"
7+ "strings"
78 "sync"
89 "sync/atomic"
910 "time"
@@ -142,9 +143,39 @@ func (bhm *BackendHealthManager) checkBackendHealth() bool {
142143 defer fasthttp .ReleaseRequest (req )
143144 defer fasthttp .ReleaseResponse (resp )
144145
145- // Simple GraphQL introspection query for health check
146+ // Determine the health check URL
147+ // If backendURL is just "http://host:port" or "http://host:port/", append /v1/graphql
148+ // If it has a path like "/v1/graphql", use that path
149+ healthCheckURL := bhm .backendURL
150+ hasGraphQLPath := false
151+
152+ if len (bhm .backendURL ) > 0 {
153+ // Simple check: if URL has a path component beyond just "/"
154+ lastSlash := - 1
155+ protoEnd := 0
156+ if idx := strings .Index (bhm .backendURL , "://" ); idx >= 0 {
157+ protoEnd = idx + 3
158+ }
159+ for i := protoEnd ; i < len (bhm .backendURL ); i ++ {
160+ if bhm .backendURL [i ] == '/' {
161+ lastSlash = i
162+ break
163+ }
164+ }
165+ // Has path if there's a slash after protocol and it's not the last char or followed by more path
166+ hasGraphQLPath = lastSlash >= protoEnd && lastSlash < len (bhm .backendURL )- 1
167+
168+ // If no GraphQL path, append /v1/graphql (standard Hasura endpoint)
169+ if ! hasGraphQLPath {
170+ // Remove trailing slash if present
171+ baseURL := strings .TrimSuffix (bhm .backendURL , "/" )
172+ healthCheckURL = baseURL + "/v1/graphql"
173+ }
174+ }
175+
176+ // Always send GraphQL introspection query for health check
146177 healthQuery := `{"query":"{__typename}"}`
147- req .SetRequestURI (bhm . backendURL )
178+ req .SetRequestURI (healthCheckURL )
148179 req .Header .SetMethod (http .MethodPost )
149180 req .Header .SetContentType ("application/json" )
150181 req .SetBody ([]byte (healthQuery ))
@@ -155,7 +186,8 @@ func (bhm *BackendHealthManager) checkBackendHealth() bool {
155186 bhm .logger .Debug (& libpack_logger.LogMessage {
156187 Message : "Backend health check failed" ,
157188 Pairs : map [string ]interface {}{
158- "error" : err .Error (),
189+ "error" : err .Error (),
190+ "check_url" : healthCheckURL ,
159191 },
160192 })
161193 return false
@@ -169,6 +201,7 @@ func (bhm *BackendHealthManager) checkBackendHealth() bool {
169201 Message : "Backend returned unhealthy status" ,
170202 Pairs : map [string ]interface {}{
171203 "status_code" : statusCode ,
204+ "check_url" : healthCheckURL ,
172205 },
173206 })
174207 }
0 commit comments