Class ProvisionRateLimiter

java.lang.Object
io.jenkins.plugins.swarmcloud.ratelimit.ProvisionRateLimiter

public class ProvisionRateLimiter extends Object
Rate limiter for agent provisioning to prevent overwhelming the Docker Swarm cluster. Implements a sliding window rate limiter with configurable limits.
  • Field Details

    • DEFAULT_MAX_PROVISIONS_PER_MINUTE

      public static final int DEFAULT_MAX_PROVISIONS_PER_MINUTE
      Default maximum provisions per minute.
      See Also:
    • DEFAULT_MIN_INTERVAL_MS

      public static final long DEFAULT_MIN_INTERVAL_MS
      Default minimum interval between provisions in milliseconds.
      See Also:
    • FAILURE_COOLDOWN_MS

      public static final long FAILURE_COOLDOWN_MS
      Cooldown period after failures in milliseconds.
  • Constructor Details

    • ProvisionRateLimiter

      public ProvisionRateLimiter()
  • Method Details

    • canProvision

      public static boolean canProvision(@NonNull String cloudName)
      Check if provisioning is allowed for the given cloud.
      Parameters:
      cloudName - The cloud name
      Returns:
      true if provisioning is allowed
    • canProvision

      public static boolean canProvision(@NonNull String cloudName, int maxPerMinute, long minIntervalMs)
      Check if provisioning is allowed with custom limits.
      Parameters:
      cloudName - The cloud name
      maxPerMinute - Maximum provisions per minute
      minIntervalMs - Minimum interval between provisions
      Returns:
      true if provisioning is allowed
    • recordProvision

      public static void recordProvision(@NonNull String cloudName)
      Record a successful provision.
      Parameters:
      cloudName - The cloud name
    • recordFailure

      public static void recordFailure(@NonNull String cloudName)
      Record a failed provision attempt.
      Parameters:
      cloudName - The cloud name
    • resetFailures

      public static void resetFailures(@NonNull String cloudName)
      Reset failure count after successful recovery.
      Parameters:
      cloudName - The cloud name
    • getInfo

      public static ProvisionRateLimiter.RateLimitInfo getInfo(@NonNull String cloudName)
      Get the current rate limit state for a cloud.
      Parameters:
      cloudName - The cloud name
      Returns:
      The state or null if not tracked
    • getWaitTime

      public static long getWaitTime(@NonNull String cloudName)
      Get wait time until next provision is allowed.
      Parameters:
      cloudName - The cloud name
      Returns:
      Wait time in milliseconds, 0 if allowed now
    • getWaitTime

      public static long getWaitTime(@NonNull String cloudName, int maxPerMinute, long minIntervalMs)
      Get wait time with custom limits.
      Parameters:
      cloudName - The cloud name
      maxPerMinute - Maximum provisions per minute
      minIntervalMs - Minimum interval between provisions
      Returns:
      Wait time in milliseconds
    • clearAll

      public static void clearAll()
      Clear all rate limit state (for testing).