Skip to content

feat: add spec.logLevel field to MCPGatewayExtension - #1153

Merged
maleck13 merged 2 commits into
Kuadrant:mainfrom
aniketpandey05:feat/log-level-field
Jul 3, 2026
Merged

feat: add spec.logLevel field to MCPGatewayExtension#1153
maleck13 merged 2 commits into
Kuadrant:mainfrom
aniketpandey05:feat/log-level-field

Conversation

@aniketpandey05

@aniketpandey05 aniketpandey05 commented Jun 17, 2026

Copy link
Copy Markdown
Contributor

Closes #1099

Adds a logLevel field to MCPGatewayExtensionSpec so the operator propagateslog verbosity to the broker-router deployment declaratively instead of requiringmanual patching of --log-level args.

Maps enum values to the broker's --log-level flag: debug=-4, info=0, warn=4, error=8.spec.logLevel takes precedence over the operator-wide BROKER_ROUTER_LOG_LEVEL fallback when set.

Changed:

  • api/v1alpha1/mcpgatewayextension_types.go new LogLevel enum type and field
  • internal/controller/broker_router.go enum to numeric flag mapping, precedence over operator-wide fallback
  • internal/controller/deployment_test.go new TestBuildBrokerRouterDeployment_SpecLogLevel
  • config/crd/..., charts/..., bundle/... regenerated manifests

Summary by CodeRabbit

  • New Features

    • Added an optional log level setting for MCP Gateway Extensions, letting you choose debug, info, warn, or error.
    • The selected setting now controls broker-router log verbosity, with a default inherited from the operator when unset.
  • Bug Fixes

    • Updated log level handling so extension-specific settings take precedence over the operator-wide default.
    • Improved validation to ensure only supported log level values are accepted.
  • Documentation

    • Updated reference docs to describe the new log level option and its supported values.

@coderabbitai

coderabbitai Bot commented Jun 17, 2026

Copy link
Copy Markdown

Review Change Stack

Important

Review skipped

No new commits to review since the last review.

⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: aaa106ce-bef7-4f67-917d-1d3bb06a260f

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

Adds a LogLevel CRD enum type (debug/info/warn/error) with kubebuilder validation and a new optional logLevel field on MCPGatewayExtensionSpec. Updates the CRD manifest and docs accordingly. The controller maps spec.logLevel to numeric --log-level values for the broker-router deployment, falling back to the operator-wide BrokerRouterLogLevel when unset, with corresponding test updates.

Changes

spec.logLevel for broker-router

Layer / File(s) Summary
LogLevel type, constants, spec field, CRD schema, and docs
api/v1alpha1/mcpgatewayextension_types.go, bundle/manifests/mcp.kuadrant.io_mcpgatewayextensions.yaml, docs/reference/mcpgatewayextension.md
Defines the LogLevel enum type and constants, adds the optional logLevel spec field, reflects it in the CRD OpenAPI schema, and documents the flag mapping and default fallback behavior.
Controller logLevelFlagValues map, --log-level wiring, and tests
internal/controller/broker_router.go, internal/controller/deployment_test.go
Maps spec.logLevel to numeric --log-level values via logLevelFlagValues, falls back to r.BrokerRouterLogLevel when unset, and updates tests to verify all four levels plus override precedence.

Estimated code review effort: 2 (Simple) | ~12 minutes

Possibly related PRs

  • Kuadrant/mcp-gateway#1141: Fixes broker-router logger setup for numeric log-level values (including warn=4), directly related to the flag mapping this PR introduces.
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 66.67% 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 spec.logLevel to MCPGatewayExtension.
Linked Issues check ✅ Passed The PR adds spec.logLevel, maps values to broker-router --log-level, and updates the controller and CRD accordingly.
Out of Scope Changes check ✅ Passed The changes stay focused on the new logLevel feature, with API, controller, tests, and docs all aligned to the issue.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

@coderabbitai coderabbitai Bot added high-risk Touches concurrency, auth, sessions, CRDs, ext_proc, or routing review-effort/medium Medium review effort (3): few files, moderate logic labels Jun 17, 2026

@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

🧹 Nitpick comments (1)
internal/controller/deployment_test.go (1)

622-691: ⚡ Quick win

Add explicit coverage for the unset spec.logLevel fallback path.

This table verifies mapped spec values and precedence, but it no longer asserts behavior when spec.logLevel is unset and only BrokerRouterLogLevel is provided.

test case additions
 	{
 		name:           "spec.logLevel overrides operator-wide BrokerRouterLogLevel",
 		brokerLogLevel: "-4",
 		specLogLevel:   mcpv1alpha1.LogLevelError,
 		want:           "--log-level=8",
 	},
+	{
+		name:           "unset spec.logLevel falls back to operator-wide BrokerRouterLogLevel",
+		brokerLogLevel: "4",
+		specLogLevel:   "",
+		want:           "--log-level=4",
+	},
+	{
+		name:           "no log-level flag when both spec.logLevel and operator fallback are unset",
+		brokerLogLevel: "",
+		specLogLevel:   "",
+		want:           "",
+	},
🤖 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 `@internal/controller/deployment_test.go` around lines 622 - 691, The
TestBuildBrokerRouterDeployment_SpecLogLevel test table is missing coverage for
the scenario where spec.logLevel is unset and the deployment should fall back to
using the operator-wide BrokerRouterLogLevel. Add a new test case to the tests
slice in this function that sets brokerLogLevel to a specific value but leaves
specLogLevel unset (use the zero value of mcpv1alpha1.LogLevel), then verify
that the resulting deployment command includes the expected log-level flag
mapped from the operator-wide BrokerRouterLogLevel value.
🤖 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 `@internal/controller/broker_router.go`:
- Around line 74-82: The logLevelFlagValues map maps warn to "4", but the
broker-router's logger switch statement in cmd/mcp-broker-router/main.go only
explicitly handles "-4", "0", and "8", causing warn level to fall back to debug.
Update the logLevelFlagValues map entries to use numeric string values that
match what the logger switch statement in the broker-router actually handles for
each log level (debug, info, warn, and error). Verify the mapping by checking
the switch statement logic in cmd/mcp-broker-router/main.go to ensure all
LogLevel values are correctly handled.

