Skip to content

odcds: convert ODCDS over ADS to pre-cluster-single-subscription - #41174

Merged
KBaichoo merged 3 commits into
envoyproxy:mainfrom
adisuissa:odcds_over_ads_fix
Sep 23, 2025
Merged

KBaichoo merged 3 commits into
envoyproxy:mainfrom
adisuissa:odcds_over_ads_fix

Conversation

@adisuissa

Copy link
Copy Markdown
Contributor

Commit Message: odcds: convert ODCDS over ADS to pre-cluster-single-subscription
Additional Description:
Prior to this PR there were issues when using OD-CDS without cds_config.
This PR converts OD-CDS over ADS to use the new XdstpOdCdsApiImpl (that is also used for xDS-federation based OD-CDS subscriptions).

Risk Level: low - only impacts OD-CDS usage
Testing: Added many integration tests. Unit tests were already added for the original OD-CDS implementations.

Docs Changes: N/A
Release Notes: Added.
Platform Specific Features: N/A
Runtime guard: This change is guarded by envoy.reloadable_features.odcds_over_ads_fix to ensure that there's an escape hatch if some unintentional change occurs.

@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: #41174 was opened by adisuissa.

see: more, trace.

@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: #41174 was opened by adisuissa.

see: more, trace.

@adisuissa
adisuissa marked this pull request as ready for review September 22, 2025 17:33
@adisuissa

Copy link
Copy Markdown
Contributor Author

This is a continuation of #40988 and uses the component introduced there to fix a bug where OD-CDS isn't working when cds_config isn't defined.
/assign @KBaichoo @yanavlasov @nezdolik

@yanavlasov yanavlasov 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 from me. Will wait for @KBaichoo or @nezdolik review as well.

/wait-any

Upstream::OdCdsApiHandlePtr);
}
}
if (odcds == nullptr) {

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.

should this be an else block instead? E.g.:

if (Runtime::runtimeFeatureEnabled("envoy.reloadable_features.odcds_over_ads_fix")) {
...
} else {
    odcds = THROW_OR_RETURN_VALUE(cm.allocateOdCdsApi(&Upstream::OdCdsApiImpl::create,
                                                          odcds_config->source(), absl::nullopt,
                                                          validation_visitor),
                                      Upstream::OdCdsApiHandlePtr);
}

Or is it written as intentional fallback in case when flag is enabled and on_demand_cds fails to initialize for some reason?

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.

It should be the else of the 2 conditions above, so I could rewrite it as follows:

      if ((Runtime::runtimeFeatureEnabled("envoy.reloadable_features.odcds_over_ads_fix")) && (odcds_config->source().config_source_specifier_case() ==
            envoy::config::core::v3::ConfigSource::ConfigSourceSpecifierCase::kAds)) {
          odcds = THROW_OR_RETURN_VALUE(cm.allocateOdCdsApi(&Upstream::XdstpOdCdsApiImpl::create,
                                                            odcds_config->source(), absl::nullopt,
                                                            validation_visitor),
                                        Upstream::OdCdsApiHandlePtr);
      } else {
...

I'm not against it, and just thought that the first case is more readable, but I'm happy to change this if you think otherwise (I'm really good with both options).

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.

sounds good, i missed that it was else for 2 conditions above


class AdsIntegrationTest : public AdsDeltaSotwIntegrationSubStateParamTest,
public HttpIntegrationTest {
class AdsIntegrationTestBase : public Grpc::BaseGrpcClientIntegrationParamTest,

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.

do we expect multiple parallel subclasses of AdsIntegrationTestBase class in future? If not, could just keep is simple with one base class

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.

Good question.
There are already multiple sub-classes of AdsIntegrationTest, but they all use the same TestWithParam parameters (although some might not need to). I think the others will need to be refactored (less parameters) to decrease the tests runtime.

KBaichoo
KBaichoo previously approved these changes Sep 23, 2025

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

Thank you for working on this. LGTM besides small comments.

Comment thread changelogs/current.yaml Outdated
was not being properly extracted in the final Prometheus stat name.
- area: odcds
change: |
Fixed a bug where using OD-CDS without cds_config would not workin some

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.

s/workin/ work in/

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.

Oops, thanks, fixed.


// A singleton through which all subscriptions will be processed.
XdstpOdcdsSubscriptionsManagerSharedPtr subscriptions_manager_;
bool old_ads_;

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?

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.

Yep, done.

// TODO(adisuissa): convert the config_source to optional.
bool old_ads = false;
if (config_source.config_source_specifier_case() ==
envoy::config::core::v3::ConfigSource::ConfigSourceSpecifierCase::kAds) {

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.

why is old_ads not just equal to the test that sets it to true?

e.g.

const bool old_ads = config_source.config_source_specifier_case() ==
      envoy::config::core::v3::ConfigSource::ConfigSourceSpecifierCase::kAds;

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.

Good idea, fixed.

@KBaichoo

Copy link
Copy Markdown
Contributor

/wait

Signed-off-by: Adi Suissa-Peleg <[email protected]>
@KBaichoo
KBaichoo merged commit d5c7a06 into envoyproxy:main Sep 23, 2025
botengyao pushed a commit that referenced this pull request Feb 20, 2026
Commit Message: tcp_proxy: fix OD-CDS over ADS
Additional Description:
This PR is similar to #41174 (and uses the same component to achieve the
same goal).
The fix allows proper use of tcp_proxy on-demand cluster discovery when
used over ADS.

Risk Level: low - only impacts OD-CDS over tcp_proxy
Testing: Added integration tests.
Docs Changes: N/A
Release Notes: Added
Platform Specific Features: N/A
Runtime guard: Added
`envoy.reloadable_features.tcp_proxy_odcds_over_ads_fix` to disable the
behavior.

---------

Signed-off-by: Adi Suissa-Peleg <[email protected]>
bmjask pushed a commit to bmjask/envoy that referenced this pull request Mar 14, 2026
Commit Message: tcp_proxy: fix OD-CDS over ADS
Additional Description:
This PR is similar to envoyproxy#41174 (and uses the same component to achieve the
same goal).
The fix allows proper use of tcp_proxy on-demand cluster discovery when
used over ADS.

Risk Level: low - only impacts OD-CDS over tcp_proxy
Testing: Added integration tests.
Docs Changes: N/A
Release Notes: Added
Platform Specific Features: N/A
Runtime guard: Added
`envoy.reloadable_features.tcp_proxy_odcds_over_ads_fix` to disable the
behavior.

---------

Signed-off-by: Adi Suissa-Peleg <[email protected]>
Signed-off-by: bjmask <[email protected]>
bvandewalle pushed a commit to bvandewalle/envoy that referenced this pull request Mar 17, 2026
Commit Message: tcp_proxy: fix OD-CDS over ADS
Additional Description:
This PR is similar to envoyproxy#41174 (and uses the same component to achieve the
same goal).
The fix allows proper use of tcp_proxy on-demand cluster discovery when
used over ADS.

Risk Level: low - only impacts OD-CDS over tcp_proxy
Testing: Added integration tests.
Docs Changes: N/A
Release Notes: Added
Platform Specific Features: N/A
Runtime guard: Added
`envoy.reloadable_features.tcp_proxy_odcds_over_ads_fix` to disable the
behavior.

---------

Signed-off-by: Adi Suissa-Peleg <[email protected]>
fishcakez pushed a commit to fishcakez/envoy that referenced this pull request Mar 25, 2026
Commit Message: tcp_proxy: fix OD-CDS over ADS
Additional Description:
This PR is similar to envoyproxy#41174 (and uses the same component to achieve the
same goal).
The fix allows proper use of tcp_proxy on-demand cluster discovery when
used over ADS.

Risk Level: low - only impacts OD-CDS over tcp_proxy
Testing: Added integration tests.
Docs Changes: N/A
Release Notes: Added
Platform Specific Features: N/A
Runtime guard: Added
`envoy.reloadable_features.tcp_proxy_odcds_over_ads_fix` to disable the
behavior.

---------

Signed-off-by: Adi Suissa-Peleg <[email protected]>
krinkinmu pushed a commit to grnmeira/envoy that referenced this pull request Apr 20, 2026
Commit Message: tcp_proxy: fix OD-CDS over ADS
Additional Description:
This PR is similar to envoyproxy#41174 (and uses the same component to achieve the
same goal).
The fix allows proper use of tcp_proxy on-demand cluster discovery when
used over ADS.

Risk Level: low - only impacts OD-CDS over tcp_proxy
Testing: Added integration tests.
Docs Changes: N/A
Release Notes: Added
Platform Specific Features: N/A
Runtime guard: Added
`envoy.reloadable_features.tcp_proxy_odcds_over_ads_fix` to disable the
behavior.

---------

Signed-off-by: Adi Suissa-Peleg <[email protected]>
wdauchy added a commit to wdauchy/envoy that referenced this pull request Apr 29, 2026
XdstpOdCdsApiImpl::XdstpOdcdsSubscriptionsManager kept a per-resource
entry in subscriptions_ for the lifetime of the singleton, even after
the cluster manager declared the on-demand discovery terminated with
Timeout or Missing. As a result, the very first request that timed
out (or was answered with removed_resources) permanently poisoned
every subsequent request for the same cluster: addSubscription's
"already subscribed to, skipping" early-return fired on every retry,
no DiscoveryRequest was ever issued, and each retry consumed the
ODCDS timeout before returning 503 NC cluster_not_found.

This regression was introduced in 1.38.0 by envoyproxy#41174 and is observable
on configurations using `odcds.source: { ads: {} }` against a delta-
ADS control plane. The legacy OdCdsApiImpl path (which holds a single
long-lived subscription rather than one per resource) is unaffected.

This change introduces a new OdCdsApi::onDiscoveryTerminated hook
(default no-op) and calls it from
ClusterManagerImpl::notifyClusterDiscoveryStatus on terminal Timeout
and Missing statuses. XdstpOdCdsApiImpl overrides the hook to erase
the matching entry from subscriptions_ via a new manager-side
removeSubscription helper, which causes PerSubscriptionData (and its
underlying xDS subscription) to be torn down. A subsequent
on-demand request for the same cluster therefore creates a fresh
subscription and re-issues a DiscoveryRequest, restoring the 1.37
behavior.

The eviction is dispatched through ClusterManagerImpl::dispatcher_
so the subscription is not destroyed synchronously from inside its
own onConfigUpdate -> notifyMissingCluster -> notifyClusterDiscoveryStatus
call stack (which would be a use-after-free).

Behavior is gated by a new runtime guard,
envoy.reloadable_features.odcds_evict_subscription_on_terminal_status,
defaulting to true, so production can revert without disabling the
broader odcds_over_ads_fix change.

Tests:
 - new TEST_F entries in xdstp_od_cds_api_impl_test.cc covering
   subscribe -> Timeout/Missing terminal -> resubscribe (and
   Available retains the subscription as designed).
 - new TEST_P(OdCdsAdsIntegrationTest, OnDemandClusterDiscoveryTimesOutThenRetrySucceeds)
   that exercises the regression end-to-end over a delta ADS
   control plane: first request times out with 503, eviction emits
   an unsubscribe on the wire, and a second request triggers a
   fresh subscribe that succeeds with 200.
 - existing OnDemandClusterDiscoveryAsksForNonexistentCluster tests
   (HTTP and xDS-TP variants) updated to reflect the new
   post-Missing unsubscribe on the wire when the new path is
   enabled.

Risk: low. The default OdCdsApi::onDiscoveryTerminated is a no-op,
so legacy OdCdsApiImpl is unchanged. The new code path is only
exercised by XdstpOdCdsApiImpl (i.e. odcds_over_ads_fix=true, which
has been the default since 1.36) and is reversible via runtime guard.

Signed-off-by: William Dauchy <[email protected]>
Made-with: Cursor
wdauchy added a commit to wdauchy/envoy that referenced this pull request Apr 29, 2026
XdstpOdCdsApiImpl::XdstpOdcdsSubscriptionsManager kept a per-resource
entry in subscriptions_ for the lifetime of the singleton, even after
the cluster manager declared the on-demand discovery terminated with
Timeout or Missing. As a result, the very first request that timed
out (or was answered with removed_resources) permanently poisoned
every subsequent request for the same cluster: addSubscription's
"already subscribed to, skipping" early-return fired on every retry,
no DiscoveryRequest was ever issued, and each retry consumed the
ODCDS timeout before returning 503 NC cluster_not_found.

This regression was introduced in 1.38.0 by envoyproxy#41174 and is observable
on configurations using `odcds.source: { ads: {} }` against a delta-
ADS control plane. The legacy OdCdsApiImpl path (which holds a single
long-lived subscription rather than one per resource) is unaffected.

This change introduces a new OdCdsApi::onDiscoveryTerminated hook
(default no-op) and calls it from
ClusterManagerImpl::notifyClusterDiscoveryStatus on terminal Timeout
and Missing statuses. XdstpOdCdsApiImpl overrides the hook to erase
the matching entry from subscriptions_ via a new manager-side
removeSubscription helper, which causes PerSubscriptionData (and its
underlying xDS subscription) to be torn down. A subsequent
on-demand request for the same cluster therefore creates a fresh
subscription and re-issues a DiscoveryRequest, restoring the 1.37
behavior.

The eviction is dispatched through ClusterManagerImpl::dispatcher_
so the subscription is not destroyed synchronously from inside its
own onConfigUpdate -> notifyMissingCluster -> notifyClusterDiscoveryStatus
call stack (which would be a use-after-free).

Behavior is gated by a new runtime guard,
envoy.reloadable_features.odcds_evict_subscription_on_terminal_status,
defaulting to true, so production can revert without disabling the
broader odcds_over_ads_fix change.

Tests:
 - new TEST_F entries in xdstp_od_cds_api_impl_test.cc covering
   subscribe -> Timeout/Missing terminal -> resubscribe (and
   Available retains the subscription as designed).
 - new TEST_P(OdCdsAdsIntegrationTest, OnDemandClusterDiscoveryTimesOutThenRetrySucceeds)
   that exercises the regression end-to-end over a delta ADS
   control plane: first request times out with 503, eviction emits
   an unsubscribe on the wire, and a second request triggers a
   fresh subscribe that succeeds with 200.
 - existing OnDemandClusterDiscoveryAsksForNonexistentCluster tests
   (HTTP and xDS-TP variants) updated to reflect the new
   post-Missing unsubscribe on the wire when the new path is
   enabled.

Risk: low. The default OdCdsApi::onDiscoveryTerminated is a no-op,
so legacy OdCdsApiImpl is unchanged. The new code path is only
exercised by XdstpOdCdsApiImpl (i.e. odcds_over_ads_fix=true, which
has been the default since 1.36) and is reversible via runtime guard.

Signed-off-by: William Dauchy <[email protected]>
wdauchy added a commit to wdauchy/envoy that referenced this pull request Apr 29, 2026
XdstpOdCdsApiImpl kept per-resource entries in its singleton
subscriptions_ map for the lifetime of the API, even after the cluster
manager declared the on-demand discovery terminated with Timeout or
Missing. Once stuck, addSubscription's "already subscribed to,
skipping" early-return fired on every retry, no DiscoveryRequest was
ever issued, and each retry just consumed the ODCDS timeout before
returning 503 NC cluster_not_found.

This is a 1.37 -> 1.38 regression introduced by envoyproxy#41174 on
configurations using `odcds.source: { ads: {} }`. The legacy
OdCdsApiImpl path (single long-lived subscription) is unaffected.

Add a no-op OdCdsApi::onDiscoveryTerminated hook called from
ClusterManagerImpl::notifyClusterDiscoveryStatus on terminal Timeout
and Missing. XdstpOdCdsApiImpl overrides it to erase the matching
subscriptions_ entry, so the next request creates a fresh
subscription and re-issues a DiscoveryRequest. Available is
intentionally retained, preserving the envoyproxy#41174 design. Eviction is
post-dispatched to avoid tearing down the subscription synchronously
from inside its own onConfigUpdate -> notifyMissingCluster ->
notifyClusterDiscoveryStatus stack.

Gated by a new runtime guard
envoy.reloadable_features.odcds_evict_subscription_on_terminal_status,
default true, so production can revert without disabling the broader
odcds_over_ads_fix change.

Tests:
 - new unit tests in xdstp_od_cds_api_impl_test.cc covering
   subscribe -> Timeout/Missing terminal -> resubscribe, and
   Available retaining the subscription.
 - new OnDemandClusterDiscoveryTimesOutThenRetrySucceeds integration
   test: first request times out with 503, eviction emits an
   unsubscribe, second request triggers a fresh subscribe that
   succeeds with 200. Fails on unmodified main, passes here.
 - OnDemandClusterDiscoveryAsksForNonexistentCluster (HTTP and xDS-TP
   variants) updated for the new post-Missing unsubscribe on the
   wire.

Risk: low. Default hook is a no-op, legacy OdCdsApiImpl unchanged.
Only XdstpOdCdsApiImpl (odcds_over_ads_fix=true, default since 1.36)
hits the new path; reversible via runtime guard.

Signed-off-by: William Dauchy <[email protected]>
Made-with: Cursor
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.

4 participants