-
Notifications
You must be signed in to change notification settings - Fork 4.5k
health: ensure /v1/health/service/:service endpoint returns the most recent results when a filter is used with streaming #12640
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
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
```release-note:bug | ||
health: ensure /v1/health/service/:service endpoint returns the most recent results when a filter is used with streaming #12640 | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -679,6 +679,85 @@ func TestHealth_ServiceNodes(t *testing.T) { | |
} | ||
} | ||
|
||
func TestHealth_ServiceNodes_BlockingQuery_withFilter(t *testing.T) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Note: we can't test streaming here because streaming happens elsewhere. |
||
if testing.Short() { | ||
t.Skip("too slow for testing.Short") | ||
} | ||
|
||
t.Parallel() | ||
|
||
_, s1 := testServer(t) | ||
codec := rpcClient(t, s1) | ||
|
||
waitForLeaderEstablishment(t, s1) | ||
|
||
register := func(t *testing.T, name, tag string) { | ||
arg := structs.RegisterRequest{ | ||
Datacenter: "dc1", | ||
ID: types.NodeID("43d419c0-433b-42c3-bf8a-193eba0b41a3"), | ||
Node: "node1", | ||
Address: "127.0.0.1", | ||
Service: &structs.NodeService{ | ||
ID: name, | ||
Service: name, | ||
Tags: []string{tag}, | ||
}, | ||
} | ||
var out struct{} | ||
require.NoError(t, msgpackrpc.CallWithCodec(codec, "Catalog.Register", &arg, &out)) | ||
} | ||
|
||
register(t, "web", "foo") | ||
|
||
var lastIndex uint64 | ||
runStep(t, "read original", func(t *testing.T) { | ||
var out structs.IndexedCheckServiceNodes | ||
req := structs.ServiceSpecificRequest{ | ||
Datacenter: "dc1", | ||
ServiceName: "web", | ||
QueryOptions: structs.QueryOptions{ | ||
Filter: "foo in Service.Tags", | ||
}, | ||
} | ||
require.NoError(t, msgpackrpc.CallWithCodec(codec, "Health.ServiceNodes", &req, &out)) | ||
|
||
require.Len(t, out.Nodes, 1) | ||
node := out.Nodes[0] | ||
require.Equal(t, "node1", node.Node.Node) | ||
require.Equal(t, "web", node.Service.Service) | ||
require.Equal(t, []string{"foo"}, node.Service.Tags) | ||
|
||
require.Equal(t, structs.QueryBackendBlocking, out.Backend) | ||
lastIndex = out.Index | ||
}) | ||
|
||
runStep(t, "read blocking query result", func(t *testing.T) { | ||
req := structs.ServiceSpecificRequest{ | ||
Datacenter: "dc1", | ||
ServiceName: "web", | ||
QueryOptions: structs.QueryOptions{ | ||
Filter: "foo in Service.Tags", | ||
}, | ||
} | ||
req.MinQueryIndex = lastIndex | ||
|
||
var out structs.IndexedCheckServiceNodes | ||
errCh := channelCallRPC(s1, "Health.ServiceNodes", &req, &out, nil) | ||
|
||
time.Sleep(200 * time.Millisecond) | ||
|
||
// Change the tags | ||
register(t, "web", "bar") | ||
|
||
if err := <-errCh; err != nil { | ||
require.NoError(t, err) | ||
} | ||
|
||
require.Equal(t, structs.QueryBackendBlocking, out.Backend) | ||
require.Len(t, out.Nodes, 0) | ||
}) | ||
} | ||
|
||
func TestHealth_ServiceNodes_MultipleServiceTags(t *testing.T) { | ||
if testing.Short() { | ||
t.Skip("too slow for testing.Short") | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -80,11 +80,12 @@ func (s *healthView) Update(events []*pbsubscribe.Event) error { | |
return errors.New("check service node was unexpectedly nil") | ||
} | ||
passed, err := s.filter.Evaluate(*csn) | ||
switch { | ||
case err != nil: | ||
if err != nil { | ||
return err | ||
case passed: | ||
} else if passed { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. When the filter no longer matched an entry we did not GC the prior record. |
||
s.state[id] = *csn | ||
} else { | ||
delete(s.state, id) | ||
} | ||
|
||
case pbsubscribe.CatalogOp_Deregister: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In general it is not safe to mutate
reply
until just before returning. This is not the first time this kind of bug has manifested.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ugh. This makes me sad. This basically means the entire endpoint is not thread-safe if the response (aka
reply
) pointer is mutated? It would only apply to those endpoints that handle blocking queries, correct? There are a lot of endpoints that are implemented this way afaict and seems like a trap.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's only one thread/goroutine involved, but it loops around during retry without resetting the
reply
var, so depending upon how the access goes and how the body of the blocking query function proceeds you can get "carry over" between attempts that you didn't intend.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Example from the last time this kind of thing specifically caused a bug: #10239
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
#6316