NE-2636: Add truncation and filtering to router tools#304
Conversation
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
|
@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. DetailsIn response to this:
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. |
📝 WalkthroughWalkthroughThe PR extends NetEdge router tools ( ChangesRouter Output Filtering and Truncation
Sequence DiagramsequenceDiagram
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
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: Thealisyed The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
|
@Thealisyed: all tests passed! Full PR test history. Your PR dashboard. DetailsInstructions 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. |
|
/assign |
|
/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') { |
There was a problem hiding this comment.
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") { |
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
I think getRouterInfo needs this same help with WrapParams
|
|
|
/assign @bentito @jcmoraisjr |
Summary
tail_lines,section, andfilterparameters toget_router_configto limit and filter HAProxy config outputlimitandfilterparameters toget_router_sessionsto cap and filter session outputTest plan
truncateConfigOutput(12 cases: tail_lines, section filter, substring filter, combined, edge cases)truncateSessionsOutput(8 cases: limit, filter, combined, edge cases)make build && make test && make lintpass cleanlySummary by CodeRabbit
New Features
Tests