Skip to content

Commit

Permalink
Track number of requested accounts per connection for sse methods
Browse files Browse the repository at this point in the history
  • Loading branch information
aleksej-paschenko committed Aug 6, 2024
1 parent cd331e7 commit 2e03550
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions pkg/pusher/sse/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import (
"sync/atomic"
"time"

"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promauto"
"github.com/tonkeeper/opentonapi/pkg/pusher/errors"
"github.com/tonkeeper/opentonapi/pkg/pusher/events"
"github.com/tonkeeper/opentonapi/pkg/pusher/sources"
Expand All @@ -24,6 +26,14 @@ type Handler struct {
currentEventID int64
}

var accountsPerRequestHistogramVec = promauto.NewHistogramVec(
prometheus.HistogramOpts{
Name: "sse_accounts_per_request",
Buckets: []float64{1, 2, 3, 4, 5, 10, 20, 30, 40, 50, 100, 1000},
},
[]string{"method"},
)

type handlerFunc func(session *session, request *http.Request) error

func NewHandler(blockSource sources.BlockSource, blockHeadersSource sources.BlockHeadersSource, txSource sources.TransactionSource, traceSource sources.TraceSource, memPool sources.MemPoolSource) *Handler {
Expand Down Expand Up @@ -77,6 +87,9 @@ func (h *Handler) SubscribeToTransactions(session *session, request *http.Reques
if err != nil {
return errors.BadRequest(fmt.Sprintf("failed to parse query parameters: %v", err))
}
if !options.AllAccounts {
accountsPerRequestHistogramVec.WithLabelValues("transactions").Observe(float64(len(options.Accounts)))
}
cancelFn := h.txSource.SubscribeToTransactions(request.Context(), func(data []byte) {
event := Event{
Name: events.AccountTxEvent,
Expand Down

0 comments on commit 2e03550

Please sign in to comment.