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 f9308302fb Tracing Query Execution HTTP APIs: make the argument 
`service layer` optional. (#13382)
f9308302fb is described below

commit f9308302fb2090803f17aeac8046920c0ec8038e
Author: Wan Kai <wankai...@foxmail.com>
AuthorDate: Thu Jul 24 15:53:46 2025 +0800

    Tracing Query Execution HTTP APIs: make the argument `service layer` 
optional. (#13382)
---
 docs/en/changes/changes.md                         |  1 +
 docs/en/debugging/query-tracing.md                 | 28 +++++++------
 .../oap/query/debug/DebuggingHTTPHandler.java      | 49 ++++++++++++++--------
 3 files changed, 47 insertions(+), 31 deletions(-)

diff --git a/docs/en/changes/changes.md b/docs/en/changes/changes.md
index eaa01eac75..78ecd4b073 100644
--- a/docs/en/changes/changes.md
+++ b/docs/en/changes/changes.md
@@ -44,6 +44,7 @@
 * BanyanDB: remove `index-only` from tag setting.
 * Fix analysis tracing profiling span failure in ES storage.
 * Add UI dashboard for Ruby runtime metrics.
+* Tracing Query Execution HTTP APIs: make the argument `service layer` 
optional.
 
 #### UI
 
diff --git a/docs/en/debugging/query-tracing.md 
b/docs/en/debugging/query-tracing.md
index cd824e9242..dd1805efd3 100644
--- a/docs/en/debugging/query-tracing.md
+++ b/docs/en/debugging/query-tracing.md
@@ -31,6 +31,8 @@ SkyWalking OAP provides the metrics/trace/log/topology query 
tracing to help use
 The query tracing service is provided within the OAP rest server, 
 which could be accessed through HTTP GET `http://{core restHost}:{core 
restPort}/debugging/query/...`.
 
+**Note:** The `layer` of the service is optional, but if the service is 
virtual then required, such the `layer` is 
`VIRTUAL_DATABASE/VIRTUAL_MQ/VIRTUAL_GATEWAY`.
+
 ### Tracing MQE Execution
 - URL: HTTP GET `http://{core restHost}:{core 
restPort}/debugging/query/mqe?{parameters}`.
 - Parameters
@@ -44,7 +46,7 @@ which could be accessed through HTTP GET `http://{core 
restHost}:{core restPort}
 | step                | The query step                                         
                     | Yes                |  
 | coldStage           | Only for BanyanDB, the flag to query from cold stage, 
default is false.     | No                 |  
 | service             | The service name                                       
                     | Yes                |               
-| serviceLayer        | The service layer name                                 
                     | Yes                |               
+| serviceLayer        | The service layer name                                 
                     | No                 |               
 | serviceInstance     | The service instance name                              
                     | No                 |               
 | endpoint            | The endpoint name                                      
                     | No                 |               
 | process             | The process name                                       
                     | No                 |               
@@ -190,7 +192,7 @@ childSpans:
   | step               | The query step                                        
                    | Yes      |  
   | coldStage          | Only for BanyanDB, the flag to query from cold stage, 
default is false.   | No       | 
   | service            | The service name                                      
                    | Yes      |               
-  | serviceLayer       | The service layer name                                
                    | Yes      |               
+  | serviceLayer       | The service layer name                                
                    | No       |               
   | serviceInstance    | The service instance name                             
                    | No       |               
   | endpoint           | The endpoint name                                     
                    | No       |               
   | minTraceDuration   | The minimum duration of the trace                     
                    | No       |               
@@ -205,7 +207,7 @@ The time and step parameters are follow the 
[Duration](../api/query-protocol.md#
 
 - Example
 ```shell
-curl -X GET 
'http://127.0.0.1:12800/debugging/query/trace/queryBasicTraces?startTime=2024-06-26%200900&endTime=2024-06-26%200915&step=MINUTE&service=mock_a_service&serviceLayer=GENERAL&serviceInstance=mock_a_service_instance&traceState=ALL&queryOrder=BY_DURATION&pageNum=1&pageSize=15&tags=http.status_code%3D404%2Chttp.method%3Dget'
 
+curl -X GET 
'http://127.0.0.1:12800/debugging/query/trace/queryBasicTraces?startTime=2024-06-26%200900&endTime=2024-06-26%200915&step=MINUTE&service=mock_a_service&serviceInstance=mock_a_service_instance&traceState=ALL&queryOrder=BY_DURATION&pageNum=1&pageSize=15&tags=http.status_code%3D404%2Chttp.method%3Dget'
 
 ```
 Response will include query result and the debuggingTrace information, the 
debuggingTrace information is the same as the MQE query tracing:
 
@@ -348,12 +350,12 @@ debuggingTrace:
   | endTime       | The end time of the query                                  
                 | Yes      |               
   | step          | The query step                                             
                 | Yes      |
   | coldStage     | Only for BanyanDB, the flag to query from cold stage, 
default is false.     | No       | 
-  | serviceLayer  | The service layer name                                     
                 | Yes      |
+  | serviceLayer  | The service layer name                                     
                 | No       |
   | services      | The services names list, separate by comma 
`mock_a_service, mock_b_service` | Yes      |
 
 - Example
 ```shell
-curl -X GET 
'http://127.0.0.1:12800/debugging/query/topology/getServicesTopology?startTime=2024-07-03&endTime=2024-07-03&step=DAY&serviceLayer=GENERAL&services=mock_a_service%2Cmock_b_service'
+curl -X GET 
'http://127.0.0.1:12800/debugging/query/topology/getServicesTopology?startTime=2024-07-03&endTime=2024-07-03&step=DAY&services=mock_a_service%2Cmock_b_service'
 ```
 
 Response will include query result and the debuggingTrace information, the 
debuggingTrace information is the same as the MQE query tracing:
@@ -379,12 +381,12 @@ debuggingTrace:
   | coldStage          | Only for BanyanDB, the flag to query from cold stage, 
default is false. | No       | 
   | clientService      | The client side service name                          
                  | Yes      |
   | serverService      | The server side service name                          
                  | Yes      |
-  | clientServiceLayer | The client side service layer name                    
                  | Yes      |
-  | serverServiceLayer | The server side service layer name                    
                  | Yes      |
+  | clientServiceLayer | The client side service layer name                    
                  | No      |
+  | serverServiceLayer | The server side service layer name                    
                  | No      |
 
 - Example
 ```shell
-curl -X GET 
'http://127.0.0.1:12800/debugging/query/topology/getServiceInstanceTopology?startTime=2024-07-03&endTime=2024-07-03&step=DAY&clientService=mock_a_service&serverService=mock_b_service&clientServiceLayer=GENERAL&serverServiceLayer=GENERAL'
+curl -X GET 
'http://127.0.0.1:12800/debugging/query/topology/getServiceInstanceTopology?startTime=2024-07-03&endTime=2024-07-03&step=DAY&clientService=mock_a_service&serverService=mock_b_service'
 ```
 
 Response will include query result and the debuggingTrace information, the 
debuggingTrace information is the same as the MQE query tracing:
@@ -409,13 +411,13 @@ debuggingTrace:
   | step           | The query step                                            
              | Yes      |  
   | coldStage      | Only for BanyanDB, the flag to query from cold stage, 
default is false. | No       | 
   | service        | The service name                                          
              | Yes      |
-  | serviceLayer   | The service layer name                                    
              | Yes      |
+  | serviceLayer   | The service layer name                                    
              | No       |
   | endpoint       | The endpoint name                                         
              | Yes      |
 
 - Example
 - Example
 ```shell
-curl -X GET 
'http://127.0.0.1:12800/debugging/query/topology/getEndpointDependencies?startTime=2024-07-03&endTime=2024-07-03&step=DAY&service=mock_a_service&serviceLayer=GENERAL&endpoint=%2Fdubbox-case%2Fcase%2Fdubbox-rest%2F404-test'
+curl -X GET 
'http://127.0.0.1:12800/debugging/query/topology/getEndpointDependencies?startTime=2024-07-03&endTime=2024-07-03&step=DAY&service=mock_a_service&endpoint=%2Fdubbox-case%2Fcase%2Fdubbox-rest%2F404-test'
 ```
 
 Response will include query result and the debuggingTrace information, the 
debuggingTrace information is the same as the MQE query tracing:
@@ -440,12 +442,12 @@ debuggingTrace:
   | step         | The query step                                              
            | Yes      | 
   | coldStage    | Only for BanyanDB, the flag to query from cold stage, 
default is false. | No       | 
   | service      | The service name                                            
            | Yes      |
-  | serviceLayer | The service layer name                                      
            | Yes      |
+  | serviceLayer | The service layer name                                      
            | No      |
   | instance     | The instance name                                           
            | Yes      |
 
 - Example
 ```shell
-curl -X GET 
'http://127.0.0.1:12800/debugging/query/topology/getProcessTopology?startTime=2024-07-03&endTime=2024-07-03&step=DAY&service=mock_a_service&serviceLayer=GENERAL&instance=mock_a_service_instance'
+curl -X GET 
'http://127.0.0.1:12800/debugging/query/topology/getProcessTopology?startTime=2024-07-03&endTime=2024-07-03&step=DAY&service=mock_a_service&instance=mock_a_service_instance'
 ```
 
 Response will include query result and the debuggingTrace information, the 
debuggingTrace information is the same as the MQE query tracing:
@@ -487,7 +489,7 @@ debuggingTrace:
 
 - Example
 ```shell
-curl -X GET 
'http://127.0.0.1:12800/debugging/query/log/queryLogs?service=e2e-service-provider&serviceLayer=GENERAL&startTime=2024-07-09&endTime=2024-07-09&step=DAY&pageNum=1&pageSize=15&queryOrder=ASC&tags=level%3DINFO'
+curl -X GET 
'http://127.0.0.1:12800/debugging/query/log/queryLogs?service=e2e-service-provider&startTime=2024-07-09&endTime=2024-07-09&step=DAY&pageNum=1&pageSize=15&queryOrder=ASC&tags=level%3DINFO'
 ```
 
 Response will include query result and the debuggingTrace information, the 
debuggingTrace information is the same as the MQE query tracing:
diff --git 
a/oap-server/server-query-plugin/status-query-plugin/src/main/java/org/apache/skywalking/oap/query/debug/DebuggingHTTPHandler.java
 
b/oap-server/server-query-plugin/status-query-plugin/src/main/java/org/apache/skywalking/oap/query/debug/DebuggingHTTPHandler.java
index 508cb73e46..342708122c 100644
--- 
a/oap-server/server-query-plugin/status-query-plugin/src/main/java/org/apache/skywalking/oap/query/debug/DebuggingHTTPHandler.java
+++ 
b/oap-server/server-query-plugin/status-query-plugin/src/main/java/org/apache/skywalking/oap/query/debug/DebuggingHTTPHandler.java
@@ -129,7 +129,7 @@ public class DebuggingHTTPHandler {
                                  @Param("step") String step,
                                  @Param("coldStage") Optional<Boolean> 
coldStage,
                                  @Param("service") String service,
-                                 @Param("serviceLayer") String serviceLayer,
+                                 @Param("serviceLayer") Optional<String> 
serviceLayer,
                                  @Param("serviceInstance") Optional<String> 
serviceInstance,
                                  @Param("endpoint") Optional<String> endpoint,
                                  @Param("process") Optional<String> process,
@@ -148,10 +148,15 @@ public class DebuggingHTTPHandler {
         entity.setDestServiceInstanceName(destServiceInstance.orElse(null));
         entity.setDestEndpointName(destEndpoint.orElse(null));
         entity.setDestProcessName(destProcess.orElse(null));
-        entity.setNormal(Layer.nameOf(serviceLayer).isNormal());
-        destServiceLayer.ifPresent(layer -> {
-            entity.setDestNormal(Layer.nameOf(layer).isNormal());
-        });
+
+        serviceLayer.ifPresentOrElse(
+            s -> entity.setNormal(Layer.nameOf(s).isNormal()),
+            () -> entity.setNormal(true)
+        );
+        destServiceLayer.ifPresentOrElse(
+            s -> entity.setDestNormal(Layer.nameOf(s).isNormal()),
+            () -> entity.setDestNormal(true)
+        );
         Duration duration = new Duration();
         duration.setStart(startTime);
         duration.setEnd(endTime);
@@ -187,8 +192,10 @@ public class DebuggingHTTPHandler {
                                    @Param("pageNum") int pageNum,
                                    @Param("pageSize") int pageSize
     ) {
+        // default to true if serviceLayer is not provided
+        final boolean isNormal = serviceLayer.map(s -> 
Layer.nameOf(s).isNormal()).orElse(true);
         Optional<String> serviceId = service.map(
-            name -> IDManager.ServiceID.buildId(name, 
Layer.nameOf(serviceLayer.orElseThrow()).isNormal()));
+            name -> IDManager.ServiceID.buildId(name, isNormal));
         Optional<String> serviceInstanceId = serviceInstance.map(
             name -> 
IDManager.ServiceInstanceID.buildId(serviceId.orElseThrow(), name));
         Optional<String> endpointId = endpoint.map(name -> 
IDManager.EndpointID.buildId(serviceId.orElseThrow(), name));
@@ -350,15 +357,17 @@ public class DebuggingHTTPHandler {
                                       @Param("endTime") String endTime,
                                       @Param("step") String step,
                                       @Param("coldStage") Optional<Boolean> 
coldStage,
-                                      @Param("serviceLayer") String 
serviceLayer,
+                                      @Param("serviceLayer") Optional<String> 
serviceLayer,
                                       @Param("services") String services) {
         Duration duration = new Duration();
         duration.setStart(startTime);
         duration.setEnd(endTime);
         duration.setStep(Step.valueOf(step));
         coldStage.ifPresent(duration::setColdStage);
+        // default to true if serviceLayer is not provided
+        final boolean isNormal = serviceLayer.map(s -> 
Layer.nameOf(s).isNormal()).orElse(true);
         List<String> ids = Arrays.stream(services.split(Const.COMMA))
-                                 .map(name -> 
IDManager.ServiceID.buildId(name, Layer.nameOf(serviceLayer).isNormal()))
+                                 .map(name -> 
IDManager.ServiceID.buildId(name, isNormal))
                                  .collect(Collectors.toList());
         Topology topology = topologyQuery.getServicesTopology(ids, duration, 
true).join();
         DebuggingQueryServiceTopologyRsp result = new 
DebuggingQueryServiceTopologyRsp(
@@ -374,17 +383,17 @@ public class DebuggingHTTPHandler {
                                              @Param("coldStage") 
Optional<Boolean> coldStage,
                                              @Param("clientService") String 
clientService,
                                              @Param("serverService") String 
serverService,
-                                             @Param("clientServiceLayer") 
String clientServiceLayer,
-                                             @Param("serverServiceLayer") 
String serverServiceLayer) {
+                                             @Param("clientServiceLayer") 
Optional<String> clientServiceLayer,
+                                             @Param("serverServiceLayer") 
Optional<String> serverServiceLayer) {
         Duration duration = new Duration();
         duration.setStart(startTime);
         duration.setEnd(endTime);
         duration.setStep(Step.valueOf(step));
         coldStage.ifPresent(duration::setColdStage);
         String clientServiceId = IDManager.ServiceID.buildId(
-            clientService, Layer.nameOf(clientServiceLayer).isNormal());
+            clientService, clientServiceLayer.map(s -> 
Layer.nameOf(s).isNormal()).orElse(true));
         String serverServiceId = IDManager.ServiceID.buildId(
-            serverService, Layer.nameOf(serverServiceLayer).isNormal());
+            serverService, serverServiceLayer.map(s -> 
Layer.nameOf(s).isNormal()).orElse(true));
         ServiceInstanceTopology topology = 
topologyQuery.getServiceInstanceTopology(
             clientServiceId, serverServiceId, duration, true).join();
         DebuggingQueryInstanceTopologyRsp result = new 
DebuggingQueryInstanceTopologyRsp(
@@ -399,7 +408,7 @@ public class DebuggingHTTPHandler {
                                           @Param("step") String step,
                                           @Param("coldStage") 
Optional<Boolean> coldStage,
                                           @Param("service") String service,
-                                          @Param("serviceLayer") String 
serviceLayer,
+                                          @Param("serviceLayer") 
Optional<String> serviceLayer,
                                           @Param("endpoint") String endpoint) {
         Duration duration = new Duration();
         duration.setStart(startTime);
@@ -407,7 +416,9 @@ public class DebuggingHTTPHandler {
         duration.setStep(Step.valueOf(step));
         coldStage.ifPresent(duration::setColdStage);
         String endpointId = IDManager.EndpointID.buildId(
-            IDManager.ServiceID.buildId(service, 
Layer.nameOf(serviceLayer).isNormal()), endpoint);
+            IDManager.ServiceID.buildId(service, serviceLayer.map(s -> 
Layer.nameOf(s).isNormal()).orElse(true)),
+            endpoint
+        );
         EndpointTopology topology = 
topologyQuery.getEndpointDependencies(endpointId, duration, true).join();
         DebuggingQueryEndpointTopologyRsp result = new 
DebuggingQueryEndpointTopologyRsp(
             topology.getNodes(), topology.getCalls(), 
transformTrace(topology.getDebuggingTrace()));
@@ -421,7 +432,7 @@ public class DebuggingHTTPHandler {
                                      @Param("step") String step,
                                      @Param("coldStage") Optional<Boolean> 
coldStage,
                                      @Param("service") String service,
-                                     @Param("serviceLayer") String 
serviceLayer,
+                                     @Param("serviceLayer") Optional<String> 
serviceLayer,
                                      @Param("instance") String process) {
         Duration duration = new Duration();
         duration.setStart(startTime);
@@ -429,7 +440,9 @@ public class DebuggingHTTPHandler {
         duration.setStep(Step.valueOf(step));
         coldStage.ifPresent(duration::setColdStage);
         String instanceId = IDManager.ServiceInstanceID.buildId(
-            IDManager.ServiceID.buildId(service, 
Layer.nameOf(serviceLayer).isNormal()), process);
+            IDManager.ServiceID.buildId(service, serviceLayer.map(s -> 
Layer.nameOf(s).isNormal()).orElse(true)),
+            process
+        );
         ProcessTopology topology = 
topologyQuery.getProcessTopology(instanceId, duration, true).join();
         DebuggingQueryProcessTopologyRsp result = new 
DebuggingQueryProcessTopologyRsp(
             topology.getNodes(), topology.getCalls(), 
transformTrace(topology.getDebuggingTrace()));
@@ -474,9 +487,9 @@ public class DebuggingHTTPHandler {
             coldStage.ifPresent(duration::setColdStage);
             condition.setQueryDuration(duration);
         }
-
+        final boolean isNormal = serviceLayer.map(s -> 
Layer.nameOf(s).isNormal()).orElse(true);
         Optional<String> serviceId = service.map(
-            name -> IDManager.ServiceID.buildId(name, 
Layer.nameOf(serviceLayer.orElseThrow()).isNormal()));
+            name -> IDManager.ServiceID.buildId(name, isNormal));
         Optional<String> serviceInstanceId = serviceInstance.map(
             name -> 
IDManager.ServiceInstanceID.buildId(serviceId.orElseThrow(), name));
         Optional<String> endpointId = endpoint.map(name -> 
IDManager.EndpointID.buildId(serviceId.orElseThrow(), name));

Reply via email to