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

Fallback plugin #1420

Closed
wants to merge 20 commits into from
Closed

Fallback plugin #1420

wants to merge 20 commits into from

Conversation

johnbelamaric
Copy link
Member

1. What does this pull request do?

Implements the fallback plugin.

2. Which issues (if any) are related?

#1382

3. Which documentation changes (if any) need to be made?

It will need its own README.

@johnbelamaric
Copy link
Member Author

@fturib

@johnbelamaric
Copy link
Member Author

This uses the proxy upstream parsing. It supports everything the proxy does. It should work like this:

{
  fallback nxdomain foo.com /etc/resolv.conf {
    # proxy options
  }
  fallback refused bar.com /etc/resolv.conf {
    # other options
  }
  fallback servfail . 8.8.8.8:53
  proxy . /etc/resolv.conf
}

for example. I haven't tried that yet though.

@johnbelamaric
Copy link
Member Author

at this point exactly ONE fallback is allowed for a given rcode. maybe that should change.

return plugin.Error("fallback", err)
}

f.rules[rc] = u
Copy link
Contributor

Choose a reason for hiding this comment

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

Hum.. for what I understand, this setup is called once per word 'fallback' found in the config file.
Therefore, the way the syntax of this stanza is designed, you can register only ONE rcode per 'fallback'.
in other word this map named rules could be replaced by a couple (int, Upstream).
Am I correct ?

Copy link
Member Author

Choose a reason for hiding this comment

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

yes, one rcode per fallback directive. See the comment above - I changed the syntax from the original, so it would be easy to re-use the proxy code.

There is only one fallback plugin, not one per directive. So, this one plugin processes all fallback directives, and so they end up in this map.

Copy link
Contributor

@fturib fturib Jan 26, 2018

Choose a reason for hiding this comment

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

maybe I misread the setup call ...
Ok. I double checked when is called the setup .. and it says once per key for each server block.
Very good. - exactly what is needed :)

/ SetupFunc is used to set up a plugin, or in other words,
// execute a directive. It will be called once per key for
// each server block it appears in.
type SetupFunc func(c *Controller) error

@codecov-io
Copy link

codecov-io commented Jan 29, 2018

Codecov Report

Merging #1420 into master will increase coverage by 0.12%.
The diff coverage is 72.09%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #1420      +/-   ##
==========================================
+ Coverage   52.02%   52.15%   +0.12%     
==========================================
  Files         175      177       +2     
  Lines        8530     8573      +43     
