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

wusheng 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 bef9eec44b [Feature] Support to query relation metrics through PromQL. 
(#12316)
bef9eec44b is described below

commit bef9eec44b5e4365937fa242cf95ed96f347b93d
Author: yswdqz <[email protected]>
AuthorDate: Sun Jun 16 14:46:22 2024 +0800

    [Feature] Support to query relation metrics through PromQL. (#12316)
---
 docs/en/api/promql-service.md                      | 18 +++++++++------
 docs/en/changes/changes.md                         |  1 +
 .../oap/query/promql/entity/LabelName.java         |  9 +++++++-
 .../query/promql/rt/PromQLExprQueryVisitor.java    | 19 +++++++++++++++
 .../promql/expected/relation-metric-vector.yml     | 27 ++++++++++++++++++++++
 test/e2e-v2/cases/promql/promql-cases.yaml         |  9 ++++++++
 6 files changed, 75 insertions(+), 8 deletions(-)

diff --git a/docs/en/api/promql-service.md b/docs/en/api/promql-service.md
index a610a9ddaa..b9497f5bcc 100644
--- a/docs/en/api/promql-service.md
+++ b/docs/en/api/promql-service.md
@@ -389,8 +389,9 @@ Not all scopes are supported for now, please check the 
following table:
 | Service                 | yes     |
 | ServiceInstance         | yes     |
 | Endpoint                | yes     |
-| ServiceRelation         | no      |
-| ServiceInstanceRelation | no      |
+| ServiceRelation         | yes     |
+| ServiceInstanceRelation | yes     |
+| EndpointRelation        | yes     |
 | Process                 | no      |
 | ProcessRelation         | no      |
 
@@ -398,11 +399,14 @@ Not all scopes are supported for now, please check the 
following table:
 Each metric contains general labels: 
[layer](../../../oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/analysis/Layer.java).
 Different metrics will have different labels depending on their Scope and 
metric value type.
 
-| Query Labels                     | Scope           | Expression Example      
                                                                       |
-|----------------------------------|-----------------|------------------------------------------------------------------------------------------------|
-| layer, service                   | Service         | 
service_cpm{service='$service', layer='$layer'}                                 
               |
-| layer, service, service_instance | ServiceInstance | 
service_instance_cpm{service='$service', service_instance='$service_instance', 
layer='$layer'} |
-| layer, service, endpoint         | Endpoint        | 
endpoint_cpm{service='$service', endpoint='$endpoint', layer='$layer'}          
               |
+| Query Labels                                                                 
     | Scope                   | Expression Example                             
                                                                                
                                                                                
    |
+|-----------------------------------------------------------------------------------|-------------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
+| layer, service                                                               
     | Service                 | service_cpm{service='$service', 
layer='$layer'}                                                                 
                                                                                
                   |
+| layer, service, service_instance                                             
     | ServiceInstance         | service_instance_cpm{service='$service', 
service_instance='$service_instance', layer='$layer'}                           
                                                                                
          |
+| layer, service, endpoint                                                     
     | Endpoint                | endpoint_cpm{service='$service', 
endpoint='$endpoint', layer='$layer'}                                           
                                                                                
                  |
+| layer, service, dest_service, dest_layer                                     
     | ServiceRelation         | service_relation_metric{service='$service', 
layer='$layer', dest_layer='$dest_layer', dest_service='$dest_service'}         
                                                                                
       |
+| layer, service, dest_service, dest_layer, service_instance, 
dest_service_instance | ServiceInstanceRelation | 
service_instance_relation_metric{service='$service', layer='$layer', 
dest_layer='$dest_layer', dest_service='$dest_service', 
dest_service_instance='$dest_service_instance', 
service_instance='$service_instance'} |
+| layer, service, dest_service, dest_layer, endpoint, dest_endpoint            
     | EndpointRelation        | endpoint_relation_metric{service='$service', 
endpoint='$endpoint', layer='$layer', dest_layer='$dest_layer', 
dest_service='$dest_service', dest_endpoint='$dest_endpoint'}                   
                      |
 
 
 
diff --git a/docs/en/changes/changes.md b/docs/en/changes/changes.md
index fca04eede6..694d0f89b5 100644
--- a/docs/en/changes/changes.md
+++ b/docs/en/changes/changes.md
@@ -10,6 +10,7 @@
 * Add Golang as a supported language for Elasticsearch.
 * Remove unnecessary BanyanDB flushing logs(info).
 * Increase `SW_CORE_GRPC_MAX_MESSAGE_SIZE` to 50MB.
+* Support to query relation metrics through PromQL.
 
 #### UI
 
diff --git 
a/oap-server/server-query-plugin/promql-plugin/src/main/java/org/apache/skywalking/oap/query/promql/entity/LabelName.java
 
b/oap-server/server-query-plugin/promql-plugin/src/main/java/org/apache/skywalking/oap/query/promql/entity/LabelName.java
index 63f8f86d5c..a891dec704 100644
--- 
a/oap-server/server-query-plugin/promql-plugin/src/main/java/org/apache/skywalking/oap/query/promql/entity/LabelName.java
+++ 
b/oap-server/server-query-plugin/promql-plugin/src/main/java/org/apache/skywalking/oap/query/promql/entity/LabelName.java
@@ -44,7 +44,14 @@ public enum LabelName {
     RECORD("record"),
     //For endpoint_traffic
     LIMIT("limit"),
-    KEYWORD("keyword");
+    KEYWORD("keyword"),
+    //for service_relation_traffic
+    DEST_SERVICE("dest_service"),
+    DEST_LAYER("dest_layer"),
+    //for service_instance_relation_traffic
+    DEST_SERVICE_INSTANCE("dest_service_instance"),
+    //for endpoint_relation
+    DEST_ENDPOINT("dest_endpoint");
 
     final String label;
 
diff --git 
a/oap-server/server-query-plugin/promql-plugin/src/main/java/org/apache/skywalking/oap/query/promql/rt/PromQLExprQueryVisitor.java
 
b/oap-server/server-query-plugin/promql-plugin/src/main/java/org/apache/skywalking/oap/query/promql/rt/PromQLExprQueryVisitor.java
index c9fba0cbd0..e9570a590f 100644
--- 
a/oap-server/server-query-plugin/promql-plugin/src/main/java/org/apache/skywalking/oap/query/promql/rt/PromQLExprQueryVisitor.java
+++ 
b/oap-server/server-query-plugin/promql-plugin/src/main/java/org/apache/skywalking/oap/query/promql/rt/PromQLExprQueryVisitor.java
@@ -440,6 +440,25 @@ public class PromQLExprQueryVisitor extends 
PromQLParserBaseVisitor<ParseResult>
                 checkLabels(labelMap, LabelName.ENDPOINT);
                 entity.setEndpointName(labelMap.get(LabelName.ENDPOINT));
                 break;
+            case ServiceRelation:
+                checkLabels(labelMap, LabelName.DEST_SERVICE, 
LabelName.DEST_LAYER);
+                
entity.setDestServiceName(labelMap.get(LabelName.DEST_SERVICE));
+                
entity.setDestNormal(Layer.nameOf(labelMap.get(LabelName.DEST_LAYER)).isNormal());
+                break;
+            case ServiceInstanceRelation:
+                checkLabels(labelMap, LabelName.DEST_SERVICE, 
LabelName.SERVICE_INSTANCE, LabelName.DEST_SERVICE_INSTANCE, 
LabelName.DEST_LAYER);
+                
entity.setDestServiceName(labelMap.get(LabelName.DEST_SERVICE));
+                
entity.setServiceInstanceName(labelMap.get(LabelName.SERVICE_INSTANCE));
+                
entity.setDestServiceInstanceName(labelMap.get(LabelName.DEST_SERVICE_INSTANCE));
+                
entity.setDestNormal(Layer.nameOf(labelMap.get(LabelName.DEST_LAYER)).isNormal());
+                break;
+            case EndpointRelation:
+                checkLabels(labelMap, LabelName.DEST_SERVICE, 
LabelName.ENDPOINT, LabelName.DEST_ENDPOINT, LabelName.DEST_LAYER);
+                
entity.setDestServiceName(labelMap.get(LabelName.DEST_SERVICE));
+                entity.setEndpointName(labelMap.get(LabelName.ENDPOINT));
+                
entity.setDestEndpointName(labelMap.get(LabelName.DEST_ENDPOINT));
+                
entity.setDestNormal(Layer.nameOf(labelMap.get(LabelName.DEST_LAYER)).isNormal());
+                break;
         }
         return entity;
     }
diff --git a/test/e2e-v2/cases/promql/expected/relation-metric-vector.yml 
b/test/e2e-v2/cases/promql/expected/relation-metric-vector.yml
new file mode 100644
index 0000000000..4d34926ddb
--- /dev/null
+++ b/test/e2e-v2/cases/promql/expected/relation-metric-vector.yml
@@ -0,0 +1,27 @@
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements.  See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License.  You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+status: success
+data:
+  resultType: vector
+  result:
+    {{- contains .data.result }}
+    - metric:
+        __name__: {{ .metric.__name__}}
+        layer: GENERAL
+      value:
+        - {{ index .value 0 }}
+        - {{ index .value 1 }}
+    {{- end}}
diff --git a/test/e2e-v2/cases/promql/promql-cases.yaml 
b/test/e2e-v2/cases/promql/promql-cases.yaml
index efb618fd7f..51adce32cb 100644
--- a/test/e2e-v2/cases/promql/promql-cases.yaml
+++ b/test/e2e-v2/cases/promql/promql-cases.yaml
@@ -92,3 +92,12 @@ cases:
     expected: expected/endpoint-metric-labeled-matrix.yml
   - query: curl -X GET http://${oap_host}:${oap_9090}/api/v1/query_range -d 
'query=endpoint_cpm{parent_service="e2e-service-consumer", 
layer="GENERAL",top_n="10", order="DES"}&start='$(($(date 
+%s)-1800))'&end='$(date +%s)
     expected: expected/endpoint-metric-sort-matrix.yml
+  ## ServiceRelation
+  - query: curl -X GET http://${oap_host}:${oap_9090}/api/v1/query -d 
'query=service_relation_client_cpm{service="e2e-service-consumer", 
dest_service="e2e-service-provider",layer="GENERAL", dest_layer="GENERAL"}'
+    expected: expected/relation-metric-vector.yml
+  ## ServiceInstanceRelation
+  - query: curl -X GET http://${oap_host}:${oap_9090}/api/v1/query -d 
'query=service_instance_relation_client_cpm{service="e2e-service-consumer", 
dest_service="e2e-service-provider",layer="GENERAL", 
dest_layer="GENERAL",dest_service_instance="provider1",service_instance="consumer1"}'
+    expected: expected/relation-metric-vector.yml
+  ## EndPointRelation
+  - query: curl -X GET http://${oap_host}:${oap_9090}/api/v1/query -d 
'query=endpoint_relation_cpm{service="e2e-service-consumer", 
dest_service="e2e-service-provider",layer="GENERAL", 
dest_layer="GENERAL",dest_endpoint="POST:/users",endpoint="POST:/users"}'
+    expected: expected/relation-metric-vector.yml

Reply via email to