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

[Issue #5395][broker] Implement AutoTopicCreation by namespace override #6471

Merged
merged 22 commits into from Mar 26, 2020

Conversation

klevy-toast
Copy link
Contributor

Fixes #5395

Motivation

This change introduces a new namespace policy autoTopicCreationOverride, which will enable an override of broker autoTopicCreation settings on the namespace level. You may keep autoTopicCreation disabled for the broker and allow it on a specific namespace using this feature.

Modifications

  • Add new namespace policy: autoTopicCreationOverride and associated API / CLI interface for setting and removing. Defaults to non-partitioned type, but also allows partitioned topics.
  • Modifies BrokerService: when checking autoTopicCreation configuration, the broker first retrieves namespace policies from zookeeper. If the autoTopicCreationOverride policy exists for that namespace then it uses those settings. If not, falls back to broker configuration.
  • Slight refactor to move TopicType enum to pulsar-common and add autoTopicCreationOverride to pulsar-common.

Verifying this change

  • Make sure that the change passes the CI checks.

(Please pick either of the following options)

This change added tests and can be verified as follows:

  • Extended BrokerServiceAutoTopicCreationTest to test the overriding behavior of the namespace policy including both non-partitioned & partitioned topics.
  • Created AutoTopicCreationOverrideTest to ensure policy validation only allows valid policies.

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

  • Dependencies (does it add or upgrade a dependency): (no)
  • The public API: (yes: new POST and DELETE for /{tenant}/{namespace}/allowAutoTopicCreationOverride in order to set new namespace policy)
  • The schema: (don't know)
  • The default values of configurations: (no)
  • The wire protocol: (no)
  • The rest endpoints: (yes: new POST and DELETE for /{tenant}/{namespace}/allowAutoTopicCreationOverride in order to set new namespace policy)
  • The admin cli options: (yes: new set-allow-auto-topic-creation-override and delete-allow-auto-topic-creation-override)
  • Anything that affects deployment: (no)

Documentation

  • Does this pull request introduce a new feature? (yes)
  • If yes, how is the feature documented? (JavaDocs)

@sijie sijie added this to the 2.6.0 milestone Mar 5, 2020
@sijie sijie added the type/feature The PR added a new feature or issue requested a new feature label Mar 5, 2020
@sijie sijie added the doc-required Your PR changes impact docs and you will update later. label Mar 5, 2020
@klevy-toast
Copy link
Contributor Author

Hi @sijie, I am unsure if the documentation that I added is enough. Is there another place I should be adding docs? Could you point me to it? Thanks.

@sijie
Copy link
Member

sijie commented Mar 6, 2020

@jiazhai @codelipenghui can you help review this pull request?

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.

The changes looks good, Some suggestions on naming:

Is it better to named to set-topic-auto-creation-policy and get-topic-auto-creation-policy?

@ApiResponses(value = { @ApiResponse(code = 403, message = "Don't have admin permission"),
@ApiResponse(code = 404, message = "Tenant or cluster or namespace doesn't exist"),
@ApiResponse(code = 400, message = "Invalid autoTopicCreation override") })
public void setAllowAutoTopicCreationOverride(@PathParam("tenant") String tenant, @PathParam("namespace") String namespace,
Copy link
Contributor

Choose a reason for hiding this comment

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

@ApiOperation(value = "Remove override of broker's allowAutoTopicCreation in a namespace")
@ApiResponses(value = { @ApiResponse(code = 403, message = "Don't have admin permission"),
@ApiResponse(code = 404, message = "Tenant or cluster or namespace doesn't exist") })
public void removeAllowAutoTopicCreationOverride(@PathParam("tenant") String tenant, @PathParam("namespace") String namespace) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Same as above comment.

@klevy-toast
Copy link
Contributor Author

klevy-toast commented Mar 10, 2020

Thanks @codelipenghui . I made changes to use AsyncResponse, and renamed things to set-auto-topic-creation-override etc.. I didn't want to change it around to topic-auto-creation-override because the original setting is called allowAutoTopicCreation so I think it is more consistent to maintain that order. There is no get command, as I figured that you could just use the namespaces policies command instead.

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.

I also want to suggest something in the name. All the namespace level policies are overwritten the broker level configurations, so do we need to add overwrite to the method name?

Comment on lines +559 to +564
validateAdminAccessForTenant(namespaceName.getTenant());
validatePoliciesReadOnlyAccess();

if (!AutoTopicCreationOverride.isValidOverride(autoTopicCreationOverride)) {
throw new RestException(Status.PRECONDITION_FAILED, "Invalid configuration for autoTopicCreationOverride");
}
Copy link
Contributor

Choose a reason for hiding this comment

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

We'd better complete the asyncResponse when there are RunTimeException occurs. Otherwise, the client just can get a 500 response but can't get any error messages.

Comment on lines +611 to +612
validateAdminAccessForTenant(namespaceName.getTenant());
validatePoliciesReadOnlyAccess();
Copy link
Contributor

Choose a reason for hiding this comment

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

Same as above comment.

@klevy-toast
Copy link
Contributor Author

@codelipenghui I don't quite understand your naming suggestion. The new setting is an override, and the methods have that in their names, so I think that it is clear that they are overriding the broker level setting.

I added catches in the top level call in order to complete the async response. Let me know if you have any more suggestions. Thanks

@codelipenghui
Copy link
Contributor

/pulsarbot run-failure-checks

@klevy-toast
Copy link
Contributor Author

fyi tests passing now @codelipenghui

@codelipenghui
Copy link
Contributor

@klevy-toast Can you help fix the checkstyle issue? The master branch enables checkstyle for pulsar-admin.

@klevy-toast
Copy link
Contributor Author

/pulsarbot run-failure-checks

@sijie sijie merged commit fdc3a9b into apache:master Mar 26, 2020
@sijie
Copy link
Member

sijie commented Mar 26, 2020

@klevy-toast thank you so much for your contributions!

@klevy-toast klevy-toast deleted the feature/autocreate-by-namespace branch March 26, 2020 15:48
@jiazhai
Copy link
Member

jiazhai commented May 8, 2020

For merge conflict. mark as 2.5.2 and cherry-picked into branch-2.5

jiazhai pushed a commit that referenced this pull request May 8, 2020
…de (#6471)

Fixes #5395

This change introduces a new namespace policy `autoTopicCreationOverride`, which will enable an override of broker `autoTopicCreation` settings on the namespace level. You may keep `autoTopicCreation` disabled for the broker and allow it on a specific namespace using this feature.

- Add new namespace policy: `autoTopicCreationOverride` and associated API / CLI interface for setting and removing. Defaults to non-partitioned type, but also allows partitioned topics.
- Modifies BrokerService: when checking `autoTopicCreation` configuration, the broker first retrieves namespace policies from zookeeper. If the `autoTopicCreationOverride` policy exists for that namespace then it uses those settings. If not, falls back to broker configuration.
- Slight refactor to move `TopicType` enum to pulsar-common and add `autoTopicCreationOverride` to pulsar-common.
(cherry picked from commit fdc3a9b)
@Anonymitaet Anonymitaet removed the doc-required Your PR changes impact docs and you will update later. label Jun 10, 2020
@Anonymitaet
Copy link
Member

huangdx0726 pushed a commit to huangdx0726/pulsar that referenced this pull request Aug 24, 2020
…override (apache#6471)

Fixes apache#5395 

### Motivation

This change introduces a new namespace policy `autoTopicCreationOverride`, which will enable an override of broker `autoTopicCreation` settings on the namespace level. You may keep `autoTopicCreation` disabled for the broker and allow it on a specific namespace using this feature.

### Modifications

- Add new namespace policy: `autoTopicCreationOverride` and associated API / CLI interface for setting and removing. Defaults to non-partitioned type, but also allows partitioned topics.
- Modifies BrokerService: when checking `autoTopicCreation` configuration, the broker first retrieves namespace policies from zookeeper. If the `autoTopicCreationOverride` policy exists for that namespace then it uses those settings. If not, falls back to broker configuration.
- Slight refactor to move `TopicType` enum to pulsar-common and add `autoTopicCreationOverride` to pulsar-common.
cbornet added a commit to cbornet/pulsar that referenced this pull request Nov 9, 2021
PR apache#6471 introduced the possibility to set auto topic creation settings at the namespace level
PR apache#6685 is a fix to take into account the auto topic creation setting when creating a subscription
but it uses the broker configuration and doesn't see the namespace level setting that was introduced in apache#6471

This fix uses the   method that fetches config overrides in ZK instead of the one from the broker configuration.
This way the  method of the pulsar-admin uses the value set for the namespace for auto-topic-creation
cbornet added a commit to cbornet/pulsar that referenced this pull request Nov 10, 2021
PR apache#6471 introduced the possibility to set auto topic creation settings at the namespace level
PR apache#6685 is a fix to take into account the auto topic creation setting when creating a subscription
but it uses the broker configuration and doesn't see the namespace level setting that was introduced in apache#6471

This fix uses the   method that fetches config overrides in ZK instead of the one from the broker configuration.
This way the  method of the pulsar-admin uses the value set for the namespace for auto-topic-creation
cbornet added a commit to cbornet/pulsar that referenced this pull request Nov 10, 2021
PR apache#6471 introduced the possibility to set auto topic creation settings at the namespace level
PR apache#6685 is a fix to take into account the auto topic creation setting when creating a subscription
but it uses the broker configuration and doesn't see the namespace level setting that was introduced in apache#6471

This fix uses the   method that fetches config overrides in ZK instead of the one from the broker configuration.
This way the  method of the pulsar-admin uses the value set for the namespace for auto-topic-creation
cbornet added a commit to cbornet/pulsar that referenced this pull request Nov 10, 2021
PR apache#6471 introduced the possibility to set auto topic creation settings at the namespace level
PR apache#6685 is a fix to take into account the auto topic creation setting when creating a subscription
but it uses the broker configuration and doesn't see the namespace level setting that was introduced in apache#6471

This fix uses the   method that fetches config overrides in ZK instead of the one from the broker configuration.
This way the  method of the pulsar-admin uses the value set for the namespace for auto-topic-creation
merlimat pushed a commit that referenced this pull request Dec 9, 2021
)

PR #6471 introduced the possibility to set auto topic creation settings at the namespace level
PR #6685 is a fix to take into account the auto topic creation setting when creating a subscription
but it uses the broker configuration and doesn't see the namespace level setting that was introduced in #6471

This fix uses the   method that fetches config overrides in ZK instead of the one from the broker configuration.
This way the  method of the pulsar-admin uses the value set for the namespace for auto-topic-creation
lhotari pushed a commit that referenced this pull request Dec 10, 2021
)

PR #6471 introduced the possibility to set auto topic creation settings at the namespace level
PR #6685 is a fix to take into account the auto topic creation setting when creating a subscription
but it uses the broker configuration and doesn't see the namespace level setting that was introduced in #6471

This fix uses the   method that fetches config overrides in ZK instead of the one from the broker configuration.
This way the  method of the pulsar-admin uses the value set for the namespace for auto-topic-creation

(cherry picked from commit 965a80f)
lhotari pushed a commit that referenced this pull request Dec 10, 2021
)

PR #6471 introduced the possibility to set auto topic creation settings at the namespace level
PR #6685 is a fix to take into account the auto topic creation setting when creating a subscription
but it uses the broker configuration and doesn't see the namespace level setting that was introduced in #6471

This fix uses the   method that fetches config overrides in ZK instead of the one from the broker configuration.
This way the  method of the pulsar-admin uses the value set for the namespace for auto-topic-creation

(cherry picked from commit 965a80f)
nicoloboschi pushed a commit to datastax/pulsar that referenced this pull request Dec 10, 2021
…che#12699)

PR apache#6471 introduced the possibility to set auto topic creation settings at the namespace level
PR apache#6685 is a fix to take into account the auto topic creation setting when creating a subscription
but it uses the broker configuration and doesn't see the namespace level setting that was introduced in apache#6471

This fix uses the   method that fetches config overrides in ZK instead of the one from the broker configuration.
This way the  method of the pulsar-admin uses the value set for the namespace for auto-topic-creation

(cherry picked from commit 965a80f)
(cherry picked from commit a034d14)
fxbing pushed a commit to fxbing/pulsar that referenced this pull request Dec 19, 2021
…che#12699)

PR apache#6471 introduced the possibility to set auto topic creation settings at the namespace level
PR apache#6685 is a fix to take into account the auto topic creation setting when creating a subscription
but it uses the broker configuration and doesn't see the namespace level setting that was introduced in apache#6471

This fix uses the   method that fetches config overrides in ZK instead of the one from the broker configuration.
This way the  method of the pulsar-admin uses the value set for the namespace for auto-topic-creation
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/broker release/2.5.2 type/feature The PR added a new feature or issue requested a new feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Enable/disable allowAutoTopicCreation per namespace
5 participants