Add ratelimit registry scaffolding for ratelimit() objects#138
Add ratelimit registry scaffolding for ratelimit() objects#138rgerhards wants to merge 13 commits intoratelimit-refactorfrom
Conversation
* track ratelimit configuration objects in a central registry keyed by rsconf * expose a lookup helper to fetch named ratelimit policies for future modules * keep store init/destruct in sync with the registry lifecycle so entries stay consistent AI-Agent: ChatGPT
Summary of ChangesHello @rgerhards, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request enhances the management of Highlights
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
Provide an implementation plan for adding a policy=<file.yml> parameter that pulls rate-limiting specs from YAML files, including library evaluation, build integration, and testing strategy. AI-Agent: ChatGPT
- add optional policy=<file.yml> support to ratelimit() and parse YAML files when libyaml is available\n- store canonical policy paths in registry entries and expose an accessor for future diagnostics\n- wire optional libyaml detection into the build, document the new parameter, and add regression coverage\n\nAI-Agent: ChatGPT
Remove the final ratelimitRegistryRemoveOwner() call from ratelimitStoreDestruct() because each entry is already pruned from the registry inside the destruction loop. Avoiding the second pass keeps teardown work proportional to the number of entries released. AI-Agent: ChatGPT
- stop ratelimitConfigSpecInit from calling free() on an uninitialised policy_path pointer so stack-based specs no longer crash when the YAML support is disabled or unused\n- rename the YAML parser state inside ratelimitPolicyLoadFromYaml to avoid shadowing the parser object interface and keep builds using -Werror=shadow happy\n\nAI-Agent: ChatGPT
Ensure stack-based ratelimit_config_spec_t instances start with a NULL policy pointer so ratelimitConfigSpecInit() can safely release previous state even when early failures occur. This fixes the invalid free reported by the static analyzer and keeps ABORT paths from reading garbage. AI-Agent: gpt-5-codex
Ensure ratelimitPolicyLoadFromYaml() clears any existing spec state before returning the NOT_IMPLEMENTED error so callers never observe stale policy_path or counters when libyaml support is absent. AI-Agent: ChatGPT
…eep the data accessible for future consumers: Added per-source policy/override structures plus read-only accessors so modules can inspect default caps and override lists without touching internals (runtime/ratelimit.h (line 47), runtime/ratelimit.c (line 1172)). Hardened config lifecycle to clone/free the new data and expanded validation to cover default/override requirements and non-zero limits (runtime/ratelimit.c (line 172), runtime/ratelimit.c (line 516), runtime/ratelimit.c (line 525)). Reworked ratelimitPolicyLoadFromYaml to accept the new default/overrides schema, enforce uniqueness, and fall back to the legacy flat form for backward compatibility (runtime/ratelimit.c (line 732)). Documented the schema and test coverage: new integration checks ensure valid per-source files load and failure cases emit actionable errors (doc/source/rainerscript/ratelimit.rst (line 58), tests/ratelimit-policy-validation.sh (line 89)).
bcadfec to
17b219d
Compare
Added dedicated state and runtime structures plus a fallback key for senders that don’t yield a template value, enabling dynamic per-source accounting (runtime/ratelimit.c (lines 105-123)). Implemented lookup/insert/reset helpers backed by existing hashtable utilities so overrides resolve once and counters reset at window boundaries (runtime/ratelimit.c (lines 663-738)). Exposed a module-ready API to construct, check, reset, and optionally mutex-protect per-source limiters; results report effective caps and usage (runtime/ratelimit.h (lines 58-87), runtime/ratelimit.c (lines 1313-1449)).
Added a built-in %hostname% sender-key template (runtime/rsconf.c (lines 136-139), runtime/rsconf.c (lines 1320-1339)) so inputs can fall back to a known definition without users creating extra template() stanzas. Extended the imtcp config schema with perSourceRate, perSourcePolicyFile, and perSourceKeyTpl, wired them into the instance defaults, and made sure the strings are freed with the rest of the config (plugins/imtcp/imtcp.c (lines 250-294), plugins/imtcp/imtcp.c (lines 360-380), plugins/imtcp/imtcp.c (lines 1016-1044)). When perSourceRate is enabled, we now require a policy file and resolve the requested template (falling back to the new default name) up front; misconfigurations are reported immediately, while stray perSource* knobs without an enabled rate limiter are rejected (plugins/imtcp/imtcp.c (lines 640-760)).
The global rate-limiter is not reused!
3616efe to
dc54ba8
Compare
dc54ba8 to
57d634c
Compare
Summary
Testing
https://chatgpt.com/codex/tasks/task_e_68e124cf18888332b1d2761417ceab4d