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

nsd: retain query params in HTTP health checks #17936

Merged
merged 3 commits into from
Jul 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
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
3 changes: 3 additions & 0 deletions .changelog/17936.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:bug
services: Fixed a bug that prevented passing query parameters in Nomad native service discovery HTTP health check paths
```
13 changes: 10 additions & 3 deletions client/serviceregistration/checks/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,11 +155,18 @@ func (c *checker) checkHTTP(ctx context.Context, qc *QueryContext, q *Query) *st
return qr
}

u := (&url.URL{
relative, err := url.Parse(q.Path)
if err != nil {
qr.Output = err.Error()
qr.Status = structs.CheckFailure
return qr
}

base := url.URL{
Scheme: q.Protocol,
Host: addr,
Path: q.Path,
}).String()
}
u := base.ResolveReference(relative).String()

request, err := http.NewRequest(q.Method, u, nil)
if err != nil {
Expand Down
23 changes: 23 additions & 0 deletions client/serviceregistration/checks/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,19 @@ func TestChecker_Do_HTTP(t *testing.T) {

// create an http server with various responses
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
// handle query param requests with string match because we want to
// test the path is set correctly instead of with escaped query params.
if strings.Contains(r.URL.Path, "query-param") {
if r.URL.RawQuery == "" {
w.WriteHeader(400)
_, _ = io.WriteString(w, "400 bad request")
} else {
w.WriteHeader(200)
_, _ = io.WriteString(w, "200 ok")
}
return
}

switch r.URL.Path {
case "/fail":
w.WriteHeader(500)
Expand Down Expand Up @@ -182,6 +195,16 @@ func TestChecker_Do_HTTP(t *testing.T) {
http.StatusCreated,
truncate,
),
}, {
name: "query param",
qc: makeQueryContext(),
q: makeQuery(structs.Healthiness, "query-param?a=b"),
expResult: makeExpResult(
structs.Healthiness,
structs.CheckSuccess,
http.StatusOK,
"nomad: http ok",
),
}}

for _, tc := range cases {
Expand Down
Loading