Skip to content

feat: add spec.logLevel field to MCPGatewayExtension#1153

Draft
rogueslasher wants to merge 2 commits into
Kuadrant:mainfrom
rogueslasher:feat/log-level-field
Draft

feat: add spec.logLevel field to MCPGatewayExtension#1153
rogueslasher wants to merge 2 commits into
Kuadrant:mainfrom
rogueslasher:feat/log-level-field

Conversation

@rogueslasher

@rogueslasher rogueslasher 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 spec.logLevel to MCP Gateway Extensions to control broker-router log verbosity (debug, info, warn, error), overriding the operator-wide default when set.
  • Bug Fixes
    • Improved log-level handling so the warn setting is applied correctly instead of falling back to the default.
  • Tests
    • Updated deployment tests to validate per-extension log-level precedence and expected --log-level values.

Signed-off-by: rogueslasher <aniketpandey25092005@gmail.com>
@coderabbitai

coderabbitai Bot commented Jun 17, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: b14a7a55-85bc-4aa6-8226-43dcf24849b8

📥 Commits

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

📒 Files selected for processing (1)
  • cmd/mcp-broker-router/main.go

📝 Walkthrough

Walkthrough

Adds a LogLevel string enum type and constants (debug, info, warn, error) to the MCPGatewayExtensionSpec API. Updates the CRD OpenAPI schema accordingly. In the controller, a logLevelFlagValues map translates the spec value to broker-router --log-level numeric strings, with fallback to the operator-wide BrokerRouterLogLevel. Fixes broker-router setupLogger to explicitly handle warn-level mapping. Tests are updated to cover spec-driven flag emission and override precedence.

Changes

spec.logLevel for broker-router

Layer / File(s) Summary
LogLevel type, constants, spec field, and CRD schema
api/v1alpha1/mcpgatewayextension_types.go, bundle/manifests/mcp.kuadrant.io_mcpgatewayextensions.yaml, bundle/manifests/mcp-gateway.clusterserviceversion.yaml
Defines LogLevel string enum with kubebuilder validation, exports four constants, adds optional logLevel field to MCPGatewayExtensionSpec, and adds the spec.logLevel property with enum constraint to the CRD OpenAPI schema. CSV timestamp updated.
Controller flag wiring, broker-router warn level fix, and tests
internal/controller/broker_router.go, cmd/mcp-broker-router/main.go, internal/controller/deployment_test.go
Adds logLevelFlagValues map translating LogLevel to numeric strings, updates buildBrokerRouterDeployment to prefer spec.logLevel over r.BrokerRouterLogLevel. Fixes setupLogger case 4 to map to slog.LevelWarn. Replaces old controller-config test with spec-driven test covering all four values and override precedence.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Possibly related issues

🚥 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 Title accurately summarizes the main change: adding a spec.logLevel field to MCPGatewayExtension.
Linked Issues check ✅ Passed Implementation fully addresses #1099 requirements: adds logLevel enum field, maps to --log-level flag with correct numeric values, provides declarative YAML configuration, and implements spec-level precedence over operator default.
Out of Scope Changes check ✅ Passed All changes directly support the logLevel feature [#1099]: API types, controller logic, unit tests, CRD schema, and manifest updates. Only supplementary change is warn log level handling fix in broker-router switch statement, which is necessary for feature completeness.

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

✨ 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 and usage tips.

@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?

@rogueslasher

rogueslasher 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.

@rogueslasher rogueslasher marked this pull request as draft June 17, 2026 11:15
Signed-off-by: rogueslasher <aniketpandey25092005@gmail.com>
@rogueslasher

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
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

2 participants