Skip to content

Commit

Permalink
geodns-logs: avoid poolCC errors in log
Browse files Browse the repository at this point in the history
(this is a tool just for the ntppool system ...)
  • Loading branch information
abh committed Aug 8, 2021
1 parent 1e75f33 commit 9012140
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 4 deletions.
25 changes: 25 additions & 0 deletions geodns-logs/process-stats_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package main

import "testing"

func TestGetPoolCC(t *testing.T) {
tests := []struct {
label string
cc string
ok bool
}{
{"1.debian.pool.ntp.org.", "", false},
{"2.dk.pool.ntp.org.", "dk", true},
{"dk.pool.ntp.org.", "dk", true},
{"0.asia.pool.ntp.org.", "asia", true},
{"1.pool.ntp.org.", "", false},
}

for _, input := range tests {
cc, ok := getPoolCC(input.label)
if cc != input.cc || ok != input.ok {
t.Logf("%q got %q (%t), expected %q (%t)", input.label, cc, ok, input.cc, input.ok)
t.Fail()
}
}
}
10 changes: 6 additions & 4 deletions geodns-logs/stats.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,12 @@ func (stats *Stats) Add(e *querylog.Entry) error {
if e.Origin == "pool.ntp.org" || strings.HasSuffix(e.Origin, "ntppool.org") {
vendor = vendorName(e.Name)

var ok bool
poolCC, ok = getPoolCC(e.LabelName)
if !ok {
log.Printf("Could not get valid poolCC label for %+v", e)
if len(vendor) == 0 && e.Name != e.Origin {
var ok bool
poolCC, ok = getPoolCC(e.LabelName)
if !ok {
log.Printf("Could not get valid poolCC label for %+v", e)
}
}
}

Expand Down

0 comments on commit 9012140

Please sign in to comment.