Class ProvisionRateLimiter
java.lang.Object
io.jenkins.plugins.swarmcloud.ratelimit.ProvisionRateLimiter
Rate limiter for agent provisioning to prevent overwhelming the Docker Swarm cluster.
Implements a sliding window rate limiter with configurable limits.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classRate limit information for monitoring. -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intDefault maximum provisions per minute.static final longDefault minimum interval between provisions in milliseconds.static final longCooldown period after failures in milliseconds. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic booleancanProvision(String cloudName) Check if provisioning is allowed for the given cloud.static booleancanProvision(String cloudName, int maxPerMinute, long minIntervalMs) Check if provisioning is allowed with custom limits.static voidclearAll()Clear all rate limit state (for testing).Get the current rate limit state for a cloud.static longgetWaitTime(String cloudName) Get wait time until next provision is allowed.static longgetWaitTime(String cloudName, int maxPerMinute, long minIntervalMs) Get wait time with custom limits.static voidrecordFailure(String cloudName) Record a failed provision attempt.static voidrecordProvision(String cloudName) Record a successful provision.static voidresetFailures(String cloudName) Reset failure count after successful recovery.
-
Field Details
-
DEFAULT_MAX_PROVISIONS_PER_MINUTE
public static final int DEFAULT_MAX_PROVISIONS_PER_MINUTEDefault maximum provisions per minute.- See Also:
-
DEFAULT_MIN_INTERVAL_MS
public static final long DEFAULT_MIN_INTERVAL_MSDefault minimum interval between provisions in milliseconds.- See Also:
-
FAILURE_COOLDOWN_MS
public static final long FAILURE_COOLDOWN_MSCooldown period after failures in milliseconds.
-
-
Constructor Details
-
ProvisionRateLimiter
public ProvisionRateLimiter()
-
-
Method Details
-
canProvision
Check if provisioning is allowed for the given cloud.- Parameters:
cloudName- The cloud name- Returns:
- true if provisioning is allowed
-
canProvision
Check if provisioning is allowed with custom limits.- Parameters:
cloudName- The cloud namemaxPerMinute- Maximum provisions per minuteminIntervalMs- Minimum interval between provisions- Returns:
- true if provisioning is allowed
-
recordProvision
Record a successful provision.- Parameters:
cloudName- The cloud name
-
recordFailure
Record a failed provision attempt.- Parameters:
cloudName- The cloud name
-
resetFailures
Reset failure count after successful recovery.- Parameters:
cloudName- The cloud name
-
getInfo
Get the current rate limit state for a cloud.- Parameters:
cloudName- The cloud name- Returns:
- The state or null if not tracked
-
getWaitTime
Get wait time until next provision is allowed.- Parameters:
cloudName- The cloud name- Returns:
- Wait time in milliseconds, 0 if allowed now
-
getWaitTime
Get wait time with custom limits.- Parameters:
cloudName- The cloud namemaxPerMinute- Maximum provisions per minuteminIntervalMs- Minimum interval between provisions- Returns:
- Wait time in milliseconds
-
clearAll
public static void clearAll()Clear all rate limit state (for testing).
-