From c572c7b0e93f9e96cd65b7ec406a00b806735492 Mon Sep 17 00:00:00 2001 From: Eugene Bujak Date: Fri, 7 Sep 2018 15:46:38 +0300 Subject: [PATCH 1/7] dnsfilter metrics -- parental cache hits were counted as safebrowsing cache hits --- dnsfilter/dnsfilter.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dnsfilter/dnsfilter.go b/dnsfilter/dnsfilter.go index 0bf004ce..59d731b6 100644 --- a/dnsfilter/dnsfilter.go +++ b/dnsfilter/dnsfilter.go @@ -563,7 +563,7 @@ func (d *Dnsfilter) lookupCommon(host string, lookupstats *LookupStats, cache gc // check cache cachedValue, isFound, err := getCachedReason(cache, host) if isFound { - atomic.AddUint64(&stats.Safebrowsing.CacheHits, 1) + atomic.AddUint64(&lookupstats.CacheHits, 1) return cachedValue, nil } if err != nil { From 3b9aaff861ac4b9df31a9e7bc661e388bf534bb5 Mon Sep 17 00:00:00 2001 From: Eugene Bujak Date: Fri, 7 Sep 2018 16:10:11 +0300 Subject: [PATCH 2/7] coredns plugin metrics -- deduplicate code --- coredns_plugin/coredns_plugin.go | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/coredns_plugin/coredns_plugin.go b/coredns_plugin/coredns_plugin.go index 7f922d0e..b06910ab 100644 --- a/coredns_plugin/coredns_plugin.go +++ b/coredns_plugin/coredns_plugin.go @@ -261,16 +261,17 @@ func gen(ch interface{}, doFunc statsFunc, name string, text string, value float doFunc(ch, name, text, value, valueType) } +func doStatsLookup(ch interface{}, doFunc statsFunc, name string, lookupstats *dnsfilter.LookupStats) { + gen(ch, doFunc, fmt.Sprintf("coredns_dnsfilter_%s_requests", name), fmt.Sprintf("Number of %s HTTP requests that were sent", name), float64(lookupstats.Requests), prometheus.CounterValue) + gen(ch, doFunc, fmt.Sprintf("coredns_dnsfilter_%s_cachehits", name), fmt.Sprintf("Number of %s lookups that didn't need HTTP requests", name), float64(lookupstats.CacheHits), prometheus.CounterValue) + gen(ch, doFunc, fmt.Sprintf("coredns_dnsfilter_%s_pending", name), fmt.Sprintf("Number of currently pending %s HTTP requests", name), float64(lookupstats.Pending), prometheus.GaugeValue) + gen(ch, doFunc, fmt.Sprintf("coredns_dnsfilter_%s_pending_max", name), fmt.Sprintf("Maximum number of pending %s HTTP requests", name), float64(lookupstats.PendingMax), prometheus.GaugeValue) +} + func (d *Plugin) doStats(ch interface{}, doFunc statsFunc) { stats := d.d.GetStats() - gen(ch, doFunc, "coredns_dnsfilter_safebrowsing_requests", "Number of safebrowsing HTTP requests that were sent", float64(stats.Safebrowsing.Requests), prometheus.CounterValue) - gen(ch, doFunc, "coredns_dnsfilter_safebrowsing_cachehits", "Number of safebrowsing lookups that didn't need HTTP requests", float64(stats.Safebrowsing.CacheHits), prometheus.CounterValue) - gen(ch, doFunc, "coredns_dnsfilter_safebrowsing_pending", "Number of currently pending safebrowsing HTTP requests", float64(stats.Safebrowsing.Pending), prometheus.GaugeValue) - gen(ch, doFunc, "coredns_dnsfilter_safebrowsing_pending_max", "Maximum number of pending safebrowsing HTTP requests", float64(stats.Safebrowsing.PendingMax), prometheus.GaugeValue) - gen(ch, doFunc, "coredns_dnsfilter_parental_requests", "Number of parental HTTP requests that were sent", float64(stats.Parental.Requests), prometheus.CounterValue) - gen(ch, doFunc, "coredns_dnsfilter_parental_cachehits", "Number of parental lookups that didn't need HTTP requests", float64(stats.Parental.CacheHits), prometheus.CounterValue) - gen(ch, doFunc, "coredns_dnsfilter_parental_pending", "Number of currently pending parental HTTP requests", float64(stats.Parental.Pending), prometheus.GaugeValue) - gen(ch, doFunc, "coredns_dnsfilter_parental_pending_max", "Maximum number of pending parental HTTP requests", float64(stats.Parental.PendingMax), prometheus.GaugeValue) + doStatsLookup(ch, doFunc, "safebrowsing", &stats.Safebrowsing) + doStatsLookup(ch, doFunc, "parental", &stats.Parental) } func (d *Plugin) Describe(ch chan<- *prometheus.Desc) { From 6fc50cd743a38f681b151703bbe06dd9cbc8e07c Mon Sep 17 00:00:00 2001 From: Eugene Bujak Date: Fri, 7 Sep 2018 16:10:43 +0300 Subject: [PATCH 3/7] dnsfilter -- small code cleanup --- dnsfilter/dnsfilter.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/dnsfilter/dnsfilter.go b/dnsfilter/dnsfilter.go index 59d731b6..b9305948 100644 --- a/dnsfilter/dnsfilter.go +++ b/dnsfilter/dnsfilter.go @@ -521,11 +521,11 @@ func (d *Dnsfilter) checkSafeBrowsing(host string) (Result, error) { } func (d *Dnsfilter) checkParental(host string) (Result, error) { - format2 := func(hashparam string) string { + format := func(hashparam string) string { url := fmt.Sprintf(defaultParentalURL, hashparam, d.config.parentalSensitivity) return url } - handleBody2 := func(body []byte, hashes map[string]bool) (Result, error) { + handleBody := func(body []byte, hashes map[string]bool) (Result, error) { // parse json var m []struct { Blocked bool `json:"blocked"` @@ -551,7 +551,7 @@ func (d *Dnsfilter) checkParental(host string) (Result, error) { } return result, nil } - result, err := d.lookupCommon(host, &stats.Parental, parentalCache, false, format2, handleBody2) + result, err := d.lookupCommon(host, &stats.Parental, parentalCache, false, format, handleBody) return result, err } From ebf2380af4d2e1777fa1566ba189c680d82fbff3 Mon Sep 17 00:00:00 2001 From: Eugene Bujak Date: Fri, 7 Sep 2018 16:13:03 +0300 Subject: [PATCH 4/7] travis -- move dependency installation to install section, simplify go test invocation to test all subdirs in one go --- .travis.yml | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/.travis.yml b/.travis.yml index 48ee22fd..bcd2fdc7 100644 --- a/.travis.yml +++ b/.travis.yml @@ -10,8 +10,10 @@ os: - linux - osx -script: - - cd dnsfilter && go get -d -t . && go test - - cd ../coredns_plugin && go get -d -t . && go test - - cd .. && make +install: + - go get -d -t ./... + +script: + - go test ./... + - make From 1b5748e32829e6a665939ea4c8c59b3c56fc3735 Mon Sep 17 00:00:00 2001 From: Eugene Bujak Date: Fri, 7 Sep 2018 16:13:23 +0300 Subject: [PATCH 5/7] travis -- don't use slow master or tip builds, just specify 1.x for latest go version --- .travis.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index bcd2fdc7..78bf68c0 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,8 +3,7 @@ sudo: false go: - 1.10.x - 1.11.x - - master - - tip + - 1.x os: - linux From 659b530381c6a3108752aed2b7c6c453aa450b01 Mon Sep 17 00:00:00 2001 From: Eugene Bujak Date: Fri, 7 Sep 2018 16:14:25 +0300 Subject: [PATCH 6/7] makefile -- use npm --prefix syntax instead of doing cd into subdir --- Makefile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index 864e6361..88c65401 100644 --- a/Makefile +++ b/Makefile @@ -12,8 +12,8 @@ all: build build: AdguardDNS coredns $(STATIC): - cd client; npm install - cd client; npm run build-prod + npm --prefix client install + npm --prefix client run build-prod AdguardDNS: $(STATIC) *.go echo mkfile_dir = $(mkfile_dir) From 9682dc6bc19ea940cf71911f6281450c7027eb16 Mon Sep 17 00:00:00 2001 From: Eugene Bujak Date: Fri, 7 Sep 2018 16:14:43 +0300 Subject: [PATCH 7/7] travis -- npm installation of dependencies belongs in install section --- .travis.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.travis.yml b/.travis.yml index 78bf68c0..71cc29b5 100644 --- a/.travis.yml +++ b/.travis.yml @@ -11,6 +11,7 @@ os: install: - go get -d -t ./... + - npm --prefix client install script: - go test ./...