[Bug] Mismatch of ProducerStats/ConsumerStats interface description and implementation
- Dominant language
- Java
- Stars
- 15.3k
- Forks
- 3.8k
- Avg merge
- 1d 14h
- Merged PRs (30d)
- 160
Description
### Search before asking
- [X] I searched in the [issues](https://github.com/apache/pulsar/issues) and found nothing similar.
### Version
2.11.0 and above
### Minimal reproduce step
1. Create a non-partitioned topic
2. Create a producer with the default 60sec statsInterval that can publish messages to topic in step 1
3. Publish 1 message every 10 sec, and 20 messages in total
4. Fetch the producer stats every 20sec by querying `getStats()` method and print out values of [getNumMsgsSent()](https://github.com/apache/pulsar/blob/v3.1.0/pulsar-client-api/src/main/java/org/apache/pulsar/client/api/ProducerStats.java#L39C10-L39C24) and [getTotalMsgsSent()](https://github.com/apache/pulsar/blob/v3.1.0/pulsar-client-api/src/main/java/org/apache/pulsar/client/api/ProducerStats.java#L99) in [ProducerStats.java](https://github.com/apache/pulsar/blob/v3.1.0/pulsar-client-api/src/main/java/org/apache/pulsar/client/api/ProducerStats.java)
5. Check the printed logs
### What did you expect to see?
Both `getNumMsgsSent()` and `getTotalMsgsSent()` should be constant values during each statsInterval(60sec) per the [description](https://github.com/apache/pulsar/blob/v3.1.0/pulsar-client-api/src/main/java/org/apache/pulsar/client/api/ProducerStats.java#L30), as all stats are referring to the last recording period(last stats interval)
### What did you see instead?
- `getNumMsgsSent()` is actually the number of messages published in the current interval, **NOT** the last interval
- `getNumMsgsSent()` is being updated within the interval
Implementation also indicates current interval
[ProducerStatsRecorderImpl.java](https://github.com/apache/pulsar/blob/v3.1.0/pulsar-client/src/main/java/org/apache/pulsar/client/impl/ProducerStatsRecorderImpl.java#L141-L144)
### Anything else?
Client stats that are referring to current in progress interval
- [ProducerStats](https://github.com/apache/pulsar/blob/v3.1.0/pulsar-client-api/src/main/java/org/apache/pulsar/client/api/ProducerStats.java#L36-L54)
- [ConsumerStats (part-1)](https://github.com/apache/pulsar/blob/v3.1.0/pulsar-client-api/src/main/java/org/apache/pulsar/client/api/ConsumerStats.java#L40-L45)
- [ConsumerStats (part-2)](https://github.com/apache/pulsar/blob/v3.1.0/pulsar-client-api/src/main/java/org/apache/pulsar/client/api/ConsumerStats.java#L60-L75)
Is there any ongoing plan to fix the documentation or the implementation ?
### Are you willing to submit a PR?
- [X] I'm willing to submit a PR!
Contributor guide
Research direction
Start with pulsar-client-api/src/main/java/org/apache/pulsar/client/api/ProducerStats.java and ConsumerStats.java, then compare their descriptions with pulsar-client/src/main/java/org/apache/pulsar/client/impl/ProducerStatsRecorderImpl.java. Determine whether the documented or implemented stats-interval behavior is intended, and align the affected interfaces and implementation so the current versus previous interval is unambiguous.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- api, backend
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100