Skip to content

Commit f930830

Browse files
authored
Tracing Query Execution HTTP APIs: make the argument service layer optional. (#13382)
1 parent 97985ec commit f930830

File tree

3 files changed

+47
-31
lines changed

3 files changed

+47
-31
lines changed

docs/en/changes/changes.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
* BanyanDB: remove `index-only` from tag setting.
4545
* Fix analysis tracing profiling span failure in ES storage.
4646
* Add UI dashboard for Ruby runtime metrics.
47+
* Tracing Query Execution HTTP APIs: make the argument `service layer` optional.
4748

4849
#### UI
4950

docs/en/debugging/query-tracing.md

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ SkyWalking OAP provides the metrics/trace/log/topology query tracing to help use
3131
The query tracing service is provided within the OAP rest server,
3232
which could be accessed through HTTP GET `http://{core restHost}:{core restPort}/debugging/query/...`.
3333

34+
**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`.
35+
3436
### Tracing MQE Execution
3537
- URL: HTTP GET `http://{core restHost}:{core restPort}/debugging/query/mqe?{parameters}`.
3638
- Parameters
@@ -44,7 +46,7 @@ which could be accessed through HTTP GET `http://{core restHost}:{core restPort}
4446
| step | The query step | Yes |
4547
| coldStage | Only for BanyanDB, the flag to query from cold stage, default is false. | No |
4648
| service | The service name | Yes |
47-
| serviceLayer | The service layer name | Yes |
49+
| serviceLayer | The service layer name | No |
4850
| serviceInstance | The service instance name | No |
4951
| endpoint | The endpoint name | No |
5052
| process | The process name | No |
@@ -190,7 +192,7 @@ childSpans:
190192
| step | The query step | Yes |
191193
| coldStage | Only for BanyanDB, the flag to query from cold stage, default is false. | No |
192194
| service | The service name | Yes |
193-
| serviceLayer | The service layer name | Yes |
195+
| serviceLayer | The service layer name | No |
194196
| serviceInstance | The service instance name | No |
195197
| endpoint | The endpoint name | No |
196198
| 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#
205207

206208
- Example
207209
```shell
208-
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'
210+
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'
209211
```
210212
Response will include query result and the debuggingTrace information, the debuggingTrace information is the same as the MQE query tracing:
211213

@@ -348,12 +350,12 @@ debuggingTrace:
348350
| endTime | The end time of the query | Yes |
349351
| step | The query step | Yes |
350352
| coldStage | Only for BanyanDB, the flag to query from cold stage, default is false. | No |
351-
| serviceLayer | The service layer name | Yes |
353+
| serviceLayer | The service layer name | No |
352354
| services | The services names list, separate by comma `mock_a_service, mock_b_service` | Yes |
353355
354356
- Example
355357
```shell
356-
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'
358+
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'
357359
```
358360
359361
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:
379381
| coldStage | Only for BanyanDB, the flag to query from cold stage, default is false. | No |
380382
| clientService | The client side service name | Yes |
381383
| serverService | The server side service name | Yes |
382-
| clientServiceLayer | The client side service layer name | Yes |
383-
| serverServiceLayer | The server side service layer name | Yes |
384+
| clientServiceLayer | The client side service layer name | No |
385+
| serverServiceLayer | The server side service layer name | No |
384386
385387
- Example
386388
```shell
387-
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'
389+
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'
388390
```
389391
390392
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:
409411
| step | The query step | Yes |
410412
| coldStage | Only for BanyanDB, the flag to query from cold stage, default is false. | No |
411413
| service | The service name | Yes |
412-
| serviceLayer | The service layer name | Yes |
414+
| serviceLayer | The service layer name | No |
413415
| endpoint | The endpoint name | Yes |
414416
415417
- Example
416418
- Example
417419
```shell
418-
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'
420+
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'
419421
```
420422
421423
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:
440442
| step | The query step | Yes |
441443
| coldStage | Only for BanyanDB, the flag to query from cold stage, default is false. | No |
442444
| service | The service name | Yes |
443-
| serviceLayer | The service layer name | Yes |
445+
| serviceLayer | The service layer name | No |
444446
| instance | The instance name | Yes |
445447
446448
- Example
447449
```shell
448-
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'
450+
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'
449451
```
450452
451453
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:
487489
488490
- Example
489491
```shell
490-
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'
492+
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'
491493
```
492494
493495
Response will include query result and the debuggingTrace information, the debuggingTrace information is the same as the MQE query tracing:

oap-server/server-query-plugin/status-query-plugin/src/main/java/org/apache/skywalking/oap/query/debug/DebuggingHTTPHandler.java

Lines changed: 31 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ public String execExpression(@Param("dumpDBRsp") boolean dumpStorageRsp,
129129
@Param("step") String step,
130130
@Param("coldStage") Optional<Boolean> coldStage,
131131
@Param("service") String service,
132-
@Param("serviceLayer") String serviceLayer,
132+
@Param("serviceLayer") Optional<String> serviceLayer,
133133
@Param("serviceInstance") Optional<String> serviceInstance,
134134
@Param("endpoint") Optional<String> endpoint,
135135
@Param("process") Optional<String> process,
@@ -148,10 +148,15 @@ public String execExpression(@Param("dumpDBRsp") boolean dumpStorageRsp,
148148
entity.setDestServiceInstanceName(destServiceInstance.orElse(null));
149149
entity.setDestEndpointName(destEndpoint.orElse(null));
150150
entity.setDestProcessName(destProcess.orElse(null));
151-
entity.setNormal(Layer.nameOf(serviceLayer).isNormal());
152-
destServiceLayer.ifPresent(layer -> {
153-
entity.setDestNormal(Layer.nameOf(layer).isNormal());
154-
});
151+
152+
serviceLayer.ifPresentOrElse(
153+
s -> entity.setNormal(Layer.nameOf(s).isNormal()),
154+
() -> entity.setNormal(true)
155+
);
156+
destServiceLayer.ifPresentOrElse(
157+
s -> entity.setDestNormal(Layer.nameOf(s).isNormal()),
158+
() -> entity.setDestNormal(true)
159+
);
155160
Duration duration = new Duration();
156161
duration.setStart(startTime);
157162
duration.setEnd(endTime);
@@ -187,8 +192,10 @@ public String queryBasicTraces(@Param("service") Optional<String> service,
187192
@Param("pageNum") int pageNum,
188193
@Param("pageSize") int pageSize
189194
) {
195+
// default to true if serviceLayer is not provided
196+
final boolean isNormal = serviceLayer.map(s -> Layer.nameOf(s).isNormal()).orElse(true);
190197
Optional<String> serviceId = service.map(
191-
name -> IDManager.ServiceID.buildId(name, Layer.nameOf(serviceLayer.orElseThrow()).isNormal()));
198+
name -> IDManager.ServiceID.buildId(name, isNormal));
192199
Optional<String> serviceInstanceId = serviceInstance.map(
193200
name -> IDManager.ServiceInstanceID.buildId(serviceId.orElseThrow(), name));
194201
Optional<String> endpointId = endpoint.map(name -> IDManager.EndpointID.buildId(serviceId.orElseThrow(), name));
@@ -350,15 +357,17 @@ public String getServicesTopology(@Param("startTime") String startTime,
350357
@Param("endTime") String endTime,
351358
@Param("step") String step,
352359
@Param("coldStage") Optional<Boolean> coldStage,
353-
@Param("serviceLayer") String serviceLayer,
360+
@Param("serviceLayer") Optional<String> serviceLayer,
354361
@Param("services") String services) {
355362
Duration duration = new Duration();
356363
duration.setStart(startTime);
357364
duration.setEnd(endTime);
358365
duration.setStep(Step.valueOf(step));
359366
coldStage.ifPresent(duration::setColdStage);
367+
// default to true if serviceLayer is not provided
368+
final boolean isNormal = serviceLayer.map(s -> Layer.nameOf(s).isNormal()).orElse(true);
360369
List<String> ids = Arrays.stream(services.split(Const.COMMA))
361-
.map(name -> IDManager.ServiceID.buildId(name, Layer.nameOf(serviceLayer).isNormal()))
370+
.map(name -> IDManager.ServiceID.buildId(name, isNormal))
362371
.collect(Collectors.toList());
363372
Topology topology = topologyQuery.getServicesTopology(ids, duration, true).join();
364373
DebuggingQueryServiceTopologyRsp result = new DebuggingQueryServiceTopologyRsp(
@@ -374,17 +383,17 @@ public String getServiceInstanceTopology(@Param("startTime") String startTime,
374383
@Param("coldStage") Optional<Boolean> coldStage,
375384
@Param("clientService") String clientService,
376385
@Param("serverService") String serverService,
377-
@Param("clientServiceLayer") String clientServiceLayer,
378-
@Param("serverServiceLayer") String serverServiceLayer) {
386+
@Param("clientServiceLayer") Optional<String> clientServiceLayer,
387+
@Param("serverServiceLayer") Optional<String> serverServiceLayer) {
379388
Duration duration = new Duration();
380389
duration.setStart(startTime);
381390
duration.setEnd(endTime);
382391
duration.setStep(Step.valueOf(step));
383392
coldStage.ifPresent(duration::setColdStage);
384393
String clientServiceId = IDManager.ServiceID.buildId(
385-
clientService, Layer.nameOf(clientServiceLayer).isNormal());
394+
clientService, clientServiceLayer.map(s -> Layer.nameOf(s).isNormal()).orElse(true));
386395
String serverServiceId = IDManager.ServiceID.buildId(
387-
serverService, Layer.nameOf(serverServiceLayer).isNormal());
396+
serverService, serverServiceLayer.map(s -> Layer.nameOf(s).isNormal()).orElse(true));
388397
ServiceInstanceTopology topology = topologyQuery.getServiceInstanceTopology(
389398
clientServiceId, serverServiceId, duration, true).join();
390399
DebuggingQueryInstanceTopologyRsp result = new DebuggingQueryInstanceTopologyRsp(
@@ -399,15 +408,17 @@ public String getEndpointDependencies(@Param("startTime") String startTime,
399408
@Param("step") String step,
400409
@Param("coldStage") Optional<Boolean> coldStage,
401410
@Param("service") String service,
402-
@Param("serviceLayer") String serviceLayer,
411+
@Param("serviceLayer") Optional<String> serviceLayer,
403412
@Param("endpoint") String endpoint) {
404413
Duration duration = new Duration();
405414
duration.setStart(startTime);
406415
duration.setEnd(endTime);
407416
duration.setStep(Step.valueOf(step));
408417
coldStage.ifPresent(duration::setColdStage);
409418
String endpointId = IDManager.EndpointID.buildId(
410-
IDManager.ServiceID.buildId(service, Layer.nameOf(serviceLayer).isNormal()), endpoint);
419+
IDManager.ServiceID.buildId(service, serviceLayer.map(s -> Layer.nameOf(s).isNormal()).orElse(true)),
420+
endpoint
421+
);
411422
EndpointTopology topology = topologyQuery.getEndpointDependencies(endpointId, duration, true).join();
412423
DebuggingQueryEndpointTopologyRsp result = new DebuggingQueryEndpointTopologyRsp(
413424
topology.getNodes(), topology.getCalls(), transformTrace(topology.getDebuggingTrace()));
@@ -421,15 +432,17 @@ public String getProcessTopology(@Param("startTime") String startTime,
421432
@Param("step") String step,
422433
@Param("coldStage") Optional<Boolean> coldStage,
423434
@Param("service") String service,
424-
@Param("serviceLayer") String serviceLayer,
435+
@Param("serviceLayer") Optional<String> serviceLayer,
425436
@Param("instance") String process) {
426437
Duration duration = new Duration();
427438
duration.setStart(startTime);
428439
duration.setEnd(endTime);
429440
duration.setStep(Step.valueOf(step));
430441
coldStage.ifPresent(duration::setColdStage);
431442
String instanceId = IDManager.ServiceInstanceID.buildId(
432-
IDManager.ServiceID.buildId(service, Layer.nameOf(serviceLayer).isNormal()), process);
443+
IDManager.ServiceID.buildId(service, serviceLayer.map(s -> Layer.nameOf(s).isNormal()).orElse(true)),
444+
process
445+
);
433446
ProcessTopology topology = topologyQuery.getProcessTopology(instanceId, duration, true).join();
434447
DebuggingQueryProcessTopologyRsp result = new DebuggingQueryProcessTopologyRsp(
435448
topology.getNodes(), topology.getCalls(), transformTrace(topology.getDebuggingTrace()));
@@ -474,9 +487,9 @@ public String queryLogs(@Param("service") Optional<String> service,
474487
coldStage.ifPresent(duration::setColdStage);
475488
condition.setQueryDuration(duration);
476489
}
477-
490+
final boolean isNormal = serviceLayer.map(s -> Layer.nameOf(s).isNormal()).orElse(true);
478491
Optional<String> serviceId = service.map(
479-
name -> IDManager.ServiceID.buildId(name, Layer.nameOf(serviceLayer.orElseThrow()).isNormal()));
492+
name -> IDManager.ServiceID.buildId(name, isNormal));
480493
Optional<String> serviceInstanceId = serviceInstance.map(
481494
name -> IDManager.ServiceInstanceID.buildId(serviceId.orElseThrow(), name));
482495
Optional<String> endpointId = endpoint.map(name -> IDManager.EndpointID.buildId(serviceId.orElseThrow(), name));

0 commit comments

Comments
 (0)