Skip to content

Commit

Permalink
fix: remove if statemets
Browse files Browse the repository at this point in the history
  • Loading branch information
darrenvechain committed Jun 22, 2024
1 parent fa38693 commit b1f52bc
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 18 deletions.
2 changes: 1 addition & 1 deletion api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ func New(
Mount(router, "/debug")
node.New(nw).
Mount(router, "/node")
subs := subscriptions.New(repo, origins, backtraceLimit, txPool, enableMetrics)
subs := subscriptions.New(repo, origins, backtraceLimit, txPool)
subs.Mount(router, "/subscriptions")

if pprofOn {
Expand Down
18 changes: 5 additions & 13 deletions api/subscriptions/subscriptions.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ type Subscriptions struct {
pendingTx *pendingTx
done chan struct{}
wg sync.WaitGroup
enableMetrics bool
}

type msgReader interface {
Expand All @@ -50,7 +49,7 @@ const (
pingPeriod = (pongWait * 7) / 10
)

func New(repo *chain.Repository, allowedOrigins []string, backtraceLimit uint32, txpool *txpool.TxPool, enableMetrics bool) *Subscriptions {
func New(repo *chain.Repository, allowedOrigins []string, backtraceLimit uint32, txpool *txpool.TxPool) *Subscriptions {
sub := &Subscriptions{
backtraceLimit: backtraceLimit,
repo: repo,
Expand All @@ -69,9 +68,8 @@ func New(repo *chain.Repository, allowedOrigins []string, backtraceLimit uint32,
return false
},
},
pendingTx: newPendingTx(txpool),
done: make(chan struct{}),
enableMetrics: enableMetrics,
pendingTx: newPendingTx(txpool),
done: make(chan struct{}),
}

sub.wg.Add(1)
Expand Down Expand Up @@ -282,10 +280,7 @@ func (s *Subscriptions) setupConn(w http.ResponseWriter, req *http.Request) (*we
}()

subject := strings.Split(req.URL.Path, "/")[2]
if s.enableMetrics {
metricsActiveConnectionCount().GaugeWithLabel(1, map[string]string{"subject": subject})
}

metricsActiveConnectionCount().GaugeWithLabel(1, map[string]string{"subject": subject})
return conn, closed, subject, nil
}

Expand All @@ -301,10 +296,7 @@ func (s *Subscriptions) closeConn(conn *websocket.Conn, err error, subject strin
log.Debug("write close message", "err", err)
}

if s.enableMetrics {
metricsActiveConnectionCount().GaugeWithLabel(-1, map[string]string{"subject": subject})
}

metricsActiveConnectionCount().GaugeWithLabel(-1, map[string]string{"subject": subject})
if err := conn.Close(); err != nil {
log.Debug("close websocket", "err", err)
}
Expand Down
2 changes: 1 addition & 1 deletion api/subscriptions/subscriptions_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ func initSubscriptionsServer(t *testing.T) {
txPool = pool
blocks = generatedBlocks
router := mux.NewRouter()
sub = New(repo, []string{}, 5, txPool, false)
sub = New(repo, []string{}, 5, txPool)
sub.Mount(router, "/subscriptions")
ts = httptest.NewServer(router)
client = &http.Client{}
Expand Down
1 change: 0 additions & 1 deletion cmd/thor/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,6 @@ func defaultAction(ctx *cli.Context) error {
uint64(ctx.Int(targetGasLimitFlag.Name)),
skipLogs,
forkConfig,
ctx.Bool(enableMetricsFlag.Name),
).Run(exitSignal)
}

Expand Down
2 changes: 0 additions & 2 deletions cmd/thor/node/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,6 @@ func New(
targetGasLimit uint64,
skipLogs bool,
forkConfig thor.ForkConfig,
enableMetrics bool,
) *Node {
return &Node{
packer: packer.New(repo, stater, master.Address(), master.Beneficiary, forkConfig),
Expand All @@ -94,7 +93,6 @@ func New(
targetGasLimit: targetGasLimit,
skipLogs: skipLogs,
forkConfig: forkConfig,
enableMetrics: enableMetrics,
}
}

Expand Down

0 comments on commit b1f52bc

Please sign in to comment.