stats/udp: nop on nil DefaultStats

This commit is contained in:
Jimmy Zelinskie 2015-02-25 21:56:58 -05:00
parent 5af37be85c
commit 9b4999c0cf
2 changed files with 16 additions and 13 deletions

View file

@ -271,15 +271,21 @@ func (s *Stats) handlePeerEvent(ps *PeerStats, event int) {
// RecordEvent broadcasts an event to the default stats queue.
func RecordEvent(event int) {
DefaultStats.RecordEvent(event)
if DefaultStats != nil {
DefaultStats.RecordEvent(event)
}
}
// RecordPeerEvent broadcasts a peer event to the default stats queue.
func RecordPeerEvent(event int, ipv6 bool) {
DefaultStats.RecordPeerEvent(event, ipv6)
if DefaultStats != nil {
DefaultStats.RecordPeerEvent(event, ipv6)
}
}
// RecordTiming broadcasts a timing event to the default stats queue.
func RecordTiming(event int, duration time.Duration) {
DefaultStats.RecordTiming(event, duration)
if DefaultStats != nil {
DefaultStats.RecordTiming(event, duration)
}
}

View file

@ -13,21 +13,18 @@ import (
"time"
"github.com/chihaya/chihaya/config"
"github.com/chihaya/chihaya/stats"
"github.com/chihaya/chihaya/tracker"
_ "github.com/chihaya/chihaya/backend/noop"
)
var testPort = "34137"
var connectAction = []byte{0, 0, 0, byte(connectActionID)}
var announceAction = []byte{0, 0, 0, byte(announceActionID)}
var scrapeAction = []byte{0, 0, 0, byte(scrapeActionID)}
var errorAction = []byte{0, 0, 0, byte(errorActionID)}
func init() {
stats.DefaultStats = stats.New(config.StatsConfig{})
}
var (
testPort = "34137"
connectAction = []byte{0, 0, 0, byte(connectActionID)}
announceAction = []byte{0, 0, 0, byte(announceActionID)}
scrapeAction = []byte{0, 0, 0, byte(scrapeActionID)}
errorAction = []byte{0, 0, 0, byte(errorActionID)}
)
func setupTracker(cfg *config.Config) (*Server, chan struct{}, error) {
tkr, err := tracker.New(cfg)