Skip to content

Provide DNSOverride for targets - #707

Merged
manugarg merged 21 commits into
cloudprober:masterfrom
sfc-gh-raram:raram-dns-branch
Apr 13, 2024
Merged

manugarg merged 21 commits into
cloudprober:masterfrom
sfc-gh-raram:raram-dns-branch

Conversation

@sfc-gh-raram

Copy link
Copy Markdown
Contributor

The default behavior of cloudprober is to use the local DNS resolver for all targets. While this covers most use cases, some times we want to resolve a target using a DNS resolver that we provide such as Cloudflare's DNS resolver (1.1.1.1). This PR allows the user to specify the dns resolver for a probe and for static targets, it will use the specified dns resolver.

This change includes a unit test and was tested in a k8s environment where the cloudprober config included probes that used the dns resolver override and the default dns resolver.

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

Hey Rahul,

Thanks for sending this. I think being able to override DNS resolver makes a lot of sense. I was wondering if you've considered adding the new option to TargetsDef proto instead:

message TargetsDef {

I think that's a better place for it and it will simplify the implementation quite a bit as we'll not have to pass this option around.

@sfc-gh-raram sfc-gh-raram changed the title Provide DNSOverride for static targets Provide DNSOverride for targets Apr 2, 2024
@sfc-gh-raram

Copy link
Copy Markdown
Contributor Author

Hey Rahul,

Thanks for sending this. I think being able to override DNS resolver makes a lot of sense. I was wondering if you've considered adding the new option to TargetsDef proto instead:

message TargetsDef {

I think that's a better place for it and it will simplify the implementation quite a bit as we'll not have to pass this option around.

Agreed. Updated the PR with the new changes. Tested them locally and in k8s. When you get a chance, could you take another look? Thank you.

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

Hi Rahul,

Few more comments. I am out of office until end of the week, so take your time.

Thanks,
Manu

Comment thread targets/proto/targets.proto Resolved
Comment thread targets/targets.go Resolved
Comment thread targets/resolver/resolver.go Resolved
Comment thread targets/resolver/resolver.go Resolved
Comment thread targets/targets.go Resolved
Comment thread targets/targets.go Resolved
Comment thread targets/targets.go Resolved
@sfc-gh-raram

Copy link
Copy Markdown
Contributor Author

I also have a question regarding the unit test. The unit test checks whether the correct DNSIP is present in the targets struct. Ideally, I would like to put this field in the resolver struct. However, I run into the issue that the resolver struct does not implement the Resolver interface since the resolve method signatures are different, preventing me from casting targets.resolver into the resolver struct. Is there a way to fix this, or am I missing something? Thank you.

@manugarg

manugarg commented Apr 9, 2024

Copy link
Copy Markdown
Contributor

I also have a question regarding the unit test. The unit test checks whether the correct DNSIP is present in the targets struct. Ideally, I would like to put this field in the resolver struct. However, I run into the issue that the resolver struct does not implement the Resolver interface since the resolve method signatures are different, preventing me from casting targets.resolver into the resolver struct. Is there a way to fix this, or am I missing something? Thank you.

Ha, that's surprising. You're right.. adding a DNS IP field to resolver makes more sense, then you should be able to access it from target's resolver by type-casting.

Does the following not work?

in resolver.go:
struct Resolver {
   ...
   DNSOverrideIP string // Used for testing
}

in targets_test.go:

...
r, ok := t.resolver.(*dnsRes.Resolver)
if !ok {
  t.Fatalf(..)
}
assert.Equal(t, wantDNSOverrideIP, r.DNSOverrideIP, ..)
...

Comment thread targets/targets.go Resolved
Comment thread targets/targets.go Resolved
Comment thread targets/targets.go Resolved
Comment thread targets/proto/targets.proto Resolved
@sfc-gh-raram

sfc-gh-raram commented Apr 12, 2024 •

Copy link
Copy Markdown
Contributor Author

I also have a question regarding the unit test. The unit test checks whether the correct DNSIP is present in the targets struct. Ideally, I would like to put this field in the resolver struct. However, I run into the issue that the resolver struct does not implement the Resolver interface since the resolve method signatures are different, preventing me from casting targets.resolver into the resolver struct. Is there a way to fix this, or am I missing something? Thank you.

Ha, that's surprising. You're right.. adding a DNS IP field to resolver makes more sense, then you should be able to access it from target's resolver by type-casting.

Does the following not work?

in resolver.go:
struct Resolver {
   ...
   DNSOverrideIP string // Used for testing
}

in targets_test.go:

...
r, ok := t.resolver.(*dnsRes.Resolver)
if !ok {
  t.Fatalf(..)
}
assert.Equal(t, wantDNSOverrideIP, r.DNSOverrideIP, ..)
...

Unfortunately, it does not work. During runtime, I receive the following error panic: interface conversion: endpoint.Resolver is *targets.targets, not *resolver.Resolver [recovered].

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

Looks good. Just last couple of minor comments if they make sense to you. Otherwise we can go with this too.

Comment thread targets/targets.go Resolved
Comment thread targets/targets.go Resolved

@manugarg manugarg 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!

@manugarg
manugarg merged commit 5d436e4 into cloudprober:master Apr 13, 2024
@sfc-gh-raram
sfc-gh-raram deleted the raram-dns-branch branch April 15, 2024 18:06
@manugarg manugarg added this to the v0.13.4 milestone Apr 23, 2024
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.

2 participants