@@ -12,6 +12,7 @@ import (
1212
1313 "github.com/cenkalti/backoff/v4"
1414 "github.com/gorilla/websocket"
15+ "github.com/m-lab/locate/metrics"
1516 "github.com/m-lab/locate/static"
1617)
1718
@@ -126,12 +127,12 @@ func (c *Conn) Dial(address string, header http.Header, dialMsg interface{}) err
126127// message.
127128//
128129// The write will fail under the following conditions:
129- // 1. The client has not called Dial (ErrNotDialed).
130- // 2. The connection is disconnected and it was not able to
131- // reconnect (ErrTooManyReconnects or an internal connection
132- // error).
133- // 3. The write call in the websocket package failed
134- // (gorilla/websocket error).
130+ // 1. The client has not called Dial (ErrNotDialed).
131+ // 2. The connection is disconnected and it was not able to
132+ // reconnect (ErrTooManyReconnects or an internal connection
133+ // error).
134+ // 3. The write call in the websocket package failed
135+ // (gorilla/websocket error).
135136func (c * Conn ) WriteMessage (messageType int , data interface {}) error {
136137 if ! c .isDialed {
137138 return ErrNotDailed
@@ -235,16 +236,20 @@ func (c *Conn) connect() error {
235236 if resp != nil && ! retryErrors [resp .StatusCode ] {
236237 log .Printf ("error trying to establish a connection with %s, err: %v, status: %d" ,
237238 c .url .String (), err , resp .StatusCode )
239+ metrics .ConnectionRequestsTotal .WithLabelValues ("error" ).Inc ()
238240 ticker .Stop ()
241+ return err
239242 }
240243 log .Printf ("could not establish a connection with %s (will retry), err: %v" ,
241244 c .url .String (), err )
245+ metrics .ConnectionRequestsTotal .WithLabelValues ("retry" ).Inc ()
242246 continue
243247 }
244248
245249 c .ws = ws
246250 c .isConnected = true
247251 log .Printf ("successfully established a connection with %s" , c .url .String ())
252+ metrics .ConnectionRequestsTotal .WithLabelValues ("OK" ).Inc ()
248253 ticker .Stop ()
249254 }
250255
0 commit comments