Skip to content

Commit

Permalink
Packing updates
Browse files Browse the repository at this point in the history
* copy in jump_test.go
* use the trusty go build tools
  • Loading branch information
jjneely committed Jan 25, 2016
1 parent e1f13d7 commit 4aaaf75
Show file tree
Hide file tree
Showing 6 changed files with 126 additions and 15 deletions.
10 changes: 5 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
8 changes: 0 additions & 8 deletions debian/README

This file was deleted.

8 changes: 8 additions & 0 deletions debian/changelog
Original file line number Diff line number Diff line change
@@ -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 <[email protected]> Mon, 25 Jan 2016 11:02:13 -0500

statsrelay (0.0.1) unstable; urgency=low

* Initial Release.
Expand Down
2 changes: 1 addition & 1 deletion debian/control
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ Source: statsrelay
Section: main
Priority: optional
Maintainer: Jack Neely <[email protected]>
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

Expand Down
6 changes: 5 additions & 1 deletion debian/rules
Original file line number Diff line number Diff line change
Expand Up @@ -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
107 changes: 107 additions & 0 deletions jump_test.go
Original file line number Diff line number Diff line change
@@ -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)
}
}
}

0 comments on commit 4aaaf75

Please sign in to comment.