[improve][broker] Support showing client ip address in client stats while using reverse proxy #23974
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Motivation
In Apache Pulsar, the broker enables producers and consumers to connect to a topic and provides an API to retrieve topic statistics. These stats include a list of connected producers and consumers, along with their IP addresses and connection times. This information is particularly valuable when dealing with a large number of producers and consumers from various client hosts, as it helps troubleshoot issues such as:
Identifying which client host has an active consumer
Detecting if a client host has stopped consuming messages
Diagnosing message backlogs
Thus, mapping the client host IP to the corresponding producer or consumer is crucial.
The Issue with Reverse Proxies
However, this mapping breaks when a reverse proxy is used between the client and broker. In such cases, the broker records only the proxy's IP address for all connected producers and consumers, making it difficult to identify the actual client host. Apache Pulsar supports multiple proxy solutions, such as Pulsar-Proxy and SNI Proxy, which further complicates troubleshooting by obscuring client IPs.
To resolve this, this PR ensures that when a client library connects to a broker via a proxy, it sends the actual client IP address. The broker then correctly identifies and records this IP in the stats API, mapping it to the appropriate producer or consumer. This approach abstracts the proxy layer from users, allowing them to see accurate client IPs without any additional effort.
This PR doesn't change client-broker protocol, API definition or configuration.
Modifications
Client lib sends an ip-address property when client lib detects a proxy, and the broker shows it in the client stats.
Verifying this change
(Please pick either of the following options)
This change is a trivial rework / code cleanup without any test coverage.
(or)
This change is already covered by existing tests, such as (please describe tests).
(or)
This change added tests and can be verified as follows:
(example:)
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
PR in forked repository: