Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1178,7 +1178,7 @@ public void getStats(
@QueryParam("getPreciseBacklog") @DefaultValue("false") boolean getPreciseBacklog,
@ApiParam(value = "If return backlog size for each subscription, require locking on ledger so be careful "
+ "not to use when there's heavy traffic.")
@QueryParam("subscriptionBacklogSize") @DefaultValue("false") boolean subscriptionBacklogSize,
@QueryParam("subscriptionBacklogSize") @DefaultValue("true") boolean subscriptionBacklogSize,
@ApiParam(value = "If return time of the earliest message in backlog")
@QueryParam("getEarliestTimeInBacklog") @DefaultValue("false") boolean getEarliestTimeInBacklog) {
validateTopicName(tenant, namespace, encodedTopic);
Expand Down Expand Up @@ -1280,7 +1280,7 @@ public void getPartitionedStats(
@QueryParam("getPreciseBacklog") @DefaultValue("false") boolean getPreciseBacklog,
@ApiParam(value = "If return backlog size for each subscription, require locking on ledger so be careful "
+ "not to use when there's heavy traffic.")
@QueryParam("subscriptionBacklogSize") @DefaultValue("false") boolean subscriptionBacklogSize,
@QueryParam("subscriptionBacklogSize") @DefaultValue("true") boolean subscriptionBacklogSize,
@ApiParam(value = "If return the earliest time in backlog")
@QueryParam("getEarliestTimeInBacklog") @DefaultValue("false") boolean getEarliestTimeInBacklog) {
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1131,6 +1131,8 @@ public SubscriptionStatsImpl getStats(Boolean getPreciseBacklog, boolean subscri
if (subscriptionBacklogSize) {
subStats.backlogSize = ((ManagedLedgerImpl) topic.getManagedLedger())
.getEstimatedBacklogSize((PositionImpl) cursor.getMarkDeletedPosition());
} else {
subStats.backlogSize = -1;
}
if (getEarliestTimeInBacklog && subStats.msgBacklog > 0) {
ManagedLedgerImpl managedLedger = ((ManagedLedgerImpl) cursor.getManagedLedger());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1234,24 +1234,27 @@ public void testGetStats() throws Exception {

assertEquals(topicStats.getEarliestMsgPublishTimeInBacklogs(), 0);
assertEquals(topicStats.getSubscriptions().get(subName).getEarliestMsgPublishTimeInBacklog(), 0);
assertEquals(topicStats.getSubscriptions().get(subName).getBacklogSize(), -1);

// publish several messages
publishMessagesOnPersistentTopic(topic, 10);
Thread.sleep(1000);

topicStats = admin.topics().getStats(topic, false, false, true);
topicStats = admin.topics().getStats(topic, false, true, true);
assertTrue(topicStats.getEarliestMsgPublishTimeInBacklogs() > 0);
assertTrue(topicStats.getSubscriptions().get(subName).getEarliestMsgPublishTimeInBacklog() > 0);
assertTrue(topicStats.getSubscriptions().get(subName).getBacklogSize() > 0);

for (int i = 0; i < 10; i++) {
Message<byte[]> message = consumer.receive();
consumer.acknowledge(message);
}
Thread.sleep(1000);

topicStats = admin.topics().getStats(topic, false, false, true);
topicStats = admin.topics().getStats(topic, false, true, true);
assertEquals(topicStats.getEarliestMsgPublishTimeInBacklogs(), 0);
assertEquals(topicStats.getSubscriptions().get(subName).getEarliestMsgPublishTimeInBacklog(), 0);
assertEquals(topicStats.getSubscriptions().get(subName).getBacklogSize(), 0);
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1493,7 +1493,7 @@ public void topics() throws Exception {
verify(mockTopics).deleteSubscription("persistent://myprop/clust/ns1/ds1", "sub1", false);

cmdTopics.run(split("stats persistent://myprop/clust/ns1/ds1"));
verify(mockTopics).getStats("persistent://myprop/clust/ns1/ds1", false, false, false);
verify(mockTopics).getStats("persistent://myprop/clust/ns1/ds1", false, true, false);

cmdTopics.run(split("stats-internal persistent://myprop/clust/ns1/ds1"));
verify(mockTopics).getInternalStats("persistent://myprop/clust/ns1/ds1", false);
Expand Down Expand Up @@ -1541,7 +1541,7 @@ public void topics() throws Exception {

cmdTopics.run(split("partitioned-stats persistent://myprop/clust/ns1/ds1 --per-partition"));
verify(mockTopics).getPartitionedStats("persistent://myprop/clust/ns1/ds1",
true, false, false, false);
true, false, true, false);

cmdTopics.run(split("partitioned-stats-internal persistent://myprop/clust/ns1/ds1"));
verify(mockTopics).getPartitionedInternalStats("persistent://myprop/clust/ns1/ds1");
Expand Down Expand Up @@ -2107,7 +2107,7 @@ public void nonPersistentTopics() throws Exception {
CmdTopics topics = new CmdTopics(() -> admin);

topics.run(split("stats non-persistent://myprop/ns1/ds1"));
verify(mockTopics).getStats("non-persistent://myprop/ns1/ds1", false, false, false);
verify(mockTopics).getStats("non-persistent://myprop/ns1/ds1", false, true, false);

topics.run(split("stats-internal non-persistent://myprop/ns1/ds1"));
verify(mockTopics).getInternalStats("non-persistent://myprop/ns1/ds1", false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -792,8 +792,8 @@ private class GetStats extends CliCommand {

@Parameter(names = { "-sbs",
"--get-subscription-backlog-size" }, description = "Set true to get backlog size for each subscription"
+ ", locking required.")
private boolean subscriptionBacklogSize = false;
+ ", locking required. If set to false, the attribute 'backlogSize' in the response will be -1")
private boolean subscriptionBacklogSize = true;

@Parameter(names = { "-etb",
"--get-earliest-time-in-backlog" }, description = "Set true to get earliest time in backlog")
Expand Down Expand Up @@ -858,7 +858,7 @@ private class GetPartitionedStats extends CliCommand {
@Parameter(names = { "-sbs",
"--get-subscription-backlog-size" }, description = "Set true to get backlog size for each subscription"
+ ", locking required.")
private boolean subscriptionBacklogSize = false;
private boolean subscriptionBacklogSize = true;

@Parameter(names = { "-etb",
"--get-earliest-time-in-backlog" }, description = "Set true to get earliest time in backlog")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public class SubscriptionStatsImpl implements SubscriptionStats {
/** Number of entries in the subscription backlog. */
public long msgBacklog;

/** Size of backlog in byte. **/
/** Size of backlog in byte, -1 means that the argument "subscriptionBacklogSize" is false when calling the API. **/
public long backlogSize;

/** Get the publish time of the earliest message in the backlog. */
Expand Down