mirror of
https://github.com/rsyslog/rsyslog.git
synced 2026-06-19 18:42:59 +02:00
Non-technical: centralize and reuse rate-limit definitions so admins can apply consistent policies across listeners. This is part of an ongoing series to improve rate limiting and its manageability. Before: inputs set per-listener interval/burst ad hoc. After: inputs can reference a named ratelimit() policy shared across listeners; per-listener values remain as fallback. Impact: New ratelimit() object and RateLimit.Name param for imtcp/imptcp. If a policy file is configured but libyaml is unavailable, config fails. Technical details: - Add top-level ratelimit() Rainerscript object. Parsed in rsconf and stored in a central registry (hashtable + rwlock) on rsconf. - New runtime API: ratelimitAddConfig(), ratelimitNewFromConfig(), plus cfgs init/destruct on rsconf lifecycle. - imtcp/imptcp accept RateLimit.Name; when set, tcpsrv/imptcp build the ratelimiter from the named policy; otherwise legacy interval/burst is used. Thread-safety retained via ratelimitSetThreadSafe(). - tcpsrv gains ownership helpers for listener params and frees them on errors; imtcp explicitly transfers ownership and nulls the pointer. - Optional libyaml: detected at configure; runtime parser loads simple key/value policy files (interval, burst, severity). - Docs: new ratelimit object page; imtcp/imptcp parameter references and module docs updated; design-decisions note added for libyaml. - Tests: add ratelimit_name.sh (guarded for imtcp+imptcp) to validate named policy application and observable throttling. Refs: https://github.com/rsyslog/rsyslog/issues/6201 With the help of AI-Agents: Antigravity imudp: add ratelimit.name support This commit adds the `ratelimit.name` parameter to imudp, allowing listeners to utilize the global rate limit registry (shared state). Features: - New `ratelimit.name` string parameter. - Integration with `ratelimitNewFromConfig`. - Strict mutual exclusivity: specifying `ratelimit.name` prohibits the use of legacy per-listener parameters (`ratelimit.burst`, `ratelimit.interval`). If a conflict occurs, an error is logged and the named rate limit takes precedence. - Updated documentation. - New regression test `tests/imudp_ratelimit_name.sh`. With the help of AI Agent: Google Antigravity
31 lines
854 B
Bash
Executable File
31 lines
854 B
Bash
Executable File
#!/bin/bash
|
|
# Test for duplicate named rate limits
|
|
# This should FAIL with a configuration error
|
|
. ${srcdir:=.}/diag.sh init
|
|
if [ -z "$RSYSLOGD" ]; then
|
|
export RSYSLOGD=../tools/rsyslogd
|
|
fi
|
|
|
|
|
|
generate_conf
|
|
add_conf '
|
|
ratelimit(name="test_limit" interval="2" burst="5")
|
|
ratelimit(name="test_limit" interval="1" burst="10")
|
|
|
|
template(name="outfmt" type="string" string="%msg%\n")
|
|
action(type="omfile" file="'$RSYSLOG_OUT_LOG'" template="outfmt")
|
|
'
|
|
|
|
# Check config only, redirect stderr
|
|
export CONF_FILE="${TESTCONF_NM}.conf"
|
|
$RSYSLOGD -N1 -M"$RSYSLOG_MODDIR" -f $CONF_FILE > /dev/null 2> stderr.log
|
|
|
|
if grep -q "ratelimit: duplicate name 'test_limit' in current config set" stderr.log; then
|
|
echo "SUCCESS: detected duplicate name error."
|
|
exit_test
|
|
else
|
|
echo "FAIL: duplicate name error not found in:"
|
|
cat stderr.log
|
|
error_exit 1
|
|
fi
|