Skip to content

Add ratelimit registry scaffolding for ratelimit() objects#138

Open
rgerhards wants to merge 13 commits intoratelimit-refactorfrom
codex/extend-ratelimit-code-for-new-config-object
Open

Add ratelimit registry scaffolding for ratelimit() objects#138
rgerhards wants to merge 13 commits intoratelimit-refactorfrom
codex/extend-ratelimit-code-for-new-config-object

Conversation

@rgerhards
Copy link
Owner

Summary

  • add a shared registry list that records ratelimit() configuration entries alongside their owning rsconf
  • expose a ratelimitRegistryLookup helper so future modules can resolve named policies without walking private lists
  • make the ratelimit store init/destruct paths keep the registry in sync to avoid leaks across reloads

Testing

  • not run (build environment not configured in this workspace)

https://chatgpt.com/codex/tasks/task_e_68e124cf18888332b1d2761417ceab4d

* 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
@gemini-code-assist
Copy link

Summary of Changes

Hello @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 ratelimit configurations by implementing a centralized registry. This registry provides a global lookup mechanism for named ratelimit policies, making them more accessible and manageable across different parts of the system. The changes also ensure robust cleanup of these configurations during system reloads, preventing resource leaks and improving overall stability.

Highlights

  • New Ratelimit Registry: Introduced a shared, global registry to track ratelimit() configuration entries, associating them with their owning rsconf objects.
  • Registry Lookup Helper: Exposed a new ratelimitRegistryLookup helper function, enabling other modules to resolve named ratelimit policies without needing to traverse private configuration lists.
  • Memory Leak Prevention: Integrated registry synchronization into the ratelimit store's initialization and destruction paths, ensuring that registry entries are properly managed and removed to prevent memory leaks during configuration reloads.
Using Gemini Code Assist

The 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 /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

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 .gemini/ folder in the base of the repository. Detailed instructions can be found here.

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

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

gemini-code-assist[bot]

This comment was marked as outdated.

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)).
@rgerhards rgerhards force-pushed the codex/extend-ratelimit-code-for-new-config-object branch from bcadfec to 17b219d Compare November 6, 2025 11:56
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!
@rgerhards rgerhards force-pushed the codex/extend-ratelimit-code-for-new-config-object branch from 3616efe to dc54ba8 Compare November 12, 2025 14:33
@rgerhards rgerhards force-pushed the codex/extend-ratelimit-code-for-new-config-object branch from dc54ba8 to 57d634c Compare November 12, 2025 15:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant