| Safe Haskell | None |
|---|---|
| Language | GHC2024 |
Arbiter.Core.RateLimit.Spec
Description
Per-job token-bucket rate limits. A payload's rateLimitFor describes how
to select its policy and key. Static inspection finds all policies that the
migration must initialize.
Synopsis
- data Durability
- data RateLimitKey = RateLimitKey {}
- rateLimitKeyText :: RateLimitKey -> Text
- data Policy = Policy {}
- tokenBucket :: Text -> Double -> NominalDiffTime -> Policy
- class HasRateLimit payload where
- rateLimitFor :: RateLimitFor payload
- rateLimitCost :: payload -> Double
- type RateLimitFor payload = Selector Policy payload (Maybe RateLimitKey)
- noLimit :: RateLimitFor payload
- limitBy :: Policy -> (payload -> Text) -> RateLimitFor payload
- globalLimit :: Policy -> Text -> RateLimitFor payload
- chooseWhen :: (payload -> Bool) -> Selector policy payload a -> Selector policy payload a -> Selector policy payload a
- limitByCase :: (Bounded k, Enum k, Eq k) => (payload -> k) -> (k -> RateLimitFor payload) -> RateLimitFor payload
- runRateLimitFor :: payload -> RateLimitFor payload -> Maybe RateLimitKey
- collectPolicies :: Ord policy => Selector policy payload a -> Set policy
- type RegistryRateLimitPolicies (registry :: JobPayloadRegistry) = RegistryPolicies registry Policy
- registryRateLimitPolicies :: forall (registry :: JobPayloadRegistry). RegistryRateLimitPolicies registry => Set Policy
- registryRateLimitTables :: forall (registry :: JobPayloadRegistry). RegistryRateLimitPolicies registry => [(Text, Bool)]
Core types
Source #data Durability
Whether the rate-limit bucket table is WAL-logged. Set at migration time.
Instances
| Eq Durability Source # | |
Defined in Arbiter.Core.RateLimit.Spec | |
| Show Durability Source # | |
Defined in Arbiter.Core.RateLimit.Spec Methods #showsPrec :: Int -> Durability -> ShowS #show :: Durability -> String #showList :: [Durability] -> ShowS | |
Source #data RateLimitKey
A resolved key with a prefix and per-key suffix. The stored form is
prefix:suffix. The separate prefix supports policy lookup.
Constructors
| RateLimitKey | |
Instances
| FromJSON RateLimitKey Source # | |
Defined in Arbiter.Core.RateLimit.Spec | |
| ToJSON RateLimitKey Source # | |
Defined in Arbiter.Core.RateLimit.Spec Methods #toJSON :: RateLimitKey -> Value #toEncoding :: RateLimitKey -> Encoding #toJSONList :: [RateLimitKey] -> Value #toEncodingList :: [RateLimitKey] -> Encoding #omitField :: RateLimitKey -> Bool | |
| Eq RateLimitKey Source # | |
Defined in Arbiter.Core.RateLimit.Spec | |
| Show RateLimitKey Source # | |
Defined in Arbiter.Core.RateLimit.Spec Methods #showsPrec :: Int -> RateLimitKey -> ShowS #show :: RateLimitKey -> String #showList :: [RateLimitKey] -> ShowS | |
Source #rateLimitKeyText :: RateLimitKey -> Text
The bucket key as stored, prefix and suffix joined.
A token-bucket policy. Burst policyMax, refilling policyRefill every
policyInterval. A policyRefill of 0 is a manually-refilled bucket.
Constructors
| Policy | |
Fields | |
Instances
| AdmissionPolicy Policy Source # | |
Defined in Arbiter.Core.RateLimit.Spec Methods Source #policyPrefixOf :: Policy -> Text | |
| Eq Policy Source # | |
| Ord Policy Source # | |
| Show Policy Source # | |
| HasRateLimit payload => CollectFor (payload :: Type) Policy Source # | |
Defined in Arbiter.Core.RateLimit.Spec Methods | |
Source #tokenBucket :: Text -> Double -> NominalDiffTime -> Policy
"N per period" with burst N (max = refill = n). The period is floored to a
tiny positive value. The prefix must not contain :, the key separator. The
migration enforces this.
Selecting a policy per job
Source #class HasRateLimit payload where
A payload's per-job key selection. Defaults to unlimited. Only limited payloads need an instance.
Minimal complete definition
Nothing
Methods
Source #rateLimitFor :: RateLimitFor payload
The selector deciding which policy (if any) limits a given job.
Source #rateLimitCost :: payload -> Double
How many tokens this job spends. Defaults to 1.
Instances
| HasRateLimit payload Source # | |
Defined in Arbiter.Core.RateLimit.Spec | |
Source #type RateLimitFor payload = Selector Policy payload (Maybe RateLimitKey)
A selective description of the rate-limit key for a payload. Evaluation returns the job key. Static inspection returns the reachable policies.
Source #noLimit :: RateLimitFor payload
This payload is unlimited.
Source #limitBy :: Policy -> (payload -> Text) -> RateLimitFor payload
Limit by a fixed policy, keyed by a per-job suffix (e.g. a tenant id).
Source #globalLimit :: Policy -> Text -> RateLimitFor payload
Limit by a fixed policy under one shared key (a single global bucket).
Source #chooseWhen :: (payload -> Bool) -> Selector policy payload a -> Selector policy payload a -> Selector policy payload a
Select between two selectors with a job predicate. Policy collection inspects both branches.
Source #limitByCase :: (Bounded k, Enum k, Eq k) => (payload -> k) -> (k -> RateLimitFor payload) -> RateLimitFor payload
N-way chooseWhen. Maps the job to a finite tag, then each tag to its selector.
Policy collection evaluates every tag in [minBound..maxBound]. The tag's
Bounded/Enum and the selector must be total over k.
Source #runRateLimitFor :: payload -> RateLimitFor payload -> Maybe RateLimitKey
Run a selector against a concrete job to get its key.
Source #collectPolicies :: Ord policy => Selector policy payload a -> Set policy
All policies that a selector can reach across all branches.
Registry reflection
Source #type RegistryRateLimitPolicies (registry :: JobPayloadRegistry) = RegistryPolicies registry Policy
Collect every policy declared across a registry's payloads, by statically
inspecting each payload's rateLimitFor. The migration seeds these.
Source #registryRateLimitPolicies :: forall (registry :: JobPayloadRegistry). RegistryRateLimitPolicies registry => Set Policy
Every distinct policy declared across the registry's payloads.
Source #registryRateLimitTables :: forall (registry :: JobPayloadRegistry). RegistryRateLimitPolicies registry => [(Text, Bool)]
Each registry table paired with whether its payload declares any policy.