==========================================
+ Hits         4438     4471      +33     
- Misses       3753     3760       +7     
- Partials      339      342       +3
Impacted Files Coverage Δ
plugin/fallback/fallback.go 64.7% <64.7%> (ø)
plugin/fallback/setup.go 76.92% <76.92%> (ø)
plugin/proxy/lookup.go 74.13% <0%> (+3.44%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 399073e...ae2e3b9. Read the comment docs.

@johnbelamaric
Copy link
Member Author

Ko added some tests and now this is ready for review.

@johnbelamaric johnbelamaric changed the title WIP: Fallback plugin Fallback plugin Feb 2, 2018
@@ -15,6 +15,7 @@ import (
_ "github.com/coredns/coredns/plugin/erratic"
_ "github.com/coredns/coredns/plugin/errors"
_ "github.com/coredns/coredns/plugin/etcd"
_ "github.com/coredns/coredns/plugin/fallback"
Copy link
Member

Choose a reason for hiding this comment

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

no reason to put it here? Can bump it to its own repo.

Copy link
Member Author

Choose a reason for hiding this comment

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

yeah, we could do that. @yuewko I will create a separate repo for it in CoreDNS org.

}
```

* `RCODE` is the string representation of the error response code. The set of valid error
Copy link
Member

Choose a reason for hiding this comment

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

Nit: **RCODE** same for PROXY_PARAMS

Copy link
Contributor

Choose a reason for hiding this comment

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

Sounds good. Will fix.

```

* `RCODE` is the string representation of the error response code. The set of valid error
strings are defined as `RcodeToString` in <https://github.com/miekg/dns/blob/master/msg.go>
Copy link
Member

Choose a reason for hiding this comment

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

I would list them here? Instead of pointing to a (large) file

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah... but RcodeToString is a rather long list.

How about including a handful of typical example rcodes here, and refer to that link for the complete list?

* `RCODE` is the string representation of the error response code. The set of valid error
strings are defined as `RcodeToString` in <https://github.com/miekg/dns/blob/master/msg.go>
* `PROXY_SPECS` accepts the same parameters as the *proxy* plugin
<https://github.com/coredns/coredns/tree/master/plugin/proxy>.
Copy link
Member

Choose a reason for hiding this comment

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

coredns.io link instead?

Copy link
Contributor

Choose a reason for hiding this comment

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

Sounds good. Will switch.

import (
"context"

"github.com/miekg/dns"
Copy link
Member

Choose a reason for hiding this comment

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

3rd party should be last import.

Copy link
Contributor

Choose a reason for hiding this comment

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

My bad. Will fix.

"github.com/coredns/coredns/request"
)

// stubNextHandler is used to simulate a proxy plugin.
Copy link
Member

Choose a reason for hiding this comment

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

the testing code has more comments on the non-testing code

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes. Will address comments.

c.called++

// Ensure that it is called with the expected Upstream
if c.expectedUpstream != nil && c.expectedUpstream != upstream {
Copy link
Member

Choose a reason for hiding this comment

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

why do you need to guard against this in a test that you control?

Copy link
Contributor

Choose a reason for hiding this comment

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

These checks are not meant to guard against error conditions. They are there to check against expected behavior as per test case.


// Ensure that it is called with the expected Upstream
if c.expectedUpstream != nil && c.expectedUpstream != upstream {
c.t.Fatalf("Expected upstream passed to proxyCreator is '%v', but got '%v'",
Copy link
Member

Choose a reason for hiding this comment

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

calling t.Fatalf in a non test function? Should return an err

Copy link
Contributor

Choose a reason for hiding this comment

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

As per comment above, the check here is indeed part of the test.

Having said that, I do think it is more appropriate to use t.Errorf (instead of t.Fatalf). Will fix.

return &dns.Msg{}, nil
}

func (e dummyExchanger) Protocol() string {
Copy link
Member

Choose a reason for hiding this comment

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

These functions call all be put on 1 line

Copy link
Contributor

Choose a reason for hiding this comment

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

Good idea. Will fix.

}
}

func TestFallbackNotCalled(t *testing.T) {
Copy link
Member

Choose a reason for hiding this comment

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

Why all this mocking and not just checking if the impl does the right thing if an upstream returns nxdomain (i.e. dnstest.Server should make this relatively painless)

Copy link
Contributor

Choose a reason for hiding this comment

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

I must confess that I'm not familiar with dnstest. I just took a quick look and it seems, IMHO, that it looks more akin to integration test.

How about adding a couple of tests using dnstest to supplement?

@miekg
Copy link
Member

miekg commented Feb 5, 2018 via email

@miekg
Copy link
Member

miekg commented Feb 5, 2018 via email

@yuewko
Copy link
Contributor

yuewko commented Feb 5, 2018

re: #1420 (comment)
In addition to replacing t.Fatalf with t.Errorf, I'll also have the Create method return an error.

re: #1420 (comment)
Sound good, I'll do that.

Thanks!!

@yuewko
Copy link
Contributor

yuewko commented Feb 5, 2018 via email

@miekg
Copy link
Member

miekg commented Feb 8, 2018

moved to github.com/coredns/fallback, coredns.io/explugins also updated.

@miekg miekg closed this Feb 8, 2018
@johnbelamaric johnbelamaric deleted the fallback branch March 9, 2018 20:13
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

5 participants