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

server: suppress spurious blocking query returns where multiple config entries are involved #12362

Merged
merged 8 commits into from
Feb 25, 2022

Conversation

rboyer
Copy link
Member

@rboyer rboyer commented Feb 15, 2022

Starting from and extending the mechanism introduced in #12110 we can specially handle the 3 main special Consul RPC endpoints that react to many config entries in a single blocking query in Connect:

  • DiscoveryChain.Get
  • ConfigEntry.ResolveServiceConfig
  • Intentions.Match

All of these will internally watch for many config entries, and at least one of those will likely be not found in any given query. Because these are blends of multiple reads the exact solution from #12110 isn't perfectly aligned, but we can tweak the approach slightly and regain the utility of that mechanism.

No Config Entries Found

In this case, despite looking for many config entries none may be found at all. Unlike #12110 in this scenario we do not return an empty reply to the caller, but instead synthesize a struct from default values to return. This can be handled nearly identically to #12110 with the first 1-2 replies being non-empty payloads followed by the standard spurious wakeup suppression mechanism from #12110.

No Change Since Last Wakeup

Once a blocking query loop on the server has completed and slept at least once, there is a further optimization we can make here to detect if any of the config entries that were present at specific versions for the prior execution of the loop are identical for the loop we just woke up for. In that scenario we can return a slightly different internal sentinel error and basically externally handle it similar to #12110.

This would mean that even if 20 discovery chain read RPC handling goroutines wakeup due to the creation of an unrelated config entry, the only ones that will terminate and reply with a blob of data are those that genuinely have new data to report.

Extra Endpoints

Since this pattern is pretty reusable, other key config-entry-adjacent endpoints used by agent/proxycfg also were updated:

  • ConfigEntry.List
  • Internal.IntentionUpstreams (tproxy)

TODO:

  • Determine if the RPC for returning service-intentions would need similar treatment (YES)
    • determine how to do this in the least invasive way to make a backport less risky
  • analyze if hashstructure is a good alternative to use for outputs of the state store instead of the IndexSignature struct
  • tests for
    • Intentions.Match
    • ConfigEntry.List
    • Internal.IntentionUpstreams

@rboyer rboyer added the pr/do-not-merge PR cannot be merged in its current form. label Feb 15, 2022
@rboyer rboyer force-pushed the more-blocking-queries-not-found branch from b59362a to 5ac56a0 Compare February 15, 2022 23:28
@vercel vercel bot temporarily deployed to Preview – consul February 15, 2022 23:28 Inactive
@vercel vercel bot temporarily deployed to Preview – consul-ui-staging February 15, 2022 23:28 Inactive
for _, sid := range upstreamIDs {
if _, ok := seenUpstreams[sid]; !ok {
seenUpstreams[sid] = struct{}{}
// Fetch all relevant config entries. We will generate a
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The body of this blockingQuery call was changed into two steps:

  1. Get all config entries we will need.
  2. Smoosh those config entries together to fabricate the result.

Iterations after the first one will stop after (1) and check if any of the config entries collected differ from the prior iteration. If they do it returns the new data, otherwise it signals to the RPC side that it is a not-changed scenario.

@rboyer rboyer changed the title WIP: making some of the more complicated config-entry related endpoints ignore more blocking query wakeups WIP: make some config entry related endpoints ignore noop blocking query wakeups Feb 15, 2022
@vercel vercel bot temporarily deployed to Preview – consul-ui-staging February 17, 2022 19:09 Inactive
@vercel vercel bot temporarily deployed to Preview – consul February 17, 2022 19:09 Inactive
@vercel vercel bot temporarily deployed to Preview – consul-ui-staging February 17, 2022 20:02 Inactive
@vercel vercel bot temporarily deployed to Preview – consul February 17, 2022 20:02 Inactive
@vercel vercel bot temporarily deployed to Preview – consul-ui-staging February 17, 2022 22:26 Inactive
@vercel vercel bot temporarily deployed to Preview – consul February 17, 2022 22:26 Inactive
@vercel vercel bot temporarily deployed to Preview – consul-ui-staging February 17, 2022 22:38 Inactive
@vercel vercel bot temporarily deployed to Preview – consul February 17, 2022 22:38 Inactive
@vercel vercel bot temporarily deployed to Preview – consul February 17, 2022 22:53 Inactive
@vercel vercel bot temporarily deployed to Preview – consul-ui-staging February 17, 2022 22:53 Inactive
@vercel vercel bot temporarily deployed to Preview – consul-ui-staging February 17, 2022 22:55 Inactive
@vercel vercel bot temporarily deployed to Preview – consul February 17, 2022 22:55 Inactive
Base automatically changed from dnephin/blocking-queries-not-found to main February 17, 2022 23:09
@vercel vercel bot temporarily deployed to Preview – consul February 18, 2022 17:46 Inactive
@vercel vercel bot temporarily deployed to Preview – consul-ui-staging February 18, 2022 17:46 Inactive
@vercel vercel bot temporarily deployed to Preview – consul February 18, 2022 17:47 Inactive
@vercel vercel bot temporarily deployed to Preview – consul-ui-staging February 18, 2022 17:47 Inactive
@vercel vercel bot temporarily deployed to Preview – consul-ui-staging February 18, 2022 17:55 Inactive
@vercel vercel bot temporarily deployed to Preview – consul February 18, 2022 17:55 Inactive
@rboyer rboyer changed the title WIP: make some config entry related endpoints ignore noop blocking query wakeups server: suppress spurious blocking query returns where multiple config entries are involved Feb 18, 2022
@rboyer rboyer marked this pull request as ready for review February 18, 2022 18:06
@rboyer rboyer requested a review from a team February 18, 2022 18:06
@rboyer rboyer self-assigned this Feb 18, 2022
@vercel vercel bot temporarily deployed to Preview – consul-ui-staging February 23, 2022 17:08 Inactive
@vercel vercel bot temporarily deployed to Preview – consul February 23, 2022 17:08 Inactive
@rboyer rboyer requested a review from kisunji February 23, 2022 17:17
@vercel vercel bot temporarily deployed to Preview – consul-ui-staging February 23, 2022 17:19 Inactive
@vercel vercel bot temporarily deployed to Preview – consul February 23, 2022 17:19 Inactive
agent/consul/rpc_test.go Outdated Show resolved Hide resolved
Co-authored-by: Chris S. Kim <ckim@hashicorp.com>
@vercel vercel bot temporarily deployed to Preview – consul-ui-staging February 25, 2022 20:38 Inactive
@vercel vercel bot temporarily deployed to Preview – consul February 25, 2022 20:38 Inactive
@rboyer rboyer merged commit 7b0548d into main Feb 25, 2022
@rboyer rboyer deleted the more-blocking-queries-not-found branch February 25, 2022 21:46
@hc-github-team-consul-core
Copy link
Collaborator

🍒 If backport labels were added before merging, cherry-picking will start automatically.

To retroactively trigger a backport after merging, add backport labels and re-run https://circleci.com/gh/hashicorp/consul/597518.

@hc-github-team-consul-core
Copy link
Collaborator

🍒❌ Cherry pick of commit 7b0548d onto release/1.11.x failed! Build Log

rboyer added a commit that referenced this pull request Feb 25, 2022
…ple config entries are involved

Backport of #12362 to 1.11.x

Conflicts:
- agent/consul/config_endpoint_test.go (imports)
- go.mod (adjacencies)
rboyer added a commit that referenced this pull request Feb 25, 2022
…ple config entries are involved (#12457)

Backport of #12362 to 1.11.x

Conflicts:
- agent/consul/config_endpoint_test.go (imports)
- go.mod (adjacencies)
rboyer added a commit that referenced this pull request Feb 25, 2022
…ple config entries are involved

Backport of #12362 to 1.10.x

Conflicts:
- agent/consul/config_endpoint.go
- agent/consul/discovery_chain_endpoint_test.go
- agent/consul/intention_endpoint_test.go
- agent/consul/internal_endpoint.go
- agent/consul/internal_endpoint_test.go
- agent/consul/rpc.go
rboyer added a commit that referenced this pull request Feb 25, 2022
…ple config entries are involved (#12459)

* [1.10.x] server: suppress spurious blocking query returns where multiple config entries are involved

Backport of #12362 to 1.10.x

Conflicts:
- agent/consul/config_endpoint.go
- agent/consul/discovery_chain_endpoint_test.go
- agent/consul/intention_endpoint_test.go
- agent/consul/internal_endpoint.go
- agent/consul/internal_endpoint_test.go
- agent/consul/rpc.go

* update vendor
rboyer added a commit that referenced this pull request Mar 3, 2022
…12512)

Minor fix for behavior in #12362

IsDefault sometimes returns true even if there was a proxy-defaults or service-defaults config entry that was consulted. This PR fixes that.
hc-github-team-consul-core pushed a commit that referenced this pull request Mar 3, 2022
…12512)

Minor fix for behavior in #12362

IsDefault sometimes returns true even if there was a proxy-defaults or service-defaults config entry that was consulted. This PR fixes that.
hc-github-team-consul-core pushed a commit that referenced this pull request Mar 3, 2022
…12512)

Minor fix for behavior in #12362

IsDefault sometimes returns true even if there was a proxy-defaults or service-defaults config entry that was consulted. This PR fixes that.
rboyer added a commit that referenced this pull request Mar 4, 2022
…uery tests (#12518)

Improves tests from #12362

These tests try to setup the following concurrent scenario:

1. (goroutine 1) execute read RPC with index=0
2. (goroutine 1) get response from (1) @ index=10
3. (goroutine 1) execute read RPC with index=10 and block
4. (goroutine 2) WHILE (3) is blocking, start slamming the system with stray writes that will cause the WatchSet to wakeup
5. (goroutine 2) after doing all writes, shut down the reader above
6. (goroutine 1) stops reading, double checks that it only ever woke up once (from 1)
hc-github-team-consul-core pushed a commit that referenced this pull request Mar 4, 2022
…uery tests (#12518)

Improves tests from #12362

These tests try to setup the following concurrent scenario:

1. (goroutine 1) execute read RPC with index=0
2. (goroutine 1) get response from (1) @ index=10
3. (goroutine 1) execute read RPC with index=10 and block
4. (goroutine 2) WHILE (3) is blocking, start slamming the system with stray writes that will cause the WatchSet to wakeup
5. (goroutine 2) after doing all writes, shut down the reader above
6. (goroutine 1) stops reading, double checks that it only ever woke up once (from 1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants