diff --git a/Makefile b/Makefile index 79405c0..507459e 100644 --- a/Makefile +++ b/Makefile @@ -8,16 +8,16 @@ # must run. XXX: This means the DEB packages are broken. # Nothing done here, we don't compile in the DSC build process -all: +all: statsrelay -statsrelay: statsrelay.go - go build -o statsrelay statsrelay.go +statsrelay: statsrelay.go jump.go + go build install: install -D -m 0755 statsrelay $(DESTDIR)/usr/bin/statsrelay -dsc: statsrelay +dsc: dpkg-source -b . clean: - rm -f *~ + rm -f *~ statsrelay diff --git a/debian/README b/debian/README deleted file mode 100644 index 5a651f4..0000000 --- a/debian/README +++ /dev/null @@ -1,8 +0,0 @@ -The Debian Package statsrelay ----------------------------- - -This package is simply a package around a pre-built binary. The build process -of this package does not build the Go source. This should be fixed at some -point, however, I need Go 1.3 built code running on Ubuntu Precise. - - -- Jack Neely Thu, 13 Nov 2014 18:00:40 -0500 diff --git a/debian/changelog b/debian/changelog index 48e1fca..f7fa6e6 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,3 +1,11 @@ +statsrelay (0.0.2) unstable; urgency=medium + + * Build with Go 1.5 + * Use Google's Jump Hash / FNV1a to better balance traffic across + statsd daemons + + -- Jack Neely Mon, 25 Jan 2016 11:02:13 -0500 + statsrelay (0.0.1) unstable; urgency=low * Initial Release. diff --git a/debian/control b/debian/control index bd6539d..3a29214 100644 --- a/debian/control +++ b/debian/control @@ -2,7 +2,7 @@ Source: statsrelay Section: main Priority: optional Maintainer: Jack Neely -Build-Depends: debhelper (>= 8.0.0) +Build-Depends: debhelper (>= 8.0.0), golang (>= 1.5), dh-golang Standards-Version: 3.9.4 Homepage: https://github.com/42Lines/statsrelay diff --git a/debian/rules b/debian/rules index 79fd842..8358514 100755 --- a/debian/rules +++ b/debian/rules @@ -4,5 +4,9 @@ # Uncomment this to turn on verbose mode. #export DH_VERBOSE=1 +export DH_OPTIONS + +export DH_GOPKG := github.com/jjneely/statsrelay + %: - dh $@ + dh $@ --buildsystem=golang --with=golang diff --git a/jump_test.go b/jump_test.go new file mode 100644 index 0000000..6a065d8 --- /dev/null +++ b/jump_test.go @@ -0,0 +1,107 @@ +package main + +import ( + "testing" +) + +var jumpHashTestNodes = []string{ + "graphite010-g5", + "graphite011-g5", + "graphite012-g5", + "graphite013-g5", + "graphite014-g5", + "graphite015-g5", + "graphite016-g5", + "graphite017-g5", + "graphite018-g5", + "graphite-data019-g5", + "graphite-data020-g5", + "graphite-data021-g5", + "graphite-data022-g5", + "graphite-data023-g5", + "graphite-data024-g5", + "graphite-data025-g5", + "graphite-data026-g5", + "graphite-data027-g5", + "graphite-data028-g5", + "graphite-data029-g5", + "graphite-data030-g5", + "graphite-data031-g5", + "graphite-data032-g5", + "graphite-data033-g5", + "graphite-data034-g5", + "graphite-data035-g5", + "graphite-data036-g5", + "graphite-data037-g5", + "graphite-data038-g5", + "graphite-data039-g5", + "graphite-data040-g5", + "graphite-data041-g5", + "graphite-data042-g5", + "graphite-data043-g5", + "graphite-data044-g5", + "graphite-data045-g5", + "graphite-data046-g5", + "graphite-data047-g5", + "graphite-data048-g5", + "graphite-data049-g5", + "graphite-data050-g5", + "graphite-data051-g5", + "graphite-data052-g5", + "graphite-data053-g5", + "graphite-data054-g5", +} + +func makeJumpTestCHR(r int) *JumpHashRing { + chr := NewJumpHashRing(r) + for _, v := range jumpHashTestNodes { + chr.AddNode(Node{v, ""}) + } + + return chr +} + +func TestFNV1a64(t *testing.T) { + data := map[string]uint64{ + "foobar": 0x85944171f73967e8, + "changed": 0xdf38879af614707b, + "5min.prod.dc06.graphite-web006-g6.kernel.net.netfilter.nf_conntrack_max": 0xdb7b58ef171eee9f, + } + + for s, hash := range data { + if Fnv1a64([]byte(s)) != hash { + t.Errorf("FNV1a64 implementation does not match reference %s => %x", + s, Fnv1a64([]byte(s))) + } + } +} + +func TestOutOfRange(t *testing.T) { + chr := makeJumpTestCHR(1) + for _, v := range jumpHashTestNodes { + k := Fnv1a64([]byte(v)) + i := Jump(k, len(chr.ring)) + if i < 0 || i >= len(chr.ring) { + t.Errorf("Jump hash returned out of bounds bucket %s => %d", v, i) + } + } +} + +func TestJumpCHR(t *testing.T) { + chr := makeJumpTestCHR(1) + t.Logf(chr.String()) + + data := map[string]string{ + "foobar": "graphite-data043-g5", + "suebob.foo.honey.i.shrunk.the.kids": "graphite-data048-g5", + "5min.prod.dc06.graphite-web006-g6.kernel.net.netfilter.nf_conntrack_max": "graphite014-g5", + } + + for key, node := range data { + n := chr.GetNode(key) + if n.Server != node { + t.Errorf("Hash not compatible with carbon-c-relay: %s => %s Should be %s", + key, n.Server, node) + } + } +}