Skip to content

feat(googlecloud): add adaptive rate limiter for Cloud Logging API queries - #896

Merged
kyasbal merged 1 commit into
GoogleCloudPlatform:mainfrom
kyasbal:feat/gcp-adaptive-rate-limiter
Aug 25, 2026
Merged

kyasbal merged 1 commit into
GoogleCloudPlatform:mainfrom
kyasbal:feat/gcp-adaptive-rate-limiter

Conversation

@kyasbal

@kyasbal kyasbal commented Aug 24, 2026

Copy link
Copy Markdown
Member

Summary

This PR introduces an adaptive rate limiter for Google Cloud Logging API queries using an Additive Increase Multiplicative Decrease (AIMD) algorithm implemented as a gRPC unary client interceptor.

Background & Motivation

When KHI runs concurrent inspection tasks across multiple log types (e.g. Kubernetes Audit, Node, Container, Autoscaler, Serial Port logs), bursts of unthrottled gRPC calls easily exceed the Cloud Logging API quota limits, triggering ResourceExhausted (429) errors.
In unthrottled clients, 429 errors trigger exponential backoff retry storms (or exhaustion failures), significantly delaying log collection or causing inspection tasks to fail.

Changes

  • pkg/api/googlecloud/ratelimit.AdaptiveRateLimiter:
    • AIMD algorithm wrapping golang.org/x/time/rate.Limiter.
    • Increment rate by IncreaseStep on success, and multiply rate by DecreaseFactor on codes.ResourceExhausted.
    • DecreaseCooldown suppression window prevents rapid consecutive throttling drops on parallel in-flight failures.
  • pkg/api/googlecloud/ratelimit.Pool:
    • Maintains isolated rate limiters keyed by quota project ID or target resource container.
  • pkg/api/googlecloud/ratelimit.UnaryClientInterceptor:
    • gRPC unary client interceptor integrating the rate limiter with client calls.
  • pkg/parameters & CLI Flags:
    • Added configurable parameters (--logging-initial-qps, --logging-min-qps, --logging-max-qps).
  • pkg/task/inspection/googlecloudcommon/impl.apioptions_task:
    • Integrates the rate limiter interceptor into ClientFactoryOptions.

Verification & Benchmark Results

Under simulated quota constraints (25.0 QPS capacity, 10 concurrent workers, 100 queries):

  • 429 Errors: Reduced from 1,245 errors (92.6%) to 8 errors (7.4%) (99.4% reduction in 429 error storms).
  • Total Network Calls: Reduced from 1,345 calls to 108 calls (12.5x reduction in wasted network retries).
  • Microbenchmarks: 462 ns/op, 0 allocs/op on 12 parallel threads.
  • All backend tests (make test-go), linters (make lint-go), and pre-commit hooks passed.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces adaptive rate limiting for Google Cloud Logging client queries using an Additive Increase / Multiplicative Decrease (AIMD) algorithm. It adds a new ratelimit package containing the AdaptiveRateLimiter, a limiter pool, and a gRPC unary client interceptor, alongside new configuration parameters and a Float64 flag parser. The review feedback highlights two key improvements: first, suppressing rate increases during the cooldown window immediately following a rate reduction to prevent aggressive overrides; second, using grpc.WithChainUnaryInterceptor instead of grpc.WithUnaryInterceptor to avoid silently overwriting other configured interceptors.

Comment thread pkg/parameters/ratelimit.go Resolved
@kyasbal
kyasbal force-pushed the feat/gcp-adaptive-rate-limiter branch from ddb7d31 to b055068 Compare August 25, 2026 01:00
…eries

Implement an AIMD (Additive Increase / Multiplicative Decrease) based adaptive
rate limiter for Cloud Logging queries to mitigate 429 ResourceExhausted errors
when querying logs in parallel.

- Add pkg/api/googlecloud/ratelimit for AIMD limiter, pool, and gRPC unary interceptor
- Add CLI parameters for logging rate limits (--logging-initial-qps, etc.)
- Inject adaptive rate limiter into ClientFactory in APIClientFactoryOptionsTask
- Add Float64 support in flag package

fix(googlecloud): address PR review comments for adaptive rate limiter

feat(googlecloud): tune adaptive rate limiter default parameters for faster sustained queries
@kyasbal
kyasbal force-pushed the feat/gcp-adaptive-rate-limiter branch from b055068 to c112236 Compare August 25, 2026 03:01
@kyasbal kyasbal added the type:feature New feature or request label Aug 25, 2026
@kyasbal
kyasbal merged commit 8ce0a88 into GoogleCloudPlatform:main Aug 25, 2026
16 checks passed
@kyasbal
kyasbal deleted the feat/gcp-adaptive-rate-limiter branch August 25, 2026 03:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

type:feature New feature or request

1 participant