Commit graph

28 commits

Author SHA1 Message Date
Miek Gieben
1c45e262f5 middleware/proxy: remove singleinflight from dns (#717)
Singleinflight interferes with the health checking of upstream. If an
upstream would fail, singleinflight would mirror that error to to other
proxy *iff* multple identical queries would be inflight. This would lead
to marking *all* upstreams as bad, essentially collapsing multiple
upstreams into a SPOF. Clearly not what we want.

Singleinflight does have some nice properties, but I've opted to rip it
out entirely. Caching should almost (but not quite) as good.

Added a test case in test that uses 3 CoreDNS instances to reflect the
setup from #715.

Found another bug as well, where (when the policy would be nil), we
would always Spray even though we've found a healthy host.
2017-06-08 16:06:14 +01:00
Miek Gieben
3b5b6a233f middleware/proxy: Kill goroutines on stop (#646)
* middleware/proxy: Kill goroutines on stop

Ports caddy's 59bf71c293

Excludes the proxy_test.go test part though.

Fixes #644

* Add tests
2017-04-26 10:58:14 +01:00
Miek Gieben
003b1bf678 Fix health race (#645)
* Revert "middleware/proxy: Make Unhealthy a pointer (#615)"

This reverts commit acbf522ceb.

* middleware/proxy: add proper locking

This add the proper locking around `Unhealthy`.
2017-04-24 20:37:43 +01:00
Miek Gieben
acbf522ceb middleware/proxy: Make Unhealthy a pointer (#615)
Pointer updates are atomic so drop the sync.RWMutex as it is not needed
anymore. This also fixes the race introduced with dfc71df (although I
believe this is the first time we properly tested that code path).
2017-04-13 16:26:05 +01:00
Michael S. Fischer
7dc431ada3 middleware/proxy: fix race; add Go 1.7 backward compatibility (#603)
* Fix race on backend health status update
* Ensure test case is compatible on Go 1.7
2017-03-17 07:20:55 +00:00
Michael S. Fischer
dfc71df07d middleware/proxy: Allow non-HTTP upstreams to be health checked (#589)
Allow HTTP health check to be performed against a regular DNS upstream server.

TODO: Add tests.
2017-03-16 21:10:54 +00:00
Miek Gieben
5ac6020f45 Pr 586 tweaks (#594)
* add proxy tcp

* add truncated for tcp to udp response

* move truncation to scrubbing

* add test that executes upstream over tcp

* middleware/proxy: some tweaks

rename force-tcp to force_tcp to be inline with the rest and use
a dnsOptions struct to put the options in to allow it to be extended.
Add some parse tests as well.

* Fix test and rename dnsOptions Options
2017-03-14 21:32:21 +00:00
Yong Tang
81af74aad0 Fix import path github.com/miekg/coredns -> github.com/coredns/coredns (#547)
This fix fixes import path from
`github.com/miekg/coredns`
->
`github.com/coredns/coredns`
2017-02-22 06:51:47 +00:00
John Belamaric
061b3fc1bd Client-side of gRPC proxy (#511)
* WIP: Client-side of gRPC proxy

* Add tests

* gofmt

* Implement OnShutdown; add a little logging

* Update for context in Exchange change

* go fmt

* Update README

* Review comments

* Compiling is good

* More README improvements
2017-02-14 22:20:20 -05:00
Miek Gieben
89dc5720d0 And make it actually work (#508) 2017-02-07 21:03:17 +00:00
Miek Gieben
dbe1b2510d middleware/proxy: fix except keyword (#505)
Fix the except keyword usage - the config would allow it, but it was
not enforced in the code.
Turns out that **FROM** was also not enforced, fix both, by (basically)
copying the code from Caddy.

Update the README and tests.

Locally test as well, shows that this works:

~~~
.:1053 {
    proxy miek.nl 8.8.8.8:53 {
        except a.miek.nl
    }
    proxy a.miek.nl 8.8.4.4:53

    errors stdout
    log stdout
}
~~~

And gives the desired results, not having a proxy line for `a.miek.nl`
results in a SERVFAIL (as expected).

Fixes #502
2017-02-07 18:01:16 +00:00
Miek Gieben
123a76c91e middleware/proxy: absorb httpproxy (#481)
* middleware/proxy: absorb httpproxy

Move the httproxy into proxy. This adds and Exchanger interface which
is used to exchange the messages with the upstream.

The https_google upstream will re-resolve itself and update the upstream
hosts used every 300s.

* Remove and add TODO
2017-02-06 19:32:48 +00:00
Miek Gieben
52e01264e8 middleware/proxy: implement Exchanger (#480)
By defining and using an proxy.Exchanger interface we make the proxy
more generic and we can then fold back httproxy into proxy.

This overrides #463 and #473 and should make futures extensions rather
trivial

* Add docs that talk about `protocol` and how to set it.
* middleware/proxy: rename New to NewLookup
  It's used as a Lookup mechanism not as a completely new proxy,
  reflect that in the name.
* Set maxfails to 3 by default when looking up names.

Most of the changes have been copied
from https://github.com/johnbelamaric/coredns/pull/1/files
2017-01-15 08:12:58 +00:00
Miek Gieben
4a8db8a4ce middleware/proxy: config syntax cleanups (#435)
* middleware/proxy: config syntax cleanups

Allow port numbers to be used in the transfer statements and clean
up the proxy stanza parsing. Also allow, when specifying an upstream,
/etc/resolv.conf (or any other file) to be used for getting the upstream
nameserver.

Add tests and fix the documentation to make clear what is allowed.

* Fix the other upstream parse as well
2016-11-24 16:57:20 +01:00
John Belamaric
6d9d60081d Add option to parse resolv.conf for proxy upstreams (#353)
* Add option to parse resolv.conf for proxy upstreams

* Add test and README update for resolv.conf proxy

* Run gofmt
2016-10-22 15:52:10 +01:00
Miek Gieben
a05901f62a middleware/proxy: make it scale (#287)
* middleware/proxy

Use connection pooling for communicating with an upstream, instead of
opening a new socket every time.

This makes the proxy more efficient and allowed for some cleanups.

* Some cleanups

* Some fixes

* more

* Kill pool

* Add nil check

* remove pool
2016-10-08 14:46:22 +01:00
Yong Tang
b9cf32f7a9 Golint middleware/proxy (#290)
While looking into the proxy middleware it appears that there are
several golint messages:
```
ubuntu@ubuntu:~/coredns$ golint middleware/proxy/
middleware/proxy/lookup.go:66:1: exported method Proxy.Forward should have comment or be unexported
middleware/proxy/proxy.go:24:6: exported type Client should have comment or be unexported
middleware/proxy/proxy.go:107:1: exported function Clients should have comment or be unexported
middleware/proxy/reverseproxy.go:10:6: exported type ReverseProxy should have comment or be unexported
middleware/proxy/reverseproxy.go:16:1: exported method ReverseProxy.ServeDNS should have comment or be unexported
middleware/proxy/upstream.go:42:6: exported type Options should have comment or be unexported
```

This fix addressed the above golint messages.

Signed-off-by: Yong Tang <yong.tang.github@outlook.com>
2016-09-23 23:00:50 +01:00
Miek Gieben
090d1872e9 Golint2 (#280)
* Fix linter errors

* More linting fixes

* More docs and making members private that dont need to be public

* Fix linter errors

* More linting fixes

* More docs and making members private that dont need to be public

* More lint fixes

This leaves:

~~~
middleware/kubernetes/nametemplate/nametemplate.go:64:6: exported type NameTemplate should have comment or be unexported
middleware/kubernetes/nametemplate/nametemplate.go:71:1: exported method NameTemplate.SetTemplate should have comment or be unexported
middleware/kubernetes/nametemplate/nametemplate.go:108:1: exported method NameTemplate.GetZoneFromSegmentArray should have comment or be unexported
middleware/kubernetes/nametemplate/nametemplate.go:116:1: exported method NameTemplate.GetNamespaceFromSegmentArray should have comment or be unexported
middleware/kubernetes/nametemplate/nametemplate.go:120:1: exported method NameTemplate.GetServiceFromSegmentArray should have comment or be unexported
middleware/kubernetes/nametemplate/nametemplate.go:124:1: exported method NameTemplate.GetTypeFromSegmentArray should have comment or be unexported
middleware/kubernetes/nametemplate/nametemplate.go:135:1: exported method NameTemplate.GetSymbolFromSegmentArray should have comment or be unexported
middleware/kubernetes/nametemplate/nametemplate.go:167:1: exported method NameTemplate.IsValid should have comment or be unexported
middleware/kubernetes/nametemplate/nametemplate.go:182:6: exported type NameValues should have comment or be unexported
middleware/kubernetes/util/util.go:1:1: package comment should be of the form "Package util ..."
middleware/kubernetes/util/util.go:27:2: exported const WildcardStar should have comment (or a comment on this block) or be unexported
middleware/proxy/lookup.go:66:1: exported method Proxy.Forward should have comment or be unexported
middleware/proxy/proxy.go:24:6: exported type Client should have comment or be unexported
middleware/proxy/proxy.go:107:1: exported function Clients should have comment or be unexported
middleware/proxy/reverseproxy.go:10:6: exported type ReverseProxy should have comment or be unexported
middleware/proxy/reverseproxy.go:16:1: exported method ReverseProxy.ServeDNS should have comment or be unexported
middleware/proxy/upstream.go:42:6: exported type Options should have comment or be unexported
~~~

I plan on reworking the proxy anyway, so I'll leave that be.
2016-09-23 09:14:12 +01:00
Yong Tang
ed907d3327 Fix proxy upstream parser issue and add test cases (#263)
This fix tries to fix 261 where proxy upstream parser is not
able to parse upstream correctly.

Several test cases have also been added to cover the changes
and prevent regression in the future.

This fix fixes 261.

Signed-off-by: Yong Tang <yong.tang.github@outlook.com>
2016-09-17 07:49:35 +01:00
Miek Gieben
9ac3cab1b7 Make CoreDNS a server type plugin for Caddy (#220)
* Make CoreDNS a server type plugin for Caddy

Remove code we don't need and port all middleware over. Fix all tests
and rework the documentation.

Also make `go generate` build a caddy binary which we then copy into
our directory. This means `go build`-builds remain working as-is.

And new etc instances in each etcd test for better isolation.
Fix more tests and rework test.Server with the newer support Caddy offers.

Fix Makefile to support new mode of operation.
2016-08-19 17:14:17 -07:00
Miek Gieben
34ffb2b314 Fix TestStubLookup and TestLookup (#213)
Changes large parts of proxy lookup mechanism.

The duplicate zone checking erroneous added a nameserver for each
zone we are auth. for, creating to many backend hosts. So even when a
host was determined do be Down() we still got an (identical) new one
from the list.

The Down() and failure checking for upstream hosts had data race in the
uh.Fails check - we now use atomic.LoadInt32 for that.

Use and debug the test/server.go test servers implementation in the
TestStubLookup test to prevent going out to the internet.

Also delete the stub cycle test. That test was wrong and did not test
what it needed to be testing.  Deleted for now.
2016-08-14 12:57:49 -06:00
Miek Gieben
558c34a23e middleware/proxy: healthchecks fixes (#183)
* middleware/proxy: add spray keyword

When spray is used, the proxy will, when all backend are down, spray to
each target. When not used, default to the old defaults: max 1 failure
and no spray. These defaults are also used when forwarding queries to
another CoreDNS instance.

Update the README with the new keyword.

* typos

* Make MaxFail = 1 again

* more reversals
2016-07-04 21:13:28 +01:00
Miek Gieben
e635b4e773 middleware/proxy: multiple enhancements (#145)
Add port 53 in the proxy host if not specified.
Check if the host is actually an IP address (v4 or v6)
Remove the http headers and other TODOs
2016-04-30 15:54:41 +01:00
Miek Gieben
25cf16af0e Use dns.IsSubDomain (#112)
For the match function use the proper thing from go dns. Fix all
callers and tests to use this.

Fixes: #107
2016-04-12 22:34:44 +01:00
Miek Gieben
efcb5cddbc Various cleanups and fixes (#88)
Add port number to health check. Add tests the rewrite

middleware.



Fixes #36
2016-04-07 17:42:35 +01:00
Miek Gieben
78432f78a9 Fix upstream tests 2016-03-19 16:11:30 +00:00
Miek Gieben
39dbd447b5 Fix middleware log 2016-03-19 11:16:08 +00:00
Miek Gieben
3ec0d9fe6b First commit 2016-03-18 20:57:35 +00:00