From 24777a77c8cbf8d63eeaead27ad40bf39d534fce Mon Sep 17 00:00:00 2001 From: Michael Quigley Date: Mon, 17 Jun 2024 13:16:07 -0400 Subject: [PATCH] share_frontends implementation and testing (#650) --- controller/limits/agent.go | 10 ++++++++-- controller/limits/resourceCountClass.go | 2 +- controller/limits/userLimits.go | 5 ++--- controller/store/limitClass.go | 2 +- .../metrics-and-limits/configuring-limits.md | 8 +++++--- etc/ctrl.yml | 1 + 6 files changed, 18 insertions(+), 10 deletions(-) diff --git a/controller/limits/agent.go b/controller/limits/agent.go index 6e9a8315..78835056 100644 --- a/controller/limits/agent.go +++ b/controller/limits/agent.go @@ -197,8 +197,14 @@ func (a *Agent) CanAccessShare(shrId int, trx *sqlx.Tx) (bool, error) { rc = scopeRc } if rc.GetShareFrontends() > store.Unlimited { - // TODO: Implement frontends+1 check - return true, nil + fes, err := a.str.FindFrontendsForPrivateShare(shr.Id, trx) + if err != nil { + return false, err + } + if len(fes)+1 > rc.GetShareFrontends() { + logrus.Infof("account '#%d' over frontends per share limit '%d'", *env.AccountId, rc.GetReservedShares()) + return false, nil + } } } else { return false, nil diff --git a/controller/limits/resourceCountClass.go b/controller/limits/resourceCountClass.go index 7d2c4117..1f888583 100644 --- a/controller/limits/resourceCountClass.go +++ b/controller/limits/resourceCountClass.go @@ -42,5 +42,5 @@ func (rcc *configResourceCountClass) GetShareFrontends() int { } func (rcc *configResourceCountClass) String() string { - return fmt.Sprintf("Config", rcc.cfg.Environments, rcc.cfg.Shares, rcc.cfg.ReservedShares, rcc.cfg.UniqueNames) + return fmt.Sprintf("Config", rcc.cfg.Environments, rcc.cfg.Shares, rcc.cfg.ReservedShares, rcc.cfg.UniqueNames, rcc.cfg.ShareFrontends) } diff --git a/controller/limits/userLimits.go b/controller/limits/userLimits.go index 3b40e256..5be269a9 100644 --- a/controller/limits/userLimits.go +++ b/controller/limits/userLimits.go @@ -42,7 +42,6 @@ func (ul *userLimits) ignoreBackends(bwc store.BandwidthClass) map[sdk.BackendMo } return ignoreBackends } - return nil } func (a *Agent) getUserLimits(acctId int, trx *sqlx.Tx) (*userLimits, error) { @@ -85,7 +84,7 @@ func (a *Agent) isResourceCountClass(alc *store.LimitClass) bool { if alc.BackendMode != nil { return false } - if alc.Environments == store.Unlimited && alc.Shares == store.Unlimited && alc.ReservedShares == store.Unlimited && alc.UniqueNames == store.Unlimited { + if alc.Environments == store.Unlimited && alc.Shares == store.Unlimited && alc.ReservedShares == store.Unlimited && alc.UniqueNames == store.Unlimited && alc.ShareFrontends == store.Unlimited { return false } return true @@ -95,7 +94,7 @@ func (a *Agent) isUnscopedBandwidthClass(alc *store.LimitClass) bool { if alc.BackendMode != nil { return false } - if alc.Environments > store.Unlimited || alc.Shares > store.Unlimited || alc.ReservedShares > store.Unlimited || alc.UniqueNames > store.Unlimited { + if alc.Environments > store.Unlimited || alc.Shares > store.Unlimited || alc.ReservedShares > store.Unlimited || alc.UniqueNames > store.Unlimited || alc.ShareFrontends > store.Unlimited { return false } if alc.PeriodMinutes < 1 { diff --git a/controller/store/limitClass.go b/controller/store/limitClass.go index 46df6159..13558ae4 100644 --- a/controller/store/limitClass.go +++ b/controller/store/limitClass.go @@ -128,7 +128,7 @@ func (lc LimitClass) String() string { out += fmt.Sprintf(", uniqueNames: %d", lc.UniqueNames) } if lc.ShareFrontends > Unlimited { - out += fmt.Sprintf(", frontends: %d", lc.ShareFrontends) + out += fmt.Sprintf(", shareFrontends: %d", lc.ShareFrontends) } if lc.RxBytes > Unlimited || lc.TxBytes > Unlimited || lc.TotalBytes > Unlimited { out += fmt.Sprintf(", periodMinutes: %d", lc.PeriodMinutes) diff --git a/docs/guides/self-hosting/metrics-and-limits/configuring-limits.md b/docs/guides/self-hosting/metrics-and-limits/configuring-limits.md index b233eb9d..1dde9044 100644 --- a/docs/guides/self-hosting/metrics-and-limits/configuring-limits.md +++ b/docs/guides/self-hosting/metrics-and-limits/configuring-limits.md @@ -20,7 +20,7 @@ The limits agent is responsible for controlling the number of resources in use ( ### Types of Limits -Limits can be specified that control the number of environments, shares, reserved shares, and unique names that can be created by an account. Limits that control the allowed number of resources are called _resource count limits_. +Limits can be specified that control the number of environments, shares, reserved shares, unique names, and frontends per-share that can be created by an account. Limits that control the allowed number of resources are called _resource count limits_. Limits can be specified to control the amount of data that can be transferred within a time period. Limits that control the amount of data that can be transferred are called _bandwidth limits_. @@ -40,6 +40,7 @@ limits: shares: -1 reserved_shares: -1 unique_names: -1 + share_frontends: -1 bandwidth: period: 5m warning: @@ -64,7 +65,7 @@ The `cycle` value controls how frequently the limits agent will evaluate enforce ### Global Resouce Count Limits -The `environments`, `shares`, `reserved_shares`, and `unique_names` specify the resource count limits, globally for the service instance. +The `environments`, `shares`, `reserved_shares`, `unique_names`, and `share_frontends` specify the resource count limits, globally for the service instance. These resource counts will be applied to all users in the service instance by default. @@ -96,6 +97,7 @@ CREATE TABLE public.limit_classes ( shares integer DEFAULT '-1'::integer NOT NULL, reserved_shares integer DEFAULT '-1'::integer NOT NULL, unique_names integer DEFAULT '-1'::integer NOT NULL, + share_frontends integer DEFAULT '-1'::integer NOT NULL, period_minutes integer DEFAULT 1440 NOT NULL, rx_bytes bigint DEFAULT '-1'::integer NOT NULL, tx_bytes bigint DEFAULT '-1'::integer NOT NULL, @@ -130,7 +132,7 @@ Create a row in this table linking the `account_id` to the `limit_class_id` to a To support overriding the resource count limits defined in the global limits configuration, a site administrator can create a limit class by inserting a row into the `limit_classes` table structured like this: ```sql -insert into limit_classes (environments, shares, reserved_shares, unique_names) values (1, 1, 1, 1); +insert into limit_classes (environments, shares, reserved_shares, unique_names, share_frontends) values (1, 1, 1, 1, 1); ``` This creates a limit class that sets the `environments`, `shares`, `reserved_shares`, and `unique_names` all to `1`. diff --git a/etc/ctrl.yml b/etc/ctrl.yml index 0c680b8d..d9b0efd0 100644 --- a/etc/ctrl.yml +++ b/etc/ctrl.yml @@ -83,6 +83,7 @@ limits: shares: -1 reserved_shares: -1 unique_names: -1 + share_frontends: -1 bandwidth: period: 5m warning: