Skip to content

fix: use direct map lookup in GetVirtualServerByHeader#1189

Draft
rogueslasher wants to merge 1 commit into
Kuadrant:mainfrom
rogueslasher:fix/get-virtual-server-by-header-map-lookup
Draft

fix: use direct map lookup in GetVirtualServerByHeader#1189
rogueslasher wants to merge 1 commit into
Kuadrant:mainfrom
rogueslasher:fix/get-virtual-server-by-header-map-lookup

Conversation

@rogueslasher

@rogueslasher rogueslasher commented Jun 24, 2026

Copy link
Copy Markdown
Contributor

What does this PR do?

GetVirtualServerByHeader was iterating over m.virtualServers with a linear scan to find a match by vs.Name, despite m.virtualServers being a map[string]*config.VirtualServer already keyed by vs.Name. This replaces the O(n) loop with a direct O(1) map lookup.

Summary by CodeRabbit

  • Bug Fixes
    • Improved virtual server header lookup to use a direct match, making results more reliable and efficient.
    • Continued to return the same “not found” message when no matching server is available.

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

coderabbitai Bot commented Jun 24, 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: 73638158-4363-433c-8cc9-adb3e359b0c3

📥 Commits

Reviewing files that changed from the base of the PR and between 3b36b81 and 6e1f908.

📒 Files selected for processing (1)
  • internal/broker/broker.go

📝 Walkthrough

Walkthrough

GetVirtualServerByHeader in broker.go replaces a full iteration over m.virtualServers with a direct map lookup using namespaceName as the key. Error behavior for missing entries is unchanged.

Changes

Virtual Server Lookup Optimization

Layer / File(s) Summary
Direct map lookup replaces iteration
internal/broker/broker.go
GetVirtualServerByHeader now uses m.virtualServers[namespaceName] directly instead of ranging over all entries to match by Name field. Same not found error path retained.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~2 minutes

Suggested labels

review-effort/small

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main change: replacing iteration with a direct map lookup in GetVirtualServerByHeader.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
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 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.

@rogueslasher

Copy link
Copy Markdown
Contributor Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Jun 24, 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.

@coderabbitai coderabbitai Bot added the review-effort/small Low review effort (1-2): straightforward, single file, config/docs label Jun 24, 2026
@rogueslasher

Copy link
Copy Markdown
Contributor Author

@Patryk-Stefanski should i file issue (as the new contributing guidelines states )for this since the pr is really a small fix

thank you

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

Labels

review-effort/small Low review effort (1-2): straightforward, single file, config/docs

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant