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

[PIP 95][Issue 12040][web] Topic lookup with listener header #12072

Merged
merged 8 commits into from
Oct 14, 2021

Conversation

EronWright
Copy link
Contributor

@EronWright EronWright commented Sep 16, 2021

Master Issue: #12040

Motivation

This PR introduces an optional HTTP header X-Pulsar-ListenerName to the TopicLookup operation of the Pulsar REST API. The header supplies the listener name to use when the broker has multiple advertised listeners. Today the TopicLookup operation accepts a query parameter listenerName for that same purpose.

The motivation for adding a header-based alternative is to improve support smart listener selection via HTTP gateways or proxies that are capable of rewriting headers (see: Istio VirtualService).

See #12040 for more background.

Modifications

  • Modify TopicLookup operation (V1 + V2) to use a header (query string takes precedence).

Verifying this change

  • Make sure that the change passes the CI checks.

The TopicLookup operation doesn't seem to have any unit tests.

Tested using ad-hoc queries, for example against a cluster that has a gateway listener.

$ curl http://octopus.home:8080/lookup/v2/topic/persistent/public/functions/coordinate -H 'X-Pulsar-ListenerName: gateway'
{"brokerUrl":"pulsar://gateway.home:6650","brokerUrlTls":"pulsar+ssl://gateway.home:6651","httpUrl":"http://octopus.home:8080","nativeUrl":"pulsar://gateway.home:6650","brokerUrlSsl":""}⏎

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

  • The public API: yes - the REST API has a new optional header parameter.

Documentation

Check the box below and label this PR (if you have committer privilege).

Need to update docs?

  • doc

    (javadocs)

@wangjialing218
Copy link
Contributor

I think it's not enough to only add the listener head to lookupTopicAsync.
For web request, there is some admin operation which may return a HTTP REDIRECT response with the http url address of the broker own the target topic. For example send a create subscription request to a broker which is not the owner of topic.
In this case, REDIRECT response using the internal webSeviceUrl and the client which send the HTTP requst may not able to connect to the REDIRECT address from outside.
Current there is only brokerSeviceUrl in advertised address, To support advertised listener for HTTP, we need add webSeviceUrl to advertised address first.

@EronWright
Copy link
Contributor Author

@wangjialing218 I agree, the advertised listener configuration does not apply to web service endpoints, it applies only to the Pulsar protocol endpoints. This PR is limited in scope. Let's discuss on the dev mailing list about whether #12040 should include this aspect.

Copy link
Contributor

@codelipenghui codelipenghui left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, could you please also help add a test for the new change?

Copy link
Contributor

@hangc0276 hangc0276 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Look good to me. Would you please add test for listenerName is empty and listenerNameHeader not null ?

@eolivelli eolivelli changed the title [Issue 12040][web] Topic lookup with listener header [PIP 95][Issue 12040][web] Topic lookup with listener header Sep 20, 2021
@EronWright
Copy link
Contributor Author

EronWright commented Sep 20, 2021

@codelipenghui since this is a part of PIP-95 feature work, should probably target 2.9 not 2.8.2. Some of the other PRs are just bug fixes that could be in 2.8.2 in my opinion, but not this one.

@eolivelli eolivelli modified the milestones: 2.9.0, 2.10.0 Oct 6, 2021
Copy link
Contributor

@eolivelli eolivelli left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@eolivelli
Copy link
Contributor

the failure is about a test related to this PR

INFO]
Error: Failures:
Error: org.apache.pulsar.broker.lookup.http.v2.TopicLookupTest.testListenerName(org.apache.pulsar.broker.lookup.http.v2.TopicLookupTest)
[INFO] Run 1: PASS
Error: Run 2: TopicLookupTest.testListenerName:53->JerseyTest.target:593->JerseyTest.target:579 » NullPointer
[INFO]
[INFO]

- ensure that setup/teardown runs when `-Dgroup=broker`
- ensure that setup/teardown runs when `-Dgroup=broker`
- use setup-per-class not setup-per-method
@EronWright
Copy link
Contributor Author

This is ready to merge. The test failure seems unrelated:

Error:  org.apache.pulsar.broker.admin.TopicPoliciesTest.testDisableSubscribeRate(org.apache.pulsar.broker.admin.TopicPoliciesTest)

@addisonj
Copy link
Contributor

/pulsarbot run-failure-checks

@EronWright
Copy link
Contributor Author

/pulsarbot run-failure-checks

@codelipenghui codelipenghui removed this from the 2.10.0 milestone Oct 14, 2021
@codelipenghui codelipenghui added this to the 2.9.0 milestone Oct 14, 2021
@codelipenghui codelipenghui merged commit c792ef8 into apache:master Oct 14, 2021
zeo1995 pushed a commit to zeo1995/pulsar that referenced this pull request Oct 14, 2021
* up/master: (37 commits)
  re-enabling integration tests for Sinks (apache#12307)
  [PIP 95][Issue 12040][web] Topic lookup with listener header (apache#12072)
  Fix the master CI broken with update dispatch rate block issue (apache#12360)
  Fix message being ignored when the non-persistent topic reader reconnect. (apache#12348)
  Fix log format. (apache#12346)
  [website][upgrade]feat: docs migration - version-2.7.2 Concepts and Architecture (apache#12354)
  [website][upgrade] feat: full docs migration for version 2.8.0 (apache#12359)
  [website][upgrade]feat: dynamic replace version info before build (apache#12337)
  Fix flaky tests: ElasticSearchClientTests (apache#12347)
  Use asyncCloseCursorLedger to replace cursorLedger.asyncClose method in the ManagedCursorImpl.VoidCallback#operationComplete (apache#12113)
  fix-npe-ZkBookieRackAffinityMapping (apache#11947)
  [pulsar-admin] Allow setting --forward-source-message-property to false when updating a pulsar function (apache#12128)
  [website][upgrade]feat: docs migration - Development (apache#12320)
  Update delete inactive topic configuration documentation (apache#12350)
  [PIP 95][Issue 12040][broker] Multiple bind addresses for Pulsar protocol (apache#12056)
  Added Debezium Source for MS SQL Server (apache#12256)
  Fix: flaky oracle tests (apache#12306)
  [C++] Use URL encoded content type for OAuth 2.0 authentication (apache#12341)
  [C++] Handle OAuth 2.0 exceptional cases gracefully (apache#12335)
  feat(cli): add restart command to pulsar-daemon (apache#12279)
  ...

# Conflicts:
#	site2/website-next/docusaurus.config.js
#	site2/website-next/versioned_sidebars/version-2.7.2-sidebars.json
#	site2/website-next/versions.json
@codelipenghui codelipenghui deleted the ewright/pip95-adminlistener branch October 14, 2021 23:29
bharanic-dev pushed a commit to bharanic-dev/pulsar that referenced this pull request Mar 18, 2022
…12072)

Master Issue: apache#12040

### Motivation

This PR introduces an optional HTTP header `X-Pulsar-ListenerName` to the `TopicLookup` operation of the Pulsar REST API.  The header supplies the listener name to use when the broker has multiple advertised listeners.  Today the `TopicLookup` operation accepts a query parameter `listenerName` for that same purpose.

The motivation for adding a header-based alternative is to improve support smart listener selection via HTTP gateways or proxies that are capable of rewriting headers (see: [Istio VirtualService](https://istio.io/latest/docs/reference/config/networking/virtual-service/#Headers)).

See apache#12040 for more background.

### Modifications

- Modify `TopicLookup` operation (V1 + V2) to use a header (query string takes precedence).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants