Commit graph

44 commits

Author SHA1 Message Date
Ondřej Benkovský
c2dbb7141a
add golangci-lint linter (#5499) 2022-07-10 11:06:33 -07:00
Andy Lindeman
6e58595c61
Log the literal value, not a format string (#5425)
Signed-off-by: Andy Lindeman <andy@lindeman.io>
2022-06-05 13:17:00 -04:00
Yong Tang
e391a39322
[plugin/log] Expand {combined} and {common} in log format (#5230)
This PR tries to address the issue raised in 5223 where `{combined}`
or `{common}` in log format will not expand when `{combined}` or `{common}`
is not the only token in the format.

This PR fixes 5223.

Signed-off-by: Yong Tang <yong.tang.github@outlook.com>
2022-03-07 06:49:56 -08:00
Zou Nengren
5191959bd7
cleanup deprecated package io/ioutil (#4920)
Signed-off-by: zounengren <zouyee1989@gmail.com>
2021-10-13 09:30:31 +02:00
Miek Gieben
491e30a292
plugin/log: fix closing of codeblock (#4680)
This fixes the rendering of this README as html. The codeblock was
closed with 4 ~, should be 3.

Signed-off-by: Miek Gieben <miek@miek.nl>
2021-06-08 07:33:15 -07:00
Miek Gieben
9178f9d1ee
Remove newlines between braces (#4279)
These are found with: `pcregrep -M "}\n\n}" **/*.go`
Sometimes a unneeded newline is inserted, remove those.

Signed-off-by: Miek Gieben <miek@miek.nl>
2020-11-11 18:45:01 +01:00
Miek Gieben
b003d06003
For caddy v1 in our org (#4018)
* For caddy v1 in our org

This RP changes all imports for caddyserver/caddy to coredns/caddy. This
is the v1 code of caddy.

For the coredns/caddy repo the following changes have been made:

* anything not needed by us is deleted
* all `telemetry` stuff is deleted
* all its import paths are also changed to point to coredns/caddy
* the v1 branch has been moved to the master branch
* a v1.1.0 tag has been added to signal the latest release

Signed-off-by: Miek Gieben <miek@miek.nl>

* Fix imports

Signed-off-by: Miek Gieben <miek@miek.nl>

* Group coredns/caddy with out plugins

Signed-off-by: Miek Gieben <miek@miek.nl>

* remove this file

Signed-off-by: Miek Gieben <miek@miek.nl>

* Relax import ordering

github.com/coredns is now also a coredns dep, this makes
github.com/coredns/caddy fit more natural in the list.

Signed-off-by: Miek Gieben <miek@miek.nl>

* Fix final import

Signed-off-by: Miek Gieben <miek@miek.nl>
2020-09-24 18:14:41 +02:00
Miek Gieben
c95faea624
docs: update README and log plugin (#3602)
README: remove the logo thing as we stopped doing that
log: remote the lines about the clock output as that's gone as well and
     discuss the query log vs other logging a bit.

Signed-off-by: Miek Gieben <miek@miek.nl>
2020-01-17 16:16:29 +01:00
Miek Gieben
24176a97e6
Move to CODEOWNERS (#3489)
* Move to CODEOWNERS

No change in who own what; just a move to CODEOWNERS. This allows
dreck cleanups.

Added .dreck.yaml for alias and exec.

Fixes: #3486

Signed-off-by: Miek Gieben <miek@miek.nl>

* stickler bot

Signed-off-by: Miek Gieben <miek@miek.nl>

* sort the file

Signed-off-by: Miek Gieben <miek@miek.nl>
2019-11-29 13:17:05 +00:00
Miek Gieben
004c5fca9d
all: simply registering plugins (#3287)
Abstract the caddy call and make it simpler.

See #3261 for some part of the discussion.

Go from:

~~~ go
func init() {
       caddy.RegisterPlugin("any", caddy.Plugin{
               ServerType: "dns",
               Action:     setup,
       })
}
~~~

To:

~~~ go
func init() { plugin.Register("any", setup) }
~~~

This requires some external documents in coredns.io to be updated as
well; the old way still works, so it's backwards compatible.

Signed-off-by: Miek Gieben <miek@miek.nl>
2019-09-20 08:02:30 +01:00
Miek Gieben
62317c3c14 update doc to not use the root zone for everything (#3288)
Update all documentation in the tree to use example.org as an example
configuration (in so far possible). As to get out of the just use "."
and fallthrough and things would be fine.

Signed-off-by: Miek Gieben <miek@miek.nl>
2019-09-19 06:17:53 -07:00
Charlie Vieth
21e9c6047b Fix log plugin benchmark and slightly improve performance (#3004)
* log: use ioutil.Discard as write buffer in benchmark

Using a buffer gives unrealistic stats and consumes a large amount of
memory.

* log: lazily check if a msg should be logged

* log: improve variable name

Change 'ok' to the more descriptive 'shouldLog'.

* log: code comments: don't reuse variable
2019-07-16 19:00:22 +00:00
Yong Tang
f8bba51f84
Update Caddy to 1.0.1, and update import path (#2961)
* Update Caddy to 1.0.1, and update import path

This fix updates caddy to 1.0.1 and also
updates the import path to github.com/caddyserver/caddy

This fix fixes 2959

Signed-off-by: Yong Tang <yong.tang.github@outlook.com>

* Also update plugin.cfg

Signed-off-by: Yong Tang <yong.tang.github@outlook.com>

* Update and bump zplugin.go

Signed-off-by: Yong Tang <yong.tang.github@outlook.com>
2019-07-03 09:04:47 +08:00
Miek Gieben
cd176f859b Run gofmt -s and golint on the codebase (#2918)
* Run gofmt -s and golint on the codebase

Run golint and fix everythign it flagged (except the context arg
ordering), mostly edits in the rewrite plugin.

Signed-off-by: Miek Gieben <miek@miek.nl>

* ... and ofcourse the test as well

Signed-off-by: Miek Gieben <miek@miek.nl>
2019-06-25 15:00:33 +08:00
Miek Gieben
58c703f5ef
Run gofmt -w -s on codebase (#2773)
This formats and simplifies all code by running gofmt -w -s on all Go
files.

Signed-off-by: Miek Gieben <miek@miek.nl>
2019-04-08 11:13:46 +01:00
Miek Gieben
45624a0c0a plugin/log: remove ErrorFunc (#2716)
The server handles this case no need to also do it in the log plugin.

Means DefaultErrorFunc can be private to the dnsserver and is now
renamed to just errorFunc

Fixes: #2715

Signed-off-by: Miek Gieben <miek@miek.nl>
2019-03-25 11:36:46 +08:00
Miek Gieben
e47d881461
pkg/replace: make it more efficient. (#2544)
* pkg/replace: make it more efficient.

Remove the map that is allocated on every write and make it more static,
but just defining a function that gets called for a label and returns
its value.

Remove the interface definition and just implement what is needed in our
case. Add benchmark test for replace as well.

Extend metadata test to test multiple values (pretty sure this didn't
work, but there wasn't a test for it, so can't be sure).

Update all callers to use it - concurrent use should be fine as we pass
everything by value.

Benchmarks in replacer:

new: BenchmarkReplacer-4   300000      4717 ns/op     240 B/op       8 allocs/op
old: BenchmarkReplacer-4   300000      4368 ns/op     384 B/op      11 allocs/op

Added benchmark function to the old code to test it.

~~~
func BenchmarkReplacer(b *testing.B) {
	w := dnstest.NewRecorder(&test.ResponseWriter{})
	r := new(dns.Msg)
	r.SetQuestion("example.org.", dns.TypeHINFO)
	r.MsgHdr.AuthenticatedData = true
	b.ResetTimer()
	b.ReportAllocs()
	repl := New(context.TODO(), r, w, "")
	for i := 0; i < b.N; i++ {
		repl.Replace("{type} {name} {size}")
	}
}
~~~

New code contains (of course a different one). The amount of ops is
more, which might be good to look at some more. For all the allocations
is seems it was quite performant.

This looks to be 50% faster, and there is less allocations in log
plugin:

old: BenchmarkLogged-4   	   20000	     70526 ns/op
new: BenchmarkLogged-4   	   30000	     57558 ns/op

Signed-off-by: Miek Gieben <miek@miek.nl>

* Stickler bot

Signed-off-by: Miek Gieben <miek@miek.nl>

* Improve test coverage

Signed-off-by: Miek Gieben <miek@miek.nl>

* typo

Signed-off-by: Miek Gieben <miek@miek.nl>

* Add test for malformed log lines

Signed-off-by: Miek Gieben <miek@miek.nl>
2019-02-12 07:38:49 +00:00
ckcd
2b651129fb plugin/log: add test and benchmark (#2515) 2019-01-30 11:12:26 +00:00
ckcd
418edd2a2f plugin/log: support multi nameScope (#2420) 2019-01-08 07:40:50 +00:00
Miek Gieben
35b74eb197
plugin/log: update nodata/NXDOMAIN story a bit (#2416)
* plugin/log: update nodata/NXDOMAIN story a bit

Add more words on nodata and NXDOMAIN which is a confusing DNS
"feature"

Fixes: #2412

Signed-off-by: Miek Gieben <miek@miek.nl>

* typos

Signed-off-by: Miek Gieben <miek@miek.nl>
2019-01-05 16:33:27 +00:00
Miek Gieben
300506ee91
plugin/log: detail {combined} and {common} (#2422)
These can be used (and are handy), document them.

Signed-off-by: Miek Gieben <miek@miek.nl>
2019-01-04 19:39:02 +00:00
Miek Gieben
9abbf4a4a0 map bool -> map struct{} (#2386)
This clear out the remaining map[x]bool usage and moves the bool to an
empty struct.

Two note worthy other changes:

* EnableChaos in the server is now also exported to make it show up in
  the documentation.
* The auto plugin is left as is, because there the boolean is
  explicitaly set to false to signal 'to-be-deleted' and the key is left
  as-is.

Signed-off-by: Miek Gieben <miek@miek.nl>
2018-12-10 02:17:15 -08:00
Miek Gieben
fc667b98e0
Fix EDNS0 compliance (#2357)
* Fix EDNS0 compliance

Do SizeAndDo in the server (ScrubWriter) and remove all uses of this
from the plugins. Also *always* do it. This is to get into compliance
for https://dnsflagday.net/.

The pkg/edns0 now exports the EDNS0 options we understand; this is
exported to allow plugins add things there. The *rewrite* plugin used
this to add custom EDNS0 option codes that the server needs to
understand.

This also needs a new release of miekg/dns because it triggered a
race-condition that was basicly there forever.

See:
* https://github.com/miekg/dns/issues/857
* https://github.com/miekg/dns/pull/859

Running a test instance and pointing the https://ednscomp.isc.org/ednscomp
to it shows the tests are now fixed:

~~~
EDNS Compliance Tester
Checking: 'miek.nl' as at 2018-12-01T17:53:15Z

miek.nl. @147.75.204.203 (drone.coredns.io.): dns=ok edns=ok edns1=ok edns@512=ok ednsopt=ok edns1opt=ok do=ok ednsflags=ok docookie=ok edns512tcp=ok optlist=ok
miek.nl. @2604:1380:2002:a000::1 (drone.coredns.io.): dns=ok edns=ok edns1=ok edns@512=ok ednsopt=ok edns1opt=ok do=ok ednsflags=ok docookie=ok edns512tcp=ok optlist=ok

All Ok
Codes
ok - test passed.
~~~

Signed-off-by: Miek Gieben <miek@miek.nl>

Signed-off-by: Miek Gieben <miek@miek.nl>

* typos in comments

Signed-off-by: Miek Gieben <miek@miek.nl>
2018-12-06 21:18:11 +00:00
Francois Tur
94c9aae323 plugin/log - Support for Metadata (#2251)
* - add metadata support to Log

* - adapt ctx after rebase
2018-11-13 11:20:49 -08:00
Miek Gieben
921b02e2d5 plugin/log: explain the {size} better (#2269)
This is now the raw size which may be larger than what a particular
client actually sees.

Clarify this a bit.

Fixes #2258

Signed-off-by: Miek Gieben <miek@miek.nl>
2018-11-03 11:58:15 -07:00
Miek Gieben
2456416444
logging: unify pkg/log and plugin/log (#2245)
Default to using pkg/log for all logging and use a fixed time prefix
which is RFC3339Millli (doesn't exist in time, so we just extended
RFC3339), i.e. Nano might be pushing it.

Logs go from:

2018/10/30 19:14:55 [INFO] CoreDNS-1.2.5
2018/10/30 19:14:55 [INFO] linux/amd64, go1.11,

to:

2018-10-30T19:10:07.547Z [INFO] CoreDNS-1.2.5
2018-10-30T19:10:07.547Z [INFO] linux/amd64, go1.11,

Which includes the timezone - which oddly the std log package doesn't
natively do.

Signed-off-by: Miek Gieben <miek@miek.nl>
2018-10-31 21:32:23 +00:00
Miek Gieben
1ef0a02b46
Revert "log/forward plugins: Extend dns query logging (#2240)" (#2256)
This reverts commit 8045aa279b.
2018-10-31 21:03:46 +00:00
Dzmitry Razhanski
8045aa279b log/forward plugins: Extend dns query logging (#2240)
Automatically submitted.
2018-10-29 18:50:31 +00:00
Miek Gieben
f3134da45e
Clean up tests logging (#1979)
* Clean up tests logging

This cleans up the travis logs so you can see the failures better.

Older tests in tests/ would call log.SetOutput(ioutil.Discard) in
a haphazard way. This add log.Discard and put an `init` function in each
package's dir (no way to do this globally). The cleanup in tests/ is
clear.

All plugins also got this init function to have some uniformity and kill
any (future) logging there in the tests as well.

There is a one-off in pkg/healthcheck because that does log.

Signed-off-by: Miek Gieben <miek@miek.nl>

* bring back original log_test.go

Signed-off-by: Miek Gieben <miek@miek.nl>

* suppress logging here as well

Signed-off-by: Miek Gieben <miek@miek.nl>
2018-07-19 16:23:06 +01:00
Miek Gieben
0930eb8beb
all: fix plugin import ordering (#1717)
Got a bit messed up with stb lib "context" usage.
2018-04-22 08:34:35 +01:00
Miek Gieben
8722336fff
global: move to context (#1699)
* global: move to context

Move from golang.org/x/net/context to std lib's context.

Change done with:

for i in $(grep -l '/context' **/*.go); do sed -e 's|golang.org/x/net/context|context|' -i $i; echo $i; done
for i in **/*.go; do goimports -w $i; done

* drop from dns.pb.go as well
2018-04-20 11:01:06 +01:00
Miek Gieben
08443a9f00
plugin/metrics: add 'server' label (#1682)
* plugin/metrics: add 'server' label

This uses the new WithServer(ctx) to get the current server from the
context.

First in a larger refactor to make all plugins do this.

* compile

* compile

* lala test

* compile and test

* typos

* Dont duplicate the code
2018-04-18 09:42:20 +01:00
Maksim Paramonau
9ae9ee4b6b fix readme.md of log plugin (#1668) 2018-04-11 19:07:10 +01:00
Maksim Paramonau
ccfe691b95 plugin/log: allow various combinations of classes of responses (#1664)
This allows to log responses of different classes, for example, denial and error.
2018-04-11 07:50:16 +01:00
Miek Gieben
5faa9e7bc1
plugin/log: log remote port addr as well (#1573)
Log the remote's port, for IPv6 addr this means we should enclose the v6
address in brackets; make this the default for 'remote'.
2018-02-28 18:15:12 -08:00
Miek Gieben
006ce4d56e
Add Chris back (#1513)
Pinged me, still interested in helping out \o/
2018-02-09 10:48:07 +00:00
Miek Gieben
fd7abd9849
Add OWNERS file (#1486)
This should have everyone, but the process was quite manual. The rename
from middleware -> plugin also meant I had to do some extra digging on
who actually submitted the PR. I also double checked the current list of
people with commit access.

Every plugin now has an OWNERS, except *reverse*. I'll file a bug for
that.
2018-02-08 10:55:51 +00:00
Miek Gieben
05ebfaa36a
plugin/log: add the super useful msg ID into the logs (#1387) 2018-01-12 18:03:47 +00:00
Miek Gieben
58221f55db
Manual pages (#1346)
* Add manual pages

Generate manual pages from the README and extend README with Name and
Description sections.

The generation requires 'ronn' which may not be available. Just check in
all generated manual pages.
2018-01-04 12:53:07 +00:00
Christian Nilsson
46a187df8f plugin/log: remove need to specify stdout (#1221)
* plugin/log: remove need to specify stdout

Since log will only be output to stdout is doesn't make sense to
specify it in Corefile.

Fixes: #1218

* fixup! plugin/log: remove need to specify stdout
2017-11-13 09:23:27 +00:00
Miek Gieben
beef212fbe
plugin/log: remove OutputFile (#1217)
* plugin/log: remove OutputFile

We use stdout for everything, remove OutputFile as it isn't used and
causes confusion.

Fixes #1216

* PR feedback
2017-11-10 15:17:12 +00:00
Miek Gieben
427aed6f5b doc update (#1140)
* doc update

Go through all README and fix mistakes, extend example and let more
corefile snippets be test for validity.

* Cant use spefic addr in test
2017-10-10 09:39:35 +02:00
Miek Gieben
284061eee7 pkg: add dnstest (#1098)
Add a full test server impl in this new package + tests. Move
dnsrecorder into this package as well and finish up the commented out
tests that were left in the old dnsrecorder package.

Update all callers and tests.
2017-09-21 15:15:47 +01:00
Miek Gieben
d8714e64e4 Remove the word middleware (#1067)
* Rename middleware to plugin

first pass; mostly used 'sed', few spots where I manually changed
text.

This still builds a coredns binary.

* fmt error

* Rename AddMiddleware to AddPlugin

* Readd AddMiddleware to remain backwards compat
2017-09-14 09:36:06 +01:00