Skip to content

[Overload] Active downstream connections resource monitor - #23361

Merged
KBaichoo merged 11 commits into
envoyproxy:mainfrom
nezdolik:downst-conn-monitor
Nov 2, 2022
Merged

KBaichoo merged 11 commits into
envoyproxy:mainfrom
nezdolik:downst-conn-monitor

Conversation

@nezdolik

@nezdolik nezdolik commented Oct 4, 2022

Copy link
Copy Markdown
Member

Signed-off-by: Kateryna Nezdolii [email protected]

Thread safe version of Active downstream connections resource monitor based on new proactive checks in overload manager framework. Continuation of work started in this #15707. After this PR is merged, we could replace existing global&per-listener connections tracking mechanism in TCP Listener and plug overload manager downstream connections resource monitor instead.
-->

Commit Message:
Additional Description:
Risk Level: Low (new extension not wired up with existing code)
Testing: Done
Docs Changes:
Release Notes:
Fixes #12419

@repokitteh-read-only

Copy link
Copy Markdown

CC @envoyproxy/api-shepherds: Your approval is needed for changes made to (api/envoy/|docs/root/api-docs/).
envoyproxy/api-shepherds assignee is @markdroth
CC @envoyproxy/api-watchers: FYI only for changes made to (api/envoy/|docs/root/api-docs/).

🐱

Caused by: #23361 was opened by nezdolik.

see: more, trace.

Signed-off-by: Kateryna Nezdolii <[email protected]>
@nezdolik

nezdolik commented Oct 4, 2022

Copy link
Copy Markdown
Member Author

/retest

@repokitteh-read-only

Copy link
Copy Markdown

Retrying Azure Pipelines:
Retried failed jobs in: envoy-presubmit

🐱

Caused by: a #23361 (comment) was created by @nezdolik.

see: more, trace.

Kateryna Nezdolii added 4 commits October 6, 2022 19:24
Signed-off-by: Kateryna Nezdolii <[email protected]>
Signed-off-by: Kateryna Nezdolii <[email protected]>
Signed-off-by: Kateryna Nezdolii <[email protected]>
Signed-off-by: Kateryna Nezdolii <[email protected]>

@KBaichoo KBaichoo left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks for working on this! Here's a first pass


// The downstream connections resource monitor tracks the global number of open downstream connections.
message DownstreamConnectionsConfig {
// Maximum threshold for global open active downstream connections, defaults to 0.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I suspect this is just for open downstream connections? e.g. if a connection is idle (not active) (no request, etc.) it will still be counted against this, right?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Right, the monitor will only track open connections on socket accept (in tcp listener). Good catch.

deps = [
":downstream_connections_monitor",
"//envoy/registry",
"//source/common/common:assert_lib",

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

seems unused?

#include "envoy/extensions/resource_monitors/downstream_connections/v3/downstream_connections.pb.h"
#include "envoy/server/proactive_resource_monitor.h"

#include "source/common/common/assert.h"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

seems unused, here and in cc. If so can we also remove dependency in build?

int64_t maxResourceUsage() const override;

protected:
int64_t max_;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

const


bool ActiveDownstreamConnectionsResourceMonitor::tryAllocateResource(int64_t increment) {
auto current = current_.load(std::memory_order_relaxed);
while (current + increment <= max_) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

can we document the logic here of why this works? Since these primitives can be non-obvious, thanks

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

sure


bool ActiveDownstreamConnectionsResourceMonitor::tryDeallocateResource(int64_t decrement) {
auto current = current_.load(std::memory_order_relaxed);
while (current - decrement >= 0) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

likewise as above

auto factory =
Registry::FactoryRegistry<Server::Configuration::ProactiveResourceMonitorFactory>::getFactory(
"envoy.resource_monitors.downstream_connections");
ASSERT(factory != nullptr);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

prefer ASSERT_NE(factory,nullptr) here and below

// The downstream connections resource monitor tracks the global number of open downstream connections.
message DownstreamConnectionsConfig {
// Maximum threshold for global open active downstream connections, defaults to 0.
// If monitor is configured via Overload manager api and has no value set, Envoy will reject all incoming connections.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

public:
void initialize(const envoy::extensions::resource_monitors::downstream_connections::v3::
DownstreamConnectionsConfig& config) {
monitor_ = std::make_unique<ActiveDownstreamConnectionsResourceMonitor>(config);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

what's the reason to not stamp it from the factory that creates these monitors, which better reflects how these would be created in practice? It would also remove edge case of default config (ie. 0 getting through)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

monitor creation through factory is covered by config_test. I followed the pattern of test layout for existing monitors, one test for config & factory and the other one for monitor itself.

EXPECT_TRUE(monitor_->tryAllocateResource(1));
EXPECT_FALSE(monitor_->tryAllocateResource(1));
EXPECT_TRUE(monitor_->tryDeallocateResource(1));
EXPECT_EQ(0, monitor_->currentResourceUsage());

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

seems like we test alloc at max, but not dealloc while at min? Can we add that here -- seems like it'd fit what the test case name describes

@KBaichoo

Copy link
Copy Markdown
Contributor

/wait

Signed-off-by: Kateryna Nezdolii <[email protected]>
@nezdolik

Copy link
Copy Markdown
Member Author

@KBaichoo applied review comments. Still need to figure out how to fix failing doc check for hidden extension, it's unfortunate that it also blocks all the other checks from running.

@adisuissa

Copy link
Copy Markdown
Contributor

@KBaichoo applied review comments. Still need to figure out how to fix failing doc check for hidden extension, it's unfortunate that it also blocks all the other checks from running.

I think you can surround it with a [#comment tag, similar to this (just need to remember to remove it eventually ;))

@KBaichoo KBaichoo left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks for adding this, it looks great (pending CI). Can we get a release note?

@KBaichoo

Copy link
Copy Markdown
Contributor

/wait

Signed-off-by: Kateryna Nezdolii <[email protected]>

@KBaichoo KBaichoo left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

/wait

Seems like CI still running into issues. Can we have release notes / docs for this @nezdolik ? Thank you

Signed-off-by: Kateryna Nezdolii <[email protected]>
@nezdolik

Copy link
Copy Markdown
Member Author

Thanks for the suggestion @adisuissa. I tried to replicate the configuration that linked above quic extension is using (comment out extension tag in extension proto+no entry in extensions_metadata.yaml), but CI check failed with: CodeChecker ERROR [extensions_registered] Metadata missing for extension: envoy.resource_monitors.downstream_connections.

@nezdolik

Copy link
Copy Markdown
Member Author

@KBaichoo should we add release notes & docs at this point, as they are user facing? The extension code is there but monitor is not yet wired with code of tcp listener. It would be wired in next PR. Adding docs/release notes may be confusing for users, they may try to enable the monitor and nothing will happen in terms of limiting the number of downstream conns.

@nezdolik

Copy link
Copy Markdown
Member Author

at this point its beyond my power and expertise to fix the failing docs check, all the variants don't work. @phlax do you have any suggestions on path forward?

@phlax

phlax commented Oct 14, 2022

Copy link
Copy Markdown
Member

do you have any suggestions on path forward?

beyond noting that the not-implemented-hide doesnt seem to be there - not immediate - i thought that you had figured a resolution - but will look again early next week if not

@nezdolik

Copy link
Copy Markdown
Member Author

@phlax wdyt about updating the check not to require category in extensions_metadata.yaml for extensions which are commented out? Eg like this one.
On main branch we have such extension with no category registered in extensions_metadata.yaml.

@phlax

phlax commented Oct 17, 2022

Copy link
Copy Markdown
Member

wdyt about updating the check not to require category in extensions_metadata.yaml for extensions which are commented out? Eg ...

almost certainly a good idea - i didnt get to looking at the check specifics yet - but i think we need some way at least for wip/alpha to skip these checks and/or not be included

@phlax

phlax commented Oct 17, 2022

Copy link
Copy Markdown
Member

On main branch we have such ...

hmm, im wondering how that one does it

@KBaichoo

Copy link
Copy Markdown
Contributor

@nezdolik , whoops you're right, makes sense to wait for it to be fully wired

waiting for docs fix.

/wait

@phlax

phlax commented Oct 22, 2022

Copy link
Copy Markdown
Member

waiting for docs fix.

apologies for delay on my side - ill look at this first thing next week

@nezdolik

Copy link
Copy Markdown
Member Author

after discussion with @phlax on how to overcome CI issue, we agreed to add docs for extension and clearly state that extension is wip and not yet usable.

@phlax

phlax commented Oct 27, 2022

Copy link
Copy Markdown
Member

in addition to any information about the status of the extension that you might want to add - dont forget to add:

 option (xds.annotations.v3.file_status).work_in_progress = true;

... to the proto file - this will add a standard warning to the docs

you might need to add:

    "@com_github_cncf_udpa//xds/annotations/v3:pkg",

to the BUILD file deps also

we should probably add to the docs somewhere about adding an extension with WIP code (and/or add to what is there already)

Signed-off-by: Kateryna Nezdolii <[email protected]>
Signed-off-by: Kateryna Nezdolii <[email protected]>
@nezdolik

Copy link
Copy Markdown
Member Author

@phlax created issue for developer docs.

@nezdolik

Copy link
Copy Markdown
Member Author

Have unhidden the docs for extension:
Screenshot 2022-10-28 at 10 16 54

@nezdolik

Copy link
Copy Markdown
Member Author

@KBaichoo this is ready for review.

@KBaichoo KBaichoo left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

nice work, thank you for adding this!

@KBaichoo

Copy link
Copy Markdown
Contributor

ping @markdroth re api shepard review

@markdroth

Copy link
Copy Markdown
Contributor

/lgtm api

@repokitteh-read-only repokitteh-read-only Bot removed the api label Nov 1, 2022
@KBaichoo
KBaichoo merged commit c519951 into envoyproxy:main Nov 2, 2022
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.

overload manager: overload signals based on number of downstream connections and active requests

5 participants