Skip to content

Commit c5ae3bd

Browse files
feat: remove the connection group count metric from the go routine
1 parent 32a0859 commit c5ae3bd

2 files changed

Lines changed: 5 additions & 17 deletions

File tree

services/rest/service.go

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,12 @@ package rest
22

33
import (
44
"context"
5-
"fmt"
6-
"net/http"
7-
"time"
8-
95
"github.com/gorilla/mux"
106
"github.com/goto/raccoon/collection"
117
"github.com/goto/raccoon/config"
12-
"github.com/goto/raccoon/metrics"
138
"github.com/goto/raccoon/services/rest/websocket"
149
"github.com/goto/raccoon/services/rest/websocket/connection"
10+
"net/http"
1511
)
1612

1713
type Service struct {
@@ -24,8 +20,6 @@ func NewRestService(c collection.Collector) *Service {
2420
wh := websocket.NewHandler(pingChannel, c)
2521
go websocket.Pinger(pingChannel, config.ServerWs.PingerSize, config.ServerWs.PingInterval, config.ServerWs.WriteWaitInterval)
2622

27-
go reportConnectionMetrics(*wh.Table())
28-
2923
go websocket.AckHandler(websocket.AckChan)
3024

3125
restHandler := NewHandler(c)
@@ -50,16 +44,6 @@ func pingHandler(w http.ResponseWriter, r *http.Request) {
5044
w.Write([]byte("pong"))
5145
}
5246

53-
func reportConnectionMetrics(conn connection.Table) {
54-
t := time.Tick(config.MetricStatsd.FlushPeriodMs)
55-
for {
56-
<-t
57-
for k, v := range conn.TotalConnectionPerGroup() {
58-
metrics.Gauge("connections_count_current", v, fmt.Sprintf("conn_group=%s", k))
59-
}
60-
}
61-
}
62-
6347
func (s *Service) Init(context.Context) error {
6448
return s.s.ListenAndServe()
6549
}

services/rest/websocket/connection/table.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,11 @@ package connection
22

33
import (
44
"errors"
5+
"fmt"
56
"sync"
67

78
"github.com/goto/raccoon/identification"
9+
"github.com/goto/raccoon/metrics"
810
)
911

1012
var (
@@ -46,6 +48,7 @@ func (t *Table) Store(c identification.Identifier) error {
4648
}
4749
t.connMap[c] = make(map[string]struct{})
4850
t.counter[c.Group] = t.counter[c.Group] + 1
51+
metrics.Gauge("connections_count_current", t.counter[c.Group], fmt.Sprintf("conn_group=%s", c.Group))
4952
return nil
5053
}
5154

@@ -75,6 +78,7 @@ func (t *Table) Remove(c identification.Identifier) {
7578
defer t.m.Unlock()
7679
delete(t.connMap, c)
7780
t.counter[c.Group] = t.counter[c.Group] - 1
81+
metrics.Gauge("connections_count_current", t.counter[c.Group], fmt.Sprintf("conn_group=%s", c.Group))
7882
}
7983

8084
func (t *Table) TotalConnection() int {

0 commit comments

Comments
 (0)