-
Notifications
You must be signed in to change notification settings - Fork 3.6k
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
[improve][broker] Add haProxyProtocolEnabled more description #19967
Conversation
@crossoverJie thanks for your contribution! Please attach this in the PR description as required. |
@BewareMyPower Could you please review this PR from a technical perspective? Thank you! |
PTAL |
This is based on this pull request #8686 , please take a look. |
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.
This comment is correct but seems redundant - it adds no extra info from my perspective.
From the purpose of this PR, it is to provide a way to obtain the real IP address, but using the "real" keyword in |
The pr had no activity for 30 days, mark with Stale label. |
Codecov Report
@@ Coverage Diff @@
## master #19967 +/- ##
=============================================
+ Coverage 37.61% 72.94% +35.33%
- Complexity 12589 31971 +19382
=============================================
Files 1691 1868 +177
Lines 129028 138586 +9558
Branches 14066 15236 +1170
=============================================
+ Hits 48530 101096 +52566
+ Misses 74183 29450 -44733
- Partials 6315 8040 +1725
Flags with carried forward coverage won't be shown. Click here to find out more.
|
Merging... Thanks for your contribution! |
@@ -85,6 +85,7 @@ advertisedAddress= | |||
# internalListenerName= | |||
|
|||
# Enable or disable the HAProxy protocol. | |||
# If true, the real IP addresses of consumers and producers can be obtained when getting topic statistics data. |
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.
Real might be misleading here. I think the IP address is the remote IP address from the proxy's perspective? If you agree, I think we should clarify further to prevent confusion. This is relevant when traffic ingresses to the proxy through any kind of NAT. A good example is a kubernetes load balancer with externalTrafficPolicy: cluster
.
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.
I also found this setting very misleading the first time I encountered it. We're not really even using the HA Proxy protocol. It seems that we appropriated the protocol message to propagate the client IP address, which seems worth documenting since the HAProxy part is largely irrelevant 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.
It looks like I might be somewhat mistaken. This PR has some relevant details #16045. The edge case is that you can get the "wrong" address if the inbound connection to the pulsar proxy does not start with the HAProxy message. Here is the relevant code:
pulsar/pulsar-proxy/src/main/java/org/apache/pulsar/proxy/server/DirectProxyHandler.java
Lines 240 to 261 in 1545396
private void writeHAProxyMessage() { | |
if (proxyConnection.hasHAProxyMessage()) { | |
final ByteBuf msg = encodeProxyProtocolMessage(proxyConnection.getHAProxyMessage()); | |
writeAndFlush(msg); | |
} else { | |
if (inboundChannel.remoteAddress() instanceof InetSocketAddress | |
&& inboundChannel.localAddress() instanceof InetSocketAddress) { | |
InetSocketAddress clientAddress = (InetSocketAddress) inboundChannel.remoteAddress(); | |
String sourceAddress = clientAddress.getAddress().getHostAddress(); | |
int sourcePort = clientAddress.getPort(); | |
InetSocketAddress proxyAddress = (InetSocketAddress) inboundChannel.localAddress(); | |
String destinationAddress = proxyAddress.getAddress().getHostAddress(); | |
int destinationPort = proxyAddress.getPort(); | |
HAProxyMessage msg = new HAProxyMessage(HAProxyProtocolVersion.V1, HAProxyCommand.PROXY, | |
HAProxyProxiedProtocol.TCP4, sourceAddress, destinationAddress, sourcePort, | |
destinationPort); | |
final ByteBuf encodedMsg = encodeProxyProtocolMessage(msg); | |
writeAndFlush(encodedMsg); | |
msg.release(); | |
} | |
} | |
} |
Motivation
When using broker-proxy, I wanted to obtain the real IP address of the client, but I couldn't find much useful information in the documentation. Finally, after reading the source code, I discovered this configuration.
Therefore, the description of
haProxyProtocolEnabled
was added.Modifications
Add more description.
Verifying this change
(Please pick either of the following options)
This change is a trivial rework / code cleanup without any test coverage.
Does this pull request potentially affect one of the following parts:
If the box was checked, please highlight the changes
Documentation
doc
doc-required
doc-not-needed
doc-complete
Matching PR in forked repository
crossoverJie#6