You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@skywalking.apache.org by wa...@apache.org on 2022/11/26 03:15:23 UTC

[skywalking] branch master updated: Fix Elasticsearch storage: Query `sortMetrics` missing transform real index column name. (#10036)

This is an automated email from the ASF dual-hosted git repository.

wankai pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/skywalking.git


The following commit(s) were added to refs/heads/master by this push:
     new ce3196beff Fix Elasticsearch storage: Query `sortMetrics` missing transform real index column name. (#10036)
ce3196beff is described below

commit ce3196beffe40b3c2d9aceb42102b08fbda36791
Author: Wan Kai <wa...@foxmail.com>
AuthorDate: Sat Nov 26 11:15:17 2022 +0800

    Fix Elasticsearch storage: Query `sortMetrics` missing transform real index column name. (#10036)
---
 docs/en/changes/changes.md                                         | 1 +
 .../storage/plugin/elasticsearch/query/AggregationQueryEsDAO.java  | 7 ++++---
 .../{metrics-top-service-sla.yml => metrics-top-service.yml}       | 0
 test/e2e-v2/cases/storage/storage-cases.yaml                       | 4 +++-
 4 files changed, 8 insertions(+), 4 deletions(-)

diff --git a/docs/en/changes/changes.md b/docs/en/changes/changes.md
index b0efc15fb2..eb89f143dc 100644
--- a/docs/en/changes/changes.md
+++ b/docs/en/changes/changes.md
@@ -133,6 +133,7 @@
 * Fix Elasticsearch storage: In `No-Sharding Mode`, add specific analyzer to the template before index creation to avoid update index error.
 * Internal API: remove undocumented ElasticSearch API usage and use documented one.
 * Fix `BanyanDB.ShardingKey` annotation missed in the generated OAL metrics classes.
+* Fix Elasticsearch storage: Query `sortMetrics` missing transform real index column name.
 
 #### UI
 
diff --git a/oap-server/server-storage-plugin/storage-elasticsearch-plugin/src/main/java/org/apache/skywalking/oap/server/storage/plugin/elasticsearch/query/AggregationQueryEsDAO.java b/oap-server/server-storage-plugin/storage-elasticsearch-plugin/src/main/java/org/apache/skywalking/oap/server/storage/plugin/elasticsearch/query/AggregationQueryEsDAO.java
index 9006ff5f6c..e99d6a6417 100644
--- a/oap-server/server-storage-plugin/storage-elasticsearch-plugin/src/main/java/org/apache/skywalking/oap/server/storage/plugin/elasticsearch/query/AggregationQueryEsDAO.java
+++ b/oap-server/server-storage-plugin/storage-elasticsearch-plugin/src/main/java/org/apache/skywalking/oap/server/storage/plugin/elasticsearch/query/AggregationQueryEsDAO.java
@@ -54,6 +54,7 @@ public class AggregationQueryEsDAO extends EsDAO implements IAggregationQueryDAO
                                             final String valueColumnName,
                                             final Duration duration,
                                             final List<KeyValue> additionalConditions) {
+        final String realValueColumn = IndexController.LogicIndicesRegister.getPhysicalColumnName(condition.getName(), valueColumnName);
         final RangeQueryBuilder basicQuery = Query.range(Metrics.TIME_BUCKET)
                                                   .lte(duration.getEndTimeBucket())
                                                   .gte(duration.getStartTimeBucket());
@@ -102,9 +103,9 @@ public class AggregationQueryEsDAO extends EsDAO implements IAggregationQueryDAO
         search.aggregation(
             Aggregation.terms(Metrics.ENTITY_ID)
                        .field(Metrics.ENTITY_ID)
-                       .order(BucketOrder.aggregation(valueColumnName, asc))
+                       .order(BucketOrder.aggregation(realValueColumn, asc))
                        .size(condition.getTopN())
-                       .subAggregation(Aggregation.avg(valueColumnName).field(valueColumnName))
+                       .subAggregation(Aggregation.avg(realValueColumn).field(realValueColumn))
                        .executionHint(TermsAggregationBuilder.ExecutionHint.MAP)
                        .collectMode(TermsAggregationBuilder.CollectMode.BREADTH_FIRST)
                        .build());
@@ -122,7 +123,7 @@ public class AggregationQueryEsDAO extends EsDAO implements IAggregationQueryDAO
         for (Map<String, Object> termsBucket : buckets) {
             SelectedRecord record = new SelectedRecord();
             record.setId((String) termsBucket.get("key"));
-            Map<String, Object> value = (Map<String, Object>) termsBucket.get(valueColumnName);
+            Map<String, Object> value = (Map<String, Object>) termsBucket.get(realValueColumn);
             record.setValue(String.valueOf(((Number) value.get("value")).longValue()));
             topNList.add(record);
         }
diff --git a/test/e2e-v2/cases/storage/expected/metrics-top-service-sla.yml b/test/e2e-v2/cases/storage/expected/metrics-top-service.yml
similarity index 100%
rename from test/e2e-v2/cases/storage/expected/metrics-top-service-sla.yml
rename to test/e2e-v2/cases/storage/expected/metrics-top-service.yml
diff --git a/test/e2e-v2/cases/storage/storage-cases.yaml b/test/e2e-v2/cases/storage/storage-cases.yaml
index 0dcd9f3811..520fbe42f2 100644
--- a/test/e2e-v2/cases/storage/storage-cases.yaml
+++ b/test/e2e-v2/cases/storage/storage-cases.yaml
@@ -57,8 +57,10 @@ cases:
       )
     expected: expected/trace-users-detail.yml
   # service metrics
+  - query: swctl --display yaml --base-url=http://${oap_host}:${oap_12800}/graphql metrics sorted --name service_apdex 5
+    expected: expected/metrics-top-service.yml
   - query: swctl --display yaml --base-url=http://${oap_host}:${oap_12800}/graphql metrics top --name service_sla 5
-    expected: expected/metrics-top-service-sla.yml
+    expected: expected/metrics-top-service.yml
   - query: swctl --display yaml --base-url=http://${oap_host}:${oap_12800}/graphql metrics linear --name=service_sla --service-name=e2e-service-provider |yq e 'to_entries' -
     expected: expected/metrics-has-value.yml
   - query: swctl --display yaml --base-url=http://${oap_host}:${oap_12800}/graphql metrics linear --name=service_cpm --service-name=e2e-service-provider |yq e 'to_entries' -