Skip to content

Commit

Permalink
Basic support of external health data
Browse files Browse the repository at this point in the history
  • Loading branch information
abh committed Mar 20, 2017
1 parent 9443634 commit 48d6c3b
Show file tree
Hide file tree
Showing 8 changed files with 39 additions and 7 deletions.
3 changes: 3 additions & 0 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ type AppConfig struct {
MaxSize int
Keep int
}
Health struct {
Directory string
}
Nodeping struct {
Token string
}
Expand Down
3 changes: 3 additions & 0 deletions dns/geodns.conf.sample
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,6 @@ path = log/queries.log
; require basic HTTP authentication; not encrypted or safe over the public internet
; user = stats
; password = Aeteereun8eoth4

[health]
; directory = dns/health
7 changes: 6 additions & 1 deletion geodns.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import (
"time"

"github.com/abh/geodns/applog"
"github.com/abh/geodns/health"
"github.com/abh/geodns/monitor"
"github.com/abh/geodns/querylog"
"github.com/abh/geodns/server"
Expand All @@ -38,7 +39,7 @@ import (
)

// VERSION is the current version of GeoDNS
var VERSION string = "2.7.0"
var VERSION string = "3.0.0"
var buildTime string
var gitVersion string

Expand Down Expand Up @@ -170,6 +171,10 @@ func main() {
// load geodns.conf config
configReader(configFileName)

if len(Config.Health.Directory) > 0 {
go health.DirectoryReader(Config.Health.Directory)
}

// load (and re-load) zone data
go configWatcher(configFileName)

Expand Down
7 changes: 3 additions & 4 deletions health/status_file.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ import (
"strings"
"sync"
"time"

"github.com/kr/pretty"
)

type StatusFile struct {
Expand All @@ -28,6 +26,9 @@ func NewStatusFile(filename string) *StatusFile {
}
}

// DirectoryReader loads (and regularly re-loads) health
// .json files from the specified files into the default
// health registry.
func DirectoryReader(dir string) {
for {
err := reloadDirectory(dir)
Expand Down Expand Up @@ -129,8 +130,6 @@ func (s *StatusFile) GetStatus(check string) StatusType {
return StatusUnknown
}

pretty.Println(s)

st, ok := s.m[check]
if !ok {
log.Printf("Not found '%s'", check)
Expand Down
2 changes: 1 addition & 1 deletion health/status_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package health
import "testing"

func TestStatusFile(t *testing.T) {
sf := NewStatusFile()
sf := NewStatusFile("test.json")
err := sf.Load("test.json")
if err != nil {
t.Fatalf("could not load test.json: %s", err)
Expand Down
2 changes: 1 addition & 1 deletion zones/picker.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ func (zone *Zone) filterHealth(servers Records) (Records, int) {

sum := 0
for i, s := range servers {
if len(servers[i].Test) == 0 || zone.HealthStatus.GetStatus(servers[i].Test) == health.StatusHealthy {
if len(servers[i].Test) == 0 || health.GetStatus(servers[i].Test) == health.StatusHealthy {
tmpServers = append(tmpServers, s)
sum += s.Weight
}
Expand Down
14 changes: 14 additions & 0 deletions zones/reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,20 @@ func setupZoneData(data map[string]interface{}, zone *Zone) {
target = rec.(string)
case []interface{}:
target, weight = getStringWeight(rec.([]interface{}))
case map[string]interface{}:
r := rec.(map[string]interface{})

if t, ok := r["cname"]; ok {
target = typeutil.ToString(t)
}

if w, ok := r["weight"]; ok {
weight = typeutil.ToInt(w)
}

if h, ok := r["health"]; ok {
record.Test = typeutil.ToString(h)
}
}
if !dns.IsFqdn(target) {
target = target + "." + zone.Origin
Expand Down
8 changes: 8 additions & 0 deletions zones/zone_health_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,14 @@ func (hs *HealthStatus) GetStatus(name string) health.StatusType {
return hs.status
}

func (hs *HealthStatus) Close() error {
return nil
}

func (hs *HealthStatus) Reload() error {
return nil
}

func TestHealth(t *testing.T) {
muxm := loadZones(t)
t.Log("setting up health status")
Expand Down

0 comments on commit 48d6c3b

Please sign in to comment.