Skip to content

Conversation

@tanji
Copy link
Collaborator

@tanji tanji commented Jan 11, 2026

MonitorQueryRules was building a proxy ID list but never persisting it, causing all proxies after the first to be lost. Also add break statement to stop iteration once proxy is found, handle empty string edge case, and use clearer variable names.

Contributor Agreement

By submitting this pull request, I agree to the terms outlined in the Contributor Agreement.

MonitorQueryRules was building a proxy ID list but never persisting it,
causing all proxies after the first to be lost. Also add break statement
to stop iteration once proxy is found, handle empty string edge case,
and use clearer variable names.
@claude
Copy link

claude bot commented Jan 11, 2026

PR Review: Fix Proxy Tracking in Query Rules Monitoring

✅ Approval - Changes Look Good

The changes address a legitimate bug in the MonitorQueryRules() function. Here's my detailed analysis:


Bug Fix Analysis

Issue Identified: The original code built a list of proxy IDs in the duplicates variable but never persisted it back to myRule.Proxies. This caused all proxies after the first to be lost when monitoring query rules across multiple ProxySQL instances.

Specific Problem (Original Code):

duplicates := strings.Split(clrule.Proxies, ",")
// ... check if proxy found ...
if !found {
    duplicates = append(duplicates, prx.Id)  // ← Built list but never saved!
}
// ... missing: myRule.Proxies = strings.Join(duplicates, ",")
cluster.QueryRules[rule.Id] = myRule  // Stores old proxy list

Fix Provided: Line 1980 now correctly persists the updated proxy list:

myRule.Proxies = strings.Join(proxyIds, ",")

Code Quality Improvements

Better Variable Naming: duplicatesproxyIds

  • More semantically accurate (not "duplicates", just proxy IDs)
  • More maintainable

Early Exit with break (Line 1974)

  • Prevents unnecessary iteration once proxy is found
  • Minor performance improvement

Empty String Handling (Lines 1965-1967)

  • Gracefully handles the edge case where clrule.Proxies == ""
  • Prevents strings.Split("") from returning [""] instead of []

Improved Comments

  • Clarifies the intent of each code block

Clean Loop Syntax (Line 1883)

  • Changed for tblname, _ := range to for tblname := range
  • Follows Go idioms (blank import when not using second value is cleaner)

Testing & Coverage

⚠️ Note: The function has no unit tests. While this PR doesn't introduce that gap, consider adding regression tests for:

  • Multiple proxies being correctly tracked
  • Empty proxy lists
  • Duplicate proxy prevention

This would prevent future regressions when this critical cluster monitoring code is modified.


Potential Concerns

  1. Slice Comparison: The code checks if prx.Id == prxid (string comparison). Ensure prx.Id is a valid, non-empty string. The empty string handling added at line 1965 helps prevent issues.

  2. Configuration Persistence: After updating myRule.Proxies, the changes are stored in cluster.QueryRules[rule.Id]. Ensure this is persisted to durable storage if needed by your architecture.

  3. Thread Safety: If cluster.QueryRules is accessed concurrently, ensure proper synchronization (appears to be handled elsewhere in your codebase).


Summary

Clear bug fix with correct logic
Improved code clarity and maintainability
Proper edge case handling
No breaking changes

Recommendation: Approve and merge. This fixes a production bug where multi-proxy query rule tracking would lose proxy assignments after the first proxy.

@tanji tanji merged commit d54e49b into develop Jan 11, 2026
1 check passed
@tanji tanji deleted the fix/query-rules-proxy-tracking branch January 13, 2026 11:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants