-
Notifications
You must be signed in to change notification settings - Fork 4.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
hotfix(upstream) display active targets based on proper definition #2310
Conversation
kong/api/routes/upstreams.lua
Outdated
-- track that we found this host:port so we only show | ||
-- the most recent one (kinda) | ||
found[entry.target] = true | ||
|
||
else | ||
ignored[entry.target] = true | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
style: switch the if and else blocks, short code path first (easier to read)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
kong/api/routes/upstreams.lua
Outdated
for i = 1, found_n do | ||
found[found[i].target] = nil | ||
end | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if you keep track of the ones dealt with in one table (now you track them in found
and ignored
), then the other table can hold the final result, and hence this final loop won't be necessary anymore
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nice catch!
target = "api-4:80", | ||
weight = 10, | ||
upstream_id = upstream3.id, | ||
}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
a case where there are multiple entries, but the last one has weight=0
(and hence is inactive) would be nice here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
Previously we defined active upstream targets as any target with a nonzero weight. This definition was properly implemented, but caused confusion. As such, we redfine 'active targets' to be the most recent entry of each nonzero target. This presents a more accurate picture of the targets currently in use by the balancer.
c3c6eba
to
ef05185
Compare
@Tieske thanks for the comments, fixed up. Also refactored the tests a bit to be easier to read and extend cases. |
Previously we defined active upstream targets as any target with
a nonzero weight. This definition was properly implemented, but
caused confusion. As such, we redfine 'active targets' to be the most
recent entry of each nonzero target. This presents a more accurate
picture of the targets currently in use by the balancer.
Fix #2306.