wu-sheng commented on a change in pull request #7145:
URL: https://github.com/apache/skywalking/pull/7145#discussion_r657540860
##########
File path:
oap-server/analyzer/meter-analyzer/src/main/java/org/apache/skywalking/oap/meter/analyzer/dsl/counter/CounterWindow.java
##########
@@ -42,20 +42,46 @@
public static final CounterWindow INSTANCE = new CounterWindow();
+ private final Map<ID, Tuple2<Long, Double>> lastElementMap =
Maps.newHashMap();
private final Map<ID, Queue<Tuple2<Long, Double>>> windows =
Maps.newHashMap();
public Tuple2<Long, Double> increase(String name, ImmutableMap<String,
String> labels, Double value, long windowSize, long now) {
ID id = new ID(name, labels);
if (!windows.containsKey(id)) {
- windows.put(id, new LinkedList<>());
+ windows.put(id, new PriorityQueue<>());
}
+
Queue<Tuple2<Long, Double>> window = windows.get(id);
window.offer(Tuple.of(now, value));
- Tuple2<Long, Double> ps = window.element();
- if ((now - ps._1) >= windowSize) {
- window.remove();
+ long waterLevel = now - windowSize;
+ Tuple2<Long, Double> peek = window.peek();
+ if (peek._1 > waterLevel) {
+ return peek;
+ }
+
+ Tuple2<Long, Double> result = peek;
+ while (peek._1 < waterLevel) {
+ result = window.poll();
+ peek = window.element();
+ }
+
+ if (waterLevel - result._1 <= peek._1 - waterLevel) {
Review comment:
```suggestion
// Choose the closed slot to the expected timestamp
if (waterLevel - result._1 <= peek._1 - waterLevel) {
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]