Skip to content

[Limiter] Expose rule book as sys_rule SQL table #4692

Merged
tillrohrmann merged 2 commits intorestatedev:mainfrom
tillrohrmann:issues/4655-5
May 8, 2026
Merged

[Limiter] Expose rule book as sys_rule SQL table #4692
tillrohrmann merged 2 commits intorestatedev:mainfrom
tillrohrmann:issues/4655-5

Conversation

@tillrohrmann
Copy link
Copy Markdown
Contributor

@tillrohrmann tillrohrmann commented May 5, 2026

Adds a non-partitioned sys_rules DataFusion table that projects the
cluster-global rule book on demand. The scanner reads RULE_BOOK_KEY
straight from the metadata store on each query so the table is
available on admin-only and worker nodes alike. As a side effect, on
nodes with a local RuleBookCache the freshly fetched book is pushed
through the existing RuleBookObserver, advancing per-PP visibility
without waiting for the next poll tick.

The RuleBookObserver type alias moves from restate-admin to
restate-limiter so restate-storage-query-datafusion can use it without
depending on admin.

This PR is based on #4691.

Copy link
Copy Markdown

@claude claude Bot left a comment

Choose a reason for hiding this comment

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

Claude Code Review

This pull request is from a fork — automated review is disabled. A repository maintainer can comment @claude review to run a one-time review.

@tillrohrmann
Copy link
Copy Markdown
Contributor Author

@codex review

@AhmedSoliman
Copy link
Copy Markdown
Contributor

Shouldn't the table name be plural? sys_rules

/// rule applies to. Examples: `"*"`, `"scope1/*"`, `"scope1/foo/bar"`.
#[cfg_attr(feature = "schema", schema(value_type = String))]
#[serde_as(as = "serde_with::DisplayFromStr")]
pub pattern: RulePattern<ReString>,
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.

:(

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

So far we didn't find a better way for specifying it.

Comment thread crates/admin-rest-model/src/rules.rs Outdated
/// Free-form description shown in the rule book; not consulted at
/// runtime.
#[serde(default, skip_serializing_if = "Option::is_none")]
pub reason: Option<String>,
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.

Awesome idea, maybe call it description?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

The credit goes to Ahmed :-) description is indeed a better name. Will update it.

@tillrohrmann
Copy link
Copy Markdown
Contributor Author

tillrohrmann commented May 5, 2026

Shouldn't the table name be plural? sys_rules

Yes, of course. I will update it.

@tillrohrmann tillrohrmann force-pushed the issues/4655-5 branch 2 times, most recently from dd919fa to fbb42ba Compare May 5, 2026 21:24
@tillrohrmann tillrohrmann requested review from AhmedSoliman and slinkydeveloper and removed request for AhmedSoliman May 5, 2026 21:24
@tillrohrmann
Copy link
Copy Markdown
Contributor Author

@nikrooz this PR adds the new sys_rules table to expose the information about the available rules to external users and the UI. In combination with #4691 I hope that the UI would be able to allow users to inspect, create and modify the rules.

Comment on lines +66 to +70
let book = client
.get::<RuleBook>(RULE_BOOK_KEY.clone())
.await
.map_err(|e| DataFusionError::External(Box::new(e)))?
.unwrap_or_default();
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.

Do we have other cases where we perform an inline read from the metadata store when querying DF? Given that most of the time this will be the same value, do we want to rely on the local cache for reads and only fallback to direct metadata reads if we don't have a cache?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

True. Reading from the cache should be good enough if it's not empty.

Copy link
Copy Markdown
Contributor

@AhmedSoliman AhmedSoliman left a comment

Choose a reason for hiding this comment

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

Looks good, my only concern is the inline metadata-store reads and the impact the UI might create on load on metadata store.

@tillrohrmann tillrohrmann force-pushed the issues/4655-5 branch 2 times, most recently from 43c14a3 to 112eb8e Compare May 7, 2026 13:08
@tillrohrmann
Copy link
Copy Markdown
Contributor Author

The failing test case should be unrelated.

tillrohrmann and others added 2 commits May 8, 2026 15:35
Adds a non-partitioned sys_rules DataFusion table that projects the
cluster-global rule book on demand. The scanner reads RULE_BOOK_KEY
straight from the metadata store on each query so the table is
available on admin-only and worker nodes alike. As a side effect, on
nodes with a local RuleBookCache the freshly fetched book is pushed
through the existing RuleBookObserver, advancing per-PP visibility
without waiting for the next poll tick.

The RuleBookObserver type alias moves from restate-admin to
restate-limiter so restate-storage-query-datafusion can use it without
depending on admin.

Additionally we have aligned the limit and usage values to be u32 as
it is unlikely that users will ever set limit values > u32::MAX.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@tillrohrmann tillrohrmann merged commit efb6271 into restatedev:main May 8, 2026
8 checks passed
@github-actions github-actions Bot locked and limited conversation to collaborators May 8, 2026
@tillrohrmann tillrohrmann deleted the issues/4655-5 branch May 8, 2026 13:37
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants