Skip to content

Add KEYVIZ_KEY_BUCKETS_PER_ROUTE validation#844

Open
bootjp wants to merge 5 commits into
mainfrom
add-keyviz-validation
Open

Add KEYVIZ_KEY_BUCKETS_PER_ROUTE validation#844
bootjp wants to merge 5 commits into
mainfrom
add-keyviz-validation

Conversation

@bootjp

@bootjp bootjp commented May 26, 2026

Copy link
Copy Markdown
Owner

Summary by CodeRabbit

  • New Features

    • Added support for a new KeyViz configuration option to control key bucket routing.
    • The deployment process now carries this setting through to the running container when enabled.
  • Bug Fixes

    • Added validation for the new setting to help prevent invalid deployment values.
    • Updated deploy change detection so configuration updates trigger a fresh container when this KeyViz option changes.

@coderabbitai

coderabbitai Bot commented May 26, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

scripts/rolling-update.sh gains support for a new KEYVIZ_KEY_BUCKETS_PER_ROUTE environment variable. The script declares it (defaulting to empty), validates it as an integer 1–256 when KeyViz is enabled, emits --keyvizKeyBucketsPerRoute to the container when set, includes it in the deploy config fingerprint, and forwards it over SSH.

Changes

KEYVIZ_KEY_BUCKETS_PER_ROUTE rollout support

Layer / File(s) Summary
Variable declaration and input validation
scripts/rolling-update.sh
Declares KEYVIZ_KEY_BUCKETS_PER_ROUTE defaulting to empty with inline documentation; validates it as an integer in [1, 256] when KEYVIZ_ENABLED=true, exiting with an error on invalid input.
Flag emission, config fingerprint, and SSH transport
scripts/rolling-update.sh
Forwards KEYVIZ_KEY_BUCKETS_PER_ROUTE in the SSH env block inside update_one_node; appends --keyvizKeyBucketsPerRoute in build_keyviz_flags when non-empty; adds a guarded fingerprint component to config_fp() so containers are recreated on value change; constructs the SSH-escaped KEYVIZ_KEY_BUCKETS_PER_ROUTE_Q for remote transport.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

🐇 Hop, hop, a new knob appears today,
Buckets per route, keeping hot keys at bay,
Validated neatly from one up to two-five-six,
SSH carries it over with all of its tricks,
The fingerprint notices if values have changed,
Our KeyViz partitions — perfectly arranged! 🗝️

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly matches the main change: adding validation for KEYVIZ_KEY_BUCKETS_PER_ROUTE.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch add-keyviz-validation

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@gemini-code-assist gemini-code-assist Bot left a comment

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.

Code Review

This pull request introduces the KEYVIZ_KEY_BUCKETS_PER_ROUTE configuration to scripts/rolling-update.sh to support sub-range buckets per route in KeyViz. Feedback suggests improving the validation logic for this variable by restricting it to a range of 1 to 256 via a precise regular expression, preventing potential integer overflow or silent clamping issues.

Comment thread scripts/rolling-update.sh Outdated
Comment on lines +277 to +280
if [[ -n "$KEYVIZ_KEY_BUCKETS_PER_ROUTE" && ! "$KEYVIZ_KEY_BUCKETS_PER_ROUTE" =~ ^[1-9][0-9]*$ ]]; then
echo "rolling-update: KEYVIZ_KEY_BUCKETS_PER_ROUTE must be empty or a positive integer, got '$KEYVIZ_KEY_BUCKETS_PER_ROUTE'" >&2
exit 1
fi

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.

medium

The current validation checks if KEYVIZ_KEY_BUCKETS_PER_ROUTE is a positive integer, but it does not enforce the maximum limit of 256 (defined as MaxKeyBucketsPerRoute in keyviz/sampler.go).

If an operator configures a value larger than 256, it will be silently clamped by the Go binary. More importantly, if they enter an extremely large number that overflows a standard integer, the Go flag parser will fail to parse it, leading to a container crash-loop. This defeats the purpose of pre-validating the flag in this script.

We can use a precise regular expression to restrict the value to the valid range of 1 to 256 inclusive, which is also completely immune to integer overflow.

Suggested change
if [[ -n "$KEYVIZ_KEY_BUCKETS_PER_ROUTE" && ! "$KEYVIZ_KEY_BUCKETS_PER_ROUTE" =~ ^[1-9][0-9]*$ ]]; then
echo "rolling-update: KEYVIZ_KEY_BUCKETS_PER_ROUTE must be empty or a positive integer, got '$KEYVIZ_KEY_BUCKETS_PER_ROUTE'" >&2
exit 1
fi
if [[ -n "$KEYVIZ_KEY_BUCKETS_PER_ROUTE" && ! "$KEYVIZ_KEY_BUCKETS_PER_ROUTE" =~ ^([1-9][0-9]?|1[0-9][0-9]|2[0-4][0-9]|25[0-6])$ ]]; then
echo "rolling-update: KEYVIZ_KEY_BUCKETS_PER_ROUTE must be empty or an integer between 1 and 256, got '$KEYVIZ_KEY_BUCKETS_PER_ROUTE'" >&2
exit 1
fi

@bootjp

bootjp commented Jun 24, 2026

Copy link
Copy Markdown
Owner Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 4db14f086a

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread scripts/rolling-update.sh Outdated
# Validate before it reaches the SSH heredoc / the binary's flag parser
# so an operator typo fails here with a clear message rather than as a
# container crash-loop on an unparseable --keyvizKeyBucketsPerRoute.
if [[ -n "$KEYVIZ_KEY_BUCKETS_PER_ROUTE" && ! "$KEYVIZ_KEY_BUCKETS_PER_ROUTE" =~ ^([1-9][0-9]?|1[0-9][0-9]|2[0-4][0-9]|25[0-6])$ ]]; then

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Gate bucket validation on KeyViz being enabled

This rejects KEYVIZ_KEY_BUCKETS_PER_ROUTE even when KEYVIZ_ENABLED=false, although the surrounding KeyViz configuration and build_keyviz_flags make the other KeyViz knobs no-ops unless the sampler is enabled. In a deploy env that carries a stale or placeholder bucket value while KeyViz is disabled, rolling-update.sh now exits before doing an otherwise unrelated rollout instead of ignoring the disabled knob. Please only validate this value when KEYVIZ_ENABLED=true or when the flag is actually emitted.

Useful? React with 👍 / 👎.

@bootjp

bootjp commented Jun 24, 2026

Copy link
Copy Markdown
Owner Author

@codex review

Addressed the current P2 finding in commit adc2db3:

  • KEYVIZ_KEY_BUCKETS_PER_ROUTE range validation now runs only when KEYVIZ_ENABLED=true, matching build_keyviz_flags so stale/placeholder bucket values remain inert while KeyViz is disabled.

Validation:

  • bash -n scripts/rolling-update.sh
  • KEYVIZ_ENABLED=false KEYVIZ_KEY_BUCKETS_PER_ROUTE=placeholder bash scripts/rolling-update.sh reaches the later NODES is required check instead of bucket validation
  • KEYVIZ_ENABLED=true KEYVIZ_KEY_BUCKETS_PER_ROUTE=placeholder bash scripts/rolling-update.sh fails with the bucket validation error
  • git diff --check HEAD~1..HEAD

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: adc2db3708

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread scripts/rolling-update.sh Outdated
"$ADMIN_TLS_CERT_FILE" "$ADMIN_TLS_KEY_FILE" \
"$ADMIN_ALLOW_PLAINTEXT_NON_LOOPBACK" "$ADMIN_ALLOW_INSECURE_DEV_COOKIE" \
"$KEYVIZ_ENABLED" "$KEYVIZ_FANOUT_NODES" \
"$KEYVIZ_ENABLED" "$KEYVIZ_FANOUT_NODES" "$KEYVIZ_KEY_BUCKETS_PER_ROUTE" \

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Ignore key bucket value in fingerprint while KeyViz is off

When KEYVIZ_ENABLED=false, build_keyviz_flags returns without emitting any KeyViz flags, so KEYVIZ_KEY_BUCKETS_PER_ROUTE does not affect the remote docker run configuration. Including it unconditionally in the config fingerprint means changing or inheriting a stale placeholder bucket value while KeyViz is disabled still makes every node report a config change and recreate the container, even though the effective deployment is unchanged. Gate this fingerprint input the same way as the flag emission (or normalize it to empty when disabled).

Useful? React with 👍 / 👎.

@bootjp

bootjp commented Jun 24, 2026

Copy link
Copy Markdown
Owner Author

@codex review

Addressed current-head P2 inline finding in 3dde408:

  • config_fp now normalizes KeyViz option inputs to empty unless KEYVIZ_ENABLED=true, matching build_keyviz_flags.
  • Disabled KeyViz deployments no longer recreate containers just because stale KEYVIZ_FANOUT_NODES / KEYVIZ_KEY_BUCKETS_PER_ROUTE values changed.
  • Caller audit: config_fp is only used to compute DEPLOY_CONFIG_FP for the deploy label comparison.

Validation:

  • bash -n scripts/rolling-update.sh
  • KEYVIZ_ENABLED=false KEYVIZ_KEY_BUCKETS_PER_ROUTE=placeholder bash scripts/rolling-update.sh reaches the later NODES check
  • KEYVIZ_ENABLED=true KEYVIZ_KEY_BUCKETS_PER_ROUTE=placeholder bash scripts/rolling-update.sh fails bucket validation
  • extracted config_fp check: disabled KeyViz ignores fanout/bucket changes; enabled KeyViz hash changes for bucket changes
  • git diff --check HEAD~1..HEAD

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Bravo.

