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

Refactoring Envoy DNS resolution as extension #17479

Merged
merged 144 commits into from
Oct 15, 2021

Conversation

yanjunxiang-google
Copy link
Contributor

@yanjunxiang-google yanjunxiang-google commented Jul 25, 2021

Problem Description:
This PR is the code changes for refactoring Envoy DNS resolution as first class extension for issue: #14310. This is a follow up PR of #17272.

Solution:
1 Move c-ares and Apple DNS resolvers to their own extensions.
2) Create a DnsResolver factory interface, and derive two sub factory classes from it: CaresDnsResolver and AppleDnsResolver, each implement the method to create the corresponding dns_resolver object.
3) Refactor the boostrap_, cluster, dns_cache and dns_filter configuration parsing code, removing the dns_resolution_config parsing logic from them, call a standalone template function to parse the configuration, get a typed configuration. In this, 2.1) if theTypedExtensionConfig is in the config, using it to get the corresponding factory.
2.2) if TypedExtensionConfig is missing, then : if this is MacOS, and the run time flag: envoy.restart_features.use_apple_api_for_dns_lookups is enabled, then have the Envoy config factory synthesize a apple DNS resolver TypedExtensionConfig, and using it to get the apple DNS resolver factory. In all other cases, have the Envoy Synthesize a pseudo-configuration for the c-ares TypedExtensionConfig, and using it to get the cares DNS resolver factory
4) The DNS resolver factory retrieved in 3) will create a corresponding DNS resolver object (cares or apple).

Build:
passed

Testing:
passed

Release Notes:
N/A

Issues: DNS resolver as an extension point #14310

Fix #14310

Signed-off-by: Yanjun Xiang yanjunxiang@google.com

Commit Message:
Additional Description:
Risk Level:
Testing:
Docs Changes:
Release Notes:
Platform Specific Features:
[Optional Runtime guard:]
[Optional Fixes #Issue]
[Optional Deprecated:]
[Optional API Considerations:]

… class extension for issue: envoyproxy#14310.

Signed-off-by: Yanjun Xiang <yanjunxiang@google.com>
@yanjunxiang-google
Copy link
Contributor Author

This PR is a work in progress. Sending it to start get comments about whether the direction wise look good.

There are pending issues need to be done:

  1. Build in Apple system.
  2. get "blaze test ..." working
  3. There are temporary code change in wasm.cc, dns_filter_resolver.h, and some config validation files. Need to address them.
    4)...

@yanjunxiang-google
Copy link
Contributor Author

/assign @htuch @yanavlasov @jmarantz @adisuissa

This PR is still working in progress as mentioned above. However, I would like to send out this preliminary version out to get comments.
This way, in case there is direction wise issue in the approach, we can correct it earlier.

Thanks!

Copy link
Contributor

@adisuissa adisuissa left a comment

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!
I've left a few comments/questions.

envoy/event/dispatcher.h Outdated Show resolved Hide resolved
envoy/event/dispatcher.h Outdated Show resolved Hide resolved
source/common/event/dispatcher_impl.cc Outdated Show resolved Hide resolved
source/extensions/common/wasm/wasm.cc Outdated Show resolved Hide resolved
source/extensions/network/dns_resolver/cares/dns_impl.h Outdated Show resolved Hide resolved
source/extensions/network/dns_resolver/cares/dns_impl.h Outdated Show resolved Hide resolved
@Shikugawa
Copy link
Member

I think this PR also closes #17335.

@yanjunxiang-google yanjunxiang-google changed the title This is the code change for refactoring Envoy DNS resolution as first… Refactoring Envoy DNS resolution as extension Jul 26, 2021
@yanjunxiang-google
Copy link
Contributor Author

/assign krajshiva

@repokitteh-read-only
Copy link

krajshiva cannot be assigned to this issue.

🐱

Caused by: a #17479 (comment) was created by @yanjunxiang-google.

see: more, trace.

Copy link
Member

@htuch htuch left a comment

Choose a reason for hiding this comment

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

The shape of this solution looks good, thanks! The main thing to sort out is to give each extension a unique proto type
/wait

source/common/event/dispatcher_impl.cc Outdated Show resolved Hide resolved
source/common/upstream/cluster_factory_impl.cc Outdated Show resolved Hide resolved
envoy/event/dispatcher.h Outdated Show resolved Hide resolved
source/common/event/dispatcher_impl.cc Outdated Show resolved Hide resolved
@yanavlasov
Copy link
Contributor

/wait

@repokitteh-read-only
Copy link

CC @envoyproxy/api-shepherds: Your approval is needed for changes made to api/envoy/.
envoyproxy/api-shepherds assignee is @adisuissa
CC @envoyproxy/api-watchers: FYI only for changes made to api/envoy/.

🐱

Caused by: #17479 was synchronize by yanjunxiang-google.

see: more, trace.

@jmarantz
Copy link
Contributor

jmarantz commented Aug 2, 2021

Ping when it's time again to take another look

/wait

@yanjunxiang-google
Copy link
Contributor Author

I think this PR also closes #17335.

thanks!

source/common/event/dispatcher_impl.cc Outdated Show resolved Hide resolved
@yanavlasov
Copy link
Contributor

Per @yanavlasov maybe there is something else going on? I guess we need to get to the bottom of it. Either we should add it or we need to figure out a different build issue.

I've just built linux envoy-static using ci/osx-build-config and did include cares DNS resolver. So i'm fairly confident that DNS resolvers are added by default and there is something in EM build that prevents it.

@mattklein123
Copy link
Member

mattklein123 commented Oct 14, 2021

I just looked through the code, and I think the problem must have to do with the extension registry h/cc files that exist in EM to force registration. I think this is missing for apple.

IMO what you have is OK, and EM can add the new registry for the apple stuff, but can we make it fail in a more obvious way? For example, here:

https://github.com/envoyproxy/envoy/pull/17479/files#diff-45b2fec2b06ec0ddec48315ea6b40a3c76edd07b46df14233ccbbd498818adc9R37-R38

Instead of checking for null when you try to do a default setup, can you actually gate this on #ifdef __APPLE__ and just release assert if the extension is not available? This should work fine for OSX CI per the above discussion, then EM will fail in an obvious way and we can fix that.

wdyt? Should be a very small change.

cc @goaway

@yanjunxiang-google
Copy link
Contributor Author

yanjunxiang-google commented Oct 14, 2021

HI, @mattklein123 ,

If adding a check something like below is purely to flag the extension build file issue, then is it really worthwhile?

'#ifdef APPLE'
if envoy.restart_features.use_apple_api_for_dns_lookups == true &&
Config::Utility::getAndCheckFactoryByNameNetwork::DnsResolverFactory(std::string(AppleDnsResolver), true) == nullptr
RELEASE_ASSERT()

#endif

We have other means to easily spot this extension build file issue, e.g., check the bootstrapping logs:

[2021-10-14 18:06:35.672][1889399][info][main] [source/server/server.cc:371] statically linked extensions:
...
[2021-10-14 18:06:35.672][1889399][info][main] [source/server/server.cc:373] envoy.network.dns_resolver: envoy.network.dns_resolver.cares <<------ Is this dns_resolver extension (apple for macOS) show up in the log? If it's missing, then it's a problem.

and:
"Didn't find a registered implementation for name: 'envoy.network.dns_resolver.cares'"
<<-------This is very good indication of the extensions are not included correctly.

ccing @htuch for his opinion on adding back the "#ifdef APPLE".

thanks,
Yanjun

@mattklein123
Copy link
Member

mattklein123 commented Oct 14, 2021

I don't want to actually check the logs, because it's going to fall back to c-ares in a non-obvious way.

All I'm saying to do is in the checkApple function do:

  1. If not #ifdef apple just do nothing/return.
  2. Otherwise pull the apple config and let it fail/crash if not there to indicate a build issue.

…er extension is not included Envoy MacOS build file

Signed-off-by: Yanjun Xiang <yanjunxiang@google.com>
@yanjunxiang-google
Copy link
Contributor Author

yanjunxiang-google commented Oct 14, 2021

HI, @mattklein123 ,

Thanks for the comments. I modified checkUseAppleApiForDnsLookups() function to add the #ifdef APPLE, RELEASE_ASSERT() logic you mentioned.

PTAL.

Signed-off-by: Yanjun Xiang <yanjunxiang@google.com>
Signed-off-by: Yanjun Xiang <yanjunxiang@google.com>
jpsim added a commit to jpsim/envoy-mobile that referenced this pull request Oct 15, 2021
envoyproxy/envoy#17479

Signed-off-by: JP Simard <jp@jpsim.com>
jpsim added a commit to jpsim/envoy-mobile that referenced this pull request Oct 15, 2021
envoyproxy/envoy#17479

Signed-off-by: JP Simard <jp@jpsim.com>
Copy link
Member

@mattklein123 mattklein123 left a comment

Choose a reason for hiding this comment

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

Thanks!

@mattklein123 mattklein123 merged commit f4a88f9 into envoyproxy:main Oct 15, 2021
@yanjunxiang-google yanjunxiang-google deleted the dns-as-extension branch October 16, 2021 15:01
mattklein123 pushed a commit that referenced this pull request Oct 18, 2021
Followup to #17479

Signed-off-by: JP Simard <jp@jpsim.com>
dubious90 pushed a commit to envoyproxy/nighthawk that referenced this pull request Oct 19, 2021
- Update `.bazelrc`
- Update `.bazelversion`
- Update after DNS resolver changes in envoyproxy/envoy#17479
  - Note: A DNS resolver factory layer has been added since earlier versions of the Envoy PR.
  - The reason `ProcessImpl` receives an injected DNS resolver factory instead of a DNS resolver is that the complicated `Api` the factory needs to work is only constructed later (in the `ProcessImpl` constructor).
  - Note: `createDefaultDnsResolverFactory()` creates the platform-specific factory and also has the *side effect* of populating the `TypedExtensionConfig`.
  - Note: The `createDnsResolver()` method on the DNS resolver factory *also* takes the `TypedExtensionConfig` as an input. So in addition to injecting the factory into `ProcessImpl`, we also need to inject the `TypedExtensionConfig` that was populated by `createDefaultDnsResolverFactory()`.

Signed-off-by: eric846 <56563761+eric846@users.noreply.github.com>
buildbreaker pushed a commit to envoyproxy/envoy-mobile that referenced this pull request Oct 20, 2021
Integrates envoyproxy/envoy#17479 & envoyproxy/envoy#17521

Envoy diff: envoyproxy/envoy@a5b3af2...c687308

This PR:

* Creates a new `extension_registry_platform_additions` library where platform-specific additions to the extensions can be configured. Currently only registers the Apple DNS resolver extension factory and no-ops on non-Apple platforms but more can be added here in the future.
* Implements the new `Stream::bytesMeter()` function on `DirectStream`.
* Increases the max binary size from 7.2MB to 7.3MB. We were already within 1% of that on `main` so it didn't take much new code to go over this limit.
jpsim added a commit that referenced this pull request Nov 28, 2022
Integrates #17479 & #17521

Envoy diff: a5b3af2...c687308

This PR:

* Creates a new `extension_registry_platform_additions` library where platform-specific additions to the extensions can be configured. Currently only registers the Apple DNS resolver extension factory and no-ops on non-Apple platforms but more can be added here in the future.
* Implements the new `Stream::bytesMeter()` function on `DirectStream`.
* Increases the max binary size from 7.2MB to 7.3MB. We were already within 1% of that on `main` so it didn't take much new code to go over this limit.

Signed-off-by: JP Simard <jp@jpsim.com>
jpsim added a commit that referenced this pull request Nov 29, 2022
Integrates #17479 & #17521

Envoy diff: a5b3af2...c687308

This PR:

* Creates a new `extension_registry_platform_additions` library where platform-specific additions to the extensions can be configured. Currently only registers the Apple DNS resolver extension factory and no-ops on non-Apple platforms but more can be added here in the future.
* Implements the new `Stream::bytesMeter()` function on `DirectStream`.
* Increases the max binary size from 7.2MB to 7.3MB. We were already within 1% of that on `main` so it didn't take much new code to go over this limit.

Signed-off-by: JP Simard <jp@jpsim.com>
mattklein123 pushed a commit that referenced this pull request Dec 11, 2024
<!--
!!!ATTENTION!!!

If you are fixing *any* crash or *any* potential security issue, *do
not*
open a pull request in this repo. Please report the issue via emailing
envoy-security@googlegroups.com where the issue will be triaged
appropriately.
Thank you in advance for helping to keep Envoy secure.

!!!ATTENTION!!!

For an explanation of how to fill out the fields, please see the
relevant section
in
[PULL_REQUESTS.md](https://github.com/envoyproxy/envoy/blob/main/PULL_REQUESTS.md)
-->


Commit Message: 
Additional Description: I believe it is stable now since we conduct a
security review and improvement for dns filter like #18651 #20744 #22861
#17479 #34409 #34456 #34490 and so on
Risk Level: low
Testing:
Docs Changes:
Release Notes:

Signed-off-by: Boteng Yao <boteng@google.com>
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.

DNS resolver as an extension point