ROX-33557: fix node resolution from hostname#19461
ROX-33557: fix node resolution from hostname#19461rhacs-bot wants to merge 1 commit intorelease-4.10from
Conversation
There was a problem hiding this comment.
Hey - I've found 2 issues, and left some high level feedback:
- In
getNodeByPrefix, the warning log for additional matches usesmatch.Name, which refers to the previously selected node instead of the current conflicting node (k); this makes the log misleading and likely not what you intended to surface for debugging. - The selection logic in
getNodeByPrefixcompares keys lexicographically (k < match.Name), but the comment says it should favor the 'closest match' and 'most likely requested node'; consider aligning the implementation with that intent (e.g., preferring the shortest matching name or longest common prefix) or adjusting the comment to reflect the actual behavior.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- In `getNodeByPrefix`, the warning log for additional matches uses `match.Name`, which refers to the previously selected node instead of the current conflicting node (`k`); this makes the log misleading and likely not what you intended to surface for debugging.
- The selection logic in `getNodeByPrefix` compares keys lexicographically (`k < match.Name`), but the comment says it should favor the 'closest match' and 'most likely requested node'; consider aligning the implementation with that intent (e.g., preferring the shortest matching name or longest common prefix) or adjusting the comment to reflect the actual behavior.
## Individual Comments
### Comment 1
<location path="sensor/kubernetes/listener/resources/node_store.go" line_range="109-110" />
<code_context>
+
+ var match *nodeWrap
+ for k, v := range s.nodes {
+ if strings.HasPrefix(k, prefix) {
+ if match != nil {
+ log.Warnf("Additional nodes match prefix %q: %s", prefix, match.Name)
+ }
</code_context>
<issue_to_address>
**issue:** Warn log for additional matches logs the previous match name instead of the newly found conflicting key, which can be misleading.
Inside the `if match != nil` block, the warning logs `match.Name` (the already selected node) instead of the newly found key `k`. This makes the warning misleading about which node is the “additional” match. Please log `k`, or both `k` and `match.Name`, so the conflicting entries are clearly identified.
</issue_to_address>
### Comment 2
<location path="sensor/kubernetes/listener/resources/node_store.go" line_range="113-120" />
<code_context>
+ if match != nil {
+ log.Warnf("Additional nodes match prefix %q: %s", prefix, match.Name)
+ }
+ if match == nil || k < match.Name {
+ // favor the closest match, whether the prefix matches more
+ // of the string. This serves two purposes:
+ // 1. it is deterministic
+ // 2. it returns the most likely requested node of the multiple
+ // matches
+ match = v
</code_context>
<issue_to_address>
**suggestion:** Lexicographical comparison does not really implement the "closest match" heuristic described in the comment.
The logic here returns the lexicographically smallest `k`, which is deterministic but not necessarily the “closest” match (e.g., `ip-10-0-24-9a` vs `ip-10-0-24-9z`). If the intent is a true notion of closeness (e.g., minimal suffix length or another distance metric), the comparison should be updated. Otherwise, consider rephrasing the comment to emphasize determinism and tie-breaking rather than semantic closeness or “most likely requested node.”
```suggestion
if match == nil || k < match.Name {
// favor a deterministic match by choosing the lexicographically
// smallest node name among matches. This serves two purposes:
// 1. it is deterministic
// 2. it provides a stable tie-breaker when multiple nodes
// match the same prefix, but does not guarantee semantic
// "closeness" to the requested node name
match = v
}
```
</issue_to_address>Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
| if strings.HasPrefix(k, prefix) { | ||
| if match != nil { |
There was a problem hiding this comment.
issue: Warn log for additional matches logs the previous match name instead of the newly found conflicting key, which can be misleading.
Inside the if match != nil block, the warning logs match.Name (the already selected node) instead of the newly found key k. This makes the warning misleading about which node is the “additional” match. Please log k, or both k and match.Name, so the conflicting entries are clearly identified.
| if match == nil || k < match.Name { | ||
| // favor the closest match, whether the prefix matches more | ||
| // of the string. This serves two purposes: | ||
| // 1. it is deterministic | ||
| // 2. it returns the most likely requested node of the multiple | ||
| // matches | ||
| match = v | ||
| } |
There was a problem hiding this comment.
suggestion: Lexicographical comparison does not really implement the "closest match" heuristic described in the comment.
The logic here returns the lexicographically smallest k, which is deterministic but not necessarily the “closest” match (e.g., ip-10-0-24-9a vs ip-10-0-24-9z). If the intent is a true notion of closeness (e.g., minimal suffix length or another distance metric), the comparison should be updated. Otherwise, consider rephrasing the comment to emphasize determinism and tie-breaking rather than semantic closeness or “most likely requested node.”
| if match == nil || k < match.Name { | |
| // favor the closest match, whether the prefix matches more | |
| // of the string. This serves two purposes: | |
| // 1. it is deterministic | |
| // 2. it returns the most likely requested node of the multiple | |
| // matches | |
| match = v | |
| } | |
| if match == nil || k < match.Name { | |
| // favor a deterministic match by choosing the lexicographically | |
| // smallest node name among matches. This serves two purposes: | |
| // 1. it is deterministic | |
| // 2. it provides a stable tie-breaker when multiple nodes | |
| // match the same prefix, but does not guarantee semantic | |
| // "closeness" to the requested node name | |
| match = v | |
| } |
|
Images are ready for the commit at 13548da. To use with deploy scripts, first |
|
/konflux-retest main-on-push |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## release-4.10 #19461 +/- ##
================================================
- Coverage 49.38% 49.37% -0.02%
================================================
Files 2660 2660
Lines 200669 200697 +28
================================================
- Hits 99103 99090 -13
- Misses 94125 94163 +38
- Partials 7441 7444 +3
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
/konflux-retest operator-bundle-on-push |
1 similar comment
|
/konflux-retest operator-bundle-on-push |
|
@rhacs-bot: The following tests failed, say
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. |
Backport f5d5cf0 from #19435.