apache / apache/pulsar

[Help Wanted] Can not estimate *lag* correctly using Admin REST API

Open
#13,925 4 comments 0 reactions 0 assignees View on GitHub
lifecycle/stale Stale
Dominant language
Java
Stars
15.3k
Forks
3.8k
Avg merge
1d 14h
Merged PRs (30d)
160

Description

We use to monitor the unfinished messages in the system.

We read each topic stats as following:

```
"persistent://public/default/my-topic-name": {
"publishers": [],
"replication": {},
"subscriptions": {
"my-consumer-name": {
"consumers": [
{ // consumer info here
}
],
"msgBacklog": 252, <<-- key field
"msgRateExpired": 0,
"msgRateOut": 0,
"msgThroughputOut": 0,
"msgRateRedeliver": 0,
"numberOfEntriesSinceFirstNotAckedMessage": 1,
"totalNonContiguousDeletedMessagesRange": 0,
"type": "Shared",
"blockedSubscriptionOnUnackedMsgs": false,
"unackedMessages": 0
}
},
"producerCount": 0,
"averageMsgSize": 0,
"msgRateIn": 0,
"msgRateOut": 0,
"msgInCount": 0, <<-- another key field
"bytesInCount": 0,
"msgOutCount": 0,
"bytesOutCount": 0,
"msgThroughputIn": 0,
"msgThroughputOut": 0,
"storageSize": 215024,
"backlogSize": 215024,
"pendingAddEntriesCount": 0
}
```

We may use `my-topic-name->subscriptions->my-consumer-name` to get the lag of this consumer, and use `my-topic-name->msgInCount` to get the total message count.

It worked like a charm at first.

However, after a few days later, some of the message may expired since we configured a time based retention policies. The statistics became strange:

1. msgInCount became to be 0;
2. storageSize and backlogSize are pretty large;
3. subscriptions->msgBacklog is a positive value
4. and it can not be consumed what ever using sdk or admin cli tool

all the above topics mentioned are non-partitioned.

May I know is there any way I did incorrect? Any help are appreciated.

## Additionally information

I am using 2.8.2 and 2.9.1. The above issue may occasionally happened on both of the these releases.

Besides, the API response is `msgInCount` and [the doc](https://pulsar.apache.org/docs/en/standalone-docker/#get-the-topic-statistics) shows `msgInCounter`. Maybe one of them is incorrect

Contributor guide

Open the contributing guide

Research direction

Start with the Admin REST API endpoint /admin/v2/broker-stats/topics and compare its msgInCount response with the documented msgInCounter field. Reproduce the reported behavior for non-partitioned topics using time-based retention, then trace how msgBacklog, storageSize, backlogSize, and message counts are calculated. Done means the statistics behavior and field naming are clarified or corrected, with documentation updated if needed.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
api, distributed-systems
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.