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

[WIP] dns: add support for clusters based on SRV DNS record #35160

Draft
wants to merge 9 commits into
base: main
Choose a base branch
from

Conversation

mikhainin
Copy link
Contributor

@mikhainin mikhainin commented Jul 11, 2024

One more attempt to address #125 (resolve cluster IPs via SRV-record)

Yet on early stage. Tested with Consul and the collowing configuration:

  clusters:
  - name: local-php
    connect_timeout: 0.25s
    lb_policy: round_robin
    # http2_protocol_options: {}
    cluster_type:
      name: envoy.clusters.dns_srv
      typed_config:
        "@type": "type.googleapis.com/envoy.extensions.clusters.dns_srv.v3.Cluster"
        srv_names:
          - srv_name: _local-php._tcp.service.consul.
    dns_resolvers:
    typed_dns_resolver_config:
      name: envoy.network.dns_resolver.cares
      typed_config:
        "@type": type.googleapis.com/envoy.extensions.network.dns_resolver.cares.v3.CaresDnsResolverConfig
        resolvers:
          - socket_address:
              address: 127.0.0.1
              port_value: 8600

Based on discussion and design doc by @kylebevans in #125 (comment)

Signed-off-by: Mikhail Galanin <mikhail.galanin@yahoo.com>
Copy link

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: #35160 was opened by mikhainin.

see: more, trace.

Copy link

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

🐱

Caused by: #35160 was opened by mikhainin.

see: more, trace.

Signed-off-by: Mikhail Galanin <mikhail.galanin@yahoo.com>
Signed-off-by: Mikhail Galanin <mikhail.galanin@yahoo.com>
Signed-off-by: Mikhail Galanin <mikhail.galanin@yahoo.com>
Signed-off-by: Mikhail Galanin <mikhail.galanin@yahoo.com>
@mikhainin
Copy link
Contributor Author

Testing locally with Consul:
run consul:

consul agent -server -advertise=127.0.0.1 -data-dir=consul-data -ui -bootstrap-expect=1 -dev -log-level=debug

Add service nodes:

consul services register -name=local-php -id=web-1 -address=192.168.1.102 -port=80 -tag=v1 -tag=prod
consul services register -name=local-php -id=web-2 -address=192.168.1.102 -port=81 -tag=v1 -tag=prod

Verify that the service local-php can be resolved via Consul:

dig @127.0.0.1 -p 8600 local-php.service.consul. SRV
# or
dig @127.0.0.1 -p 8600 _local-php._tcp.service.consul. SRV

main doc: https://developer.hashicorp.com/consul/docs/services/discovery/dns-static-lookups

Signed-off-by: Mikhail Galanin <mikhail.galanin@yahoo.com>
@mikhainin
Copy link
Contributor Author

Hi there, apologies for openning in this state - I acknowledge that there still lots.
I just needed someone to point me at what I'm missing and get feedback whether I'm going in the right direction.

@mikhainin mikhainin marked this pull request as ready for review August 19, 2024 19:39
@wbpcode wbpcode marked this pull request as draft August 21, 2024 12:49
@wbpcode
Copy link
Member

wbpcode commented Aug 21, 2024

Thanks for you contribution. But based on our contributing rules (see https://github.com/envoyproxy/envoy/blob/main/CONTRIBUTING.md), any extension, should have a maintainer sponsor to help review and maintain the code.

And I think this should be a DNS extension rather than a new cluster extension?

@mikhainin
Copy link
Contributor Author

mikhainin commented Aug 21, 2024

should have a maintainer sponsor to help review and maintain the code

@wbpcode, Thank you for your comment. I posted a message in slack some while ago but didn't hear anything back. What would be the right way for this?

And I think this should be a DNS extension rather than a new cluster extension?

Based on previous discussion, it was decided to go with the cluster extension. Basically, I followed the previous proposal.

I will be happy to discuss the new design if someone helps me to find the right place. The initial issue doesn't seem to have activity :/

Copy link

This pull request has been automatically marked as stale because it has not had activity in the last 30 days. It will be closed in 7 days if no further activity occurs. Please feel free to give a status update now, ping for review, or re-open when it's ready. Thank you for your contributions!

@github-actions github-actions bot added the stale stalebot believes this issue/PR has not been touched recently label Sep 20, 2024
@mikhainin
Copy link
Contributor Author

This isn't yet forgotten, going to ping maintainers in the maillist

@github-actions github-actions bot removed the stale stalebot believes this issue/PR has not been touched recently label Sep 26, 2024
Copy link

This pull request has been automatically marked as stale because it has not had activity in the last 30 days. It will be closed in 7 days if no further activity occurs. Please feel free to give a status update now, ping for review, or re-open when it's ready. Thank you for your contributions!

@github-actions github-actions bot added the stale stalebot believes this issue/PR has not been touched recently label Oct 26, 2024
Signed-off-by: Mikhail Galanin <mikhail.galanin@yahoo.com>
@github-actions github-actions bot removed the stale stalebot believes this issue/PR has not been touched recently label Oct 31, 2024
@ggreenway ggreenway self-assigned this Nov 15, 2024
@ggreenway
Copy link
Contributor

I'll sponsor this extension. I'll take a closer look at the PR early next week.

@mikhainin
Copy link
Contributor Author

Hi @ggreenway, Thank you for the response.
Just in case, I'm happy to move this extension to contrinb if someone feels it would be a better move.

Copy link
Contributor

@ggreenway ggreenway left a comment

Choose a reason for hiding this comment

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

A good next step is to write more tests. I'd focus first on an integration test.

}

message SrvName {
string srv_name = 1;
Copy link
Contributor

Choose a reason for hiding this comment

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

Do you anticipate adding additional fields to this message in the future?

@@ -4,6 +4,7 @@ EXTENSION_CONFIG_VISIBILITY = ["//visibility:public"]
EXTENSION_PACKAGE_VISIBILITY = ["//visibility:public"]
EXTENSIONS = {
"envoy.clusters.dynamic_forward_proxy": "//source/extensions/clusters/dynamic_forward_proxy:cluster",
"envoy.clusters.dns_srv": "//source/extensions/clusters/dns_srv:cluster",
Copy link
Contributor

Choose a reason for hiding this comment

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

@envoyproxy/envoy-mobile-triage is it correct to add this extension here?


// One SRV-record may return several hostnames
// We will need to resolve all of the hostnames to IPs. Potentially,
// There can be several hostnames for each hostname.
Copy link
Contributor

Choose a reason for hiding this comment

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

Do you mean "there can be several IPs for each hostname"?

Copy link

@luckyxkw luckyxkw left a comment

Choose a reason for hiding this comment

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

Hi glad you initiated this PR! We have been doing a similar customization in X (i.e. add a resolveSrv method in DNS resolver, and a new cluster type that uses the new resolveSrc method) for quite some time.

I am not really an expert in making envoy changes. The code is inherited from my ex-colleague. But I am happy to collaborate if you want.

// in DnsResolverImpl::PendingResolution::onAresGetAddrInfoCallback()).
pending_srv_res->owned_ = true;
return pending_srv_res.release();
return nullptr;
Copy link

Choose a reason for hiding this comment

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

Nit: return nullptr can be removed?

if (parse_srv_status == ARES_SUCCESS) {
for (ares_srv_reply* current_reply = srv_reply; current_reply != NULL;
current_reply = current_reply->next) {
}
Copy link

Choose a reason for hiding this comment

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

Did you plan to put anything in the loop block?

Signed-off-by: Mikhail Galanin <mikhail.galanin@yahoo.com>
Signed-off-by: Mikhail Galanin <mikhail.galanin@yahoo.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants