aboutsummaryrefslogtreecommitdiff
path: root/plugin/cache/handler.go (follow)
AgeCommit message (Collapse)AuthorFilesLines
2021-01-15Prevent race from prefetching (#4368)Gravatar sschepens 1-20/+16
Automatically submitted.
2020-12-11Move .LocalAddr() out of goroutine (#4281)Gravatar Miek Gieben 1-1/+2
I don't have theory why this panics, but concurrency has something to do with it, so get the address before we call the goroutine. See #4271 Signed-off-by: Miek Gieben <miek@miek.nl>
2020-10-15cache: do the msg copy right (#4207)Gravatar Miek Gieben 1-7/+7
Not sure why this is proving so difficult.. pointers are hard? [Was tempted to rollback all tweaks here, but the original issue we're fixing it too important to not have a proper fix]. But we need to make a copy of the message at the earliest point in the handler because we are changing it (adding an opt rr). If we do this on the original message (which is a pointer) we change it (obvs). When undoing those changes we do work on a copy. Re: testing. There isn't a explicit test for this, so I've added on to the top-level test/ directory, which indeed makes the issue visible: master: ~~~ go test -v -run=TestLookupCacheWithoutEdns === RUN TestLookupCacheWithoutEdns cache_test.go:154: Expected no OPT RR, but got: ;; OPT PSEUDOSECTION: ; EDNS: version 0; flags: do; udp: 2048 --- FAIL: TestLookupCacheWithoutEdns (0.01s) FAIL ~~~ This branch: ~~~ % go test -v -run=TestLookupCacheWithoutEdns === RUN TestLookupCacheWithoutEdns --- PASS: TestLookupCacheWithoutEdns (0.01s) PASS ok github.com/coredns/coredns/test 0.109s ~~~ Signed-off-by: Miek Gieben <miek@miek.nl>
2020-10-14plugin/cache: fix removing OPT (#4190)Gravatar Miek Gieben 1-2/+2
By checking state.Do() were are checking if the request had DO, but we are _always_ adding Do now - do we need to save the DO from the ORIGINAL request, which must be done in the ResponseWriter. Also skip OPT records in filterDNSSEC as we can't set the TTL on those records, this prevents writing a number to OPT's MBZ. Note none of the tests have changed and still PASS. This is due to the fact that CoreDNSServerAndPorts isn't a full server as we start in main, it lacks the scrubwriter for instance. This is not bad per se, but should be documented in the test code. Signed-off-by: Miek Gieben <miek@miek.nl>
2020-09-17cache: default to DNSSEC (#4085)Gravatar Miek Gieben 1-5/+37
* cache: default to DNSSEC This change does away with the DNS/DNSSEC distinction the cache currently makes. Cache will always make coredns perform a DNSSEC query and store that result. If a client just needs plain DNS, the DNSSEC records are stripped from the response. It should also be more memory efficient, because we store a reply once and not one DNS and another for DNSSEC. Fixes: #3836 Signed-off-by: Miek Gieben <miek@miek.nl> * Change OPT RR when one is present in the msg. Signed-off-by: Miek Gieben <miek@miek.nl> * Fix comment for isDNSSEC Signed-off-by: Miek Gieben <miek@miek.nl> * Update plugin/cache/handler.go Co-authored-by: Chris O'Haver <cohaver@infoblox.com> * Update plugin/cache/item.go Co-authored-by: Chris O'Haver <cohaver@infoblox.com> * Code review; fix comment for isDNSSEC Signed-off-by: Miek Gieben <miek@miek.nl> * Update doc and set AD to false Set Authenticated Data to false when DNSSEC was not wanted. Also update the readme with the new behavior. Signed-off-by: Miek Gieben <miek@miek.nl> * Update plugin/cache/handler.go Co-authored-by: Chris O'Haver <cohaver@infoblox.com> Co-authored-by: Chris O'Haver <cohaver@infoblox.com>
2020-03-31introduce metric naming test (#3789)Gravatar Zou Nengren 1-45/+0
* introduce metric naming test Signed-off-by: zounengren <zounengren@cmss.chinamobile.com> * Update metrics.go Signed-off-by: zounengren <zounengren@cmss.chinamobile.com>
2020-03-20plugin/cache: fix negative cache masking cases (#3744)Gravatar Chris O'Haver 1-3/+3
* fix negative cache masking cases Signed-off-by: Chris O'Haver <cohaver@infoblox.com> * remove unecessary param Signed-off-by: Chris O'Haver <cohaver@infoblox.com>
2020-01-03registry cache_miss logic (#3578)Gravatar Zou Nengren 1-0/+1
Signed-off-by: zouyee <zounyee1989@gmail.com>
2019-11-29Add a serve_stale option for plugin/cache (#3468)Gravatar Gonzalo Paniagua Javier 1-11/+52
Automatically submitted.
2019-10-03cache: move goroutine closure to separate function to save memory (#3353)Gravatar Miek Gieben 1-20/+25
The goroutine closure was causing objects to be heap allocated. Moving it to a separate function fixes that. ```benchmark old ns/op new ns/op delta BenchmarkCacheResponse/NoPrefetch-12 773 713 -7.76% BenchmarkCacheResponse/Prefetch-12 878 837 -4.67% BenchmarkHash-12 9.17 9.18 +0.11% benchmark old allocs new allocs delta BenchmarkCacheResponse/NoPrefetch-12 9 8 -11.11% BenchmarkCacheResponse/Prefetch-12 9 8 -11.11% BenchmarkHash-12 0 0 +0.00% benchmark old bytes new bytes delta BenchmarkCacheResponse/NoPrefetch-12 471 327 -30.57% BenchmarkCacheResponse/Prefetch-12 471 327 -30.57% BenchmarkHash-12 0 0 +0.00% ``` Signed-off-by: Charlie Vieth <charlie.vieth@gmail.com> Signed-off-by: Miek Gieben <miek@miek.nl>
2018-09-19Ensure Re-register of metrics variables after a reload (#2080)Gravatar Francois Tur 1-3/+0
* - ensure plugins that use prometheus.MustRegister, re-register after reload - removing once.Do on the startup function was simplest way to do it. * - fix underscored names (advice of bot) * - tune existing UT for reload, and add a test verifying failing reload does not prevent correct registering for metrics * - ensure different ports for tests that can run in same time ..
2018-08-29Default to scrubbing replies in the server (#2012)Gravatar Miek Gieben 1-2/+0
Every plugin needs to deal with EDNS0 and should call Scrub to make a message fit the client's buffer. Move this functionality into the server and wrapping the ResponseWriter into a ScrubWriter that handles these bits for us. Result: Less code and faster, because multiple chained plugins could all be calling scrub and SizeAndDo - now there is just one place. Most tests in file/* and dnssec/* needed adjusting because in those unit tests you don't see OPT RRs anymore. The DNSSEC signer was also looking at the returned OPT RR to see if it needed to sign - as those are now added by the server (and thus later), this needed to change slightly. Scrub itself still exist (for backward compat reasons), but has been made a noop. Scrub has been renamed to scrub as it should not be used by external plugins. Fixes: #2010 Signed-off-by: Miek Gieben <miek@miek.nl>
2018-06-26plugin/cache: Fix: metric `cache miss total` shall include ttl case (#1897)Gravatar Jun Li 1-8/+9
In the case of ttl <= 0, `cacheMisses` should increase its counter. Signed-off-by: Jun Li <lijun.git@gmail.com>
2018-06-19Ensure cache.ResponseWriter can be used asynchronously during prefetch (#1884)Gravatar Tobias Schmidt 1-7/+5
The default dns.Response implementation of a dns.ResponseWriter will panic if RemoteAddr() is called after the connection to the client has been closed already. The current cache implementation doesn't create a new request+responsewriter during an asynchronous prefetch, but piggybacks on the request triggering the prefetch. This change copies the RemoteAddr first, so that it's safe to use it later during the actual prefetch request. A better implementation would be to completely decouple the prefetch request from the client triggering a request.
2018-04-27Cache metrics server (#1746)Gravatar Miek Gieben 1-32/+26
* plugin/cache: per server metrics Use per server metrics in the cache plugin as well. This required some plumbing changes. Also use request.Request more. * fix cherry-pick
2018-04-22all: fix plugin import ordering (#1717)Gravatar Miek Gieben 1-2/+1
Got a bit messed up with stb lib "context" usage.
2018-04-20global: move to context (#1699)Gravatar Miek Gieben 1-1/+2
* 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-03-25Fix dns-01-003 (#1634)Gravatar Miek Gieben 1-2/+9
* plugin/{cache,forward,proxy}: don't allow responses that are bogus Responses that are not matching what we've been querying for should be dropped. They are converted into FormErrs by forward and proxy; as a 2nd backstop cache will also not cache these. * plug * add explicit test
2018-01-17plugin/cache: Fix prefetching issues (#1363)Gravatar Tobias Schmidt 1-18/+35
* Improve plugin/cache metrics * Add coredns_cache_prefetch_total metric to track number of prefetches. * Remove unnecessary Cache.get() call which would incorrectly increment cache counters. * Initialize all counters and gauges at zero. * Allow prefetching of a single request per ttl The original implementation didn't allow prefetching queries which are only requested once during the duration of a TTL. The minimum amount of queries which had to be seen was therefore capped at 2. This change also implements a real prefetch test. The existing test was a noop and always passed regardless of any prefetch implementation. * Fix prefetching for items with a short TTL The default prefetch threshold (percentage) is 10% of the lifetime of a cache item. With the previous implementation, this disabled prefetching for all items with a TTL < 10s (the resulting percentage would be 0, at which point a cached item is already discarded). This change uses a time based threshold calculation and ensures that a prefetch is triggered at a TTL of 1 at the latest. * Fix wrong duration reporting of cached responses The logging and metrics plugins (among others) included the duration of a cache prefetch in the request latency of client request. This change fixes this wrong reporting and executes the prefetch request in a goroutine in the background.
2017-12-27metrics: correctly register all metrics (#1335)Gravatar Miek Gieben 1-12/+6
After initial startup, see if prometheus is loaded and if so, register our metrics with it. Stop doing the init() func and just use the sync.Once so we don't double registrer our metrics.
2017-10-13plugin/cache: don't update freq is prefetch isn't used. (#1144)Gravatar Miek Gieben 1-1/+3
Small optimization.
2017-09-20plugin/cache: cap TTL on first answer (#1092)Gravatar Miek Gieben 1-1/+1
Cache would let the first response through and would then cap subsequent ones to whatever the cache duration was. This would lead to huge drops in TTL values: 3600 -> 20 for instance, which is not only bad, but can mess up your careful TTL planning business. This PR fixes that and applies the cache duration to all replies. As a bonus I could remove a time.Sleep() from the cache test and just check for the cache duration as the TTL on the reply. Fixes #1038
2017-09-14Remove the word middleware (#1067)Gravatar Miek Gieben 1-0/+119
* 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