Search in sources :

Example 1 with SubscriptionStatsImpl

use of org.apache.pulsar.common.policies.data.stats.SubscriptionStatsImpl in project pulsar by apache.

the class NonPersistentTopic method unsubscribe.

@Override
public CompletableFuture<Void> unsubscribe(String subscriptionName) {
    // That creates deadlock. so, execute remove it in different thread.
    return CompletableFuture.runAsync(() -> {
        NonPersistentSubscription sub = subscriptions.remove(subscriptionName);
        // preserve accumulative stats form removed subscription
        SubscriptionStatsImpl stats = sub.getStats();
        bytesOutFromRemovedSubscriptions.add(stats.bytesOutCounter);
        msgOutFromRemovedSubscriptions.add(stats.msgOutCounter);
    }, brokerService.executor());
}
Also used : SubscriptionStatsImpl(org.apache.pulsar.common.policies.data.stats.SubscriptionStatsImpl) NonPersistentSubscriptionStatsImpl(org.apache.pulsar.common.policies.data.stats.NonPersistentSubscriptionStatsImpl)

Example 2 with SubscriptionStatsImpl

use of org.apache.pulsar.common.policies.data.stats.SubscriptionStatsImpl in project pulsar by apache.

the class PersistentTopicTest method testKeySharedMetadataExposedToStats.

@Test
public void testKeySharedMetadataExposedToStats() throws Exception {
    PersistentTopic topic = new PersistentTopic(successTopicName, ledgerMock, brokerService);
    PersistentSubscription sub1 = new PersistentSubscription(topic, "key-shared-stats1", cursorMock, false);
    PersistentSubscription sub2 = new PersistentSubscription(topic, "key-shared-stats2", cursorMock, false);
    PersistentSubscription sub3 = new PersistentSubscription(topic, "key-shared-stats3", cursorMock, false);
    Consumer consumer1 = new Consumer(sub1, SubType.Key_Shared, topic.getName(), 1, 0, "Cons1", true, serverCnx, "myrole-1", Collections.emptyMap(), false, InitialPosition.Latest, new KeySharedMeta().setKeySharedMode(KeySharedMode.AUTO_SPLIT).setAllowOutOfOrderDelivery(false), MessageId.latest, DEFAULT_CONSUMER_EPOCH);
    sub1.addConsumer(consumer1);
    consumer1.close();
    SubscriptionStatsImpl stats1 = sub1.getStats(false, false, false);
    assertEquals(stats1.keySharedMode, "AUTO_SPLIT");
    assertFalse(stats1.allowOutOfOrderDelivery);
    Consumer consumer2 = new Consumer(sub2, SubType.Key_Shared, topic.getName(), 2, 0, "Cons2", true, serverCnx, "myrole-1", Collections.emptyMap(), false, InitialPosition.Latest, new KeySharedMeta().setKeySharedMode(KeySharedMode.AUTO_SPLIT).setAllowOutOfOrderDelivery(true), MessageId.latest, DEFAULT_CONSUMER_EPOCH);
    sub2.addConsumer(consumer2);
    consumer2.close();
    SubscriptionStatsImpl stats2 = sub2.getStats(false, false, false);
    assertEquals(stats2.keySharedMode, "AUTO_SPLIT");
    assertTrue(stats2.allowOutOfOrderDelivery);
    KeySharedMeta ksm = new KeySharedMeta().setKeySharedMode(KeySharedMode.STICKY).setAllowOutOfOrderDelivery(false);
    ksm.addHashRange().setStart(0).setEnd(65535);
    Consumer consumer3 = new Consumer(sub3, SubType.Key_Shared, topic.getName(), 3, 0, "Cons3", true, serverCnx, "myrole-1", Collections.emptyMap(), false, InitialPosition.Latest, ksm, MessageId.latest, DEFAULT_CONSUMER_EPOCH);
    sub3.addConsumer(consumer3);
    consumer3.close();
    SubscriptionStatsImpl stats3 = sub3.getStats(false, false, false);
    assertEquals(stats3.keySharedMode, "STICKY");
    assertFalse(stats3.allowOutOfOrderDelivery);
}
Also used : PersistentDispatcherSingleActiveConsumer(org.apache.pulsar.broker.service.persistent.PersistentDispatcherSingleActiveConsumer) PersistentTopic(org.apache.pulsar.broker.service.persistent.PersistentTopic) KeySharedMeta(org.apache.pulsar.common.api.proto.KeySharedMeta) PersistentSubscription(org.apache.pulsar.broker.service.persistent.PersistentSubscription) SubscriptionStatsImpl(org.apache.pulsar.common.policies.data.stats.SubscriptionStatsImpl) Test(org.testng.annotations.Test)

Example 3 with SubscriptionStatsImpl

use of org.apache.pulsar.common.policies.data.stats.SubscriptionStatsImpl in project pulsar by apache.

the class PersistentTopicStatsTest method testPersistentTopicStatsAggregationPartialProducerIsNotSupported.

@Test
public void testPersistentTopicStatsAggregationPartialProducerIsNotSupported() {
    TopicStatsImpl topicStats1 = new TopicStatsImpl();
    topicStats1.msgRateIn = 1;
    topicStats1.msgThroughputIn = 1;
    topicStats1.msgRateOut = 1;
    topicStats1.msgThroughputOut = 1;
    topicStats1.averageMsgSize = 1;
    topicStats1.storageSize = 1;
    final PublisherStatsImpl publisherStats1 = new PublisherStatsImpl();
    publisherStats1.setSupportsPartialProducer(false);
    publisherStats1.setProducerName("name1");
    topicStats1.addPublisher(publisherStats1);
    topicStats1.subscriptions.put("test_ns", new SubscriptionStatsImpl());
    topicStats1.replication.put("test_ns", new ReplicatorStatsImpl());
    TopicStatsImpl topicStats2 = new TopicStatsImpl();
    topicStats2.msgRateIn = 1;
    topicStats2.msgThroughputIn = 2;
    topicStats2.msgRateOut = 3;
    topicStats2.msgThroughputOut = 4;
    topicStats2.averageMsgSize = 5;
    topicStats2.storageSize = 6;
    final PublisherStatsImpl publisherStats2 = new PublisherStatsImpl();
    publisherStats2.setSupportsPartialProducer(false);
    publisherStats2.setProducerName("name1");
    topicStats2.addPublisher(publisherStats2);
    topicStats2.subscriptions.put("test_ns", new SubscriptionStatsImpl());
    topicStats2.replication.put("test_ns", new ReplicatorStatsImpl());
    TopicStatsImpl target = new TopicStatsImpl();
    target.add(topicStats1);
    target.add(topicStats2);
    assertEquals(target.msgRateIn, 2.0);
    assertEquals(target.msgThroughputIn, 3.0);
    assertEquals(target.msgRateOut, 4.0);
    assertEquals(target.msgThroughputOut, 5.0);
    assertEquals(target.averageMsgSize, 3.0);
    assertEquals(target.storageSize, 7);
    assertEquals(target.getPublishers().size(), 1);
    assertEquals(target.subscriptions.size(), 1);
    assertEquals(target.replication.size(), 1);
}
Also used : TopicStatsImpl(org.apache.pulsar.common.policies.data.stats.TopicStatsImpl) ReplicatorStatsImpl(org.apache.pulsar.common.policies.data.stats.ReplicatorStatsImpl) SubscriptionStatsImpl(org.apache.pulsar.common.policies.data.stats.SubscriptionStatsImpl) PublisherStatsImpl(org.apache.pulsar.common.policies.data.stats.PublisherStatsImpl) Test(org.testng.annotations.Test)

Example 4 with SubscriptionStatsImpl

use of org.apache.pulsar.common.policies.data.stats.SubscriptionStatsImpl in project pulsar by apache.

the class PersistentTopicStatsTest method testPersistentTopicStatsAggregationByProducerName.

@Test
public void testPersistentTopicStatsAggregationByProducerName() {
    TopicStatsImpl topicStats1 = new TopicStatsImpl();
    topicStats1.msgRateIn = 1;
    topicStats1.msgThroughputIn = 1;
    topicStats1.msgRateOut = 1;
    topicStats1.msgThroughputOut = 1;
    topicStats1.averageMsgSize = 1;
    topicStats1.storageSize = 1;
    final PublisherStatsImpl publisherStats1 = new PublisherStatsImpl();
    publisherStats1.setSupportsPartialProducer(true);
    publisherStats1.msgRateIn = 1;
    publisherStats1.setProducerName("name1");
    topicStats1.addPublisher(publisherStats1);
    topicStats1.subscriptions.put("test_ns", new SubscriptionStatsImpl());
    topicStats1.replication.put("test_ns", new ReplicatorStatsImpl());
    TopicStatsImpl topicStats2 = new TopicStatsImpl();
    topicStats2.msgRateIn = 1;
    topicStats2.msgThroughputIn = 2;
    topicStats2.msgRateOut = 3;
    topicStats2.msgThroughputOut = 4;
    topicStats2.averageMsgSize = 5;
    topicStats2.storageSize = 6;
    final PublisherStatsImpl publisherStats2 = new PublisherStatsImpl();
    publisherStats2.setSupportsPartialProducer(true);
    publisherStats2.msgRateIn = 1;
    publisherStats2.setProducerName("name1");
    topicStats2.addPublisher(publisherStats2);
    topicStats2.subscriptions.put("test_ns", new SubscriptionStatsImpl());
    topicStats2.replication.put("test_ns", new ReplicatorStatsImpl());
    TopicStatsImpl topicStats3 = new TopicStatsImpl();
    topicStats3.msgRateIn = 0;
    topicStats3.msgThroughputIn = 0;
    topicStats3.msgRateOut = 0;
    topicStats3.msgThroughputOut = 0;
    topicStats3.averageMsgSize = 0;
    topicStats3.storageSize = 0;
    final PublisherStatsImpl publisherStats3 = new PublisherStatsImpl();
    publisherStats3.setSupportsPartialProducer(true);
    publisherStats3.msgRateIn = 1;
    publisherStats3.setProducerName("name2");
    topicStats3.addPublisher(publisherStats3);
    topicStats3.subscriptions.put("test_ns", new SubscriptionStatsImpl());
    topicStats3.replication.put("test_ns", new ReplicatorStatsImpl());
    TopicStatsImpl target = new TopicStatsImpl();
    target.add(topicStats1);
    target.add(topicStats2);
    target.add(topicStats3);
    assertEquals(target.msgRateIn, 2.0);
    assertEquals(target.msgThroughputIn, 3.0);
    assertEquals(target.msgRateOut, 4.0);
    assertEquals(target.msgThroughputOut, 5.0);
    assertEquals(target.averageMsgSize, 2.0);
    assertEquals(target.storageSize, 7);
    assertEquals(target.getPublishers().size(), 2);
    final Map<String, Double> expectedPublishersMap = Maps.newHashMap();
    expectedPublishersMap.put("name1", 2.0);
    expectedPublishersMap.put("name2", 1.0);
    assertEquals(target.getPublishers().stream().collect(Collectors.toMap(PublisherStats::getProducerName, e -> ((PublisherStatsImpl) e).msgRateIn)), expectedPublishersMap);
    assertEquals(target.subscriptions.size(), 1);
    assertEquals(target.replication.size(), 1);
}
Also used : TopicStatsImpl(org.apache.pulsar.common.policies.data.stats.TopicStatsImpl) ReplicatorStatsImpl(org.apache.pulsar.common.policies.data.stats.ReplicatorStatsImpl) SubscriptionStatsImpl(org.apache.pulsar.common.policies.data.stats.SubscriptionStatsImpl) PublisherStatsImpl(org.apache.pulsar.common.policies.data.stats.PublisherStatsImpl) Test(org.testng.annotations.Test)

Example 5 with SubscriptionStatsImpl

use of org.apache.pulsar.common.policies.data.stats.SubscriptionStatsImpl in project pulsar by apache.

the class PersistentTopicStatsTest method testPersistentTopicStatsAggregationPartialProducerSupported.

@Test
public void testPersistentTopicStatsAggregationPartialProducerSupported() {
    TopicStatsImpl topicStats1 = new TopicStatsImpl();
    topicStats1.msgRateIn = 1;
    topicStats1.msgThroughputIn = 1;
    topicStats1.msgRateOut = 1;
    topicStats1.msgThroughputOut = 1;
    topicStats1.averageMsgSize = 1;
    topicStats1.storageSize = 1;
    final PublisherStatsImpl publisherStats1 = new PublisherStatsImpl();
    publisherStats1.setSupportsPartialProducer(true);
    publisherStats1.setProducerName("name1");
    topicStats1.addPublisher(publisherStats1);
    topicStats1.subscriptions.put("test_ns", new SubscriptionStatsImpl());
    topicStats1.replication.put("test_ns", new ReplicatorStatsImpl());
    TopicStatsImpl topicStats2 = new TopicStatsImpl();
    topicStats2.msgRateIn = 1;
    topicStats2.msgThroughputIn = 2;
    topicStats2.msgRateOut = 3;
    topicStats2.msgThroughputOut = 4;
    topicStats2.averageMsgSize = 5;
    topicStats2.storageSize = 6;
    final PublisherStatsImpl publisherStats2 = new PublisherStatsImpl();
    publisherStats2.setSupportsPartialProducer(true);
    publisherStats2.setProducerName("name1");
    topicStats2.addPublisher(publisherStats2);
    topicStats2.subscriptions.put("test_ns", new SubscriptionStatsImpl());
    topicStats2.replication.put("test_ns", new ReplicatorStatsImpl());
    TopicStatsImpl target = new TopicStatsImpl();
    target.add(topicStats1);
    target.add(topicStats2);
    assertEquals(target.msgRateIn, 2.0);
    assertEquals(target.msgThroughputIn, 3.0);
    assertEquals(target.msgRateOut, 4.0);
    assertEquals(target.msgThroughputOut, 5.0);
    assertEquals(target.averageMsgSize, 3.0);
    assertEquals(target.storageSize, 7);
    assertEquals(target.getPublishers().size(), 1);
    assertEquals(target.getPublishers().get(0).getProducerName(), "name1");
    assertEquals(target.subscriptions.size(), 1);
    assertEquals(target.replication.size(), 1);
}
Also used : TopicStatsImpl(org.apache.pulsar.common.policies.data.stats.TopicStatsImpl) ReplicatorStatsImpl(org.apache.pulsar.common.policies.data.stats.ReplicatorStatsImpl) SubscriptionStatsImpl(org.apache.pulsar.common.policies.data.stats.SubscriptionStatsImpl) PublisherStatsImpl(org.apache.pulsar.common.policies.data.stats.PublisherStatsImpl) Test(org.testng.annotations.Test)

Aggregations

SubscriptionStatsImpl (org.apache.pulsar.common.policies.data.stats.SubscriptionStatsImpl)10 PublisherStatsImpl (org.apache.pulsar.common.policies.data.stats.PublisherStatsImpl)6 ReplicatorStatsImpl (org.apache.pulsar.common.policies.data.stats.ReplicatorStatsImpl)6 Test (org.testng.annotations.Test)6 TopicStatsImpl (org.apache.pulsar.common.policies.data.stats.TopicStatsImpl)5 List (java.util.List)2 ExecutionException (java.util.concurrent.ExecutionException)2 ManagedLedgerImpl (org.apache.bookkeeper.mledger.impl.ManagedLedgerImpl)2 PositionImpl (org.apache.bookkeeper.mledger.impl.PositionImpl)2 Consumer (org.apache.pulsar.broker.service.Consumer)2 Dispatcher (org.apache.pulsar.broker.service.Dispatcher)2 SubType (org.apache.pulsar.common.api.proto.CommandSubscribe.SubType)2 ConsumerStatsImpl (org.apache.pulsar.common.policies.data.stats.ConsumerStatsImpl)2 ObjectObjectHashMap (com.carrotsearch.hppc.ObjectObjectHashMap)1 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 Preconditions.checkNotNull (com.google.common.base.Preconditions.checkNotNull)1 Lists (com.google.common.collect.Lists)1 Maps (com.google.common.collect.Maps)1 Sets (com.google.common.collect.Sets)1 ByteBuf (io.netty.buffer.ByteBuf)1