-
Notifications
You must be signed in to change notification settings - Fork 4.4k
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
Support "near" parameter in prepared query service block #2137
Changes from 10 commits
3797e65
865c264
100a467
4c1afb1
03fea4b
d567d6a
c457ee0
0c2ad07
104b234
62884a2
00819e8
7fd0c3c
01b28b9
46b6726
2b24644
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -368,7 +368,25 @@ func (p *PreparedQuery) Execute(args *structs.PreparedQueryExecuteRequest, | |
// Shuffle the results in case coordinates are not available if they | ||
// requested an RTT sort. | ||
reply.Nodes.Shuffle() | ||
if err := p.srv.sortNodesByDistanceFrom(args.Source, reply.Nodes); err != nil { | ||
|
||
// Build the query source. This can be provided by the client, or by | ||
// the prepared query. Client-specified takes priority. | ||
qs := args.Source | ||
if qs.Datacenter == "" { | ||
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. DC should always be supplied by |
||
qs.Datacenter = args.Agent.Datacenter | ||
} | ||
if query.Service.Near != "" && qs.Node == "" { | ||
qs.Node = query.Service.Near | ||
} | ||
|
||
// Respect the magic "_agent" flag. | ||
if qs.Node == "_agent" { | ||
qs.Node = args.Agent.Node | ||
} | ||
|
||
// Perform the distance sort | ||
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. Do we want to memoize this value for ~60s or whatever the interval is for the tomography calcs? I seem to recall someone saying this calc was "expensive," but if it's not, disregard. DNS can set a TTL, so maybe this isn't a huge issue, but that depends on the level of DNS caching at a given site. 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. It's not too bad - I'd probably leave as-is since this can be DNS TTL-ed and read-scaled with staleness across the servers. |
||
err = p.srv.sortNodesByDistanceFrom(qs, reply.Nodes) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
|
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.
I think this'll break other endpoints that depend on
?near=_agent
getting resolved at this level. I think you can pass the existingSource
member of the execute request into here.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.
Does it break? This just pushes the check out to the
consul
side instead of theagent
. I was trying to avoid checking the magic flag in the agent and on the consul side (since theNear
parameter can live in either place now).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.
Still think you'll need to revert this change - should not be needed any more and there are other RPC endpoints that do the sort which rely on
_agent
getting resolved on the agent side, not the server side.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.
Oh I see, catalog and health both allow distance sorting. Will fix!