Skip to content

Commit

Permalink
feat(insights): include tenant id in rate limitter key (#6808)
Browse files Browse the repository at this point in the history
Signed-off-by: Jakub Dyszkiewicz <jakub.dyszkiewicz@gmail.com>
  • Loading branch information
jakubdyszkiewicz authored May 22, 2023
1 parent 440e465 commit 7444701
Showing 1 changed file with 11 additions and 9 deletions.
20 changes: 11 additions & 9 deletions pkg/insights/resyncer.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,9 +161,9 @@ func (r *resyncer) Start(stop <-chan struct{}) error {
log.Error(err, "Resource is not registered in the registry, ignoring it", "resource", resourceChanged.Type)
}
if resourceChanged.Type == core_mesh.MeshType && resourceChanged.Operation == events.Delete {
r.deleteRateLimiter(resourceChanged.Key.Name)
r.deleteRateLimiter(resourceChanged.Key.Name, resourceChanged.TenantID)
}
if !r.getRateLimiter(resourceChanged.Key.Mesh).Allow() {
if !r.getRateLimiter(resourceChanged.Key.Mesh, resourceChanged.TenantID).Allow() {
continue
}
if _, ok := resourcesAffectingServiceInsights[resourceChanged.Type]; ok {
Expand All @@ -187,18 +187,20 @@ func (r *resyncer) Start(stop <-chan struct{}) error {
}
}

func (r *resyncer) getRateLimiter(mesh string) *rate.Limiter {
if _, ok := r.rateLimiters[mesh]; !ok {
r.rateLimiters[mesh] = r.rateLimiterFactory()
func (r *resyncer) getRateLimiter(mesh string, tenantID string) *rate.Limiter {
key := mesh + ":" + tenantID
if _, ok := r.rateLimiters[key]; !ok {
r.rateLimiters[key] = r.rateLimiterFactory()
}
return r.rateLimiters[mesh]
return r.rateLimiters[key]
}

func (r *resyncer) deleteRateLimiter(mesh string) {
if _, ok := r.rateLimiters[mesh]; !ok {
func (r *resyncer) deleteRateLimiter(mesh string, tenantID string) {
key := mesh + ":" + tenantID
if _, ok := r.rateLimiters[key]; !ok {
return
}
delete(r.rateLimiters, mesh)
delete(r.rateLimiters, key)
}

func (r *resyncer) createOrUpdateServiceInsights(ctx context.Context, now time.Time) error {
Expand Down

0 comments on commit 7444701

Please sign in to comment.