---

Nitpick comments:
In `@internal/controller/deployment_test.go`:
- Around line 622-691: The TestBuildBrokerRouterDeployment_SpecLogLevel test
table is missing coverage for the scenario where spec.logLevel is unset and the
deployment should fall back to using the operator-wide BrokerRouterLogLevel. Add
a new test case to the tests slice in this function that sets brokerLogLevel to
a specific value but leaves specLogLevel unset (use the zero value of
mcpv1alpha1.LogLevel), then verify that the resulting deployment command
includes the expected log-level flag mapped from the operator-wide
BrokerRouterLogLevel value.
🪄 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: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 01abd1cc-b46c-432a-b6fb-ef98f674cc65

📥 Commits

Reviewing files that changed from the base of the PR and between e99c0a6 and f97b6dc.

⛔ Files ignored due to path filters (2)
  • charts/mcp-gateway/crds/mcp.kuadrant.io_mcpgatewayextensions.yaml is excluded by !charts/mcp-gateway/crds/**
  • config/crd/mcp.kuadrant.io_mcpgatewayextensions.yaml is excluded by !config/crd/mcp.kuadrant.io_*.yaml
📒 Files selected for processing (5)
  • api/v1alpha1/mcpgatewayextension_types.go
  • bundle/manifests/mcp-gateway.clusterserviceversion.yaml
  • bundle/manifests/mcp.kuadrant.io_mcpgatewayextensions.yaml
  • internal/controller/broker_router.go
  • internal/controller/deployment_test.go

Comment thread internal/controller/broker_router.go
@david-martin

Copy link
Copy Markdown
Member

Thanks for the contributions! One thing to flag: our contributing guidelines ask contributors to limit themselves to one open PR at a time. The idea is that getting one change reviewed and merged is more valuable than having several open in parallel.

You currently have four open PRs. Could you pick whichever one you think is most ready for review, and we'll focus on getting that one through first?

@aniketpandey05

aniketpandey05 commented Jun 17, 2026

Copy link
Copy Markdown
Contributor Author

@david-martin sorry for that i had commented on a few issues so i though i should make them ; the most complete pr is #1137 should i make the other prs draft i understand that multiple prs increase the review burden

sorry for that would make sure to keep one pr open at a time

@david-martin

Copy link
Copy Markdown
Member

sorry for that would make sure to keep one pr open at a time

No worries @rogueslasher

We're figuring out and evolving the process to ensure it sets expectations and works well for both contributors and reviewers.
Let's try moving PRs to draft if they're not ready for review yet as the signal to reviewers that they can be deferred for now.

@aniketpandey05

Copy link
Copy Markdown
Contributor Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Jun 20, 2026

Copy link
Copy Markdown
✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@david-martin david-martin added the triage/has-issue PR links to an existing issue label Jun 22, 2026
@aniketpandey05

Copy link
Copy Markdown
Contributor Author

@maleck13 please review this one

thank you

@maleck13

maleck13 commented Jul 1, 2026

Copy link
Copy Markdown
Contributor

Needs work before merge:

  1. Rebase to resolve conflicts
  2. Add the two missing fallback test cases
  3. Update docs/reference/ for the new field

The rewritten test (TestBuildBrokerRouterDeployment_SpecLogLevel) dropped two cases from the original test:

  • spec.logLevel unset + BrokerRouterLogLevel set → should fall back to operator-wide value
  • Both unset → no --log-level flag emitted

Did the tests get removed for a good reason?

Signed-off-by: rogueslasher <aniketpandey25092005@gmail.com>
@aniketpandey05
aniketpandey05 force-pushed the feat/log-level-field branch from 98e4000 to 83895b3 Compare July 3, 2026 10:28
…k test cases

Signed-off-by: Aniket Pandey <aniketpandey25092005@gmail.com>
@aniketpandey05
aniketpandey05 force-pushed the feat/log-level-field branch from 83895b3 to 2e1cb95 Compare July 3, 2026 10:42
@aniketpandey05
aniketpandey05 marked this pull request as ready for review July 3, 2026 11:06
@aniketpandey05

Copy link
Copy Markdown
Contributor Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Jul 3, 2026

Copy link
Copy Markdown
✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@aniketpandey05

Copy link
Copy Markdown
Contributor Author

@maleck13 sorry for dropping the tests they were accidentally replaced instead of kept alongside the new one. Fixed now along with the rebase and docs update.
thank you

@maleck13

maleck13 commented Jul 3, 2026

Copy link
Copy Markdown
Contributor

Going to approve, but ideally we would exercise this new property via one of the e2e tests

@maleck13
maleck13 merged commit 1f413b9 into Kuadrant:main Jul 3, 2026
19 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

high-risk Touches concurrency, auth, sessions, CRDs, ext_proc, or routing review-effort/medium Medium review effort (3): few files, moderate logic triage/has-issue PR links to an existing issue

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Allow setting log level via MCPGatewayExtension CR

3 participants