Repository navigation
Refactor: Use generalized LRU cache for rate limiter cache. - #249
Conversation
There was a problem hiding this comment.
All reported issues were addressed across 7 files
Tip: instead of fixing issues one by one fix them all with cubic
Re-trigger cubic
|
Early pass only, I know pkg #138 still has open comments so this will need another look once that API settles. Direction is fine, swapping the http rate limiter onto the shared LRU is the right first consumer. A few things I would not ship as-is, left them inline. |
roguepikachu
left a comment
There was a problem hiding this comment.
Request changes
Verified locally on k3d with this branch wired to a local build of kubevela/pkg#138. Once rateLimiter actually reaches the HTTP provider, the LRU-backed limiter works (first request allowed, second blocked with request exceeds the rate limiter).
Please address the items below before merge. This PR should wait on kubevela/pkg#138.
Required
- Do not ignore the
NewLRUStoreerror inNewRateLimiter. - Use TTL
0for limiter entries (or otherwise avoid a fixed 5m TTL that can drop an active limiter while the rate window still matters). Entry-count LRU withMaxSizeis enough here. - End-to-end usability: the stock
requestWorkflowStepDefinition does not passrateLimiterintohttp.#HTTPDo, so callers cannot exercise this path today. Please wireparameter.rateLimiterthrough the request step template (in this repo if workflow ships the definition, or coordinate the same change on the kubevelarequestWSD). Without that, the Go change is effectively dead for WorkflowRuns.
Happy to re-review once these are in.
|
@roguepikachu , Have addressed all the changes
Also cubic-dev comments have been addressed since they overlap with the reviews suggested. |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #249 +/- ##
==========================================
+ Coverage 62.49% 69.85% +7.36%
==========================================
Files 62 73 +11
Lines 4415 5845 +1430
==========================================
+ Hits 2759 4083 +1324
- Misses 1324 1370 +46
- Partials 332 392 +60
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Signed-off-by: kash2104 <kparikh1104@gmail.com>
Signed-off-by: kash2104 <kparikh1104@gmail.com>
Signed-off-by: kash2104 <kparikh1104@gmail.com>
|
@cubic-dev-ai review |
@roguepikachu I have started the AI code review. It will take a few minutes to complete. |
There was a problem hiding this comment.
Request: wire ratelimiter through the stock request WSD
kubevela already landed this on the request step template (kubevela/kubevela#7326: vela-templates/definitions/internal/workflowstep/request.cue and the generated chart request.yaml).
This repo's chart definition still does not forward it:
charts/vela-workflow/templates/definitions/request.yaml
Today http.#HTTPDo already accepts request.ratelimiter (pkg/providers/http/http.cue), but the stock request step never passes parameter.ratelimiter into $params.request. So on a workflow-only install, WorkflowRuns cannot exercise the LRU rate limiter path this PR introduces.
Please mirror the kubevela change here:
- In the
http.#HTTPDorequest block, add:
if parameter.ratelimiter != _|_ {
ratelimiter: parameter.ratelimiter
}- Add to
parameter:
ratelimiter?: {
limit: int & >0
period: string
}(Optionally keep the same duration regex / usage comments as kubevela for consistency.)
Without this, the Go/LRU migration works, but stock request steps remain unable to use ratelimiter when definitions come from this chart.
There was a problem hiding this comment.
All reported issues were addressed across 3 files (changes from recent commits).
Tip: Review your code locally with the cubic CLI to iterate faster.
Fix all with cubic | Re-trigger cubic
Signed-off-by: kash2104 <kparikh1104@gmail.com>
|
@roguepikachu Updated the |
|
@cubic-dev-ai review |
@roguepikachu I have started the AI code review. It will take a few minutes to complete. |
There was a problem hiding this comment.
Two small cleanups before I can approve:
- Remove dead
pkg/providers/http/ratelimiterpackage
Both HTTP providers import pkg/providers/legacy/http/ratelimiter after this refactor, but pkg/providers/http/ratelimiter/ still ships the old groupcache/lru implementation (and its test). Nothing references it anymore.
Please delete that package and run go mod tidy so github.com/golang/groupcache drops out of go.mod if nothing else needs it.
- Restore multiline CUE in
request.yaml
Commit c9bf22e collapsed the template into one escaped JSON string. Functionally fine, but this chart has historically used a readable multiline template: | block, and that is much easier to review and diff going forward. Please restore the multiline format while keeping the new timeout and ratelimiter fields.
Happy to approve once these are in @kash2104
There was a problem hiding this comment.
All reported issues were addressed across 12 files
Requires human review: Auto-approval blocked because this review re-detected 1 unresolved issue already reported by Cubic.
Re-trigger cubic
Signed-off-by: kash2104 <kparikh1104@gmail.com>
|
@roguepikachu Removed the unused |
roguepikachu
left a comment
There was a problem hiding this comment.
LGTM. Thanks for the follow-ups on the WSD wiring, the dead groupcache package cleanup, and restoring the multiline request template. Nice work getting this across the finish line.
|
Thank you for your contribution! One suggestion for the future, once you have resolved a comment, please mark it as resolved in github |
Description of your changes
This PR replaces the
lru.Cachewith thelru cachethat will be introduced inkubevela/pkgPR to use the centralized package instead of declaring as per the current status.Fixes #247
I have:
make reviewableto ensure this PR is ready for review.backport release-x.ylabels to auto-backport this PR if necessary.How has this code been tested
Since the PR for the generic cache hasn't been merged yet, used workspaces to test this features.
Note: Avoid running go mod tidy in any repo, as it updates the module graph and throws error saying that
package cache doesn't exist in kubevela/pkgdependency.mkto disable the workspace when downloading the pinned module version for CRDs.This ensures that the CRDs are copied from the module version pinned in go.mod rather than from the local workspace checkout.
github.com/kubevela/pkgandgithub.com/kubevela/workflowis being used and that the changes work as expected.Special notes for your reviewer
This change depends on the generic LRU cache implementation introduced in the corresponding
github.com/kubevela/pkgPR, which has not been merged yet. As a result, the cache package is not available in the published module version.Summary by cubic
Switches the HTTP rate limiter cache to the shared
github.com/kubevela/pkg/cacheLRU, makes initialization explicit and context-aware, and adds per-request rate limit and timeout parameters to therequestdefinition.ratelimiter.NewRateLimiternow has signatureNewRateLimiter(ctx context.Context, size int) (*RateLimiter, error). Callers must pass a context and handle the error.cmd/main.goinitializes once viapkg/providers/http.InitRateLimiter(rootCtx)andpkg/providers/legacy/http.InitRateLimiter(rootCtx); providers also lazily initialize withsync.Once.requestnow accepts aratelimiterwithlimit > 0and a Go-durationperiod, plus atimeout; invalid values fail when the step runs.github.com/kubevela/pkgis bumped to the version providing the shared LRU store.Written for commit 9d30ce5. Summary will update on new commits.