ryandotsmith / l2met

Convert a formatted log stream into metrics
http://r.32k.io/l2met-introduction
GNU General Public License v3.0
284 stars 26 forks source link

master branch breaks if METCHAN_URL not specified #89

Closed BRMatt closed 11 years ago

BRMatt commented 11 years ago
$ go run main.go                                                       

panic: runtime error: invalid memory address or nil pointer dereference             
[signal 0xb code=0x1 addr=0x8 pc=0x4af2d3]                                          

goroutine 1 [running]:                                                              
net/url.(*URL).String(0x0, 0xc2000ab500, 0x0)                                       
        /usr/local/go/src/pkg/net/url/url.go:445 +0x33                              
github.com/ryandotsmith/l2met/metchan.New(0x655e00, 0x0, 0x0)                       
        /home/matt/.go/src/github.com/ryandotsmith/l2met/metchan/metchan.go:58 +0x40
main.main()                                                                         
        /home/matt/code/l2met/main.go:34 +0x74                                      

goroutine 2 [syscall]:                                                              
exit status 2                                                                       
$ METCHAN_URL="https://user:password@example.com" go run main.go    
at=initialized-mem-store                                              

By the looks of things the meta channel constructed in main() is passed around to a few places, so it probably wouldn't be a good idea to pass them a nil reference. I'm a little rusty with go, but am I right in thinking one could create an interface which both metchan.Channel and some other metchan.fake.Channel could implement to hide the fact a metchan hasn't been configured?

ryandotsmith commented 11 years ago

@BRMatt Thanks for catching this. Take a look at my fix and let me know what you think.

ryandotsmith commented 11 years ago

I am pretty sure we have a good fix in place. Feel free to re-open if I am wrong.

BRMatt commented 11 years ago

Sorry I wasn't able to reply earlier. The fix looks good, much simpler than what I was suggesting. However, shouldn't there be an if c.enabled check in Channel.Start to stop it starting the outlet reporter?

ryandotsmith commented 11 years ago

:clap:

BRMatt commented 11 years ago

:boom: :metal: