Skip to content

NE-2636: Add truncation and filtering to router tools#304

Open
Thealisyed wants to merge 1 commit into
openshift:mainfrom
Thealisyed:NE-2636-router-truncation
Open

NE-2636: Add truncation and filtering to router tools#304
Thealisyed wants to merge 1 commit into
openshift:mainfrom
Thealisyed:NE-2636-router-truncation

Conversation

@Thealisyed
Copy link
Copy Markdown

@Thealisyed Thealisyed commented May 11, 2026

Summary

  • Add tail_lines, section, and filter parameters to get_router_config to limit and filter HAProxy config output
  • Add limit and filter parameters to get_router_sessions to cap and filter session output
  • Both tools show truncation metadata so the AI can refine queries when output is limited

Test plan

  • Unit tests for truncateConfigOutput (12 cases: tail_lines, section filter, substring filter, combined, edge cases)
  • Unit tests for truncateSessionsOutput (8 cases: limit, filter, combined, edge cases)
  • make build && make test && make lint pass cleanly
  • CodeRabbit review passes with 0 findings

Summary by CodeRabbit

  • New Features

    • Router configuration queries now support filtering by HAProxy section type and substring matching, with configurable output truncation.
    • Router session queries now support substring filtering and configurable result limits.
    • Enhanced output includes truncation status summaries and properly formatted code blocks.
  • Tests

    • Added comprehensive test coverage for configuration and session output filtering and truncation.

Add output truncation and filtering to get_router_config and
get_router_sessions to prevent large HAProxy outputs from flooding
the AI context window or hitting MCP response size limits.

get_router_config gains tail_lines (default 200), section
(global/defaults/frontend/backend/listen), and filter parameters.
get_router_sessions gains limit (default 50) and filter parameters.
Both tools display truncation metadata so the AI knows how to refine.

Handlers refactored to use WrapParams sticky-error pattern.

Assisted with Claude
@openshift-ci-robot openshift-ci-robot added the jira/valid-reference Indicates that this PR references a valid Jira ticket of any type. label May 11, 2026
@openshift-ci-robot
Copy link
Copy Markdown

openshift-ci-robot commented May 11, 2026

@Thealisyed: This pull request references NE-2636 which is a valid jira issue.

Warning: The referenced jira issue has an invalid target version for the target branch this PR targets: expected the story to target the "5.0.0" version, but no target version was set.

Details

In response to this:

Summary

  • Add tail_lines, section, and filter parameters to get_router_config to limit and filter HAProxy config output
  • Add limit and filter parameters to get_router_sessions to cap and filter session output
  • Both tools show truncation metadata so the AI can refine queries when output is limited

Test plan

  • Unit tests for truncateConfigOutput (12 cases: tail_lines, section filter, substring filter, combined, edge cases)
  • Unit tests for truncateSessionsOutput (8 cases: limit, filter, combined, edge cases)
  • make build && make test && make lint pass cleanly
  • CodeRabbit review passes with 0 findings

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the openshift-eng/jira-lifecycle-plugin repository.

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 11, 2026

📝 Walkthrough

Walkthrough

The PR extends NetEdge router tools (get_router_config and get_router_sessions) with structured parameter validation, output filtering by HAProxy section type and substring matching, and configurable tail-line/session-count truncation, supported by new helper functions and comprehensive test coverage.

Changes

Router Output Filtering and Truncation

Layer / File(s) Summary
Data & Configuration
pkg/toolsets/netedge/router.go (lines 21–34)
Introduces defaultConfigTailLines and defaultSessionLimit constants, and module-level variables (podGVR, haproxySectionKeywords) used by truncation and filtering logic.
Tool Schema — Config
pkg/toolsets/netedge/router.go (lines 35–61)
get_router_config schema is expanded with tail_lines, section (enum: global, backend, frontend), and filter (substring match) parameters with descriptions.
Tool Schema — Sessions
pkg/toolsets/netedge/router.go (lines 98–115)
get_router_sessions schema is expanded with limit (default applied) and filter (substring match) parameters.
Handler: Config Execution & Truncation
pkg/toolsets/netedge/router.go (lines 130–169)
getRouterConfig is rewritten to use api.WrapParams for validation, resolve router pod if unset, fetch HAProxy config via pod exec, and post-process output via truncateConfigOutput with truncation/filter summary messages.
Handler: Sessions Execution & Truncation
pkg/toolsets/netedge/router.go (lines 205–246)
getRouterSessions is rewritten to use api.WrapParams for validation, resolve router pod if unset, fetch session data via pod exec, and post-process via truncateSessionsOutput with truncation/filter summary messages.
Helper Functions
pkg/toolsets/netedge/router.go (lines 248–348)
New helpers added: configSectionType (HAProxy section header detection), truncateConfigOutput (section/filter-aware tail truncation), truncateSessionsOutput (block splitting and filtering), and blockContainsSubstring (case-insensitive substring matching).
Tests
pkg/toolsets/netedge/router_test.go (lines 1–216)
TestTruncateConfigOutput and TestTruncateSessionsOutput verify truncation semantics, section/backend filtering (case-insensitive), edge cases (empty input, no-match filters), and large-data scenarios with expected line/session counts.

Sequence Diagram

sequenceDiagram
    participant Client
    participant Handler as Router Config Handler
    participant API as WrapParams<br/>(Validation)
    participant Resolver as Pod Resolver
    participant Executor as Pod Executor
    participant Processor as Output Processor
    participant Response

    Client->>Handler: Call get_router_config<br/>(pod?, tail_lines, section?, filter?)
    Handler->>API: Validate parameters
    API-->>Handler: Validated params or error
    Handler->>Resolver: Resolve router pod<br/>(if pod unset)
    Resolver-->>Handler: Router pod reference
    Handler->>Executor: Exec pod for<br/>/var/lib/haproxy/conf/haproxy.config
    Executor-->>Handler: Raw config output
    Handler->>Processor: truncateConfigOutput<br/>(output, section, filter, tail_lines)
    Processor->>Processor: Filter by section type<br/>(if section set)
    Processor->>Processor: Filter by substring<br/>(if filter set)
    Processor->>Processor: Truncate to tail_lines
    Processor-->>Handler: Filtered & truncated output,<br/>summary (lines shown/total,<br/>truncation flag)
    Handler->>Response: Format as code block<br/>+ summary message
    Response-->>Client: Structured response
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Poem

A rabbit hops through HAProxy halls,
Now filtering configs, truncating calls,
With section-smart snips and substring delight,
The router output shines bright,
Tests hopping ahead—the truncation's just right! 🐰✨

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 11.11% 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
Title check ✅ Passed The title 'NE-2636: Add truncation and filtering to router tools' clearly and concisely describes the main changes: adding truncation and filtering capabilities to router tools. It accurately reflects the core functionality additions in the changeset.
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.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.

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

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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

@openshift-ci openshift-ci Bot requested review from Cali0707 and Kaustubh-pande May 11, 2026 12:16
@openshift-ci
Copy link
Copy Markdown

openshift-ci Bot commented May 11, 2026

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: Thealisyed
Once this PR has been reviewed and has the lgtm label, please assign manusa for approval. For more information see the Code Review Process.

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@openshift-ci
Copy link
Copy Markdown

openshift-ci Bot commented May 11, 2026

@Thealisyed: all tests passed!

Full PR test history. Your PR dashboard.

Details

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. I understand the commands that are listed here.

@Thealisyed
Copy link
Copy Markdown
Author

Thealisyed commented May 11, 2026

A follow up PR to add truncation and filtering to router tools. The PR we are following up from
cc: @bentito

@bentito
Copy link
Copy Markdown

bentito commented May 11, 2026

/assign

@jcmoraisjr
Copy link
Copy Markdown
Member

/assign


func configSectionType(line string) string {
for _, kw := range haproxySectionKeywords {
if strings.HasPrefix(line, kw) && (len(line) == len(kw) || line[len(kw)] == ' ' || line[len(kw)] == '\t') {
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

This is a smart default for HAProxy where dynamic backends often appear at the end.

var current []string

for _, line := range lines {
if strings.HasPrefix(line, "0x") {
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

This should help group into logical blocks so the pagination breaks things less awkwardly

// getRouterSessions requires a live cluster as it queries the HAProxy admin socket
// via exec on a running router pod. It cannot work against offline data (must-gather).
func getRouterSessions(params api.ToolHandlerParams) (*api.ToolCallResult, error) {
p := api.WrapParams(params)
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

I think getRouterInfo needs this same help with WrapParams

@bentito
Copy link
Copy Markdown

bentito commented May 13, 2026

docs/openshift/NETEDGE.md
Needs update this to detail the new tail_lines, section, filter, and limit parameters so users and agents are aware of these capabilities.

@bentito
Copy link
Copy Markdown

bentito commented May 13, 2026

/assign @bentito @jcmoraisjr

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

Labels

jira/valid-reference Indicates that this PR references a valid Jira ticket of any type.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants