Skip to content
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] Support showing client ip address in client stats while using reverse proxy #23974

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

rdhabalia
Copy link
Contributor

@rdhabalia rdhabalia commented Feb 12, 2025

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

  • Make sure that the change passes the CI checks.

(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:)

  • Added integration tests for end-to-end deployment with large payloads (10MB)
  • Extended integration test for recovery after broker failure

Does this pull request potentially affect one of the following parts:

If the box was checked, please highlight the changes

  • Dependencies (add or upgrade a dependency)
  • The public API
  • The schema
  • The default values of configurations
  • The threading model
  • The binary protocol
  • The REST endpoints
  • The admin CLI options
  • The metrics
  • Anything that affects deployment

Documentation

  • doc
  • doc-required
  • doc-not-needed
  • doc-complete

Matching PR in forked repository

PR in forked repository:

@rdhabalia rdhabalia self-assigned this Feb 12, 2025
@codecov-commenter
Copy link

codecov-commenter commented Feb 14, 2025

Codecov Report

Attention: Patch coverage is 85.71429% with 3 lines in your changes missing coverage. Please review.

Project coverage is 74.30%. Comparing base (bbc6224) to head (17c830e).
Report is 917 commits behind head on master.

Files with missing lines Patch % Lines
...ava/org/apache/pulsar/broker/service/Consumer.java 50.00% 0 Missing and 1 partial ⚠️
...va/org/apache/pulsar/client/impl/ConsumerImpl.java 85.71% 0 Missing and 1 partial ⚠️
...va/org/apache/pulsar/client/impl/ProducerImpl.java 85.71% 0 Missing and 1 partial ⚠️
Additional details and impacted files

Impacted file tree graph

@@             Coverage Diff              @@
##             master   #23974      +/-   ##
============================================
+ Coverage     73.57%   74.30%   +0.73%     
+ Complexity    32624    32311     -313     
============================================
  Files          1877     1853      -24     
  Lines        139502   143862    +4360     
  Branches      15299    16347    +1048     
============================================
+ Hits         102638   106902    +4264     
+ Misses        28908    28575     -333     
- Partials       7956     8385     +429     
Flag Coverage Δ
inttests 26.79% <61.90%> (+2.20%) ⬆️
systests 23.26% <57.14%> (-1.06%) ⬇️
unittests 73.84% <85.71%> (+0.99%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
...ava/org/apache/pulsar/broker/service/Producer.java 80.90% <100.00%> (+0.52%) ⬆️
.../java/org/apache/pulsar/client/impl/ClientCnx.java 73.23% <100.00%> (+1.45%) ⬆️
...java/org/apache/pulsar/common/naming/Metadata.java 80.00% <ø> (ø)
...ava/org/apache/pulsar/broker/service/Consumer.java 85.00% <50.00%> (-1.67%) ⬇️
...va/org/apache/pulsar/client/impl/ConsumerImpl.java 80.51% <85.71%> (+2.94%) ⬆️
...va/org/apache/pulsar/client/impl/ProducerImpl.java 84.25% <85.71%> (+0.66%) ⬆️

... and 1038 files with indirect coverage changes

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants