Skip to content

Commit

Permalink
try this way
Browse files Browse the repository at this point in the history
  • Loading branch information
dmanc committed May 3, 2024
1 parent fdbb4aa commit a0260d7
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 21 deletions.
7 changes: 6 additions & 1 deletion common/ratelimit/limiter.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"github.com/Layr-Labs/eigenda/common"
"github.com/Layr-Labs/eigensdk-go/logging"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promauto"
)

type BucketStore = common.KVStore[common.RateBucketParams]
Expand All @@ -22,11 +23,15 @@ type rateLimiter struct {
bucketLevels *prometheus.GaugeVec
}

func NewRateLimiter(rateParams common.GlobalRateParams, bucketStore BucketStore, logger logging.Logger) common.RateLimiter {
func NewRateLimiter(reg prometheus.Registerer, rateParams common.GlobalRateParams, bucketStore BucketStore, logger logging.Logger) common.RateLimiter {
return &rateLimiter{
globalRateParams: rateParams,
bucketStore: bucketStore,
logger: logger.With("component", "RateLimiter"),
bucketLevels: promauto.With(reg).NewGaugeVec(prometheus.GaugeOpts{
Name: "rate_limiter_bucket_levels",
Help: "Current level of each bucket for rate limiting",
}, []string{"requester_id", "bucket_index"}),
}
}

Expand Down
10 changes: 0 additions & 10 deletions common/ratelimit/metrics.go

This file was deleted.

3 changes: 2 additions & 1 deletion common/ratelimit/ratelimit_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"github.com/Layr-Labs/eigenda/common/ratelimit"
"github.com/Layr-Labs/eigenda/common/store"
"github.com/Layr-Labs/eigensdk-go/logging"
"github.com/prometheus/client_golang/prometheus"
"github.com/stretchr/testify/assert"
)

Expand All @@ -25,7 +26,7 @@ func makeTestRatelimiter() (common.RateLimiter, error) {
return nil, err
}

ratelimiter := ratelimit.NewRateLimiter(globalParams, bucketStore, logging.NewNoopLogger())
ratelimiter := ratelimit.NewRateLimiter(prometheus.NewRegistry(), globalParams, bucketStore, logging.NewNoopLogger())

return ratelimiter, nil

Expand Down
5 changes: 3 additions & 2 deletions disperser/apiserver/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
gethcommon "github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/crypto"
"github.com/google/uuid"
"github.com/prometheus/client_golang/prometheus"
"github.com/urfave/cli"

pb "github.com/Layr-Labs/eigenda/api/grpc/disperser"
Expand Down Expand Up @@ -570,7 +571,7 @@ func newTestServer(transactor core.Transactor) *apiserver.DispersalServer {
if err != nil {
panic("failed to create bucket store")
}
ratelimiter := ratelimit.NewRateLimiter(globalParams, bucketStore, logger)
ratelimiter := ratelimit.NewRateLimiter(prometheus.NewRegistry(), globalParams, bucketStore, logger)

rateConfig := apiserver.RateConfig{
QuorumRateInfos: map[core.QuorumID]apiserver.QuorumRateInfo{
Expand Down Expand Up @@ -623,7 +624,7 @@ func newTestServer(transactor core.Transactor) *apiserver.DispersalServer {
return apiserver.NewDispersalServer(disperser.ServerConfig{
GrpcPort: "51001",
GrpcTimeout: 1 * time.Second,
}, queue, transactor, logger, disperser.NewMetrics("9001", logger), ratelimiter, rateConfig)
}, queue, transactor, logger, disperser.NewMetrics(prometheus.NewRegistry(), "9001", logger), ratelimiter, rateConfig)
}

func disperseBlob(t *testing.T, server *apiserver.DispersalServer, data []byte) (pb.BlobStatus, uint, []byte) {
Expand Down
8 changes: 5 additions & 3 deletions disperser/cmd/apiserver/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"github.com/Layr-Labs/eigenda/common"
"github.com/Layr-Labs/eigenda/disperser/apiserver"
"github.com/Layr-Labs/eigenda/disperser/common/blobstore"
"github.com/prometheus/client_golang/prometheus"

"github.com/Layr-Labs/eigenda/common/aws/dynamodb"
"github.com/Layr-Labs/eigenda/common/aws/s3"
Expand Down Expand Up @@ -91,6 +92,8 @@ func RunDisperserServer(ctx *cli.Context) error {
blobMetadataStore := blobstore.NewBlobMetadataStore(dynamoClient, logger, config.BlobstoreConfig.TableName, time.Duration((storeDurationBlocks+blockStaleMeasure)*12)*time.Second)
blobStore := blobstore.NewSharedStorage(bucketName, s3Client, blobMetadataStore, logger)

reg := prometheus.NewRegistry()

var ratelimiter common.RateLimiter
if config.EnableRatelimiter {
globalParams := config.RatelimiterConfig.GlobalRateParams
Expand All @@ -108,11 +111,10 @@ func RunDisperserServer(ctx *cli.Context) error {
return err
}
}
ratelimiter = ratelimit.NewRateLimiter(globalParams, bucketStore, logger)
ratelimiter = ratelimit.NewRateLimiter(reg, globalParams, bucketStore, logger)
}

// TODO: create a separate metrics for batcher
metrics := disperser.NewMetrics(config.MetricsConfig.HTTPPort, logger)
metrics := disperser.NewMetrics(reg, config.MetricsConfig.HTTPPort, logger)
server := apiserver.NewDispersalServer(
config.ServerConfig,
blobStore,
Expand Down
5 changes: 1 addition & 4 deletions disperser/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"fmt"
"net/http"

"github.com/Layr-Labs/eigenda/common/ratelimit"
"github.com/Layr-Labs/eigensdk-go/logging"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/collectors"
Expand Down Expand Up @@ -38,12 +37,10 @@ const (
AccountRateLimitedFailure string = "ratelimited-account" // The request rate limited at account level
)

func NewMetrics(httpPort string, logger logging.Logger) *Metrics {
func NewMetrics(reg *prometheus.Registry, httpPort string, logger logging.Logger) *Metrics {
namespace := "eigenda_disperser"
reg := prometheus.NewRegistry()
reg.MustRegister(collectors.NewProcessCollector(collectors.ProcessCollectorOpts{}))
reg.MustRegister(collectors.NewGoCollector())
ratelimit.RegisterMetrics(reg)

metrics := &Metrics{
// TODO: revamp this metric -- it'll focus on quorum tracking, which is relevant
Expand Down

0 comments on commit a0260d7

Please sign in to comment.