@@ -32,16 +32,7 @@ func main() {
3232 log .Fatalf ("Problem in init logger, %s" , err )
3333 }
3434
35- statsdClient , err := metrics .NewStatsd (
36- cfg .Statsd .Host ,
37- cfg .Statsd .Port ,
38- cfg .Statsd .Protocol ,
39- cfg .Statsd .Prefix ,
40- cfg .Statsd .Enable )
41-
42- if nil != err {
43- log .Errorf ("Statsd create socked error: %s" , err )
44- }
35+ middlewareWrap := middleware .NewWrap (log .StandardLogger ())
4536
4637 busyNodeDuration , err := time .ParseDuration (cfg .Grid .BusyNodeDuration )
4738 if err != nil {
@@ -84,8 +75,7 @@ func main() {
8475 poolInstance .SetBusyNodeDuration (busyNodeDuration )
8576 poolInstance .SetReservedNodeDuration (reservedNodeDuration )
8677
87- poolMetricsSender := poolMetrics .NewSender (statsdClient , poolInstance , time .Second * 1 ) // todo: move to config
88- go poolMetricsSender .SendAll ()
78+
8979
9080 go func () {
9181 for {
@@ -103,13 +93,29 @@ func main() {
10393 }
10494 }()
10595
106- m := middleware .NewLogMiddleware (statsdClient )
107- http .Handle ("/wd/hub/session" , m .Log (& handlers.CreateSession {Pool : poolInstance , ClientFactory : clientFactory })) //selenium
108- http .Handle ("/session" , m .Log (& handlers.CreateSession {Pool : poolInstance , ClientFactory : clientFactory })) //wda
109- http .Handle ("/grid/register" , m .Log (& handlers.RegisterNode {Pool : poolInstance }))
96+
97+
98+ if cfg .Statsd != nil {
99+ statsdClient , err := metrics .NewStatsd (
100+ cfg .Statsd .Host ,
101+ cfg .Statsd .Port ,
102+ cfg .Statsd .Protocol ,
103+ cfg .Statsd .Prefix ,
104+ cfg .Statsd .Enable )
105+ poolMetricsSender := poolMetrics .NewSender (statsdClient , poolInstance , time .Second * 1 ) // todo: move to config
106+ go poolMetricsSender .SendAll ()
107+ if err != nil {
108+ log .Errorf ("Statsd create socked error: %s" , err )
109+ }
110+ middlewareWrap .Add (middleware .NewStatsd (log .StandardLogger (), statsdClient , true ).RegisterMetrics )
111+ }
112+
113+ http .Handle ("/wd/hub/session" , middlewareWrap .Do (& handlers.CreateSession {Pool : poolInstance , ClientFactory : clientFactory })) //selenium
114+ http .Handle ("/session" , middlewareWrap .Do (& handlers.CreateSession {Pool : poolInstance , ClientFactory : clientFactory })) //wda
115+ http .Handle ("/grid/register" , middlewareWrap .Do (& handlers.RegisterNode {Pool : poolInstance }))
110116 http .Handle ("/grid/api/proxy" , & handlers.APIProxy {Pool : poolInstance })
111117 http .HandleFunc ("/_info" , heartbeat )
112- http .Handle ("/" , m . Log (& handlers.UseSession {Pool : poolInstance , Cache : cache }))
118+ http .Handle ("/" , middlewareWrap . Do (& handlers.UseSession {Pool : poolInstance , Cache : cache }))
113119
114120 server := & http.Server {Addr : fmt .Sprintf (":%v" , cfg .Grid .Port )}
115121 serverError := make (chan error )
0 commit comments