Merge pull request #8 in DNS/adguard-dns from parental_metrics to master
* commit '9682dc6bc19ea940cf71911f6281450c7027eb16': travis -- npm installation of dependencies belongs in install section makefile -- use npm --prefix syntax instead of doing cd into subdir travis -- don't use slow master or tip builds, just specify 1.x for latest go version travis -- move dependency installation to install section, simplify go test invocation to test all subdirs in one go dnsfilter -- small code cleanup coredns plugin metrics -- deduplicate code dnsfilter metrics -- parental cache hits were counted as safebrowsing cache hits
This commit is contained in:
commit
38b3fe6718
14
.travis.yml
14
.travis.yml
@ -3,15 +3,17 @@ sudo: false
|
|||||||
go:
|
go:
|
||||||
- 1.10.x
|
- 1.10.x
|
||||||
- 1.11.x
|
- 1.11.x
|
||||||
- master
|
- 1.x
|
||||||
- tip
|
|
||||||
|
|
||||||
os:
|
os:
|
||||||
- linux
|
- linux
|
||||||
- osx
|
- osx
|
||||||
|
|
||||||
script:
|
install:
|
||||||
- cd dnsfilter && go get -d -t . && go test
|
- go get -d -t ./...
|
||||||
- cd ../coredns_plugin && go get -d -t . && go test
|
- npm --prefix client install
|
||||||
- cd .. && make
|
|
||||||
|
script:
|
||||||
|
- go test ./...
|
||||||
|
- make
|
||||||
|
|
||||||
|
4
Makefile
4
Makefile
@ -12,8 +12,8 @@ all: build
|
|||||||
build: AdguardDNS coredns
|
build: AdguardDNS coredns
|
||||||
|
|
||||||
$(STATIC):
|
$(STATIC):
|
||||||
cd client; npm install
|
npm --prefix client install
|
||||||
cd client; npm run build-prod
|
npm --prefix client run build-prod
|
||||||
|
|
||||||
AdguardDNS: $(STATIC) *.go
|
AdguardDNS: $(STATIC) *.go
|
||||||
echo mkfile_dir = $(mkfile_dir)
|
echo mkfile_dir = $(mkfile_dir)
|
||||||
|
@ -261,16 +261,17 @@ func gen(ch interface{}, doFunc statsFunc, name string, text string, value float
|
|||||||
doFunc(ch, name, text, value, valueType)
|
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) {
|
func (d *Plugin) doStats(ch interface{}, doFunc statsFunc) {
|
||||||
stats := d.d.GetStats()
|
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)
|
doStatsLookup(ch, doFunc, "safebrowsing", &stats.Safebrowsing)
|
||||||
gen(ch, doFunc, "coredns_dnsfilter_safebrowsing_cachehits", "Number of safebrowsing lookups that didn't need HTTP requests", float64(stats.Safebrowsing.CacheHits), prometheus.CounterValue)
|
doStatsLookup(ch, doFunc, "parental", &stats.Parental)
|
||||||
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)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *Plugin) Describe(ch chan<- *prometheus.Desc) {
|
func (d *Plugin) Describe(ch chan<- *prometheus.Desc) {
|
||||||
|
@ -521,11 +521,11 @@ func (d *Dnsfilter) checkSafeBrowsing(host string) (Result, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (d *Dnsfilter) checkParental(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)
|
url := fmt.Sprintf(defaultParentalURL, hashparam, d.config.parentalSensitivity)
|
||||||
return url
|
return url
|
||||||
}
|
}
|
||||||
handleBody2 := func(body []byte, hashes map[string]bool) (Result, error) {
|
handleBody := func(body []byte, hashes map[string]bool) (Result, error) {
|
||||||
// parse json
|
// parse json
|
||||||
var m []struct {
|
var m []struct {
|
||||||
Blocked bool `json:"blocked"`
|
Blocked bool `json:"blocked"`
|
||||||
@ -551,7 +551,7 @@ func (d *Dnsfilter) checkParental(host string) (Result, error) {
|
|||||||
}
|
}
|
||||||
return result, nil
|
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
|
return result, err
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -563,7 +563,7 @@ func (d *Dnsfilter) lookupCommon(host string, lookupstats *LookupStats, cache gc
|
|||||||
// check cache
|
// check cache
|
||||||
cachedValue, isFound, err := getCachedReason(cache, host)
|
cachedValue, isFound, err := getCachedReason(cache, host)
|
||||||
if isFound {
|
if isFound {
|
||||||
atomic.AddUint64(&stats.Safebrowsing.CacheHits, 1)
|
atomic.AddUint64(&lookupstats.CacheHits, 1)
|
||||||
return cachedValue, nil
|
return cachedValue, nil
|
||||||
}
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
Loading…
Reference in New Issue
Block a user