Skip to content

Commit

Permalink
(BIDS-2872) copy ratelimit over from v1
Browse files Browse the repository at this point in the history
  • Loading branch information
guybrush committed Jul 30, 2024
1 parent cf035e3 commit 012c097
Show file tree
Hide file tree
Showing 4 changed files with 1,223 additions and 8 deletions.
4 changes: 4 additions & 0 deletions backend/cmd/api/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (

"github.com/gobitfly/beaconchain/pkg/commons/log"
"github.com/gobitfly/beaconchain/pkg/commons/metrics"
"github.com/gobitfly/beaconchain/pkg/commons/ratelimit"
"github.com/gobitfly/beaconchain/pkg/commons/types"
"github.com/gobitfly/beaconchain/pkg/commons/utils"
"github.com/gobitfly/beaconchain/pkg/commons/version"
Expand Down Expand Up @@ -62,6 +63,9 @@ func main() {
}(cfg.Metrics.Address)
}

ratelimit.Init()
router.Use(ratelimit.HttpMiddleware)

srv := &http.Server{
Handler: router,
Addr: net.JoinHostPort(cfg.Frontend.Server.Host, cfg.Frontend.Server.Port),
Expand Down
4 changes: 4 additions & 0 deletions backend/pkg/commons/metrics/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,10 @@ var (
Name: "state",
Help: "Gauge for various states",
}, []string{"state"})
Counter = promauto.NewCounterVec(prometheus.CounterOpts{
Name: "counter",
Help: "Generic counter of events with name in labels",
}, []string{"name"})
)

func init() {
Expand Down
Loading

0 comments on commit 012c097

Please sign in to comment.