Skip to content

Commit

Permalink
move permember ratelimiter to it's own package
Browse files Browse the repository at this point in the history
This is required to break the the cyclic dependency and allow
membership' tests to use testlogger package
  • Loading branch information
dkrotx committed Sep 25, 2024
1 parent 50e3558 commit eac4235
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 12 deletions.
9 changes: 7 additions & 2 deletions common/membership/hashring_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,11 @@ import (
"github.com/golang/mock/gomock"
"github.com/stretchr/testify/assert"
"go.uber.org/goleak"
"go.uber.org/zap/zaptest/observer"

"github.com/uber/cadence/common"
"github.com/uber/cadence/common/clock"
"github.com/uber/cadence/common/log"
"github.com/uber/cadence/common/log/testlogger"
"github.com/uber/cadence/common/metrics"
)

Expand Down Expand Up @@ -104,6 +105,7 @@ type hashringTestData struct {
mockPeerProvider *MockPeerProvider
mockTimeSource clock.MockedTimeSource
hashRing *ring
observedLogs *observer.ObservedLogs
}

func newHashringTestData(t *testing.T) *hashringTestData {
Expand All @@ -114,11 +116,14 @@ func newHashringTestData(t *testing.T) *hashringTestData {
td.mockPeerProvider = NewMockPeerProvider(ctrl)
td.mockTimeSource = clock.NewMockedTimeSourceAt(time.Now())

logger, observedLogs := testlogger.NewObserved(t)
td.observedLogs = observedLogs

td.hashRing = newHashring(
"test-service",
td.mockPeerProvider,
td.mockTimeSource,
log.NewNoop(),
logger,
metrics.NoopScope(0),
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,14 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.

package quotas
package permember

import (
"math"

"github.com/uber/cadence/common/dynamicconfig"
"github.com/uber/cadence/common/membership"
"github.com/uber/cadence/common/quotas"
)

// PerMember allows creating per instance RPS based on globalRPS averaged by member count for a given service.
Expand Down Expand Up @@ -52,7 +53,7 @@ func NewPerMemberDynamicRateLimiterFactory(
globalRPS dynamicconfig.IntPropertyFnWithDomainFilter,
instanceRPS dynamicconfig.IntPropertyFnWithDomainFilter,
resolver membership.Resolver,
) LimiterFactory {
) quotas.LimiterFactory {
return perMemberFactory{
service: service,
globalRPS: globalRPS,
Expand All @@ -68,8 +69,8 @@ type perMemberFactory struct {
resolver membership.Resolver
}

func (f perMemberFactory) GetLimiter(domain string) Limiter {
return NewDynamicRateLimiter(func() float64 {
func (f perMemberFactory) GetLimiter(domain string) quotas.Limiter {
return quotas.NewDynamicRateLimiter(func() float64 {
return PerMember(
f.service,
float64(f.globalRPS(domain)),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.

package quotas
package permember

import (
"testing"
Expand Down
4 changes: 2 additions & 2 deletions common/resource/resourceImpl.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ import (
"github.com/uber/cadence/common/partition"
"github.com/uber/cadence/common/persistence"
persistenceClient "github.com/uber/cadence/common/persistence/client"
"github.com/uber/cadence/common/quotas"
"github.com/uber/cadence/common/quotas/global/rpc"
"github.com/uber/cadence/common/quotas/permember"
"github.com/uber/cadence/common/service"
)

Expand Down Expand Up @@ -182,7 +182,7 @@ func New(
persistenceBean, err := persistenceClient.NewBeanFromFactory(persistenceClient.NewFactory(
&params.PersistenceConfig,
func() float64 {
return quotas.PerMember(
return permember.PerMember(
serviceName,
float64(serviceConfig.PersistenceGlobalMaxQPS()),
float64(serviceConfig.PersistenceMaxQPS()),
Expand Down
3 changes: 2 additions & 1 deletion service/frontend/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import (
"github.com/uber/cadence/common/log/tag"
"github.com/uber/cadence/common/quotas"
"github.com/uber/cadence/common/quotas/global/collection"
"github.com/uber/cadence/common/quotas/permember"
"github.com/uber/cadence/common/resource"
"github.com/uber/cadence/common/service"
"github.com/uber/cadence/service/frontend/admin"
Expand Down Expand Up @@ -263,7 +264,7 @@ func (s *Service) createGlobalQuotaCollections() (globalRatelimiterCollections,
}
func (s *Service) createBaseLimiters() ratelimiterCollections {
create := func(shared, perInstance dynamicconfig.IntPropertyFnWithDomainFilter) *quotas.Collection {
return quotas.NewCollection(quotas.NewPerMemberDynamicRateLimiterFactory(
return quotas.NewCollection(permember.NewPerMemberDynamicRateLimiterFactory(
service.Frontend,
shared,
perInstance,
Expand Down
5 changes: 3 additions & 2 deletions service/history/engine/engineimpl/history_engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ import (
cndc "github.com/uber/cadence/common/ndc"
"github.com/uber/cadence/common/persistence"
"github.com/uber/cadence/common/quotas"
"github.com/uber/cadence/common/quotas/permember"
"github.com/uber/cadence/common/reconciliation/invariant"
"github.com/uber/cadence/common/service"
"github.com/uber/cadence/common/types"
Expand Down Expand Up @@ -188,15 +189,15 @@ func NewEngineWithShardContext(
shard.GetConfig().NumArchiveSystemWorkflows,
quotas.NewDynamicRateLimiter(config.ArchiveRequestRPS.AsFloat64()),
quotas.NewDynamicRateLimiter(func() float64 {
return quotas.PerMember(
return permember.PerMember(
service.History,
float64(config.ArchiveInlineHistoryGlobalRPS()),
float64(config.ArchiveInlineHistoryRPS()),
shard.GetService().GetMembershipResolver(),
)
}),
quotas.NewDynamicRateLimiter(func() float64 {
return quotas.PerMember(
return permember.PerMember(
service.History,
float64(config.ArchiveInlineVisibilityGlobalRPS()),
float64(config.ArchiveInlineVisibilityRPS()),
Expand Down

0 comments on commit eac4235

Please sign in to comment.