Cool-Coding opened a new issue #8707:
URL: https://github.com/apache/skywalking/issues/8707


   ### Search before asking
   
   - [X] I had searched in the 
[issues](https://github.com/apache/skywalking/issues?q=is%3Aissue) and found no 
similar issues.
   
   
   ### Apache SkyWalking Component
   
   OAP server (apache/skywalking)
   
   ### What happened
   
   ```
    - name: instance_metrics_first_aggregation
       exp: metrics_aggregation.tagEqual('dimensionality', 'minute', 'level', 
'1').sum(['service', 'instance']).increase('PT5M')
     - name: instance_metrics_second_aggregation
       exp: metrics_aggregation.tagEqual('dimensionality', 'minute', 'level', 
'2').sum(['service', 'instance']).increase('PT5M')
   ```
    
   The value of first and second aggregation are wrong.
   
   ### What you expected to happen
   
   Both of first and second aggregation use the metrics_aggregation metric.  
the increase method uses 
<code>org.apache.skywalking.oap.meter.analyzer.dsl.counter.CounterWindow</code> 
to calculate.
   
   The CounterWindow class is a Singleton class.  it uses <code>Map</code> to 
store the window data. the Map key is combined by name and labels of some 
metric. but both of  first and second aggregation have the same metric name and 
labels. the metric name is "metrics_aggregation" and the labels is "service, 
instance".  this will result in that they will use the same window.
   
   the increase method is as below
   
   ``` java
     public Tuple2<Long, Double> increase(String name, ImmutableMap<String, 
String> labels, Double value, long windowSize, long now) {
           ID id = new ID(name, labels);
           Queue<Tuple2<Long, Double>> window = windows.computeIfAbsent(id, 
unused -> new PriorityQueue<>());
           window.offer(Tuple.of(now, value));
           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();
           }
   
           // Choose the closed slot to the expected timestamp
           if (waterLevel - result._1 <= peek._1 - waterLevel) {
               return result;
           }
   
           return peek;
       }
   ```
   
   The right configurations i think and have proved are as below.
   
   - self.yaml in fetcher-prom-rules
   
   > I delete the first and second aggregation and create a new metric named 
"instance_metrics_aggregation".
   
   
   ```
    - name: instance_metrics_aggregation
       exp: metrics_aggregation.tagEqual('dimensionality', 
'minute').sum(['service', 'instance', 'level']).increase('PT5M').tag({tags -> 
if (tags['level'] == '1') {tags.level = 'first aggregation'} }).tag({tags -> if 
(tags['level'] == '2') {tags.level = 'second aggregation'} })
   
   ```
   
   - self-observability in ui-initialized-templates
   
   ```
         {
           "width": "3",
           "title": "Aggregation",
           "height": "200",
           "entityType": "ServiceInstance",
           "independentSelector": false,
           "metricType": "LABELED_VALUE",
           "metricName": "meter_oap_instance_metrics_aggregation",
           "queryMetricType": "readLabeledMetricsValues",
           "chartType": "ChartBar",
           "unit": "Per 5 Minute"
         }
   ```
   
   ### How to reproduce
   
   I have debuged in the increase method and watch the metric value in the ui 
page.
   
   ### Anything else
   
   _No response_
   
   ### Are you willing to submit PR?
   
   - [X] Yes I am willing to submit a PR!
   
   ### Code of Conduct
   
   - [X] I agree to follow this project's [Code of 
Conduct](https://www.apache.org/foundation/policies/conduct)
   


-- 
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.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to