Skip to content

refactor: improve config validation in precise-prefix-cache-scorer#690

Open
lisperz wants to merge 1 commit intollm-d:mainfrom
lisperz:refactor/improve-prefix-cache-config
Open

refactor: improve config validation in precise-prefix-cache-scorer#690
lisperz wants to merge 1 commit intollm-d:mainfrom
lisperz:refactor/improve-prefix-cache-config

Conversation

@lisperz
Copy link
Copy Markdown

@lisperz lisperz commented Mar 9, 2026

Summary

This PR improves the precise-prefix-cache-scorer plugin by adding proper configuration validation and extracting magic numbers to named constants.

Changes

  1. Extract hardcoded timeout to constant

    • Moved the 10-minute subscription timeout to a named constant defaultSubscriptionTimeout
    • Makes the value more maintainable and self-documenting
  2. Add pod discovery configuration validation

    • Validates that podDiscoveryConfig is present when discoverPods is enabled
    • Validates socket port is within valid range (1-65535)
    • Returns clear error messages for invalid configurations
  3. Add unit tests

    • Created comprehensive tests for the new validation logic
    • Covers edge cases: missing config, invalid ports (zero, negative, too large)

Motivation

Without validation, invalid configurations could cause runtime panics when the scorer tries to access nil pointers or use invalid port numbers. This change catches configuration errors early during plugin initialization with clear error messages.

Testing

go test ./pkg/plugins/scorer -run TestNew_PodDiscoveryValidation -v

All new validation paths are covered by unit tests.

- Extract hardcoded subscription timeout to named constant
- Add validation for pod discovery configuration
- Validate socket port range when discoverPods is enabled

This prevents runtime panics from invalid configuration and makes
the timeout value more maintainable.

Signed-off-by: lisperz <zhuchen200245@163.com>
@lisperz lisperz force-pushed the refactor/improve-prefix-cache-config branch from 9da6cd2 to 6db2f96 Compare March 9, 2026 04:26
@github-actions
Copy link
Copy Markdown

This PR is marked as stale after 21d of inactivity. After an additional 14d of inactivity (7d to become rotten, then 7d more), it will be closed. To prevent this PR from being closed, add a comment or remove the lifecycle/stale label.

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

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

1 participant