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

Provide DNSOverride for targets #707

Merged
merged 21 commits into from
Apr 13, 2024

Conversation

sfc-gh-raram
Copy link
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.

Copy link
Contributor

@manugarg manugarg left a comment

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

Copy link
Contributor

@manugarg manugarg left a comment

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

targets/proto/targets.proto Outdated Show resolved Hide resolved
targets/targets.go Outdated Show resolved Hide resolved
targets/resolver/resolver.go Outdated Show resolved Hide resolved
targets/resolver/resolver.go Outdated Show resolved Hide resolved
targets/targets.go Outdated Show resolved Hide resolved
targets/targets.go Outdated Show resolved Hide resolved
targets/targets.go Outdated Show resolved Hide resolved
@sfc-gh-raram
Copy link
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
Copy link
Contributor

manugarg commented Apr 9, 2024

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, ..)
...

targets/targets.go Outdated Show resolved Hide resolved
targets/targets.go Outdated Show resolved Hide resolved
targets/targets.go Outdated Show resolved Hide resolved
@sfc-gh-raram
Copy link
Contributor Author

sfc-gh-raram commented Apr 12, 2024

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

Copy link
Contributor

@manugarg manugarg left a comment

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.

targets/targets.go Show resolved Hide resolved
targets/targets.go Show resolved Hide resolved
Copy link
Contributor

@manugarg manugarg left a comment

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
8 checks passed
@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.

None yet

2 participants