Skip to content

dynamic_forward_proxy: fix sub_cluster_confg stuck with warm up due to DFPCluster removed - #35848

Merged
alyssawilk merged 22 commits into
envoyproxy:mainfrom
itsLucario:dfp-subcluster-warmup-fix
Oct 14, 2024
Merged

alyssawilk merged 22 commits into
envoyproxy:mainfrom
itsLucario:dfp-subcluster-warmup-fix

Conversation

@itsLucario

@itsLucario itsLucario commented Aug 26, 2024 •

Copy link
Copy Markdown
Contributor

Commit Message:

  • Add an optional argument called ignore_removal to ClusterManagerImpl::addOrUpdateCluster and ClusterManagerImpl::loadCluster. This argument defaults to false, so it won't affect any existing flows. We'll be setting this in Cluster Data.
  • If the ignore_removal value is true, then the cluster won't be removed when ClusterManagerImpl::removeCluster is called.
  • To remove a cluster that has been added with ignore_removal set to true, the remove_ignored argument must be set to true when ClusterManagerImpl::removeCluster is called.

This helps to manage clusters whose lifecycle is managed by custom implementations similar to DFP clusters.

Additional Description:

  • Currently clusters that are dynamically added with custom implementations from filters, etc. are removed when a CDS event is triggered. This is because these dynamically created clusters will come in diff of CDS and will be removed by the cluster manager.

Risk Level: low
Testing: unit test
Docs Changes: no
Release Notes: no
Platform Specific Features:
[Optional Runtime guard:]
[Optional Fixes commit #PR or SHA]
[Optional Deprecated:]
[Optional API Considerations:]

Fixes: #35171

@repokitteh-read-only

Copy link
Copy Markdown

Hi @itsLucario, welcome and thank you for your contribution.

We will try to review your Pull Request as quickly as possible.

In the meantime, please take a look at the contribution guidelines if you have not done so already.

🐱

Caused by: #35848 was opened by itsLucario.

see: more, trace.

@repokitteh-read-only

Copy link
Copy Markdown

As a reminder, PRs marked as draft will not be automatically assigned reviewers,
or be handled by maintainer-oncall triage.

Please mark your PR as ready when you want it to be reviewed!

🐱

Caused by: #35848 was opened by itsLucario.

see: more, trace.

@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 @adisuissa
CC @envoyproxy/api-watchers: FYI only for changes made to (api/envoy/|docs/root/api-docs/).

🐱

Caused by: #35848 was opened by itsLucario.

see: more, trace.

@itsLucario itsLucario changed the title fix dfp subcluster getting stuck with warmup due to removal on CDS dynamic_forward_proxy: fix sub_cluster_confg stuck with warm up due to cluster removed Aug 26, 2024
@itsLucario
itsLucario force-pushed the dfp-subcluster-warmup-fix branch from 284cf40 to 04b55d2 Compare August 26, 2024 19:31
@itsLucario
itsLucario marked this pull request as ready for review August 27, 2024 13:22
@itsLucario itsLucario changed the title dynamic_forward_proxy: fix sub_cluster_confg stuck with warm up due to cluster removed dynamic_forward_proxy: fix sub_cluster_confg stuck with warm up due to DFPCluster removed Aug 27, 2024
@itsLucario

Copy link
Copy Markdown
Contributor Author

@adisuissa Can you please help with review?

@adisuissa adisuissa 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 contributing.
Left a high-level question.

bool connection_pool_per_downstream_connection = 51;

// If ``ignore_removal`` is true, the cluster manager will ignore the cluster while removing during CDS event.
// This is useful when cluster is created and managed by custom implementation. For example, Dynamic Forward Proxy.

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'm not sure this is the right place to make this change.
Shouldn't this be part of the dynamic-forward-proxy config, and not per-cluster?
The risk is that clusters are will linger for a long time, and it is unclear why would one want to keep them around with no way to remove.

@itsLucario itsLucario Sep 3, 2024 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Thanks. That's a valid question. Yes, this can be part of dynamic-forward-proxy, and we can instruct it to recreate the DFP cluster if it's not found (in case it was removed by the cluster manager).

However, in environments like service-mesh or configurations where CDS can be a very frequent event, the cluster manager will end up removing it very frequently. Also, when used as an egress, DFPClusters can be high in number, and removing and recreating them on CDS after the cluster manager removes them can affect performance.

In use cases like dynamic-forward-proxy, where clusters are created and managed by a custom implementation (create/update/remove), CDS should not impact them. dynamic-forward-proxy has TTL which does remove cluster if not used for the TTL duration.

We can hide the field from docs and let this to be used for clusters managed by custom implementations.
So the idea was to make the cluster manager know that these DFP clusters shouldn't be removed.

Open for feedback and thoughts.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

hide the field from docs

Personally, I think it could be a choice, and note clearly in comment: it's just for internal usage, not for users.

Another choice is: we add one more argument, ignore_removal, in ClusterManagerImpl::addOrUpdateCluster and ClusterManagerImpl::loadCluster.
It should works too, but with more code base changes.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Right! @doujiang24 The later one needs more changes. Leaving note and hide from docs is simpler.
Made changes: Note in the comment and hide it from docs.

Open for thoughts

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.

Hiding from the docs should not be considered, IMHO, as it should be used for API that needs more testing (not to be hidden from some use-cases).
I think the question is whether it makes sense for DFP to have both clusters that are removed and clusters that are kept all the time. From your comments I gather that in DFP one would want to ignore the CDS removal, so it seems that a single knob (on the DFP config) makes more sense, no?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

On CDS event when clusters are being removed, the cluster manager cannot differentiate whether it is a DFP cluster or a normal cluster.

There is nothing to differentiate and prevent these DFP clusters from getting removed by cluster manager.

Please correct me if I'm wrong or not making sense.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The lifecycle of the sub clusters are managed by the DFP cluster, both creation and deletion.
So, we want to add a flag for the sub clusters to not be removed by other events.

The flag do not have to be a configuration, just a internal flag.

If hidding from docs is not be considered, maybe we can try the option 2? #35848 (comment) cc @itsLucario

@itsLucario itsLucario Sep 17, 2024 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Right! Summarizing the other approach.

We'll remove the ignore_removal attribute from Cluster API Spec.
Introduce an optional argument ignore_removal default set to false (optional param to ensure existing flow won't break) in ClusterManagerImpl:: addOrUpdateCluster and ClusterManagerImpl::loadCluster so that ClusterData can set this value and can check while removing.

Does this sound right! If people are fine, I'll proceed with working on changes.

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.

FWIW, I didn't say that removing the API field is required, I just suggested moving it to the DFP config instead of having it in a per-Cluster config.

Taking a step back, there are a few things to clarify:

  1. Changing the API should be done in a considerate manner, as it impacts not only Envoy users, but also xDS-server maintainers. Moreover, removing fields essentially cannot be done, so we prefer to get it mostly right now. That is why we are discussing if a field should be added, and if so where.
  2. If a PR suggests changing the way Envoy behaves right now (breaking behavior change), this can either be done by adding a field or a runtime-flag. The former is a long-term support, say a filter that needs to support 2 modes of operation. The latter is when a bug is observed, and the fix causes a user-facing change. Runtime-flags allow Envoy users ~6 months to gradually ensure that the other systems behave correctly with the new change.

In the context of this PR, it is unclear to me whether it should be a config-enabled feature or a runtime-flag guarded change. I'm leaning towards the runtime guarded change according to your description (but could be persuaded towards an API feature if there are use-cases where the clusters that are added by DFP need to removed upon a CDS update).

@itsLucario itsLucario Sep 19, 2024 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Thanks for the thoughts!

  1. Totally agreed. Chaging API should be done in considerate manner. After your thoughts it makes more sense to follow different approach. I feel the approach mentioned by @doujiang24 is fiesible and easy to use even in future usecases.
  2. The PR is not going to change any current behaviour and doesn't break any current behaviour as well. This should be straight enough that we want to avoid removal of cluster by cluster manager whose lifecycle is managed by custom implementation.

As this PR doesn't change/break any current behaviour, I think runtime-flag guard is not required. I have updated the description aaccordingly

@ravenblackx

Copy link
Copy Markdown
Contributor

Ping @adisuissa I think this is waiting for opinion from you.

@ravenblackx

Copy link
Copy Markdown
Contributor

Pinged @adisuissa again, and also in slack.

@adisuissa adisuissa 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.

Apologies, I was under the weather, and just got back to this.

bool connection_pool_per_downstream_connection = 51;

// If ``ignore_removal`` is true, the cluster manager will ignore the cluster while removing during CDS event.
// This is useful when cluster is created and managed by custom implementation. For example, Dynamic Forward Proxy.

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.

Hiding from the docs should not be considered, IMHO, as it should be used for API that needs more testing (not to be hidden from some use-cases).
I think the question is whether it makes sense for DFP to have both clusters that are removed and clusters that are kept all the time. From your comments I gather that in DFP one would want to ignore the CDS removal, so it seems that a single knob (on the DFP config) makes more sense, no?

if (existing_active_cluster != active_clusters_.end() &&
existing_active_cluster->second->added_via_api_) {
existing_active_cluster->second->added_via_api_ &&
existing_active_cluster->second->ignore_removal_ == remove_ignored) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
existing_active_cluster->second->ignore_removal_ == remove_ignored) {
(!existing_active_cluster->second->ignore_removal_ || remove_ignored)) {

does this could be better?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This will make cluster to remove when remove_ignored set to true and cluster data has ignore_removal set to false.

This should fine as well. removeCluster will behave as current for cluster with ignore_removal false irrespective of remove_ignored value. And remove_ignored will only take effect for cluster with ignore_removal set to true.

@itsLucario

Copy link
Copy Markdown
Contributor Author

/retest

@alyssawilk

Copy link
Copy Markdown
Contributor

also this needs a main merge
/wait

nbn01 added 3 commits September 30, 2024 05:53
Signed-off-by: nbn01 <[email protected]>
Signed-off-by: nbn01 <[email protected]>
@repokitteh-read-only

Copy link
Copy Markdown

CC @envoyproxy/runtime-guard-changes: FYI only for changes made to (source/common/runtime/runtime_features.cc).

🐱

Caused by: #35848 was synchronize by itsLucario.

see: more, trace.

nbn01 added 3 commits September 30, 2024 09:33
adisuissa
adisuissa previously approved these changes Oct 2, 2024

@adisuissa adisuissa 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.

LGTM, thanks!

@adisuissa

Copy link
Copy Markdown
Contributor

I'm trying to rerun the job, but it may need another main merge (due to a recent CI upgrade)

@adisuissa

Copy link
Copy Markdown
Contributor

Seems that CI complains about coverage. Please follow link at https://github.com/envoyproxy/envoy/actions/runs/11157572663/job/31012169240#step:12:6358 to see the code that is not covered.
/wait

Signed-off-by: nbn01 <[email protected]>
@itsLucario

Copy link
Copy Markdown
Contributor Author

/retest

@adisuissa adisuissa 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!
LGTM, and left some minor nits.
Good to merge IMHO.

@itsLucario

Copy link
Copy Markdown
Contributor Author

/retest

auto existing_active_cluster = active_clusters_.find(cluster_name);
if (existing_active_cluster != active_clusters_.end() &&
existing_active_cluster->second->added_via_api_) {
existing_active_cluster->second->added_via_api_ &&

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 picking up this change, and sorry coming in late with a possibly naive question.
So the problem is we add a DFP cluster via CDS, the DFP cluster adds each host as a sub-cluster, and subsequently the DFP sub-clusters are removed by CDS updates right?

Would it be cleaner rather than adding the ignore tags, to simply have the sub-clusters not tagged as added via API? Or would that then cause problems for removal?

If it complicates removal WDYT of instead of having an "added by API" bool and a "ignore" bool, if we change both addOrUpdateCluster to include a enum Type (Static, Cds, DFP) where each cluster retains its type and we ignore CDS removals for DFP?

/wait-any for comments

@itsLucario itsLucario Oct 10, 2024 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Thanks for your inputs.

Like you said, tagging clusters with not added_via_api would make the changes more complex and could impact existing behavior.

The cluster api spec already has type and cluster_type fields, but the DFP sub-cluster sets type to STRICT_DNS. Having another enum in API spec or having enum as addOrUpdateCluster param will abstract the resulting behavior, i.e., avoiding cds removal.

I feel avoid_cds_removal parameter makes it clear & clean for the caller and easy to manage, not just for DFP sub-clusters, but for any other use cases in future where custom implementations will manage the cluster lifecycle (similar to DFP).

Open for thoughts :)

@alyssawilk alyssawilk 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.

fair enough!

@alyssawilk
alyssawilk merged commit df48c7d into envoyproxy:main Oct 14, 2024
grnmeira pushed a commit to grnmeira/envoy that referenced this pull request Oct 17, 2024
…o DFPCluster removed (envoyproxy#35848)

Commit Message:
- Add an optional argument called `ignore_removal` to
`ClusterManagerImpl::addOrUpdateCluster` and
`ClusterManagerImpl::loadCluster`. This argument defaults to `false`, so
it won't affect any existing flows. We'll be setting this in Cluster
Data.
- If the `ignore_removal` value is `true`, then the cluster won't be
removed when `ClusterManagerImpl::removeCluster` is called.
- To remove a cluster that has been added with `ignore_removal` set to
`true`, the `remove_ignored` argument must be set to `true` when
`ClusterManagerImpl::removeCluster` is called.

This helps to manage clusters whose lifecycle is managed by custom
implementations similar to DFP clusters.

Additional Description:
- Currently clusters that are dynamically added with custom
implementations from filters, etc. are removed when a CDS event is
triggered. This is because these dynamically created clusters will come
in diff of CDS and will be removed by the cluster manager.

Risk Level: low
Testing: unit test
Docs Changes: no
Release Notes: no

Signed-off-by: Gustavo <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Dynamic forward proxy with sub_clusters_config get stuck with wait for warmup

5 participants