-
Notifications
You must be signed in to change notification settings - Fork 3.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: new stream count limiter (#13006)
Signed-off-by: Vladyslav Diachenko <vlad.diachenko@grafana.com> Co-authored-by: JordanRushing <rushing.jordan@gmail.com>
- Loading branch information
1 parent
987e551
commit 1111595
Showing
7 changed files
with
239 additions
and
55 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package ingester | ||
|
||
import "go.uber.org/atomic" | ||
|
||
type ownedStreamService struct { | ||
tenantID string | ||
limiter *Limiter | ||
fixedLimit *atomic.Int32 | ||
|
||
//todo: implement job to recalculate it | ||
ownedStreamCount *atomic.Int64 | ||
} | ||
|
||
func newOwnedStreamService(tenantID string, limiter *Limiter) *ownedStreamService { | ||
svc := &ownedStreamService{ | ||
tenantID: tenantID, | ||
limiter: limiter, | ||
ownedStreamCount: atomic.NewInt64(0), | ||
fixedLimit: atomic.NewInt32(0), | ||
} | ||
svc.updateFixedLimit() | ||
return svc | ||
} | ||
|
||
func (s *ownedStreamService) getOwnedStreamCount() int { | ||
return int(s.ownedStreamCount.Load()) | ||
} | ||
|
||
func (s *ownedStreamService) updateFixedLimit() { | ||
limit, _, _, _ := s.limiter.GetStreamCountLimit(s.tenantID) | ||
s.fixedLimit.Store(int32(limit)) | ||
} | ||
|
||
func (s *ownedStreamService) getFixedLimit() int { | ||
return int(s.fixedLimit.Load()) | ||
} | ||
|
||
func (s *ownedStreamService) incOwnedStreamCount() { | ||
s.ownedStreamCount.Inc() | ||
} | ||
|
||
func (s *ownedStreamService) decOwnedStreamCount() { | ||
s.ownedStreamCount.Dec() | ||
} |
Oops, something went wrong.