You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pulsar.apache.org by GitBox <gi...@apache.org> on 2021/10/29 12:49:30 UTC
[GitHub] [pulsar] madhavan-narayanan opened a new pull request #12536: [pulsar-broker]
madhavan-narayanan opened a new pull request #12536:
URL: https://github.com/apache/pulsar/pull/12536
<!--
### Contribution Checklist
- Name the pull request in the form "[Issue XYZ][component] Title of the pull request", where *XYZ* should be replaced by the actual issue number.
Skip *Issue XYZ* if there is no associated github issue for this pull request.
Skip *component* if you are unsure about which is the best component. E.g. `[docs] Fix typo in produce method`.
- Fill out the template below to describe the changes contributed by the pull request. That will give reviewers the context they need to do the review.
- Each pull request should address only one issue, not mix up code from multiple issues.
- Each commit in the pull request has a meaningful commit message
- Once all items of the checklist are addressed, remove the above text and this checklist, leaving only the filled out template below.
**(The sections below can be removed for hotfixes of typos)**
-->
### Motivation
Operators of enterprise Pulsar cluster(s) would need the flexibility and control to intercept broker events (including ledger writes/reads) for template validations, observability and access control. This changeset contains enhancements to existing interceptor mechanism to support this
### Modifications
- Enhanced org.apache.pulsar.broker.intercept.BrokerInterceptor interface to include additional events for tracing
- Created a new interface org.apache.pulsar.common.intercept.MessagePayloadProcessor to allow interception of ledger write/read operations
- Enhanced PulsarAdmin to give operators a control in managing super-users
### Verifying this change
- [x ] Make sure that the change passes the CI checks.
This change added tests and can be verified as follows:
- *Added new test cases to MangedLedgerInterceptorImplTest.java and BrokerInterceptorTest.java *
### Does this pull request potentially affect one of the following parts:
*If `yes` was chosen, please highlight the changes*
- Dependencies (does it add or upgrade a dependency): no
- The public API: no
- The schema: no
- The default values of configurations: no
- The wire protocol: no
- The rest endpoints: no
- The admin cli options: no
- Anything that affects deployment: no
### Documentation
Check the box below and label this PR (if you have committer privilege).
Need to update docs?
- [ ] `doc-required`
(If you need help on updating docs, create a doc issue)
- [x] `no-need-doc`
(Please explain why)
- [ ] `doc`
(If this PR contains doc changes)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@pulsar.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [pulsar] madhavan-narayanan commented on pull request #12536: [pulsar-broker] Broker extensions to allow operators of enterprise wide cluster better control and flexibility
Posted by GitBox <gi...@apache.org>.
madhavan-narayanan commented on pull request #12536:
URL: https://github.com/apache/pulsar/pull/12536#issuecomment-966197459
> > @madhavan-narayanan It should be good to start with a proposal for this new feature, I noticed there are new API introduced. For starting a proposal for Pulsar, you can check https://lists.apache.org/thread/m8dr0hz7qn7rkd48bcp430lcq2q3674g
>
> @codelipenghui , thanks for your comment. I will start a proposal as you suggested.
Created a feature request https://github.com/apache/pulsar/issues/12752
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@pulsar.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [pulsar] codelipenghui commented on pull request #12536: [pulsar-broker] Broker extensions to allow operators of enterprise wide cluster better control and flexibility
Posted by GitBox <gi...@apache.org>.
codelipenghui commented on pull request #12536:
URL: https://github.com/apache/pulsar/pull/12536#issuecomment-993211390
Thanks for your great work @madhavan-narayanan.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@pulsar.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [pulsar] madhavan-narayanan closed pull request #12536: [pulsar-broker] Broker extensions to allow operators of enterprise wide cluster better control and flexibility
Posted by GitBox <gi...@apache.org>.
madhavan-narayanan closed pull request #12536:
URL: https://github.com/apache/pulsar/pull/12536
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@pulsar.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [pulsar] madhavan-narayanan commented on pull request #12536: [pulsar-broker] Broker extensions to allow operators of enterprise wide cluster better control and flexibility
Posted by GitBox <gi...@apache.org>.
madhavan-narayanan commented on pull request #12536:
URL: https://github.com/apache/pulsar/pull/12536#issuecomment-992575196
> @madhavan-narayanan The change looks good overall, I have left some comments, PTAL. And please help resolve the conflicts. Thanks.
@codelipenghui , thanks for the review. I have rebased my branch with latest master and resolved the conflicts. Also incorporated the review comments. However due to the rebase, this PR is showing all intermediate commits, although the merge will involve my changes. Please let know if you can proceed with this or if you want to me to close this PR and raise a new one.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@pulsar.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [pulsar] hangc0276 commented on a change in pull request #12536: [pulsar-broker] Broker extensions to allow operators of enterprise wide cluster better control and flexibility
Posted by GitBox <gi...@apache.org>.
hangc0276 commented on a change in pull request #12536:
URL: https://github.com/apache/pulsar/pull/12536#discussion_r767757778
##########
File path: pulsar-broker/src/main/java/org/apache/pulsar/broker/intercept/ManagedLedgerInterceptorImpl.java
##########
@@ -131,4 +153,47 @@ public void onUpdateManagedLedgerInfo(Map<String, String> propertiesMap) {
}
}
}
+
+ private PayloadProcessorHandle processPayload(Set<ManagedLedgerPayloadProcessor.Processor> processors,
+ Object context, ByteBuf payload) {
+
+ ByteBuf tmpData = payload;
+ final Set<ImmutablePair<ManagedLedgerPayloadProcessor.Processor, ByteBuf>> processedSet = new LinkedHashSet<>();
+ for (ManagedLedgerPayloadProcessor.Processor payloadProcessor : processors) {
+ if (payloadProcessor != null) {
+ tmpData = payloadProcessor.process(context, tmpData);
+ processedSet.add(new ImmutablePair<>(payloadProcessor, tmpData));
+ }
+ }
+ final ByteBuf dataToReturn = tmpData;
+ return new PayloadProcessorHandle() {
+ @Override
+ public ByteBuf getProcessedPayload() {
+ return dataToReturn;
+ }
+
+ @Override
+ public void release() {
+ for (ImmutablePair<ManagedLedgerPayloadProcessor.Processor, ByteBuf> p : processedSet) {
+ p.left.release(p.right);
Review comment:
different payloadProcessor referenced to the same ByteBuf. And the same ByteBuf will be released multi times.
Additionally, we only need to record the final ByteBuf.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@pulsar.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [pulsar] codelipenghui commented on pull request #12536: [pulsar-broker] Broker extensions to allow operators of enterprise wide cluster better control and flexibility
Posted by GitBox <gi...@apache.org>.
codelipenghui commented on pull request #12536:
URL: https://github.com/apache/pulsar/pull/12536#issuecomment-993059236
@madhavan-narayanan I think you forget to add --force after rebase your branch? :)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@pulsar.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [pulsar] madhavan-narayanan commented on a change in pull request #12536: [pulsar-broker] Broker extensions to allow operators of enterprise wide cluster better control and flexibility
Posted by GitBox <gi...@apache.org>.
madhavan-narayanan commented on a change in pull request #12536:
URL: https://github.com/apache/pulsar/pull/12536#discussion_r767794480
##########
File path: pulsar-broker/src/main/java/org/apache/pulsar/broker/service/Producer.java
##########
@@ -307,6 +308,7 @@ public TransportCnx getCnx() {
}
private static final class MessagePublishContext implements PublishContext, Runnable {
+ Map<String, Object> propertyMap = new HashMap<>();
Review comment:
Done. propertyMap is created only when needed
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@pulsar.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [pulsar] github-actions[bot] commented on pull request #12536: [pulsar-broker]
Posted by GitBox <gi...@apache.org>.
github-actions[bot] commented on pull request #12536:
URL: https://github.com/apache/pulsar/pull/12536#issuecomment-954716943
@madhavan-narayanan:Thanks for providing doc info!
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@pulsar.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [pulsar] merlimat commented on a change in pull request #12536: [pulsar-broker] Broker extensions to allow operators of enterprise wide cluster better control and flexibility
Posted by GitBox <gi...@apache.org>.
merlimat commented on a change in pull request #12536:
URL: https://github.com/apache/pulsar/pull/12536#discussion_r742145102
##########
File path: managed-ledger/src/main/java/org/apache/bookkeeper/mledger/ManagedLedgerConfig.java
##########
@@ -77,6 +77,7 @@
private int newEntriesCheckDelayInMillis = 10;
private Clock clock = Clock.systemUTC();
private ManagedLedgerInterceptor managedLedgerInterceptor;
+ private ManagedLedgerInterceptor managedLedgerPayloadProcessor;
Review comment:
If we're using the same interface, couldn't we have a single `managedLedgerInterceptor` instance>
##########
File path: pulsar-broker/src/main/java/org/apache/pulsar/broker/intercept/BrokerInterceptors.java
##########
@@ -102,6 +108,78 @@ public void beforeSendMessage(Subscription subscription,
}
}
+ @Override
+ public void consumerCreated(ServerCnx cnx,
+ Consumer consumer,
+ Map<String, String> metadata) {
+ for (BrokerInterceptorWithClassLoader value : interceptors.values()) {
Review comment:
I know this was already the style of other methods here, though we should try to avoid the allocation of an iterator instance in the case where there are no interceptors. eg:
```java
if (interceptors.isEmpty()) {
return;
}
for (BrokerInterceptorWithClassLoader value : interceptors.values()) {
// ....
}
```
##########
File path: managed-ledger/src/main/java/org/apache/bookkeeper/mledger/impl/EntryCacheImpl.java
##########
@@ -221,7 +221,7 @@ private void asyncReadEntry0(ReadHandle lh, PositionImpl position, final ReadEnt
Iterator<LedgerEntry> iterator = ledgerEntries.iterator();
if (iterator.hasNext()) {
LedgerEntry ledgerEntry = iterator.next();
- EntryImpl returnEntry = EntryImpl.create(ledgerEntry);
+ EntryImpl returnEntry = EntryImpl.create(ledgerEntry, ml.getConfig().getManagedLedgerPayloadProcessor());
Review comment:
Maybe we can store the interceptor as a member variable of `EntryCacheImpl`.
##########
File path: pulsar-client-admin-api/src/main/java/org/apache/pulsar/client/admin/PulsarAdminBuilder.java
##########
@@ -264,4 +264,11 @@ PulsarAdminBuilder authentication(String authPluginClassName, Map<String, String
*/
PulsarAdminBuilder setContextClassLoader(ClassLoader clientBuilderClassLoader);
+ /**
+ * Set extra headers.
+ * @param extraClientHeaders
+ * @return
+ */
+ PulsarAdminBuilder extraClientHeaders(String extraClientHeaders);
Review comment:
I think this change should go in a separate PR since it's a bit different from the payload interceptor change.
Also, it's not clear from API perspective how the extra headers are going to be used and what is the format of that string is.
##########
File path: pulsar-broker/src/main/java/org/apache/pulsar/broker/service/Producer.java
##########
@@ -307,6 +308,7 @@ public TransportCnx getCnx() {
}
private static final class MessagePublishContext implements PublishContext, Runnable {
+ Map<String, Object> propertyMap = new HashMap<>();
Review comment:
It's not clear why we need to use the property map here and we should try to avoid the allocation if it's not being used.
##########
File path: pulsar-broker/src/main/java/org/apache/pulsar/broker/intercept/ManagedLedgerPayloadProcessor.java
##########
@@ -0,0 +1,91 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.pulsar.broker.intercept;
+
+import io.netty.buffer.ByteBuf;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Set;
+import java.util.concurrent.CompletableFuture;
+import org.apache.bookkeeper.client.LedgerHandle;
+import org.apache.bookkeeper.mledger.impl.OpAddEntry;
+import org.apache.bookkeeper.mledger.intercept.ManagedLedgerInterceptor;
+import org.apache.pulsar.broker.ServiceConfiguration;
+import org.apache.pulsar.broker.service.Topic;
+import org.apache.pulsar.common.intercept.MessagePayloadProcessor;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class ManagedLedgerPayloadProcessor implements ManagedLedgerInterceptor {
+ private static final Logger log = LoggerFactory.getLogger(ManagedLedgerPayloadProcessor.class);
+ private static final String INDEX = "index";
+ private ServiceConfiguration serviceConfig;
+
+
+ private final Set<MessagePayloadProcessor> brokerEntryPayloadProcessors;
+ public ManagedLedgerPayloadProcessor(ServiceConfiguration serviceConfig,
+ Set<MessagePayloadProcessor> brokerEntryPayloadProcessors) {
+ this.serviceConfig = serviceConfig;
+ this.brokerEntryPayloadProcessors = brokerEntryPayloadProcessors;
+ }
+ @Override
+ public OpAddEntry beforeAddEntry(OpAddEntry op, int numberOfMessages) {
+ return null;
+ }
+ @Override
+ public ByteBuf beforeStoreEntryToLedger(OpAddEntry op, ByteBuf ledgerData) {
+ Map<String, Object> contextMap = new HashMap<>();
+ ByteBuf dataToStore = ledgerData;
+
+ for (MessagePayloadProcessor payloadProcessor : brokerEntryPayloadProcessors) {
+ dataToStore = payloadProcessor.interceptIn(
+ serviceConfig.getClusterName(),
+ dataToStore, contextMap);
+ if (op.getCtx() instanceof Topic.PublishContext){
+ Topic.PublishContext ctx = (Topic.PublishContext) op.getCtx();
+ contextMap.forEach((k, v) -> {
+ ctx.setProperty(k, v);
+ });
+ }
+ }
+ return dataToStore;
+ }
+
+ @Override
+ public ByteBuf beforeCacheEntryFromLedger(ByteBuf ledgerData){
+ ByteBuf dataToCache = ledgerData;
+ for (MessagePayloadProcessor payloadProcessor : brokerEntryPayloadProcessors) {
+ dataToCache = payloadProcessor.interceptOut(dataToCache);
+ }
+ return dataToCache;
+ }
+
+ @Override
+ public void onManagedLedgerPropertiesInitialize(Map<String, String> propertiesMap) {
+ }
+ @Override
+ public CompletableFuture<Void> onManagedLedgerLastLedgerInitialize(String name, LedgerHandle lh) {
+ CompletableFuture<Void> promise = new CompletableFuture<>();
+ promise.complete(null);
+ return promise;
Review comment:
```suggestion
return CompletableFuture.completedFuture(null);
```
##########
File path: managed-ledger/src/main/java/org/apache/bookkeeper/mledger/intercept/ManagedLedgerInterceptor.java
##########
@@ -58,4 +59,23 @@
* @param propertiesMap map of properties.
*/
void onUpdateManagedLedgerInfo(Map<String, String> propertiesMap);
+
+ /**
+ * Intercept after entry is read from ledger, before it gets cached.
+ * @param ledgerData data from ledger
+ * @return data after processing, if any
+ */
+ default ByteBuf beforeCacheEntryFromLedger(ByteBuf ledgerData){
Review comment:
I think we need to be very explicit here (and careful :) ) on the reference-count expectations here for the buffers, to avoid memory leaks or use-after-destroyed scenarios.
##########
File path: pulsar-broker/src/main/java/org/apache/pulsar/broker/service/ServerCnx.java
##########
@@ -1420,11 +1435,15 @@ protected void handleAck(CommandAck ack) {
final long consumerId = ack.getConsumerId();
if (consumerFuture != null && consumerFuture.isDone() && !consumerFuture.isCompletedExceptionally()) {
+ Consumer consumer = consumerFuture.getNow(null);
Review comment:
Since we have the `consumer` variable here, we can also change the next line to avoid doing `getNow()` again.
##########
File path: pulsar-broker/src/main/java/org/apache/pulsar/broker/intercept/BrokerInterceptors.java
##########
@@ -102,6 +108,78 @@ public void beforeSendMessage(Subscription subscription,
}
}
+ @Override
+ public void consumerCreated(ServerCnx cnx,
+ Consumer consumer,
+ Map<String, String> metadata) {
+ for (BrokerInterceptorWithClassLoader value : interceptors.values()) {
+ value.consumerCreated(
+ cnx,
+ consumer,
+ metadata);
+ }
+ }
+
+ @Override
+ public void producerCreated(ServerCnx cnx, Producer producer,
+ Map<String, String> metadata){
+ for (BrokerInterceptorWithClassLoader value : interceptors.values()) {
+ value.producerCreated(cnx, producer, metadata);
+ }
+ }
+
+ @Override
+ public void messageProduced(ServerCnx cnx, Producer producer, long startTimeNs, long ledgerId,
+ long entryId, Rate rateIn,
+ Topic.PublishContext publishContext) {
+ for (BrokerInterceptorWithClassLoader value : interceptors.values()) {
+ value.messageProduced(cnx, producer, startTimeNs, ledgerId, entryId, rateIn, publishContext);
+ }
+ }
+
+ @Override
+ public void messageDispatched(ServerCnx cnx, Consumer consumer, long ledgerId,
+ long entryId, ByteBuf headersAndPayload) {
+ for (BrokerInterceptorWithClassLoader value : interceptors.values()) {
+ value.messageDispatched(cnx, consumer, ledgerId, entryId, headersAndPayload);
+ }
+ }
+
+ @Override
+ public void messageAcked(ServerCnx cnx, Consumer consumer,
+ CommandAck ackCmd) {
+ for (BrokerInterceptorWithClassLoader value : interceptors.values()) {
+ value.messageAcked(cnx, consumer, ackCmd);
+ }
+ }
+
+ @Override
+ public boolean delegateSuperUserCheck(){
+ for (BrokerInterceptorWithClassLoader value : interceptors.values()) {
+ if (value.delegateSuperUserCheck()) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ @Override
+ public boolean isSuperUser(PulsarService pulsarService, String appId, String originalPrincipal){
Review comment:
I think this would be more suitable to custom authorization provider, where there is already the `isSuperUser()` method.
##########
File path: managed-ledger/src/main/java/org/apache/bookkeeper/mledger/impl/EntryImpl.java
##########
@@ -47,12 +48,22 @@ protected EntryImpl newObject(Handle<EntryImpl> handle) {
ByteBuf data;
public static EntryImpl create(LedgerEntry ledgerEntry) {
+ return create(ledgerEntry,null);
+ }
+
+ public static EntryImpl create(LedgerEntry ledgerEntry, ManagedLedgerInterceptor managedLedgerInterceptor) {
EntryImpl entry = RECYCLER.get();
entry.timestamp = System.nanoTime();
entry.ledgerId = ledgerEntry.getLedgerId();
entry.entryId = ledgerEntry.getEntryId();
entry.data = ledgerEntry.getEntryBuffer();
- entry.data.retain();
+ ByteBuf cacheBuf = entry.data;
+ if(managedLedgerInterceptor != null)
+ cacheBuf = managedLedgerInterceptor.beforeCacheEntryFromLedger(entry.data);
+ if(cacheBuf != null && cacheBuf != entry.data)
+ entry.data = cacheBuf;
+ else
+ entry.data.retain();
Review comment:
Instead of checking the equality of the buffer instance, the interceptor should have a well defined semantic on the expectation of the reference count of the returned buffer.
##########
File path: managed-ledger/src/main/java/org/apache/bookkeeper/mledger/ManagedLedgerConfig.java
##########
@@ -77,6 +77,7 @@
private int newEntriesCheckDelayInMillis = 10;
private Clock clock = Clock.systemUTC();
private ManagedLedgerInterceptor managedLedgerInterceptor;
+ private ManagedLedgerInterceptor managedLedgerPayloadProcessor;
Review comment:
If we're using the same interface, couldn't we have a single `managedLedgerInterceptor` instance>
##########
File path: pulsar-broker/src/main/java/org/apache/pulsar/broker/intercept/BrokerInterceptors.java
##########
@@ -102,6 +108,78 @@ public void beforeSendMessage(Subscription subscription,
}
}
+ @Override
+ public void consumerCreated(ServerCnx cnx,
+ Consumer consumer,
+ Map<String, String> metadata) {
+ for (BrokerInterceptorWithClassLoader value : interceptors.values()) {
Review comment:
I know this was already the style of other methods here, though we should try to avoid the allocation of an iterator instance in the case where there are no interceptors. eg:
```java
if (interceptors.isEmpty()) {
return;
}
for (BrokerInterceptorWithClassLoader value : interceptors.values()) {
// ....
}
```
##########
File path: managed-ledger/src/main/java/org/apache/bookkeeper/mledger/impl/EntryCacheImpl.java
##########
@@ -221,7 +221,7 @@ private void asyncReadEntry0(ReadHandle lh, PositionImpl position, final ReadEnt
Iterator<LedgerEntry> iterator = ledgerEntries.iterator();
if (iterator.hasNext()) {
LedgerEntry ledgerEntry = iterator.next();
- EntryImpl returnEntry = EntryImpl.create(ledgerEntry);
+ EntryImpl returnEntry = EntryImpl.create(ledgerEntry, ml.getConfig().getManagedLedgerPayloadProcessor());
Review comment:
Maybe we can store the interceptor as a member variable of `EntryCacheImpl`.
##########
File path: pulsar-client-admin-api/src/main/java/org/apache/pulsar/client/admin/PulsarAdminBuilder.java
##########
@@ -264,4 +264,11 @@ PulsarAdminBuilder authentication(String authPluginClassName, Map<String, String
*/
PulsarAdminBuilder setContextClassLoader(ClassLoader clientBuilderClassLoader);
+ /**
+ * Set extra headers.
+ * @param extraClientHeaders
+ * @return
+ */
+ PulsarAdminBuilder extraClientHeaders(String extraClientHeaders);
Review comment:
I think this change should go in a separate PR since it's a bit different from the payload interceptor change.
Also, it's not clear from API perspective how the extra headers are going to be used and what is the format of that string is.
##########
File path: pulsar-broker/src/main/java/org/apache/pulsar/broker/service/Producer.java
##########
@@ -307,6 +308,7 @@ public TransportCnx getCnx() {
}
private static final class MessagePublishContext implements PublishContext, Runnable {
+ Map<String, Object> propertyMap = new HashMap<>();
Review comment:
It's not clear why we need to use the property map here and we should try to avoid the allocation if it's not being used.
##########
File path: pulsar-broker/src/main/java/org/apache/pulsar/broker/intercept/ManagedLedgerPayloadProcessor.java
##########
@@ -0,0 +1,91 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.pulsar.broker.intercept;
+
+import io.netty.buffer.ByteBuf;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Set;
+import java.util.concurrent.CompletableFuture;
+import org.apache.bookkeeper.client.LedgerHandle;
+import org.apache.bookkeeper.mledger.impl.OpAddEntry;
+import org.apache.bookkeeper.mledger.intercept.ManagedLedgerInterceptor;
+import org.apache.pulsar.broker.ServiceConfiguration;
+import org.apache.pulsar.broker.service.Topic;
+import org.apache.pulsar.common.intercept.MessagePayloadProcessor;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class ManagedLedgerPayloadProcessor implements ManagedLedgerInterceptor {
+ private static final Logger log = LoggerFactory.getLogger(ManagedLedgerPayloadProcessor.class);
+ private static final String INDEX = "index";
+ private ServiceConfiguration serviceConfig;
+
+
+ private final Set<MessagePayloadProcessor> brokerEntryPayloadProcessors;
+ public ManagedLedgerPayloadProcessor(ServiceConfiguration serviceConfig,
+ Set<MessagePayloadProcessor> brokerEntryPayloadProcessors) {
+ this.serviceConfig = serviceConfig;
+ this.brokerEntryPayloadProcessors = brokerEntryPayloadProcessors;
+ }
+ @Override
+ public OpAddEntry beforeAddEntry(OpAddEntry op, int numberOfMessages) {
+ return null;
+ }
+ @Override
+ public ByteBuf beforeStoreEntryToLedger(OpAddEntry op, ByteBuf ledgerData) {
+ Map<String, Object> contextMap = new HashMap<>();
+ ByteBuf dataToStore = ledgerData;
+
+ for (MessagePayloadProcessor payloadProcessor : brokerEntryPayloadProcessors) {
+ dataToStore = payloadProcessor.interceptIn(
+ serviceConfig.getClusterName(),
+ dataToStore, contextMap);
+ if (op.getCtx() instanceof Topic.PublishContext){
+ Topic.PublishContext ctx = (Topic.PublishContext) op.getCtx();
+ contextMap.forEach((k, v) -> {
+ ctx.setProperty(k, v);
+ });
+ }
+ }
+ return dataToStore;
+ }
+
+ @Override
+ public ByteBuf beforeCacheEntryFromLedger(ByteBuf ledgerData){
+ ByteBuf dataToCache = ledgerData;
+ for (MessagePayloadProcessor payloadProcessor : brokerEntryPayloadProcessors) {
+ dataToCache = payloadProcessor.interceptOut(dataToCache);
+ }
+ return dataToCache;
+ }
+
+ @Override
+ public void onManagedLedgerPropertiesInitialize(Map<String, String> propertiesMap) {
+ }
+ @Override
+ public CompletableFuture<Void> onManagedLedgerLastLedgerInitialize(String name, LedgerHandle lh) {
+ CompletableFuture<Void> promise = new CompletableFuture<>();
+ promise.complete(null);
+ return promise;
Review comment:
```suggestion
return CompletableFuture.completedFuture(null);
```
##########
File path: managed-ledger/src/main/java/org/apache/bookkeeper/mledger/intercept/ManagedLedgerInterceptor.java
##########
@@ -58,4 +59,23 @@
* @param propertiesMap map of properties.
*/
void onUpdateManagedLedgerInfo(Map<String, String> propertiesMap);
+
+ /**
+ * Intercept after entry is read from ledger, before it gets cached.
+ * @param ledgerData data from ledger
+ * @return data after processing, if any
+ */
+ default ByteBuf beforeCacheEntryFromLedger(ByteBuf ledgerData){
Review comment:
I think we need to be very explicit here (and careful :) ) on the reference-count expectations here for the buffers, to avoid memory leaks or use-after-destroyed scenarios.
##########
File path: pulsar-broker/src/main/java/org/apache/pulsar/broker/service/ServerCnx.java
##########
@@ -1420,11 +1435,15 @@ protected void handleAck(CommandAck ack) {
final long consumerId = ack.getConsumerId();
if (consumerFuture != null && consumerFuture.isDone() && !consumerFuture.isCompletedExceptionally()) {
+ Consumer consumer = consumerFuture.getNow(null);
Review comment:
Since we have the `consumer` variable here, we can also change the next line to avoid doing `getNow()` again.
##########
File path: pulsar-broker/src/main/java/org/apache/pulsar/broker/intercept/BrokerInterceptors.java
##########
@@ -102,6 +108,78 @@ public void beforeSendMessage(Subscription subscription,
}
}
+ @Override
+ public void consumerCreated(ServerCnx cnx,
+ Consumer consumer,
+ Map<String, String> metadata) {
+ for (BrokerInterceptorWithClassLoader value : interceptors.values()) {
+ value.consumerCreated(
+ cnx,
+ consumer,
+ metadata);
+ }
+ }
+
+ @Override
+ public void producerCreated(ServerCnx cnx, Producer producer,
+ Map<String, String> metadata){
+ for (BrokerInterceptorWithClassLoader value : interceptors.values()) {
+ value.producerCreated(cnx, producer, metadata);
+ }
+ }
+
+ @Override
+ public void messageProduced(ServerCnx cnx, Producer producer, long startTimeNs, long ledgerId,
+ long entryId, Rate rateIn,
+ Topic.PublishContext publishContext) {
+ for (BrokerInterceptorWithClassLoader value : interceptors.values()) {
+ value.messageProduced(cnx, producer, startTimeNs, ledgerId, entryId, rateIn, publishContext);
+ }
+ }
+
+ @Override
+ public void messageDispatched(ServerCnx cnx, Consumer consumer, long ledgerId,
+ long entryId, ByteBuf headersAndPayload) {
+ for (BrokerInterceptorWithClassLoader value : interceptors.values()) {
+ value.messageDispatched(cnx, consumer, ledgerId, entryId, headersAndPayload);
+ }
+ }
+
+ @Override
+ public void messageAcked(ServerCnx cnx, Consumer consumer,
+ CommandAck ackCmd) {
+ for (BrokerInterceptorWithClassLoader value : interceptors.values()) {
+ value.messageAcked(cnx, consumer, ackCmd);
+ }
+ }
+
+ @Override
+ public boolean delegateSuperUserCheck(){
+ for (BrokerInterceptorWithClassLoader value : interceptors.values()) {
+ if (value.delegateSuperUserCheck()) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ @Override
+ public boolean isSuperUser(PulsarService pulsarService, String appId, String originalPrincipal){
Review comment:
I think this would be more suitable to custom authorization provider, where there is already the `isSuperUser()` method.
##########
File path: managed-ledger/src/main/java/org/apache/bookkeeper/mledger/impl/EntryImpl.java
##########
@@ -47,12 +48,22 @@ protected EntryImpl newObject(Handle<EntryImpl> handle) {
ByteBuf data;
public static EntryImpl create(LedgerEntry ledgerEntry) {
+ return create(ledgerEntry,null);
+ }
+
+ public static EntryImpl create(LedgerEntry ledgerEntry, ManagedLedgerInterceptor managedLedgerInterceptor) {
EntryImpl entry = RECYCLER.get();
entry.timestamp = System.nanoTime();
entry.ledgerId = ledgerEntry.getLedgerId();
entry.entryId = ledgerEntry.getEntryId();
entry.data = ledgerEntry.getEntryBuffer();
- entry.data.retain();
+ ByteBuf cacheBuf = entry.data;
+ if(managedLedgerInterceptor != null)
+ cacheBuf = managedLedgerInterceptor.beforeCacheEntryFromLedger(entry.data);
+ if(cacheBuf != null && cacheBuf != entry.data)
+ entry.data = cacheBuf;
+ else
+ entry.data.retain();
Review comment:
Instead of checking the equality of the buffer instance, the interceptor should have a well defined semantic on the expectation of the reference count of the returned buffer.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@pulsar.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [pulsar] hangc0276 commented on pull request #12536: [pulsar-broker] Broker extensions to allow operators of enterprise wide cluster better control and flexibility
Posted by GitBox <gi...@apache.org>.
hangc0276 commented on pull request #12536:
URL: https://github.com/apache/pulsar/pull/12536#issuecomment-992539264
@madhavan-narayanan Would you please cleanup the not related commits?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@pulsar.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [pulsar] madhavan-narayanan commented on a change in pull request #12536: [pulsar-broker] Broker extensions to allow operators of enterprise wide cluster better control and flexibility
Posted by GitBox <gi...@apache.org>.
madhavan-narayanan commented on a change in pull request #12536:
URL: https://github.com/apache/pulsar/pull/12536#discussion_r767796452
##########
File path: managed-ledger/src/main/java/org/apache/bookkeeper/mledger/intercept/ManagedLedgerInterceptor.java
##########
@@ -58,4 +59,23 @@
* @param propertiesMap map of properties.
*/
void onUpdateManagedLedgerInfo(Map<String, String> propertiesMap);
+
+ /**
+ * Intercept after entry is read from ledger, before it gets cached.
+ * @param ledgerData data from ledger
+ * @return data after processing, if any
+ */
+ default ByteBuf beforeCacheEntryFromLedger(ByteBuf ledgerData){
Review comment:
Agree. The interface is better defined and documented now
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@pulsar.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [pulsar] madhavan-narayanan commented on a change in pull request #12536: [pulsar-broker] Broker extensions to allow operators of enterprise wide cluster better control and flexibility
Posted by GitBox <gi...@apache.org>.
madhavan-narayanan commented on a change in pull request #12536:
URL: https://github.com/apache/pulsar/pull/12536#discussion_r767796775
##########
File path: pulsar-broker/src/main/java/org/apache/pulsar/broker/intercept/BrokerInterceptors.java
##########
@@ -102,6 +108,78 @@ public void beforeSendMessage(Subscription subscription,
}
}
+ @Override
+ public void consumerCreated(ServerCnx cnx,
+ Consumer consumer,
+ Map<String, String> metadata) {
+ for (BrokerInterceptorWithClassLoader value : interceptors.values()) {
+ value.consumerCreated(
+ cnx,
+ consumer,
+ metadata);
+ }
+ }
+
+ @Override
+ public void producerCreated(ServerCnx cnx, Producer producer,
+ Map<String, String> metadata){
+ for (BrokerInterceptorWithClassLoader value : interceptors.values()) {
+ value.producerCreated(cnx, producer, metadata);
+ }
+ }
+
+ @Override
+ public void messageProduced(ServerCnx cnx, Producer producer, long startTimeNs, long ledgerId,
+ long entryId, Rate rateIn,
+ Topic.PublishContext publishContext) {
+ for (BrokerInterceptorWithClassLoader value : interceptors.values()) {
+ value.messageProduced(cnx, producer, startTimeNs, ledgerId, entryId, rateIn, publishContext);
+ }
+ }
+
+ @Override
+ public void messageDispatched(ServerCnx cnx, Consumer consumer, long ledgerId,
+ long entryId, ByteBuf headersAndPayload) {
+ for (BrokerInterceptorWithClassLoader value : interceptors.values()) {
+ value.messageDispatched(cnx, consumer, ledgerId, entryId, headersAndPayload);
+ }
+ }
+
+ @Override
+ public void messageAcked(ServerCnx cnx, Consumer consumer,
+ CommandAck ackCmd) {
+ for (BrokerInterceptorWithClassLoader value : interceptors.values()) {
+ value.messageAcked(cnx, consumer, ackCmd);
+ }
+ }
+
+ @Override
+ public boolean delegateSuperUserCheck(){
+ for (BrokerInterceptorWithClassLoader value : interceptors.values()) {
+ if (value.delegateSuperUserCheck()) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ @Override
+ public boolean isSuperUser(PulsarService pulsarService, String appId, String originalPrincipal){
Review comment:
Removed from the changeset
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@pulsar.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [pulsar] madhavan-narayanan commented on pull request #12536: [pulsar-broker] Broker extensions to allow operators of enterprise wide cluster better control and flexibility
Posted by GitBox <gi...@apache.org>.
madhavan-narayanan commented on pull request #12536:
URL: https://github.com/apache/pulsar/pull/12536#issuecomment-959734005
> @madhavan-narayanan It should be good to start with a proposal for this new feature, I noticed there are new API introduced. For starting a proposal for Pulsar, you can check https://lists.apache.org/thread/m8dr0hz7qn7rkd48bcp430lcq2q3674g
@codelipenghui , thanks for your comment. I will start a proposal as you suggested.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@pulsar.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [pulsar] madhavan-narayanan commented on pull request #12536: [pulsar-broker] Broker extensions to allow operators of enterprise wide cluster better control and flexibility
Posted by GitBox <gi...@apache.org>.
madhavan-narayanan commented on pull request #12536:
URL: https://github.com/apache/pulsar/pull/12536#issuecomment-959734005
> @madhavan-narayanan It should be good to start with a proposal for this new feature, I noticed there are new API introduced. For starting a proposal for Pulsar, you can check https://lists.apache.org/thread/m8dr0hz7qn7rkd48bcp430lcq2q3674g
@codelipenghui , thanks for your comment. I will start a proposal as you suggested.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@pulsar.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [pulsar] codelipenghui commented on pull request #12536: [pulsar-broker] Broker extensions to allow operators of enterprise wide cluster better control and flexibility
Posted by GitBox <gi...@apache.org>.
codelipenghui commented on pull request #12536:
URL: https://github.com/apache/pulsar/pull/12536#issuecomment-966367464
@madhavan-narayanan Thanks.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@pulsar.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [pulsar] madhavan-narayanan commented on a change in pull request #12536: [pulsar-broker] Broker extensions to allow operators of enterprise wide cluster better control and flexibility
Posted by GitBox <gi...@apache.org>.
madhavan-narayanan commented on a change in pull request #12536:
URL: https://github.com/apache/pulsar/pull/12536#discussion_r767796154
##########
File path: managed-ledger/src/main/java/org/apache/bookkeeper/mledger/impl/EntryImpl.java
##########
@@ -47,12 +48,22 @@ protected EntryImpl newObject(Handle<EntryImpl> handle) {
ByteBuf data;
public static EntryImpl create(LedgerEntry ledgerEntry) {
+ return create(ledgerEntry,null);
+ }
+
+ public static EntryImpl create(LedgerEntry ledgerEntry, ManagedLedgerInterceptor managedLedgerInterceptor) {
EntryImpl entry = RECYCLER.get();
entry.timestamp = System.nanoTime();
entry.ledgerId = ledgerEntry.getLedgerId();
entry.entryId = ledgerEntry.getEntryId();
entry.data = ledgerEntry.getEntryBuffer();
- entry.data.retain();
+ ByteBuf cacheBuf = entry.data;
+ if(managedLedgerInterceptor != null)
+ cacheBuf = managedLedgerInterceptor.beforeCacheEntryFromLedger(entry.data);
+ if(cacheBuf != null && cacheBuf != entry.data)
+ entry.data = cacheBuf;
+ else
+ entry.data.retain();
Review comment:
Done.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@pulsar.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [pulsar] codelipenghui commented on pull request #12536: [pulsar-broker] Broker extensions to allow operators of enterprise wide cluster better control and flexibility
Posted by GitBox <gi...@apache.org>.
codelipenghui commented on pull request #12536:
URL: https://github.com/apache/pulsar/pull/12536#issuecomment-992372432
@madhavan-narayanan The change looks good overall, I have left some comments, PTAL.
And please help resolve the conflicts. Thanks.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@pulsar.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [pulsar] madhavan-narayanan commented on a change in pull request #12536: [pulsar-broker] Broker extensions to allow operators of enterprise wide cluster better control and flexibility
Posted by GitBox <gi...@apache.org>.
madhavan-narayanan commented on a change in pull request #12536:
URL: https://github.com/apache/pulsar/pull/12536#discussion_r768251711
##########
File path: pulsar-broker/src/main/java/org/apache/pulsar/broker/intercept/BrokerInterceptor.java
##########
@@ -58,6 +65,66 @@ default void beforeSendMessage(Subscription subscription,
MessageMetadata msgMetadata) {
}
+ /**
+ * Called by the broker when a new connection is created.
+ */
+ default void onConnectionCreated(ServerCnx cnx){
+ }
+
+ /**
+ * Called by the broker when a new connection is created.
+ */
+ default void producerCreated(ServerCnx cnx, Producer producer,
+ Map<String, String> metadata){
+ }
+
+ /**
+ * Intercept after a consumer is created.
+ *
+ * @param cnx client Connection
+ * @param consumer Consumer object
+ * @param metadata A map of metdata
+ */
+ default void consumerCreated(ServerCnx cnx,
+ Consumer consumer,
+ Map<String, String> metadata) {
+ }
+
+ /**
+ * Intercept after a message is produced.
+ *
+ * @param cnx client Connection
+ * @param producer Producer object
+ * @param publishContext Publish Context
+ */
+ default void messageProduced(ServerCnx cnx, Producer producer, long startTimeNs, long ledgerId,
Review comment:
Fix done
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@pulsar.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [pulsar] codelipenghui commented on pull request #12536: [pulsar-broker] Broker extensions to allow operators of enterprise wide cluster better control and flexibility
Posted by GitBox <gi...@apache.org>.
codelipenghui commented on pull request #12536:
URL: https://github.com/apache/pulsar/pull/12536#issuecomment-959107261
@madhavan-narayanan It should be good to start with a proposal for this new feature, I noticed there are new API introduced. For starting a proposal for Pulsar, you can check https://lists.apache.org/thread/m8dr0hz7qn7rkd48bcp430lcq2q3674g
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@pulsar.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [pulsar] madhavan-narayanan commented on a change in pull request #12536: [pulsar-broker] Broker extensions to allow operators of enterprise wide cluster better control and flexibility
Posted by GitBox <gi...@apache.org>.
madhavan-narayanan commented on a change in pull request #12536:
URL: https://github.com/apache/pulsar/pull/12536#discussion_r767884699
##########
File path: pulsar-broker/src/main/java/org/apache/pulsar/broker/intercept/ManagedLedgerInterceptorImpl.java
##########
@@ -131,4 +153,47 @@ public void onUpdateManagedLedgerInfo(Map<String, String> propertiesMap) {
}
}
}
+
+ private PayloadProcessorHandle processPayload(Set<ManagedLedgerPayloadProcessor.Processor> processors,
+ Object context, ByteBuf payload) {
+
+ ByteBuf tmpData = payload;
+ final Set<ImmutablePair<ManagedLedgerPayloadProcessor.Processor, ByteBuf>> processedSet = new LinkedHashSet<>();
+ for (ManagedLedgerPayloadProcessor.Processor payloadProcessor : processors) {
+ if (payloadProcessor != null) {
+ tmpData = payloadProcessor.process(context, tmpData);
+ processedSet.add(new ImmutablePair<>(payloadProcessor, tmpData));
+ }
+ }
+ final ByteBuf dataToReturn = tmpData;
+ return new PayloadProcessorHandle() {
+ @Override
+ public ByteBuf getProcessedPayload() {
+ return dataToReturn;
+ }
+
+ @Override
+ public void release() {
+ for (ImmutablePair<ManagedLedgerPayloadProcessor.Processor, ByteBuf> p : processedSet) {
+ p.left.release(p.right);
Review comment:
I have fixed the comments in ManagedLedgerPayloadProcessor::Processor::release to explicitly state that the release is to be done only when process() returned a different ByteBuf instance.
LinkedHashSet is used for the processor set and hence the traversal order is the same as insertion order. The final ByteBuf is indeed recorded
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@pulsar.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [pulsar] madhavan-narayanan commented on a change in pull request #12536: [pulsar-broker] Broker extensions to allow operators of enterprise wide cluster better control and flexibility
Posted by GitBox <gi...@apache.org>.
madhavan-narayanan commented on a change in pull request #12536:
URL: https://github.com/apache/pulsar/pull/12536#discussion_r767795850
##########
File path: pulsar-client-admin-api/src/main/java/org/apache/pulsar/client/admin/PulsarAdminBuilder.java
##########
@@ -264,4 +264,11 @@ PulsarAdminBuilder authentication(String authPluginClassName, Map<String, String
*/
PulsarAdminBuilder setContextClassLoader(ClassLoader clientBuilderClassLoader);
+ /**
+ * Set extra headers.
+ * @param extraClientHeaders
+ * @return
+ */
+ PulsarAdminBuilder extraClientHeaders(String extraClientHeaders);
Review comment:
N/A anymore. Removed from the changeset
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@pulsar.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [pulsar] madhavan-narayanan commented on a change in pull request #12536: [pulsar-broker] Broker extensions to allow operators of enterprise wide cluster better control and flexibility
Posted by GitBox <gi...@apache.org>.
madhavan-narayanan commented on a change in pull request #12536:
URL: https://github.com/apache/pulsar/pull/12536#discussion_r767788514
##########
File path: managed-ledger/src/main/java/org/apache/bookkeeper/mledger/ManagedLedgerConfig.java
##########
@@ -77,6 +77,7 @@
private int newEntriesCheckDelayInMillis = 10;
private Clock clock = Clock.systemUTC();
private ManagedLedgerInterceptor managedLedgerInterceptor;
+ private ManagedLedgerInterceptor managedLedgerPayloadProcessor;
Review comment:
Done
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@pulsar.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [pulsar] hangc0276 commented on a change in pull request #12536: [pulsar-broker] Broker extensions to allow operators of enterprise wide cluster better control and flexibility
Posted by GitBox <gi...@apache.org>.
hangc0276 commented on a change in pull request #12536:
URL: https://github.com/apache/pulsar/pull/12536#discussion_r767610794
##########
File path: pulsar-common/src/main/java/org/apache/pulsar/common/intercept/BrokerEntryMetadataUtils.java
##########
@@ -57,4 +58,28 @@
}
return interceptors;
}
+ public static <T> Set<T> loadInterceptors(
Review comment:
We'd better merge the `loadBrokerEntryMetadataInterceptors` into `loadInterceptors` method.
##########
File path: pulsar-broker/src/main/java/org/apache/pulsar/broker/intercept/BrokerInterceptors.java
##########
@@ -102,6 +108,78 @@ public void beforeSendMessage(Subscription subscription,
}
}
+ @Override
+ public void consumerCreated(ServerCnx cnx,
+ Consumer consumer,
+ Map<String, String> metadata) {
+ for (BrokerInterceptorWithClassLoader value : interceptors.values()) {
Review comment:
+1 please check null or empty first.
##########
File path: pulsar-broker/src/main/java/org/apache/pulsar/broker/intercept/ManagedLedgerInterceptorImpl.java
##########
@@ -38,10 +42,28 @@
private final Set<BrokerEntryMetadataInterceptor> brokerEntryMetadataInterceptors;
+ private final Set<ManagedLedgerPayloadProcessor.Processor> inputProcessors;
+ private final Set<ManagedLedgerPayloadProcessor.Processor> outputProcessors;
public ManagedLedgerInterceptorImpl(Set<BrokerEntryMetadataInterceptor> brokerEntryMetadataInterceptors) {
Review comment:
this method just used by tests, could we remove it?
##########
File path: pulsar-broker/src/main/java/org/apache/pulsar/broker/service/ServerCnx.java
##########
@@ -1420,11 +1435,15 @@ protected void handleAck(CommandAck ack) {
final long consumerId = ack.getConsumerId();
if (consumerFuture != null && consumerFuture.isDone() && !consumerFuture.isCompletedExceptionally()) {
+ Consumer consumer = consumerFuture.getNow(null);
Review comment:
+1
##########
File path: pulsar-broker/src/main/java/org/apache/pulsar/broker/service/Producer.java
##########
@@ -452,6 +479,10 @@ static MessagePublishContext get(Producer producer, long sequenceId, Rate rateIn
callback.originalSequenceId = -1L;
callback.startTimeNs = startTimeNs;
callback.isMarker = isMarker;
+ if (callback.propertyMap != null) {
+ callback.propertyMap.clear();
+ callback.propertyMap = null;
Review comment:
Could we just clear the `propertyMap` to reuse the hashMap object?
##########
File path: pulsar-broker/src/main/java/org/apache/pulsar/broker/service/Consumer.java
##########
@@ -848,6 +848,10 @@ public MessageId getStartMessageId() {
return startMessageId;
}
+ public Map<String, String> getMetadata() {
Review comment:
No usage found of the method
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@pulsar.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [pulsar] madhavan-narayanan commented on a change in pull request #12536: [pulsar-broker] Broker extensions to allow operators of enterprise wide cluster better control and flexibility
Posted by GitBox <gi...@apache.org>.
madhavan-narayanan commented on a change in pull request #12536:
URL: https://github.com/apache/pulsar/pull/12536#discussion_r768244579
##########
File path: pulsar-broker/src/main/java/org/apache/pulsar/broker/intercept/BrokerInterceptor.java
##########
@@ -58,6 +65,66 @@ default void beforeSendMessage(Subscription subscription,
MessageMetadata msgMetadata) {
}
+ /**
+ * Called by the broker when a new connection is created.
+ */
+ default void onConnectionCreated(ServerCnx cnx){
+ }
+
+ /**
+ * Called by the broker when a new connection is created.
+ */
+ default void producerCreated(ServerCnx cnx, Producer producer,
+ Map<String, String> metadata){
+ }
+
+ /**
+ * Intercept after a consumer is created.
+ *
+ * @param cnx client Connection
+ * @param consumer Consumer object
+ * @param metadata A map of metdata
+ */
+ default void consumerCreated(ServerCnx cnx,
+ Consumer consumer,
+ Map<String, String> metadata) {
+ }
+
+ /**
+ * Intercept after a message is produced.
+ *
+ * @param cnx client Connection
+ * @param producer Producer object
+ * @param publishContext Publish Context
+ */
+ default void messageProduced(ServerCnx cnx, Producer producer, long startTimeNs, long ledgerId,
Review comment:
I agree. It was an oversight. I used rateIn as it was readily computed and available in MessagePublishContext::run. I will fix it now
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@pulsar.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [pulsar] github-actions[bot] commented on pull request #12536: [pulsar-broker] Broker extensions to allow operators of enterprise wide cluster better control and flexibility
Posted by GitBox <gi...@apache.org>.
github-actions[bot] commented on pull request #12536:
URL: https://github.com/apache/pulsar/pull/12536#issuecomment-954719223
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@pulsar.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [pulsar] madhavan-narayanan commented on a change in pull request #12536: [pulsar-broker] Broker extensions to allow operators of enterprise wide cluster better control and flexibility
Posted by GitBox <gi...@apache.org>.
madhavan-narayanan commented on a change in pull request #12536:
URL: https://github.com/apache/pulsar/pull/12536#discussion_r767788925
##########
File path: managed-ledger/src/main/java/org/apache/bookkeeper/mledger/impl/EntryCacheImpl.java
##########
@@ -221,7 +221,7 @@ private void asyncReadEntry0(ReadHandle lh, PositionImpl position, final ReadEnt
Iterator<LedgerEntry> iterator = ledgerEntries.iterator();
if (iterator.hasNext()) {
LedgerEntry ledgerEntry = iterator.next();
- EntryImpl returnEntry = EntryImpl.create(ledgerEntry);
+ EntryImpl returnEntry = EntryImpl.create(ledgerEntry, ml.getConfig().getManagedLedgerPayloadProcessor());
Review comment:
Done
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@pulsar.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [pulsar] madhavan-narayanan commented on a change in pull request #12536: [pulsar-broker] Broker extensions to allow operators of enterprise wide cluster better control and flexibility
Posted by GitBox <gi...@apache.org>.
madhavan-narayanan commented on a change in pull request #12536:
URL: https://github.com/apache/pulsar/pull/12536#discussion_r767792636
##########
File path: pulsar-broker/src/main/java/org/apache/pulsar/broker/intercept/BrokerInterceptors.java
##########
@@ -102,6 +108,78 @@ public void beforeSendMessage(Subscription subscription,
}
}
+ @Override
+ public void consumerCreated(ServerCnx cnx,
+ Consumer consumer,
+ Map<String, String> metadata) {
+ for (BrokerInterceptorWithClassLoader value : interceptors.values()) {
Review comment:
Done
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@pulsar.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [pulsar] madhavan-narayanan commented on a change in pull request #12536: [pulsar-broker] Broker extensions to allow operators of enterprise wide cluster better control and flexibility
Posted by GitBox <gi...@apache.org>.
madhavan-narayanan commented on a change in pull request #12536:
URL: https://github.com/apache/pulsar/pull/12536#discussion_r767793800
##########
File path: pulsar-broker/src/main/java/org/apache/pulsar/broker/intercept/ManagedLedgerPayloadProcessor.java
##########
@@ -0,0 +1,91 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.pulsar.broker.intercept;
+
+import io.netty.buffer.ByteBuf;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Set;
+import java.util.concurrent.CompletableFuture;
+import org.apache.bookkeeper.client.LedgerHandle;
+import org.apache.bookkeeper.mledger.impl.OpAddEntry;
+import org.apache.bookkeeper.mledger.intercept.ManagedLedgerInterceptor;
+import org.apache.pulsar.broker.ServiceConfiguration;
+import org.apache.pulsar.broker.service.Topic;
+import org.apache.pulsar.common.intercept.MessagePayloadProcessor;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class ManagedLedgerPayloadProcessor implements ManagedLedgerInterceptor {
+ private static final Logger log = LoggerFactory.getLogger(ManagedLedgerPayloadProcessor.class);
+ private static final String INDEX = "index";
+ private ServiceConfiguration serviceConfig;
+
+
+ private final Set<MessagePayloadProcessor> brokerEntryPayloadProcessors;
+ public ManagedLedgerPayloadProcessor(ServiceConfiguration serviceConfig,
+ Set<MessagePayloadProcessor> brokerEntryPayloadProcessors) {
+ this.serviceConfig = serviceConfig;
+ this.brokerEntryPayloadProcessors = brokerEntryPayloadProcessors;
+ }
+ @Override
+ public OpAddEntry beforeAddEntry(OpAddEntry op, int numberOfMessages) {
+ return null;
+ }
+ @Override
+ public ByteBuf beforeStoreEntryToLedger(OpAddEntry op, ByteBuf ledgerData) {
+ Map<String, Object> contextMap = new HashMap<>();
+ ByteBuf dataToStore = ledgerData;
+
+ for (MessagePayloadProcessor payloadProcessor : brokerEntryPayloadProcessors) {
+ dataToStore = payloadProcessor.interceptIn(
+ serviceConfig.getClusterName(),
+ dataToStore, contextMap);
+ if (op.getCtx() instanceof Topic.PublishContext){
+ Topic.PublishContext ctx = (Topic.PublishContext) op.getCtx();
+ contextMap.forEach((k, v) -> {
+ ctx.setProperty(k, v);
+ });
+ }
+ }
+ return dataToStore;
+ }
+
+ @Override
+ public ByteBuf beforeCacheEntryFromLedger(ByteBuf ledgerData){
+ ByteBuf dataToCache = ledgerData;
+ for (MessagePayloadProcessor payloadProcessor : brokerEntryPayloadProcessors) {
+ dataToCache = payloadProcessor.interceptOut(dataToCache);
+ }
+ return dataToCache;
+ }
+
+ @Override
+ public void onManagedLedgerPropertiesInitialize(Map<String, String> propertiesMap) {
+ }
+ @Override
+ public CompletableFuture<Void> onManagedLedgerLastLedgerInitialize(String name, LedgerHandle lh) {
+ CompletableFuture<Void> promise = new CompletableFuture<>();
+ promise.complete(null);
+ return promise;
Review comment:
N/A with the latest changes. This class doesn't exist anymore
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@pulsar.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [pulsar] madhavan-narayanan commented on a change in pull request #12536: [pulsar-broker] Broker extensions to allow operators of enterprise wide cluster better control and flexibility
Posted by GitBox <gi...@apache.org>.
madhavan-narayanan commented on a change in pull request #12536:
URL: https://github.com/apache/pulsar/pull/12536#discussion_r767808681
##########
File path: pulsar-broker/src/main/java/org/apache/pulsar/broker/service/Consumer.java
##########
@@ -848,6 +848,10 @@ public MessageId getStartMessageId() {
return startMessageId;
}
+ public Map<String, String> getMetadata() {
Review comment:
This method can be used by the implementation of broker interceptor methods 'messageAcked' and 'messageDispatched' to get context information about the consumer and include in trace.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@pulsar.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [pulsar] madhavan-narayanan commented on a change in pull request #12536: [pulsar-broker] Broker extensions to allow operators of enterprise wide cluster better control and flexibility
Posted by GitBox <gi...@apache.org>.
madhavan-narayanan commented on a change in pull request #12536:
URL: https://github.com/apache/pulsar/pull/12536#discussion_r768286071
##########
File path: pulsar-broker-common/src/main/java/org/apache/pulsar/broker/ServiceConfiguration.java
##########
@@ -1089,6 +1089,11 @@
)
private boolean disableBrokerInterceptors = true;
+ @FieldContext(
+ category = CATEGORY_SERVER,
+ doc = "List of interceptors for payload processing.")
+ private Set<String> brokerEntryPayloadProcessors = new java.util.LinkedHashSet<>();
Review comment:
Done
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@pulsar.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [pulsar] merlimat commented on a change in pull request #12536: [pulsar-broker] Broker extensions to allow operators of enterprise wide cluster better control and flexibility
Posted by GitBox <gi...@apache.org>.
merlimat commented on a change in pull request #12536:
URL: https://github.com/apache/pulsar/pull/12536#discussion_r742145102
##########
File path: managed-ledger/src/main/java/org/apache/bookkeeper/mledger/ManagedLedgerConfig.java
##########
@@ -77,6 +77,7 @@
private int newEntriesCheckDelayInMillis = 10;
private Clock clock = Clock.systemUTC();
private ManagedLedgerInterceptor managedLedgerInterceptor;
+ private ManagedLedgerInterceptor managedLedgerPayloadProcessor;
Review comment:
If we're using the same interface, couldn't we have a single `managedLedgerInterceptor` instance>
##########
File path: pulsar-broker/src/main/java/org/apache/pulsar/broker/intercept/BrokerInterceptors.java
##########
@@ -102,6 +108,78 @@ public void beforeSendMessage(Subscription subscription,
}
}
+ @Override
+ public void consumerCreated(ServerCnx cnx,
+ Consumer consumer,
+ Map<String, String> metadata) {
+ for (BrokerInterceptorWithClassLoader value : interceptors.values()) {
Review comment:
I know this was already the style of other methods here, though we should try to avoid the allocation of an iterator instance in the case where there are no interceptors. eg:
```java
if (interceptors.isEmpty()) {
return;
}
for (BrokerInterceptorWithClassLoader value : interceptors.values()) {
// ....
}
```
##########
File path: managed-ledger/src/main/java/org/apache/bookkeeper/mledger/impl/EntryCacheImpl.java
##########
@@ -221,7 +221,7 @@ private void asyncReadEntry0(ReadHandle lh, PositionImpl position, final ReadEnt
Iterator<LedgerEntry> iterator = ledgerEntries.iterator();
if (iterator.hasNext()) {
LedgerEntry ledgerEntry = iterator.next();
- EntryImpl returnEntry = EntryImpl.create(ledgerEntry);
+ EntryImpl returnEntry = EntryImpl.create(ledgerEntry, ml.getConfig().getManagedLedgerPayloadProcessor());
Review comment:
Maybe we can store the interceptor as a member variable of `EntryCacheImpl`.
##########
File path: pulsar-client-admin-api/src/main/java/org/apache/pulsar/client/admin/PulsarAdminBuilder.java
##########
@@ -264,4 +264,11 @@ PulsarAdminBuilder authentication(String authPluginClassName, Map<String, String
*/
PulsarAdminBuilder setContextClassLoader(ClassLoader clientBuilderClassLoader);
+ /**
+ * Set extra headers.
+ * @param extraClientHeaders
+ * @return
+ */
+ PulsarAdminBuilder extraClientHeaders(String extraClientHeaders);
Review comment:
I think this change should go in a separate PR since it's a bit different from the payload interceptor change.
Also, it's not clear from API perspective how the extra headers are going to be used and what is the format of that string is.
##########
File path: pulsar-broker/src/main/java/org/apache/pulsar/broker/service/Producer.java
##########
@@ -307,6 +308,7 @@ public TransportCnx getCnx() {
}
private static final class MessagePublishContext implements PublishContext, Runnable {
+ Map<String, Object> propertyMap = new HashMap<>();
Review comment:
It's not clear why we need to use the property map here and we should try to avoid the allocation if it's not being used.
##########
File path: pulsar-broker/src/main/java/org/apache/pulsar/broker/intercept/ManagedLedgerPayloadProcessor.java
##########
@@ -0,0 +1,91 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.pulsar.broker.intercept;
+
+import io.netty.buffer.ByteBuf;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Set;
+import java.util.concurrent.CompletableFuture;
+import org.apache.bookkeeper.client.LedgerHandle;
+import org.apache.bookkeeper.mledger.impl.OpAddEntry;
+import org.apache.bookkeeper.mledger.intercept.ManagedLedgerInterceptor;
+import org.apache.pulsar.broker.ServiceConfiguration;
+import org.apache.pulsar.broker.service.Topic;
+import org.apache.pulsar.common.intercept.MessagePayloadProcessor;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class ManagedLedgerPayloadProcessor implements ManagedLedgerInterceptor {
+ private static final Logger log = LoggerFactory.getLogger(ManagedLedgerPayloadProcessor.class);
+ private static final String INDEX = "index";
+ private ServiceConfiguration serviceConfig;
+
+
+ private final Set<MessagePayloadProcessor> brokerEntryPayloadProcessors;
+ public ManagedLedgerPayloadProcessor(ServiceConfiguration serviceConfig,
+ Set<MessagePayloadProcessor> brokerEntryPayloadProcessors) {
+ this.serviceConfig = serviceConfig;
+ this.brokerEntryPayloadProcessors = brokerEntryPayloadProcessors;
+ }
+ @Override
+ public OpAddEntry beforeAddEntry(OpAddEntry op, int numberOfMessages) {
+ return null;
+ }
+ @Override
+ public ByteBuf beforeStoreEntryToLedger(OpAddEntry op, ByteBuf ledgerData) {
+ Map<String, Object> contextMap = new HashMap<>();
+ ByteBuf dataToStore = ledgerData;
+
+ for (MessagePayloadProcessor payloadProcessor : brokerEntryPayloadProcessors) {
+ dataToStore = payloadProcessor.interceptIn(
+ serviceConfig.getClusterName(),
+ dataToStore, contextMap);
+ if (op.getCtx() instanceof Topic.PublishContext){
+ Topic.PublishContext ctx = (Topic.PublishContext) op.getCtx();
+ contextMap.forEach((k, v) -> {
+ ctx.setProperty(k, v);
+ });
+ }
+ }
+ return dataToStore;
+ }
+
+ @Override
+ public ByteBuf beforeCacheEntryFromLedger(ByteBuf ledgerData){
+ ByteBuf dataToCache = ledgerData;
+ for (MessagePayloadProcessor payloadProcessor : brokerEntryPayloadProcessors) {
+ dataToCache = payloadProcessor.interceptOut(dataToCache);
+ }
+ return dataToCache;
+ }
+
+ @Override
+ public void onManagedLedgerPropertiesInitialize(Map<String, String> propertiesMap) {
+ }
+ @Override
+ public CompletableFuture<Void> onManagedLedgerLastLedgerInitialize(String name, LedgerHandle lh) {
+ CompletableFuture<Void> promise = new CompletableFuture<>();
+ promise.complete(null);
+ return promise;
Review comment:
```suggestion
return CompletableFuture.completedFuture(null);
```
##########
File path: managed-ledger/src/main/java/org/apache/bookkeeper/mledger/intercept/ManagedLedgerInterceptor.java
##########
@@ -58,4 +59,23 @@
* @param propertiesMap map of properties.
*/
void onUpdateManagedLedgerInfo(Map<String, String> propertiesMap);
+
+ /**
+ * Intercept after entry is read from ledger, before it gets cached.
+ * @param ledgerData data from ledger
+ * @return data after processing, if any
+ */
+ default ByteBuf beforeCacheEntryFromLedger(ByteBuf ledgerData){
Review comment:
I think we need to be very explicit here (and careful :) ) on the reference-count expectations here for the buffers, to avoid memory leaks or use-after-destroyed scenarios.
##########
File path: pulsar-broker/src/main/java/org/apache/pulsar/broker/service/ServerCnx.java
##########
@@ -1420,11 +1435,15 @@ protected void handleAck(CommandAck ack) {
final long consumerId = ack.getConsumerId();
if (consumerFuture != null && consumerFuture.isDone() && !consumerFuture.isCompletedExceptionally()) {
+ Consumer consumer = consumerFuture.getNow(null);
Review comment:
Since we have the `consumer` variable here, we can also change the next line to avoid doing `getNow()` again.
##########
File path: pulsar-broker/src/main/java/org/apache/pulsar/broker/intercept/BrokerInterceptors.java
##########
@@ -102,6 +108,78 @@ public void beforeSendMessage(Subscription subscription,
}
}
+ @Override
+ public void consumerCreated(ServerCnx cnx,
+ Consumer consumer,
+ Map<String, String> metadata) {
+ for (BrokerInterceptorWithClassLoader value : interceptors.values()) {
+ value.consumerCreated(
+ cnx,
+ consumer,
+ metadata);
+ }
+ }
+
+ @Override
+ public void producerCreated(ServerCnx cnx, Producer producer,
+ Map<String, String> metadata){
+ for (BrokerInterceptorWithClassLoader value : interceptors.values()) {
+ value.producerCreated(cnx, producer, metadata);
+ }
+ }
+
+ @Override
+ public void messageProduced(ServerCnx cnx, Producer producer, long startTimeNs, long ledgerId,
+ long entryId, Rate rateIn,
+ Topic.PublishContext publishContext) {
+ for (BrokerInterceptorWithClassLoader value : interceptors.values()) {
+ value.messageProduced(cnx, producer, startTimeNs, ledgerId, entryId, rateIn, publishContext);
+ }
+ }
+
+ @Override
+ public void messageDispatched(ServerCnx cnx, Consumer consumer, long ledgerId,
+ long entryId, ByteBuf headersAndPayload) {
+ for (BrokerInterceptorWithClassLoader value : interceptors.values()) {
+ value.messageDispatched(cnx, consumer, ledgerId, entryId, headersAndPayload);
+ }
+ }
+
+ @Override
+ public void messageAcked(ServerCnx cnx, Consumer consumer,
+ CommandAck ackCmd) {
+ for (BrokerInterceptorWithClassLoader value : interceptors.values()) {
+ value.messageAcked(cnx, consumer, ackCmd);
+ }
+ }
+
+ @Override
+ public boolean delegateSuperUserCheck(){
+ for (BrokerInterceptorWithClassLoader value : interceptors.values()) {
+ if (value.delegateSuperUserCheck()) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ @Override
+ public boolean isSuperUser(PulsarService pulsarService, String appId, String originalPrincipal){
Review comment:
I think this would be more suitable to custom authorization provider, where there is already the `isSuperUser()` method.
##########
File path: managed-ledger/src/main/java/org/apache/bookkeeper/mledger/impl/EntryImpl.java
##########
@@ -47,12 +48,22 @@ protected EntryImpl newObject(Handle<EntryImpl> handle) {
ByteBuf data;
public static EntryImpl create(LedgerEntry ledgerEntry) {
+ return create(ledgerEntry,null);
+ }
+
+ public static EntryImpl create(LedgerEntry ledgerEntry, ManagedLedgerInterceptor managedLedgerInterceptor) {
EntryImpl entry = RECYCLER.get();
entry.timestamp = System.nanoTime();
entry.ledgerId = ledgerEntry.getLedgerId();
entry.entryId = ledgerEntry.getEntryId();
entry.data = ledgerEntry.getEntryBuffer();
- entry.data.retain();
+ ByteBuf cacheBuf = entry.data;
+ if(managedLedgerInterceptor != null)
+ cacheBuf = managedLedgerInterceptor.beforeCacheEntryFromLedger(entry.data);
+ if(cacheBuf != null && cacheBuf != entry.data)
+ entry.data = cacheBuf;
+ else
+ entry.data.retain();
Review comment:
Instead of checking the equality of the buffer instance, the interceptor should have a well defined semantic on the expectation of the reference count of the returned buffer.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@pulsar.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [pulsar] codelipenghui commented on pull request #12536: [pulsar-broker] Broker extensions to allow operators of enterprise wide cluster better control and flexibility
Posted by GitBox <gi...@apache.org>.
codelipenghui commented on pull request #12536:
URL: https://github.com/apache/pulsar/pull/12536#issuecomment-959107261
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@pulsar.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [pulsar] madhavan-narayanan commented on pull request #12536: [pulsar-broker] Broker extensions to allow operators of enterprise wide cluster better control and flexibility
Posted by GitBox <gi...@apache.org>.
madhavan-narayanan commented on pull request #12536:
URL: https://github.com/apache/pulsar/pull/12536#issuecomment-959734005
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@pulsar.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [pulsar] merlimat commented on a change in pull request #12536: [pulsar-broker] Broker extensions to allow operators of enterprise wide cluster better control and flexibility
Posted by GitBox <gi...@apache.org>.
merlimat commented on a change in pull request #12536:
URL: https://github.com/apache/pulsar/pull/12536#discussion_r742145102
##########
File path: managed-ledger/src/main/java/org/apache/bookkeeper/mledger/ManagedLedgerConfig.java
##########
@@ -77,6 +77,7 @@
private int newEntriesCheckDelayInMillis = 10;
private Clock clock = Clock.systemUTC();
private ManagedLedgerInterceptor managedLedgerInterceptor;
+ private ManagedLedgerInterceptor managedLedgerPayloadProcessor;
Review comment:
If we're using the same interface, couldn't we have a single `managedLedgerInterceptor` instance>
##########
File path: pulsar-broker/src/main/java/org/apache/pulsar/broker/intercept/BrokerInterceptors.java
##########
@@ -102,6 +108,78 @@ public void beforeSendMessage(Subscription subscription,
}
}
+ @Override
+ public void consumerCreated(ServerCnx cnx,
+ Consumer consumer,
+ Map<String, String> metadata) {
+ for (BrokerInterceptorWithClassLoader value : interceptors.values()) {
Review comment:
I know this was already the style of other methods here, though we should try to avoid the allocation of an iterator instance in the case where there are no interceptors. eg:
```java
if (interceptors.isEmpty()) {
return;
}
for (BrokerInterceptorWithClassLoader value : interceptors.values()) {
// ....
}
```
##########
File path: managed-ledger/src/main/java/org/apache/bookkeeper/mledger/impl/EntryCacheImpl.java
##########
@@ -221,7 +221,7 @@ private void asyncReadEntry0(ReadHandle lh, PositionImpl position, final ReadEnt
Iterator<LedgerEntry> iterator = ledgerEntries.iterator();
if (iterator.hasNext()) {
LedgerEntry ledgerEntry = iterator.next();
- EntryImpl returnEntry = EntryImpl.create(ledgerEntry);
+ EntryImpl returnEntry = EntryImpl.create(ledgerEntry, ml.getConfig().getManagedLedgerPayloadProcessor());
Review comment:
Maybe we can store the interceptor as a member variable of `EntryCacheImpl`.
##########
File path: pulsar-client-admin-api/src/main/java/org/apache/pulsar/client/admin/PulsarAdminBuilder.java
##########
@@ -264,4 +264,11 @@ PulsarAdminBuilder authentication(String authPluginClassName, Map<String, String
*/
PulsarAdminBuilder setContextClassLoader(ClassLoader clientBuilderClassLoader);
+ /**
+ * Set extra headers.
+ * @param extraClientHeaders
+ * @return
+ */
+ PulsarAdminBuilder extraClientHeaders(String extraClientHeaders);
Review comment:
I think this change should go in a separate PR since it's a bit different from the payload interceptor change.
Also, it's not clear from API perspective how the extra headers are going to be used and what is the format of that string is.
##########
File path: pulsar-broker/src/main/java/org/apache/pulsar/broker/service/Producer.java
##########
@@ -307,6 +308,7 @@ public TransportCnx getCnx() {
}
private static final class MessagePublishContext implements PublishContext, Runnable {
+ Map<String, Object> propertyMap = new HashMap<>();
Review comment:
It's not clear why we need to use the property map here and we should try to avoid the allocation if it's not being used.
##########
File path: pulsar-broker/src/main/java/org/apache/pulsar/broker/intercept/ManagedLedgerPayloadProcessor.java
##########
@@ -0,0 +1,91 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.pulsar.broker.intercept;
+
+import io.netty.buffer.ByteBuf;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Set;
+import java.util.concurrent.CompletableFuture;
+import org.apache.bookkeeper.client.LedgerHandle;
+import org.apache.bookkeeper.mledger.impl.OpAddEntry;
+import org.apache.bookkeeper.mledger.intercept.ManagedLedgerInterceptor;
+import org.apache.pulsar.broker.ServiceConfiguration;
+import org.apache.pulsar.broker.service.Topic;
+import org.apache.pulsar.common.intercept.MessagePayloadProcessor;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class ManagedLedgerPayloadProcessor implements ManagedLedgerInterceptor {
+ private static final Logger log = LoggerFactory.getLogger(ManagedLedgerPayloadProcessor.class);
+ private static final String INDEX = "index";
+ private ServiceConfiguration serviceConfig;
+
+
+ private final Set<MessagePayloadProcessor> brokerEntryPayloadProcessors;
+ public ManagedLedgerPayloadProcessor(ServiceConfiguration serviceConfig,
+ Set<MessagePayloadProcessor> brokerEntryPayloadProcessors) {
+ this.serviceConfig = serviceConfig;
+ this.brokerEntryPayloadProcessors = brokerEntryPayloadProcessors;
+ }
+ @Override
+ public OpAddEntry beforeAddEntry(OpAddEntry op, int numberOfMessages) {
+ return null;
+ }
+ @Override
+ public ByteBuf beforeStoreEntryToLedger(OpAddEntry op, ByteBuf ledgerData) {
+ Map<String, Object> contextMap = new HashMap<>();
+ ByteBuf dataToStore = ledgerData;
+
+ for (MessagePayloadProcessor payloadProcessor : brokerEntryPayloadProcessors) {
+ dataToStore = payloadProcessor.interceptIn(
+ serviceConfig.getClusterName(),
+ dataToStore, contextMap);
+ if (op.getCtx() instanceof Topic.PublishContext){
+ Topic.PublishContext ctx = (Topic.PublishContext) op.getCtx();
+ contextMap.forEach((k, v) -> {
+ ctx.setProperty(k, v);
+ });
+ }
+ }
+ return dataToStore;
+ }
+
+ @Override
+ public ByteBuf beforeCacheEntryFromLedger(ByteBuf ledgerData){
+ ByteBuf dataToCache = ledgerData;
+ for (MessagePayloadProcessor payloadProcessor : brokerEntryPayloadProcessors) {
+ dataToCache = payloadProcessor.interceptOut(dataToCache);
+ }
+ return dataToCache;
+ }
+
+ @Override
+ public void onManagedLedgerPropertiesInitialize(Map<String, String> propertiesMap) {
+ }
+ @Override
+ public CompletableFuture<Void> onManagedLedgerLastLedgerInitialize(String name, LedgerHandle lh) {
+ CompletableFuture<Void> promise = new CompletableFuture<>();
+ promise.complete(null);
+ return promise;
Review comment:
```suggestion
return CompletableFuture.completedFuture(null);
```
##########
File path: managed-ledger/src/main/java/org/apache/bookkeeper/mledger/intercept/ManagedLedgerInterceptor.java
##########
@@ -58,4 +59,23 @@
* @param propertiesMap map of properties.
*/
void onUpdateManagedLedgerInfo(Map<String, String> propertiesMap);
+
+ /**
+ * Intercept after entry is read from ledger, before it gets cached.
+ * @param ledgerData data from ledger
+ * @return data after processing, if any
+ */
+ default ByteBuf beforeCacheEntryFromLedger(ByteBuf ledgerData){
Review comment:
I think we need to be very explicit here (and careful :) ) on the reference-count expectations here for the buffers, to avoid memory leaks or use-after-destroyed scenarios.
##########
File path: pulsar-broker/src/main/java/org/apache/pulsar/broker/service/ServerCnx.java
##########
@@ -1420,11 +1435,15 @@ protected void handleAck(CommandAck ack) {
final long consumerId = ack.getConsumerId();
if (consumerFuture != null && consumerFuture.isDone() && !consumerFuture.isCompletedExceptionally()) {
+ Consumer consumer = consumerFuture.getNow(null);
Review comment:
Since we have the `consumer` variable here, we can also change the next line to avoid doing `getNow()` again.
##########
File path: pulsar-broker/src/main/java/org/apache/pulsar/broker/intercept/BrokerInterceptors.java
##########
@@ -102,6 +108,78 @@ public void beforeSendMessage(Subscription subscription,
}
}
+ @Override
+ public void consumerCreated(ServerCnx cnx,
+ Consumer consumer,
+ Map<String, String> metadata) {
+ for (BrokerInterceptorWithClassLoader value : interceptors.values()) {
+ value.consumerCreated(
+ cnx,
+ consumer,
+ metadata);
+ }
+ }
+
+ @Override
+ public void producerCreated(ServerCnx cnx, Producer producer,
+ Map<String, String> metadata){
+ for (BrokerInterceptorWithClassLoader value : interceptors.values()) {
+ value.producerCreated(cnx, producer, metadata);
+ }
+ }
+
+ @Override
+ public void messageProduced(ServerCnx cnx, Producer producer, long startTimeNs, long ledgerId,
+ long entryId, Rate rateIn,
+ Topic.PublishContext publishContext) {
+ for (BrokerInterceptorWithClassLoader value : interceptors.values()) {
+ value.messageProduced(cnx, producer, startTimeNs, ledgerId, entryId, rateIn, publishContext);
+ }
+ }
+
+ @Override
+ public void messageDispatched(ServerCnx cnx, Consumer consumer, long ledgerId,
+ long entryId, ByteBuf headersAndPayload) {
+ for (BrokerInterceptorWithClassLoader value : interceptors.values()) {
+ value.messageDispatched(cnx, consumer, ledgerId, entryId, headersAndPayload);
+ }
+ }
+
+ @Override
+ public void messageAcked(ServerCnx cnx, Consumer consumer,
+ CommandAck ackCmd) {
+ for (BrokerInterceptorWithClassLoader value : interceptors.values()) {
+ value.messageAcked(cnx, consumer, ackCmd);
+ }
+ }
+
+ @Override
+ public boolean delegateSuperUserCheck(){
+ for (BrokerInterceptorWithClassLoader value : interceptors.values()) {
+ if (value.delegateSuperUserCheck()) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ @Override
+ public boolean isSuperUser(PulsarService pulsarService, String appId, String originalPrincipal){
Review comment:
I think this would be more suitable to custom authorization provider, where there is already the `isSuperUser()` method.
##########
File path: managed-ledger/src/main/java/org/apache/bookkeeper/mledger/impl/EntryImpl.java
##########
@@ -47,12 +48,22 @@ protected EntryImpl newObject(Handle<EntryImpl> handle) {
ByteBuf data;
public static EntryImpl create(LedgerEntry ledgerEntry) {
+ return create(ledgerEntry,null);
+ }
+
+ public static EntryImpl create(LedgerEntry ledgerEntry, ManagedLedgerInterceptor managedLedgerInterceptor) {
EntryImpl entry = RECYCLER.get();
entry.timestamp = System.nanoTime();
entry.ledgerId = ledgerEntry.getLedgerId();
entry.entryId = ledgerEntry.getEntryId();
entry.data = ledgerEntry.getEntryBuffer();
- entry.data.retain();
+ ByteBuf cacheBuf = entry.data;
+ if(managedLedgerInterceptor != null)
+ cacheBuf = managedLedgerInterceptor.beforeCacheEntryFromLedger(entry.data);
+ if(cacheBuf != null && cacheBuf != entry.data)
+ entry.data = cacheBuf;
+ else
+ entry.data.retain();
Review comment:
Instead of checking the equality of the buffer instance, the interceptor should have a well defined semantic on the expectation of the reference count of the returned buffer.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@pulsar.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [pulsar] github-actions[bot] commented on pull request #12536: [pulsar-broker] Broker extensions to allow operators of enterprise wide cluster better control and flexibility
Posted by GitBox <gi...@apache.org>.
github-actions[bot] commented on pull request #12536:
URL: https://github.com/apache/pulsar/pull/12536#issuecomment-954973757
@madhavan-narayanan:Thanks for providing doc info!
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@pulsar.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [pulsar] madhavan-narayanan commented on a change in pull request #12536: [pulsar-broker] Broker extensions to allow operators of enterprise wide cluster better control and flexibility
Posted by GitBox <gi...@apache.org>.
madhavan-narayanan commented on a change in pull request #12536:
URL: https://github.com/apache/pulsar/pull/12536#discussion_r767806546
##########
File path: pulsar-broker/src/main/java/org/apache/pulsar/broker/service/Topic.java
##########
@@ -98,6 +98,13 @@ default long getNumberOfMessages() {
default boolean isMarkerMessage() {
return false;
}
+
+ default void setProperty(String propertyName, Object value) {
+ }
+
+ default Object getProperty(String propertyName) {
+ return null;
+ }
Review comment:
These method are used to store context information from managed ledger interceptors so that they can be made available to the broker interceptors for tracing. For example, when encryption/decryption is done, the time taken for the encryption/decryption can be stored and retrieved using these methods
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@pulsar.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [pulsar] codelipenghui commented on a change in pull request #12536: [pulsar-broker] Broker extensions to allow operators of enterprise wide cluster better control and flexibility
Posted by GitBox <gi...@apache.org>.
codelipenghui commented on a change in pull request #12536:
URL: https://github.com/apache/pulsar/pull/12536#discussion_r768241716
##########
File path: pulsar-broker/src/main/java/org/apache/pulsar/broker/service/ServerCnx.java
##########
@@ -2620,6 +2639,12 @@ public ByteBufPair newMessageAndIntercept(long consumerId, long ledgerId, long e
val brokerInterceptor = getBrokerService().getInterceptor();
if (brokerInterceptor != null) {
brokerInterceptor.onPulsarCommand(command, this);
+
+ CompletableFuture<Consumer> consumerFuture = consumers.get(consumerId);
+ if (consumerFuture != null && consumerFuture.isDone() && !consumerFuture.isCompletedExceptionally()) {
+ Consumer consumer = consumerFuture.getNow(null);
+ brokerInterceptor.messageDispatched(this, consumer, ledgerId, entryId, metadataAndPayload);
Review comment:
Yes, redeliveries will invoke this method again, with the redelivery count, we are able to know this is message redelivery or not. It's ok for me.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@pulsar.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [pulsar] madhavan-narayanan commented on a change in pull request #12536: [pulsar-broker] Broker extensions to allow operators of enterprise wide cluster better control and flexibility
Posted by GitBox <gi...@apache.org>.
madhavan-narayanan commented on a change in pull request #12536:
URL: https://github.com/apache/pulsar/pull/12536#discussion_r767801706
##########
File path: pulsar-broker/src/main/java/org/apache/pulsar/broker/intercept/BrokerInterceptor.java
##########
@@ -58,6 +65,66 @@ default void beforeSendMessage(Subscription subscription,
MessageMetadata msgMetadata) {
}
+ /**
+ * Called by the broker when a new connection is created.
+ */
+ default void onConnectionCreated(ServerCnx cnx){
+ }
+
+ /**
+ * Called by the broker when a new connection is created.
+ */
+ default void producerCreated(ServerCnx cnx, Producer producer,
+ Map<String, String> metadata){
+ }
+
+ /**
+ * Intercept after a consumer is created.
+ *
+ * @param cnx client Connection
+ * @param consumer Consumer object
+ * @param metadata A map of metdata
+ */
+ default void consumerCreated(ServerCnx cnx,
+ Consumer consumer,
+ Map<String, String> metadata) {
+ }
+
+ /**
+ * Intercept after a message is produced.
+ *
+ * @param cnx client Connection
+ * @param producer Producer object
+ * @param publishContext Publish Context
+ */
+ default void messageProduced(ServerCnx cnx, Producer producer, long startTimeNs, long ledgerId,
Review comment:
This is currently used in our logs to indicate the overall publish rate for the topic seen by the broker when this message was stored in the ledger. Used to troubleshoot latency issues and to support customer queries. Is there anything wrong in exposing this parameter?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@pulsar.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [pulsar] madhavan-narayanan commented on a change in pull request #12536: [pulsar-broker] Broker extensions to allow operators of enterprise wide cluster better control and flexibility
Posted by GitBox <gi...@apache.org>.
madhavan-narayanan commented on a change in pull request #12536:
URL: https://github.com/apache/pulsar/pull/12536#discussion_r768286155
##########
File path: pulsar-broker/src/main/java/org/apache/pulsar/broker/service/Producer.java
##########
@@ -518,6 +551,10 @@ public void recycle() {
startTimeNs = -1L;
chunked = false;
isMarker = false;
+ if (propertyMap != null) {
+ propertyMap.clear();
+ propertyMap = null;
Review comment:
Done
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@pulsar.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [pulsar] madhavan-narayanan commented on a change in pull request #12536: [pulsar-broker] Broker extensions to allow operators of enterprise wide cluster better control and flexibility
Posted by GitBox <gi...@apache.org>.
madhavan-narayanan commented on a change in pull request #12536:
URL: https://github.com/apache/pulsar/pull/12536#discussion_r739640873
##########
File path: pulsar-broker-common/src/main/java/org/apache/pulsar/broker/ServiceConfiguration.java
##########
@@ -1008,6 +1008,11 @@
)
private boolean disableBrokerInterceptors = true;
+ @FieldContext(
+ category = CATEGORY_SERVER,
+ doc = "List of interceptors for payload processing.")
+ private String brokerEntryPayloadProcessor;
Review comment:
I will fix it. Thanks for catching this.
##########
File path: managed-ledger/src/main/java/org/apache/bookkeeper/mledger/impl/EntryImpl.java
##########
@@ -47,12 +48,22 @@ protected EntryImpl newObject(Handle<EntryImpl> handle) {
ByteBuf data;
public static EntryImpl create(LedgerEntry ledgerEntry) {
+ return create(ledgerEntry,null);
+ }
+
+ public static EntryImpl create(LedgerEntry ledgerEntry, ManagedLedgerInterceptor managedLedgerInterceptor) {
Review comment:
I extended the create() to ensure that future usages of this method from other places don't miss out the interceptor.
I do agree that it will be clean to have the calling methods process the ledger entry using interceptors and pass the result.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@pulsar.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [pulsar] codelipenghui merged pull request #12536: [pulsar-broker] Broker extensions to allow operators of enterprise wide cluster better control and flexibility
Posted by GitBox <gi...@apache.org>.
codelipenghui merged pull request #12536:
URL: https://github.com/apache/pulsar/pull/12536
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@pulsar.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [pulsar] madhavan-narayanan commented on pull request #12536: [pulsar-broker] Broker extensions to allow operators of enterprise wide cluster better control and flexibility
Posted by GitBox <gi...@apache.org>.
madhavan-narayanan commented on pull request #12536:
URL: https://github.com/apache/pulsar/pull/12536#issuecomment-993231206
@hangc0276 , @codelipenghui , @merlimat , @Jason918
Thanks a lot for your patient review and guidance. This PR will greatly help us as Pulsar cluster operators to move with increased velocity and accelerate internal adoption of Pulsar.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@pulsar.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [pulsar] madhavan-narayanan commented on a change in pull request #12536: [pulsar-broker] Broker extensions to allow operators of enterprise wide cluster better control and flexibility
Posted by GitBox <gi...@apache.org>.
madhavan-narayanan commented on a change in pull request #12536:
URL: https://github.com/apache/pulsar/pull/12536#discussion_r767804470
##########
File path: pulsar-broker/src/main/java/org/apache/pulsar/broker/service/ServerCnx.java
##########
@@ -2620,6 +2639,12 @@ public ByteBufPair newMessageAndIntercept(long consumerId, long ledgerId, long e
val brokerInterceptor = getBrokerService().getInterceptor();
if (brokerInterceptor != null) {
brokerInterceptor.onPulsarCommand(command, this);
+
+ CompletableFuture<Consumer> consumerFuture = consumers.get(consumerId);
+ if (consumerFuture != null && consumerFuture.isDone() && !consumerFuture.isCompletedExceptionally()) {
+ Consumer consumer = consumerFuture.getNow(null);
+ brokerInterceptor.messageDispatched(this, consumer, ledgerId, entryId, metadataAndPayload);
Review comment:
Got it. Right now this is used to trace when messages are dispatched to consumers. Redeliveries will invoke this method again, right?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@pulsar.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [pulsar] madhavan-narayanan commented on a change in pull request #12536: [pulsar-broker] Broker extensions to allow operators of enterprise wide cluster better control and flexibility
Posted by GitBox <gi...@apache.org>.
madhavan-narayanan commented on a change in pull request #12536:
URL: https://github.com/apache/pulsar/pull/12536#discussion_r767816790
##########
File path: pulsar-broker/src/main/java/org/apache/pulsar/broker/intercept/ManagedLedgerInterceptorImpl.java
##########
@@ -38,10 +42,28 @@
private final Set<BrokerEntryMetadataInterceptor> brokerEntryMetadataInterceptors;
+ private final Set<ManagedLedgerPayloadProcessor.Processor> inputProcessors;
+ private final Set<ManagedLedgerPayloadProcessor.Processor> outputProcessors;
public ManagedLedgerInterceptorImpl(Set<BrokerEntryMetadataInterceptor> brokerEntryMetadataInterceptors) {
Review comment:
Done
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@pulsar.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [pulsar] madhavan-narayanan commented on pull request #12536: [pulsar-broker] Broker extensions to allow operators of enterprise wide cluster better control and flexibility
Posted by GitBox <gi...@apache.org>.
madhavan-narayanan commented on pull request #12536:
URL: https://github.com/apache/pulsar/pull/12536#issuecomment-992544644
> @madhavan-narayanan Would you please cleanup the not related commits?
@hangc0276 , I have done a rebase of my branch to resolve conflicts with latest master and that has resulted in this. I am raising a new PR that has only my commits. Sorry about this.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@pulsar.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [pulsar] madhavan-narayanan commented on a change in pull request #12536: [pulsar-broker] Broker extensions to allow operators of enterprise wide cluster better control and flexibility
Posted by GitBox <gi...@apache.org>.
madhavan-narayanan commented on a change in pull request #12536:
URL: https://github.com/apache/pulsar/pull/12536#discussion_r767795561
##########
File path: pulsar-broker/src/main/java/org/apache/pulsar/broker/service/ServerCnx.java
##########
@@ -1420,11 +1435,15 @@ protected void handleAck(CommandAck ack) {
final long consumerId = ack.getConsumerId();
if (consumerFuture != null && consumerFuture.isDone() && !consumerFuture.isCompletedExceptionally()) {
+ Consumer consumer = consumerFuture.getNow(null);
Review comment:
Done
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@pulsar.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [pulsar] Jason918 commented on a change in pull request #12536: [pulsar-broker] Broker extensions to allow operators of enterprise wide cluster better control and flexibility
Posted by GitBox <gi...@apache.org>.
Jason918 commented on a change in pull request #12536:
URL: https://github.com/apache/pulsar/pull/12536#discussion_r739596906
##########
File path: pulsar-broker-common/src/main/java/org/apache/pulsar/broker/ServiceConfiguration.java
##########
@@ -1008,6 +1008,11 @@
)
private boolean disableBrokerInterceptors = true;
+ @FieldContext(
+ category = CATEGORY_SERVER,
+ doc = "List of interceptors for payload processing.")
+ private String brokerEntryPayloadProcessor;
Review comment:
It could be a list of interceptors, so the type should be Set<String>.
##########
File path: managed-ledger/src/main/java/org/apache/bookkeeper/mledger/impl/EntryImpl.java
##########
@@ -47,12 +48,22 @@ protected EntryImpl newObject(Handle<EntryImpl> handle) {
ByteBuf data;
public static EntryImpl create(LedgerEntry ledgerEntry) {
+ return create(ledgerEntry,null);
+ }
+
+ public static EntryImpl create(LedgerEntry ledgerEntry, ManagedLedgerInterceptor managedLedgerInterceptor) {
Review comment:
Put the 'managedLedgerInterceptor' in here seem a little strange.
IMHO, it's better put outside of `create`, the `managedLedgerInterceptor` processes the `ledgerEntry` and then pass the result to this create method.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@pulsar.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [pulsar] codelipenghui commented on pull request #12536: [pulsar-broker] Broker extensions to allow operators of enterprise wide cluster better control and flexibility
Posted by GitBox <gi...@apache.org>.
codelipenghui commented on pull request #12536:
URL: https://github.com/apache/pulsar/pull/12536#issuecomment-959107261
@madhavan-narayanan It should be good to start with a proposal for this new feature, I noticed there are new API introduced. For starting a proposal for Pulsar, you can check https://lists.apache.org/thread/m8dr0hz7qn7rkd48bcp430lcq2q3674g
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@pulsar.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [pulsar] codelipenghui commented on a change in pull request #12536: [pulsar-broker] Broker extensions to allow operators of enterprise wide cluster better control and flexibility
Posted by GitBox <gi...@apache.org>.
codelipenghui commented on a change in pull request #12536:
URL: https://github.com/apache/pulsar/pull/12536#discussion_r768240618
##########
File path: pulsar-broker/src/main/java/org/apache/pulsar/broker/intercept/BrokerInterceptor.java
##########
@@ -58,6 +65,66 @@ default void beforeSendMessage(Subscription subscription,
MessageMetadata msgMetadata) {
}
+ /**
+ * Called by the broker when a new connection is created.
+ */
+ default void onConnectionCreated(ServerCnx cnx){
+ }
+
+ /**
+ * Called by the broker when a new connection is created.
+ */
+ default void producerCreated(ServerCnx cnx, Producer producer,
+ Map<String, String> metadata){
+ }
+
+ /**
+ * Intercept after a consumer is created.
+ *
+ * @param cnx client Connection
+ * @param consumer Consumer object
+ * @param metadata A map of metdata
+ */
+ default void consumerCreated(ServerCnx cnx,
+ Consumer consumer,
+ Map<String, String> metadata) {
+ }
+
+ /**
+ * Intercept after a message is produced.
+ *
+ * @param cnx client Connection
+ * @param producer Producer object
+ * @param publishContext Publish Context
+ */
+ default void messageProduced(ServerCnx cnx, Producer producer, long startTimeNs, long ledgerId,
Review comment:
I see, I think it's better to get the rateIn from the producer?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@pulsar.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [pulsar] madhavan-narayanan commented on pull request #12536: [pulsar-broker] Broker extensions to allow operators of enterprise wide cluster better control and flexibility
Posted by GitBox <gi...@apache.org>.
madhavan-narayanan commented on pull request #12536:
URL: https://github.com/apache/pulsar/pull/12536#issuecomment-993064639
> @madhavan-narayanan I think you forget to add --force after rebase your branch? :)
Sorry about that
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@pulsar.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [pulsar] hangc0276 commented on a change in pull request #12536: [pulsar-broker] Broker extensions to allow operators of enterprise wide cluster better control and flexibility
Posted by GitBox <gi...@apache.org>.
hangc0276 commented on a change in pull request #12536:
URL: https://github.com/apache/pulsar/pull/12536#discussion_r768275226
##########
File path: pulsar-broker-common/src/main/java/org/apache/pulsar/broker/ServiceConfiguration.java
##########
@@ -1089,6 +1089,11 @@
)
private boolean disableBrokerInterceptors = true;
+ @FieldContext(
+ category = CATEGORY_SERVER,
+ doc = "List of interceptors for payload processing.")
+ private Set<String> brokerEntryPayloadProcessors = new java.util.LinkedHashSet<>();
Review comment:
new LinkedHashSet<>() ?
##########
File path: pulsar-broker/src/main/java/org/apache/pulsar/broker/service/Producer.java
##########
@@ -518,6 +551,10 @@ public void recycle() {
startTimeNs = -1L;
chunked = false;
isMarker = false;
+ if (propertyMap != null) {
+ propertyMap.clear();
+ propertyMap = null;
Review comment:
Could we reuse here?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@pulsar.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [pulsar] codelipenghui commented on a change in pull request #12536: [pulsar-broker] Broker extensions to allow operators of enterprise wide cluster better control and flexibility
Posted by GitBox <gi...@apache.org>.
codelipenghui commented on a change in pull request #12536:
URL: https://github.com/apache/pulsar/pull/12536#discussion_r767658589
##########
File path: pulsar-broker/src/main/java/org/apache/pulsar/broker/service/ServerCnx.java
##########
@@ -2620,6 +2639,12 @@ public ByteBufPair newMessageAndIntercept(long consumerId, long ledgerId, long e
val brokerInterceptor = getBrokerService().getInterceptor();
if (brokerInterceptor != null) {
brokerInterceptor.onPulsarCommand(command, this);
+
+ CompletableFuture<Consumer> consumerFuture = consumers.get(consumerId);
+ if (consumerFuture != null && consumerFuture.isDone() && !consumerFuture.isCompletedExceptionally()) {
+ Consumer consumer = consumerFuture.getNow(null);
+ brokerInterceptor.messageDispatched(this, consumer, ledgerId, entryId, metadataAndPayload);
Review comment:
The `metadataAndPayload` does not contain the redeliveryCount, ackSet etc. I think it might be used in the future for the interceptor.
##########
File path: pulsar-broker/src/main/java/org/apache/pulsar/broker/service/Topic.java
##########
@@ -98,6 +98,13 @@ default long getNumberOfMessages() {
default boolean isMarkerMessage() {
return false;
}
+
+ default void setProperty(String propertyName, Object value) {
+ }
+
+ default Object getProperty(String propertyName) {
+ return null;
+ }
Review comment:
Looks not related to this PR?
##########
File path: pulsar-broker/src/main/java/org/apache/pulsar/broker/intercept/BrokerInterceptor.java
##########
@@ -58,6 +65,66 @@ default void beforeSendMessage(Subscription subscription,
MessageMetadata msgMetadata) {
}
+ /**
+ * Called by the broker when a new connection is created.
+ */
+ default void onConnectionCreated(ServerCnx cnx){
+ }
+
+ /**
+ * Called by the broker when a new connection is created.
+ */
+ default void producerCreated(ServerCnx cnx, Producer producer,
+ Map<String, String> metadata){
+ }
+
+ /**
+ * Intercept after a consumer is created.
+ *
+ * @param cnx client Connection
+ * @param consumer Consumer object
+ * @param metadata A map of metdata
+ */
+ default void consumerCreated(ServerCnx cnx,
+ Consumer consumer,
+ Map<String, String> metadata) {
+ }
+
+ /**
+ * Intercept after a message is produced.
+ *
+ * @param cnx client Connection
+ * @param producer Producer object
+ * @param publishContext Publish Context
+ */
+ default void messageProduced(ServerCnx cnx, Producer producer, long startTimeNs, long ledgerId,
Review comment:
Could you please provide more context about why we should add `rateIn` as a param for this method?
##########
File path: pulsar-broker/src/main/java/org/apache/pulsar/broker/intercept/BrokerInterceptors.java
##########
@@ -102,6 +108,78 @@ public void beforeSendMessage(Subscription subscription,
}
}
+ @Override
+ public void consumerCreated(ServerCnx cnx,
+ Consumer consumer,
+ Map<String, String> metadata) {
+ for (BrokerInterceptorWithClassLoader value : interceptors.values()) {
Review comment:
+1
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@pulsar.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [pulsar] madhavan-narayanan commented on a change in pull request #12536: [pulsar-broker] Broker extensions to allow operators of enterprise wide cluster better control and flexibility
Posted by GitBox <gi...@apache.org>.
madhavan-narayanan commented on a change in pull request #12536:
URL: https://github.com/apache/pulsar/pull/12536#discussion_r767810551
##########
File path: pulsar-broker/src/main/java/org/apache/pulsar/broker/service/Producer.java
##########
@@ -452,6 +479,10 @@ static MessagePublishContext get(Producer producer, long sequenceId, Rate rateIn
callback.originalSequenceId = -1L;
callback.startTimeNs = startTimeNs;
callback.isMarker = isMarker;
+ if (callback.propertyMap != null) {
+ callback.propertyMap.clear();
+ callback.propertyMap = null;
Review comment:
Done
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@pulsar.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org