Permalink
Browse files

v3 refactoring wip

  • Loading branch information...
abh committed Feb 13, 2017
1 parent 1429979 commit e40da8e7c6372f343f7ee6b718817bea06182f79
Showing with 1,372 additions and 1,157 deletions.
  1. +2 −0 .gitignore
  2. +1 −1 .travis.yml
  3. +22 −2 Makefile
  4. +2 −1 config.go
  5. +37 −33 geodns.go
  6. +272 −0 http.go
  7. +0 −436 monitor.go
  8. +99 −0 monitor/hub.go
  9. +123 −0 monitor/monitor.go
  10. +44 −0 monitor/monitor_test.go
  11. +0 −57 monitor_test.go
  12. +0 −301 serve_test.go
  13. +3 −1 { → server}/metrics.go
  14. +7 −7 { → server}/serve.go
  15. +325 −0 server/serve_test.go
  16. +74 −0 server/server.go
  17. +0 −130 server_test.go
  18. +2 −0 targeting/targeting_test.go
  19. +6 −4 util.go
  20. +82 −85 server.go → zones/muxmanager.go
  21. +152 −0 zones/reader_test.go
  22. +119 −99 zones/zone_test.go
@@ -5,3 +5,5 @@
/run
.idea
/dns/geodns.conf
geodns-*-*
geodns-*-*.tar
@@ -22,5 +22,5 @@ install:
- go install
script:
- cd $TRAVIS_BUILD_DIR && go test -gocheck.v
- cd $TRAVIS_BUILD_DIR && make test
- go test -gocheck.v -gocheck.b -gocheck.btime=2s
@@ -4,14 +4,34 @@ all: templates.go
templates.go: templates/*.html monitor.go
go generate
.PHONY: test
test:
go test $(go list ./... | grep -v /vendor/)
testrace:
go test -race $(go list ./... | grep -v /vendor/)
testrace: .PHONY
go test -race $(shell go list ./... | grep -v /vendor/)
devel:
go build -tags devel
bench:
go test -check.b -check.bmem
TARS=$(wildcard geodns-*-*.tar)
push: $(TARS) tmp-install.sh
rsync -avz tmp-install.sh $(TARS) x3.dev:webtmp/2016/07/
builds: linux-build linux-build-i386 freebsd-build push
linux-build:
docker run --rm -v `pwd`:/go/src/github.com/abh/geodns geodns-build ./build
linux-build-i386:
docker run --rm -v `pwd`:/go/src/github.com/abh/geodns geodns-build-i386 ./build
freebsd-build:
ssh 192.168.64.5 'cd go/src/github.com/abh/geodns; GOPATH=~/go ./build'
ssh root@192.168.64.5 'jexec -U ask fbsd32 /home/ask/build'
.PHONY:
@@ -34,7 +34,8 @@ type AppConfig struct {
Token string
}
Pingdom struct {
Username string
Username string
Password string
AccountEmail string
AppKey string
@@ -30,7 +30,9 @@ import (
"time"
"github.com/abh/geodns/applog"
"github.com/abh/geodns/monitor"
"github.com/abh/geodns/querylog"
"github.com/abh/geodns/server"
"github.com/abh/geodns/zones"
"github.com/pborman/uuid"
)
@@ -45,14 +47,9 @@ var gitVersion string
var development bool
var (
serverID string
serverIP string
serverGroups []string
serverUUID = uuid.New()
serverInfo *monitor.ServerInfo
)
var timeStarted = time.Now()
var (
flagconfig = flag.String("config", "./dns/", "directory of zone files")
flagconfigfile = flag.String("configfile", "geodns.conf", "filename of config file (in 'config' directory)")
@@ -79,6 +76,11 @@ func init() {
log.SetPrefix("geodns ")
log.SetFlags(log.Lmicroseconds | log.Lshortfile)
serverInfo = &monitor.ServerInfo{}
serverInfo.UUID = uuid.New()
serverInfo.Started = time.Now()
}
func main() {
@@ -98,8 +100,6 @@ func main() {
os.Exit(0)
}
srv := Server{}
if *flaglog {
applog.Enabled = true
}
@@ -110,9 +110,9 @@ func main() {
if len(*flagidentifier) > 0 {
ids := strings.Split(*flagidentifier, ",")
serverID = ids[0]
serverInfo.ID = ids[0]
if len(ids) > 1 {
serverGroups = ids[1:]
serverInfo.Groups = ids[1:]
}
}
@@ -125,17 +125,16 @@ func main() {
}
if *flagcheckconfig {
dirName := *flagconfig
err := configReader(configFileName)
if err != nil {
log.Println("Errors reading config", err)
os.Exit(2)
}
Zones := make(zones.Zones)
srv.setupPgeodnsZone(Zones)
err = srv.zonesReadDir(dirName, Zones)
// dirName := *flagconfig
// Zones := make(zones.Zones)
// srv.setupPgeodnsZone(Zones)
// err = srv.zonesReadDir(dirName, Zones)
if err != nil {
log.Println("Errors reading zones", err)
os.Exit(2)
@@ -174,17 +173,6 @@ func main() {
// load (and re-load) zone data
go configWatcher(configFileName)
metrics := NewMetrics()
go metrics.Updater()
if qlc := Config.QueryLog; len(qlc.Path) > 0 {
ql, err := querylog.NewFileLogger(qlc.Path, qlc.MaxSize, qlc.Keep)
if err != nil {
log.Fatalf("Could not start file query logger: %s", err)
}
srv.SetQueryLogger(ql)
}
if *flaginter == "*" {
addrs, _ := net.InterfaceAddrs()
ips := make([]string, 0)
@@ -207,17 +195,33 @@ func main() {
log.Println("StatHat integration has been removed in favor of more generic metrics")
}
// the global-ish zones 'context' is quite a mess
zonelist := make(zones.Zones)
go monitor(zonelist)
srv.setupRootZone()
srv.setupPgeodnsZone(zonelist)
go srv.zonesReader(*flagconfig, zonelist)
mon := monitor.NewMonitor(serverInfo)
go mon.Run()
srv := server.NewServer(serverInfo)
if qlc := Config.QueryLog; len(qlc.Path) > 0 {
ql, err := querylog.NewFileLogger(qlc.Path, qlc.MaxSize, qlc.Keep)
if err != nil {
log.Fatalf("Could not start file query logger: %s", err)
}
srv.SetQueryLogger(ql)
}
muxm, err := zones.NewMuxManager(*flagconfig, srv)
if err != nil {
log.Printf("error loading zones: %s", err)
}
go muxm.Run()
for _, host := range inter {
go srv.listenAndServe(host)
go srv.ListenAndServe(host)
}
go func() {
// setup metrics httpd stuff
}()
terminate := make(chan os.Signal)
signal.Notify(terminate, os.Interrupt)
Oops, something went wrong.

0 comments on commit e40da8e

Please sign in to comment.