Sentinel Statistic should add time stamp to fix statistics window misalignment problem
- Dominant language
- Java
- Stars
- 23.1k
- Forks
- 8.1k
- PR merge metrics
- No merged PRs in 30d
Description
## Issue Description
Type: *bug report*
### Describe what happened (or what feature you want)
Statistic should add time stamp
### Describe what you expected to happen
`StatisticNode.java
`
```
@Override
public void addPassRequest(int count) {
rollingCounterInSecond.addPass(count);
rollingCounterInMinute.addPass(count);
}
@Override
public void addRtAndSuccess(long rt, int successCount) {
rollingCounterInSecond.addSuccess(successCount);
rollingCounterInSecond.addRT(rt);
rollingCounterInMinute.addSuccess(successCount);
rollingCounterInMinute.addRT(rt);
}
@Override
public void increaseBlockQps(int count) {
rollingCounterInSecond.addBlock(count);
rollingCounterInMinute.addBlock(count);
}
@Override
public void increaseExceptionQps(int count) {
rollingCounterInSecond.addException(count);
rollingCounterInMinute.addException(count);
}
```
**Such as second、 minute multidimensional statistics should be consistent**. **But now they take the current time of the system independently which may lead to some mistake statistics**. **Part of the statistics from last second(rollingCounterInSecond) is counted to the next second(rollingCounterInMinute)**。In particular, the request is in the last second and very close to the next second or high concurrency.
And I think that is why some sentinel users they **question the QPS did not reach the threshold but the request was limited by the flow rule**。 This is because the last second's blocked request counted to next second.
ps: rollingCounterInMinute is the datasource fo dashboard statistics
To fix this bug, I think the multidimensional statistics should based on same time stamp, then the data can be counted in correct and same time window, no matter wherever and whenever.
### How to reproduce it (as minimally and precisely as possible)
### Tell us your environment
### Anything else we need to know?
Contributor guide
Research direction
Start in StatisticNode.java with addPassRequest, addRtAndSuccess, increaseBlockQps, and increaseExceptionQps. Trace how rollingCounterInSecond and rollingCounterInMinute obtain their time windows, then verify that both dimensions use the same timestamp and that requests near a boundary are counted in the correct window. Done means the statistics windows remain aligned under boundary timing and concurrency.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- backend, observability
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 25/100