Reviewed commit: 3dde408ad0

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 4543fcfba4

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread scripts/rolling-update.sh
Comment on lines +1183 to +1184
if [[ -n "$key_buckets" ]]; then
_flags+=(--keyvizKeyBucketsPerRoute "$key_buckets")

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Close key bucket branch before hot-key flags

This new if is never closed before the function body ends, so the remote heredoc sent to bash -s is syntactically invalid for every rollout, not just KeyViz-enabled ones. I extracted the remote block from lines 691-1482 and bash -n fails with syntax error near unexpected token '}', so the first node aborts before it can recreate the container; add the missing fi after appending --keyvizKeyBucketsPerRoute.

Useful? React with 👍 / 👎.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@scripts/rolling-update.sh`:
- Around line 1426-1428: The config fingerprint assembly in rolling-update.sh is
still including raw KEYVIZ_FANOUT_NODES even when KeyViz is disabled, which can
cause unnecessary churn from stale fanout changes. Update the config_fp inputs
so the fingerprint uses the gated KeyViz fingerprint variables from the
KeyViz-related section and does not hash KEYVIZ_FANOUT_NODES directly when
KEYVIZ_ENABLED is false; check the fingerprint-building block around
keyviz_fanout_nodes_fp and keyviz_key_buckets_per_route_fp.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 494ba677-460b-416c-940b-f651cbc589e9

📥 Commits

Reviewing files that changed from the base of the PR and between 16990b0 and 4543fcf.

📒 Files selected for processing (1)
  • scripts/rolling-update.sh

Comment thread scripts/rolling-update.sh
Comment on lines +1426 to 1428
"$KEYVIZ_ENABLED" "$keyviz_fanout_nodes_fp" "$keyviz_key_buckets_per_route_fp" \
"$KEYVIZ_ENABLED" "$KEYVIZ_FANOUT_NODES" \
"$KEYVIZ_HOT_KEYS_ENABLED" "$KEYVIZ_HOT_KEYS_PER_ROUTE" \

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🩺 Stability & Availability | 🟠 Major | ⚡ Quick win

config_fp still hashes raw fanout while KeyViz is disabled.

Line 1427 reintroduces KEYVIZ_FANOUT_NODES directly, so disabled KeyViz can still churn fingerprints on stale fanout changes.

Suggested fix
-    "$KEYVIZ_ENABLED" "$keyviz_fanout_nodes_fp" "$keyviz_key_buckets_per_route_fp" \
-    "$KEYVIZ_ENABLED" "$KEYVIZ_FANOUT_NODES" \
+    "$KEYVIZ_ENABLED" "$keyviz_fanout_nodes_fp" "$keyviz_key_buckets_per_route_fp" \
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
"$KEYVIZ_ENABLED" "$keyviz_fanout_nodes_fp" "$keyviz_key_buckets_per_route_fp" \
"$KEYVIZ_ENABLED" "$KEYVIZ_FANOUT_NODES" \
"$KEYVIZ_HOT_KEYS_ENABLED" "$KEYVIZ_HOT_KEYS_PER_ROUTE" \
"$KEYVIZ_ENABLED" "$keyviz_fanout_nodes_fp" "$keyviz_key_buckets_per_route_fp" \
"$KEYVIZ_HOT_KEYS_ENABLED" "$KEYVIZ_HOT_KEYS_PER_ROUTE" \
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@scripts/rolling-update.sh` around lines 1426 - 1428, The config fingerprint
assembly in rolling-update.sh is still including raw KEYVIZ_FANOUT_NODES even
when KeyViz is disabled, which can cause unnecessary churn from stale fanout
changes. Update the config_fp inputs so the fingerprint uses the gated KeyViz
fingerprint variables from the KeyViz-related section and does not hash
KEYVIZ_FANOUT_NODES directly when KEYVIZ_ENABLED is false; check the
fingerprint-building block around keyviz_fanout_nodes_fp and
keyviz_key_buckets_per_route_fp.

@bootjp

bootjp commented Jun 24, 2026

Copy link
Copy Markdown
Owner Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 4543fcfba4

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread scripts/rolling-update.sh
Comment on lines +1183 to +1184
if [[ -n "$key_buckets" ]]; then
_flags+=(--keyvizKeyBucketsPerRoute "$key_buckets")

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Close the key bucket guard before the hot-key block

When this script reaches update_one_node, the remote heredoc is passed to bash -s, and the new if [[ -n "$key_buckets" ]]; then has no matching fi before the function's closing brace. I extracted the REMOTE heredoc and bash -n reports syntax error near unexpected token '}', so every rolling update attempt will fail while parsing the remote script before it can start or skip a container.

Useful? React with 👍 / 👎.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant