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

@Thealisyed Thealisyed commented May 11, 2026

Copy link
Copy Markdown

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

Summary by CodeRabbit

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 responses include truncation/filtering status summaries and formatted code blocks.
  • Tests
    • Added coverage for configuration/session truncation behavior, filtering (including no-match cases), and large-output scenarios.

@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

openshift-ci-robot commented May 11, 2026

Copy link
Copy Markdown

@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

coderabbitai Bot commented May 11, 2026

Copy link
Copy Markdown

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: b988ffbf-d332-4265-89fd-b3a194faf9bb

📥 Commits

Reviewing files that changed from the base of the PR and between 01e7043 and 8d07428.

📒 Files selected for processing (2)
  • pkg/toolsets/netedge/router.go
  • pkg/toolsets/netedge/router_test.go
🚧 Files skipped from review as they are similar to previous changes (1)
  • pkg/toolsets/netedge/router_test.go

📝 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
Constants and Module-Level Setup
pkg/toolsets/netedge/router.go
Introduces defaultConfigTailLines and defaultSessionLimit constants, and module-level variables (podGVR, haproxySectionKeywords) used by truncation and filtering logic.
Config Tool: Schema, Parameter Handling, and Output Processing
pkg/toolsets/netedge/router.go
Extends get_router_config schema with tail_lines, section (enum: global, backend, frontend), and filter (substring match) parameters; rewrites handler 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 and code-block formatting.
Sessions Tool: Schema, Parameter Handling, and Output Processing
pkg/toolsets/netedge/router.go
Extends get_router_sessions schema with limit (default applied) and filter (substring match) parameters; rewrites handler 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 and code-block formatting.
Info Handler Parameter Parsing Update
pkg/toolsets/netedge/router.go
Updates getRouterInfo to use api.WrapParams with OptionalString and explicit p.Err() validation, aligning parameter parsing pattern with config and sessions handlers.
Truncation and Filtering Helper Functions
pkg/toolsets/netedge/router.go
Implements new helpers: configSectionType (HAProxy section header detection), truncateConfigOutput (section/filter-aware tail truncation), truncateSessionsOutput (block splitting and filtering), and blockContainsSubstring (case-insensitive substring matching).
Test Coverage for Truncation Helpers
pkg/toolsets/netedge/router_test.go
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 ConfigHandler as getRouterConfig
    participant SessionsHandler as getRouterSessions
    participant WrapParams
    participant PodResolver
    participant Executor as Pod Executor
    participant ConfigProcessor as truncateConfigOutput
    participant SessionProcessor as truncateSessionsOutput

    Client->>ConfigHandler: Call with pod?, tail_lines, section?, filter?
    ConfigHandler->>WrapParams: Validate parameters
    WrapParams-->>ConfigHandler: Validated params
    ConfigHandler->>PodResolver: Resolve router pod if unset
    PodResolver-->>ConfigHandler: Pod reference
    ConfigHandler->>Executor: Exec pod for haproxy.config
    Executor-->>ConfigHandler: Raw config
    ConfigHandler->>ConfigProcessor: Filter by section/substring, truncate to tail_lines
    ConfigProcessor-->>ConfigHandler: Filtered output + metadata

    Client->>SessionsHandler: Call with pod?, limit, filter?
    SessionsHandler->>WrapParams: Validate parameters
    WrapParams-->>SessionsHandler: Validated params
    SessionsHandler->>PodResolver: Resolve router pod if unset
    PodResolver-->>SessionsHandler: Pod reference
    SessionsHandler->>Executor: Exec pod for session data
    Executor-->>SessionsHandler: Raw sessions
    SessionsHandler->>SessionProcessor: Split blocks, filter, truncate to limit
    SessionProcessor-->>SessionsHandler: Filtered blocks + metadata
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
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and specifically describes the main change: adding truncation and filtering capabilities to router tools, with the ticket reference providing additional context.
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

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

openshift-ci Bot commented May 11, 2026

Copy link
Copy Markdown

[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

openshift-ci Bot commented May 11, 2026

Copy link
Copy Markdown

@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

Thealisyed commented May 11, 2026

Copy link
Copy Markdown
Author

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

@bentito

bentito commented May 11, 2026

Copy link
Copy Markdown

/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

bentito commented May 13, 2026

Copy link
Copy Markdown

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

bentito commented May 13, 2026

Copy link
Copy Markdown

/assign @bentito @jcmoraisjr

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@Thealisyed Thealisyed force-pushed the NE-2636-router-truncation branch from 01e7043 to 8d07428 Compare June 15, 2026 16:12
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