Support async query for the composite GraphQL query. (#12525)
This commit is contained in:
parent
9b17ff1efe
commit
85b03402e4
|
|
@ -49,6 +49,7 @@
|
|||
* Add Unknown Node when receive Kubernetes peer address is not aware in current cluster.
|
||||
* Fix CounterWindow concurrent increase cause NPE by PriorityQueue
|
||||
* Fix format the endpoint name with empty string.
|
||||
* Support async query for the composite GraphQL query.
|
||||
|
||||
#### UI
|
||||
|
||||
|
|
|
|||
|
|
@ -148,7 +148,7 @@ public class DebuggingHTTPHandler {
|
|||
duration.setStart(startTime);
|
||||
duration.setEnd(endTime);
|
||||
duration.setStep(Step.valueOf(step));
|
||||
ExpressionResult expressionResult = mqeQuery.execExpression(expression, entity, duration, true, dumpStorageRsp);
|
||||
ExpressionResult expressionResult = mqeQuery.execExpression(expression, entity, duration, true, dumpStorageRsp).join();
|
||||
DebuggingTrace execTrace = expressionResult.getDebuggingTrace();
|
||||
DebuggingMQERsp result = new DebuggingMQERsp(
|
||||
expressionResult.getType(), expressionResult.getResults(), expressionResult.getError(),
|
||||
|
|
@ -160,8 +160,8 @@ public class DebuggingHTTPHandler {
|
|||
|
||||
@SneakyThrows
|
||||
@Get("/debugging/query/trace/queryBasicTraces")
|
||||
public String queryBasicTraces(@Param("service") String service,
|
||||
@Param("serviceLayer") String serviceLayer,
|
||||
public String queryBasicTraces(@Param("service") Optional<String> service,
|
||||
@Param("serviceLayer") Optional<String> serviceLayer,
|
||||
@Param("serviceInstance") Optional<String> serviceInstance,
|
||||
@Param("endpoint") Optional<String> endpoint,
|
||||
@Param("traceId") Optional<String> traceId,
|
||||
|
|
@ -176,10 +176,11 @@ public class DebuggingHTTPHandler {
|
|||
@Param("pageNum") int pageNum,
|
||||
@Param("pageSize") int pageSize
|
||||
) {
|
||||
String serviceId = IDManager.ServiceID.buildId(service, Layer.nameOf(serviceLayer).isNormal());
|
||||
Optional<String> serviceId = service.map(
|
||||
name -> IDManager.ServiceID.buildId(name, Layer.nameOf(serviceLayer.orElseThrow()).isNormal()));
|
||||
Optional<String> serviceInstanceId = serviceInstance.map(
|
||||
name -> IDManager.ServiceInstanceID.buildId(serviceId, name));
|
||||
Optional<String> endpointId = endpoint.map(name -> IDManager.EndpointID.buildId(serviceId, name));
|
||||
name -> IDManager.ServiceInstanceID.buildId(serviceId.orElseThrow(), name));
|
||||
Optional<String> endpointId = endpoint.map(name -> IDManager.EndpointID.buildId(serviceId.orElseThrow(), name));
|
||||
Duration duration = new Duration();
|
||||
duration.setStart(startTime);
|
||||
duration.setEnd(endTime);
|
||||
|
|
@ -188,7 +189,7 @@ public class DebuggingHTTPHandler {
|
|||
pagination.setPageNum(pageNum);
|
||||
pagination.setPageSize(pageSize);
|
||||
TraceQueryCondition condition = new TraceQueryCondition();
|
||||
condition.setServiceId(serviceId);
|
||||
condition.setServiceId(serviceId.orElse(null));
|
||||
condition.setServiceInstanceId(serviceInstanceId.orElse(null));
|
||||
condition.setEndpointId(endpointId.orElse(null));
|
||||
condition.setTraceId(traceId.orElse(null));
|
||||
|
|
@ -210,7 +211,7 @@ public class DebuggingHTTPHandler {
|
|||
condition.setTags(tagList);
|
||||
});
|
||||
|
||||
TraceBrief traceBrief = traceQuery.queryBasicTraces(condition, true);
|
||||
TraceBrief traceBrief = traceQuery.queryBasicTraces(condition, true).join();
|
||||
DebuggingQueryTraceBriefRsp result = new DebuggingQueryTraceBriefRsp(
|
||||
traceBrief.getTraces(), transformTrace(traceBrief.getDebuggingTrace()));
|
||||
return transToYAMLString(result);
|
||||
|
|
@ -219,7 +220,7 @@ public class DebuggingHTTPHandler {
|
|||
@SneakyThrows
|
||||
@Get("/debugging/query/trace/queryTrace")
|
||||
public String queryTrace(@Param("traceId") String traceId) {
|
||||
Trace trace = traceQuery.queryTrace(traceId, true);
|
||||
Trace trace = traceQuery.queryTrace(traceId, true).join();
|
||||
DebuggingQueryTraceRsp result = new DebuggingQueryTraceRsp(
|
||||
trace.getSpans(), transformTrace(trace.getDebuggingTrace()));
|
||||
return transToYAMLString(result);
|
||||
|
|
@ -297,7 +298,7 @@ public class DebuggingHTTPHandler {
|
|||
duration.setStart(startTime);
|
||||
duration.setEnd(endTime);
|
||||
duration.setStep(Step.valueOf(step));
|
||||
Topology topology = topologyQuery.getGlobalTopology(duration, serviceLayer.orElse(null), true);
|
||||
Topology topology = topologyQuery.getGlobalTopology(duration, serviceLayer.orElse(null), true).join();
|
||||
DebuggingQueryServiceTopologyRsp result = new DebuggingQueryServiceTopologyRsp(
|
||||
topology.getNodes(), topology.getCalls(), transformTrace(topology.getDebuggingTrace()));
|
||||
return transToYAMLString(result);
|
||||
|
|
@ -318,7 +319,7 @@ public class DebuggingHTTPHandler {
|
|||
List<String> ids = Arrays.stream(services.split(Const.COMMA))
|
||||
.map(name -> IDManager.ServiceID.buildId(name, Layer.nameOf(serviceLayer).isNormal()))
|
||||
.collect(Collectors.toList());
|
||||
Topology topology = topologyQuery.getServicesTopology(ids, duration, true);
|
||||
Topology topology = topologyQuery.getServicesTopology(ids, duration, true).join();
|
||||
DebuggingQueryServiceTopologyRsp result = new DebuggingQueryServiceTopologyRsp(
|
||||
topology.getNodes(), topology.getCalls(), transformTrace(topology.getDebuggingTrace()));
|
||||
return transToYAMLString(result);
|
||||
|
|
@ -339,7 +340,7 @@ public class DebuggingHTTPHandler {
|
|||
duration.setStep(Step.valueOf(step));
|
||||
String clientServiceId = IDManager.ServiceID.buildId(clientService, Layer.nameOf(clientServiceLayer).isNormal());
|
||||
String serverServiceId = IDManager.ServiceID.buildId(serverService, Layer.nameOf(serverServiceLayer).isNormal());
|
||||
ServiceInstanceTopology topology = topologyQuery.getServiceInstanceTopology(clientServiceId, serverServiceId, duration, true);
|
||||
ServiceInstanceTopology topology = topologyQuery.getServiceInstanceTopology(clientServiceId, serverServiceId, duration, true).join();
|
||||
DebuggingQueryInstanceTopologyRsp result = new DebuggingQueryInstanceTopologyRsp(
|
||||
topology.getNodes(), topology.getCalls(), transformTrace(topology.getDebuggingTrace()));
|
||||
return transToYAMLString(result);
|
||||
|
|
@ -359,7 +360,7 @@ public class DebuggingHTTPHandler {
|
|||
duration.setStep(Step.valueOf(step));
|
||||
String endpointId = IDManager.EndpointID.buildId(
|
||||
IDManager.ServiceID.buildId(service, Layer.nameOf(serviceLayer).isNormal()), endpoint);
|
||||
EndpointTopology topology = topologyQuery.getEndpointDependencies(endpointId, duration, true);
|
||||
EndpointTopology topology = topologyQuery.getEndpointDependencies(endpointId, duration, true).join();
|
||||
DebuggingQueryEndpointTopologyRsp result = new DebuggingQueryEndpointTopologyRsp(
|
||||
topology.getNodes(), topology.getCalls(), transformTrace(topology.getDebuggingTrace()));
|
||||
return transToYAMLString(result);
|
||||
|
|
@ -379,7 +380,7 @@ public class DebuggingHTTPHandler {
|
|||
duration.setStep(Step.valueOf(step));
|
||||
String instanceId = IDManager.ServiceInstanceID.buildId(
|
||||
IDManager.ServiceID.buildId(service, Layer.nameOf(serviceLayer).isNormal()), process);
|
||||
ProcessTopology topology = topologyQuery.getProcessTopology(instanceId, duration, true);
|
||||
ProcessTopology topology = topologyQuery.getProcessTopology(instanceId, duration, true).join();
|
||||
DebuggingQueryProcessTopologyRsp result = new DebuggingQueryProcessTopologyRsp(
|
||||
topology.getNodes(), topology.getCalls(), transformTrace(topology.getDebuggingTrace()));
|
||||
return transToYAMLString(result);
|
||||
|
|
@ -447,7 +448,7 @@ public class DebuggingHTTPHandler {
|
|||
excludingKeywordsOfContent.ifPresent(e -> condition.setExcludingKeywordsOfContent(
|
||||
Arrays.stream(e.split(Const.COMMA)).collect(Collectors.toList())));
|
||||
|
||||
Logs logs = logQuery.queryLogs(condition, true);
|
||||
Logs logs = logQuery.queryLogs(condition, true).join();
|
||||
DebuggingQueryLogsRsp result = new DebuggingQueryLogsRsp(
|
||||
logs.getLogs(), logs.getErrorReason(), transformTrace(logs.getDebuggingTrace()));
|
||||
return transToYAMLString(result);
|
||||
|
|
|
|||
|
|
@ -309,11 +309,11 @@ public class PromQLApiHandler {
|
|||
} else if (Objects.equals(metricName, ServiceTraffic.INDEX_NAME)) {
|
||||
String serviceName = parseResult.getLabelMap().get(LabelName.SERVICE.getLabel());
|
||||
if (StringUtil.isNotBlank(serviceName)) {
|
||||
Service service = metadataQuery.findService(serviceName);
|
||||
Service service = metadataQuery.findService(serviceName).join();
|
||||
response.getData().add(buildMetricInfoFromTraffic(metricName, service));
|
||||
} else {
|
||||
List<Service> services = metadataQuery.listServices(
|
||||
parseResult.getLabelMap().get(LabelName.LAYER.getLabel()));
|
||||
parseResult.getLabelMap().get(LabelName.LAYER.getLabel())).join();
|
||||
services.forEach(service -> {
|
||||
response.getData().add(buildMetricInfoFromTraffic(metricName, service));
|
||||
});
|
||||
|
|
@ -322,7 +322,7 @@ public class PromQLApiHandler {
|
|||
String serviceName = parseResult.getLabelMap().get(LabelName.SERVICE.getLabel());
|
||||
String layer = parseResult.getLabelMap().get(LabelName.LAYER.getLabel());
|
||||
List<ServiceInstance> instances = metadataQuery.listInstances(
|
||||
duration, IDManager.ServiceID.buildId(serviceName, Layer.valueOf(layer).isNormal()));
|
||||
duration, IDManager.ServiceID.buildId(serviceName, Layer.valueOf(layer).isNormal())).join();
|
||||
instances.forEach(instance -> {
|
||||
response.getData().add(buildMetricInfoFromTraffic(metricName, instance));
|
||||
});
|
||||
|
|
@ -334,7 +334,7 @@ public class PromQLApiHandler {
|
|||
List<Endpoint> endpoints = metadataQuery.findEndpoint(
|
||||
keyword, IDManager.ServiceID.buildId(serviceName, Layer.valueOf(layer).isNormal()),
|
||||
Integer.parseInt(limit)
|
||||
);
|
||||
).join();
|
||||
endpoints.forEach(endpoint -> {
|
||||
response.getData().add(buildMetricInfoFromTraffic(metricName, endpoint));
|
||||
});
|
||||
|
|
|
|||
|
|
@ -49,7 +49,7 @@ public class AggregationQuery implements GraphQLQueryResolver {
|
|||
condition.setOrder(order);
|
||||
condition.setTopN(topN);
|
||||
List<TopNEntity> list = new ArrayList<>();
|
||||
query.sortMetrics(condition, duration).forEach(selectedRecord -> {
|
||||
query.sortMetrics(condition, duration).join().forEach(selectedRecord -> {
|
||||
TopNEntity entity = new TopNEntity(selectedRecord);
|
||||
list.add(entity);
|
||||
});
|
||||
|
|
@ -64,7 +64,7 @@ public class AggregationQuery implements GraphQLQueryResolver {
|
|||
condition.setOrder(order);
|
||||
condition.setTopN(topN);
|
||||
List<TopNEntity> list = new ArrayList<>();
|
||||
query.sortMetrics(condition, duration).forEach(selectedRecord -> {
|
||||
query.sortMetrics(condition, duration).join().forEach(selectedRecord -> {
|
||||
TopNEntity entity = new TopNEntity(selectedRecord);
|
||||
list.add(entity);
|
||||
});
|
||||
|
|
@ -82,7 +82,7 @@ public class AggregationQuery implements GraphQLQueryResolver {
|
|||
condition.setOrder(order);
|
||||
condition.setTopN(topN);
|
||||
List<TopNEntity> list = new ArrayList<>();
|
||||
query.sortMetrics(condition, duration).forEach(selectedRecord -> {
|
||||
query.sortMetrics(condition, duration).join().forEach(selectedRecord -> {
|
||||
TopNEntity entity = new TopNEntity(selectedRecord);
|
||||
list.add(entity);
|
||||
});
|
||||
|
|
@ -97,7 +97,7 @@ public class AggregationQuery implements GraphQLQueryResolver {
|
|||
condition.setOrder(order);
|
||||
condition.setTopN(topN);
|
||||
List<TopNEntity> list = new ArrayList<>();
|
||||
query.sortMetrics(condition, duration).forEach(selectedRecord -> {
|
||||
query.sortMetrics(condition, duration).join().forEach(selectedRecord -> {
|
||||
TopNEntity entity = new TopNEntity(selectedRecord);
|
||||
list.add(entity);
|
||||
});
|
||||
|
|
@ -115,7 +115,7 @@ public class AggregationQuery implements GraphQLQueryResolver {
|
|||
condition.setOrder(order);
|
||||
condition.setTopN(topN);
|
||||
List<TopNEntity> list = new ArrayList<>();
|
||||
query.sortMetrics(condition, duration).forEach(selectedRecord -> {
|
||||
query.sortMetrics(condition, duration).join().forEach(selectedRecord -> {
|
||||
TopNEntity entity = new TopNEntity(selectedRecord);
|
||||
list.add(entity);
|
||||
});
|
||||
|
|
|
|||
|
|
@ -24,6 +24,7 @@ import java.util.ArrayList;
|
|||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import org.apache.skywalking.oap.server.core.CoreModule;
|
||||
|
|
@ -48,6 +49,7 @@ import org.apache.skywalking.oap.server.library.util.CollectionUtils;
|
|||
import static com.google.common.base.Strings.isNullOrEmpty;
|
||||
import static java.util.Objects.isNull;
|
||||
import static java.util.Objects.nonNull;
|
||||
import static org.apache.skywalking.oap.query.graphql.resolver.AsyncQueryUtils.queryAsync;
|
||||
import static org.apache.skywalking.oap.server.library.util.CollectionUtils.isNotEmpty;
|
||||
|
||||
public class AlarmQuery implements GraphQLQueryResolver {
|
||||
|
|
@ -79,29 +81,31 @@ public class AlarmQuery implements GraphQLQueryResolver {
|
|||
return new AlarmTrend();
|
||||
}
|
||||
|
||||
public Alarms getAlarm(final Duration duration, final Scope scope, final String keyword,
|
||||
public CompletableFuture<Alarms> getAlarm(final Duration duration, final Scope scope, final String keyword,
|
||||
final Pagination paging, final List<Tag> tags,
|
||||
final DataFetchingEnvironment env) throws Exception {
|
||||
Integer scopeId = null;
|
||||
if (scope != null) {
|
||||
scopeId = scope.getScopeId();
|
||||
}
|
||||
final EventQueryCondition.EventQueryConditionBuilder conditionPrototype =
|
||||
EventQueryCondition.builder()
|
||||
.paging(new Pagination(1, IEventQueryDAO.MAX_SIZE));
|
||||
if (nonNull(duration)) {
|
||||
conditionPrototype.time(duration);
|
||||
}
|
||||
Alarms alarms = getQueryService().getAlarm(
|
||||
scopeId, keyword, paging, duration, tags);
|
||||
final DataFetchingEnvironment env) {
|
||||
return queryAsync(() -> {
|
||||
Integer scopeId = null;
|
||||
if (scope != null) {
|
||||
scopeId = scope.getScopeId();
|
||||
}
|
||||
final EventQueryCondition.EventQueryConditionBuilder conditionPrototype =
|
||||
EventQueryCondition.builder()
|
||||
.paging(new Pagination(1, IEventQueryDAO.MAX_SIZE));
|
||||
if (nonNull(duration)) {
|
||||
conditionPrototype.time(duration);
|
||||
}
|
||||
Alarms alarms = getQueryService().getAlarm(
|
||||
scopeId, keyword, paging, duration, tags);
|
||||
|
||||
final boolean selectEvents = env.getSelectionSet().contains("**/events/**");
|
||||
final boolean selectEvents = env.getSelectionSet().contains("**/events/**");
|
||||
|
||||
if (selectEvents) {
|
||||
return findRelevantEvents(alarms, conditionPrototype);
|
||||
}
|
||||
if (selectEvents) {
|
||||
return findRelevantEvents(alarms, conditionPrototype);
|
||||
}
|
||||
|
||||
return alarms;
|
||||
return alarms;
|
||||
});
|
||||
}
|
||||
|
||||
private Alarms findRelevantEvents(
|
||||
|
|
|
|||
|
|
@ -0,0 +1,41 @@
|
|||
/*
|
||||
* 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.
|
||||
*
|
||||
*/
|
||||
|
||||
package org.apache.skywalking.oap.query.graphql.resolver;
|
||||
|
||||
import java.util.concurrent.Callable;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.concurrent.Executor;
|
||||
import java.util.concurrent.ForkJoinPool;
|
||||
|
||||
import static java.util.concurrent.ForkJoinPool.defaultForkJoinWorkerThreadFactory;
|
||||
|
||||
public class AsyncQueryUtils {
|
||||
private static final Executor EXECUTOR = new ForkJoinPool(
|
||||
Runtime.getRuntime().availableProcessors(), defaultForkJoinWorkerThreadFactory, null, true);
|
||||
|
||||
protected static <U> CompletableFuture<U> queryAsync(Callable<U> caller) {
|
||||
return CompletableFuture.supplyAsync(() -> {
|
||||
try {
|
||||
return caller.call();
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}, EXECUTOR);
|
||||
}
|
||||
}
|
||||
|
|
@ -18,8 +18,8 @@
|
|||
package org.apache.skywalking.oap.query.graphql.resolver;
|
||||
|
||||
import graphql.kickstart.tools.GraphQLQueryResolver;
|
||||
import java.io.IOException;
|
||||
import java.util.Optional;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.apache.skywalking.oap.server.core.CoreModule;
|
||||
import org.apache.skywalking.oap.server.core.query.BrowserLogQueryService;
|
||||
|
|
@ -27,6 +27,8 @@ import org.apache.skywalking.oap.server.core.query.input.BrowserErrorLogQueryCon
|
|||
import org.apache.skywalking.oap.server.core.query.type.BrowserErrorLogs;
|
||||
import org.apache.skywalking.oap.server.library.module.ModuleManager;
|
||||
|
||||
import static org.apache.skywalking.oap.query.graphql.resolver.AsyncQueryUtils.queryAsync;
|
||||
|
||||
@RequiredArgsConstructor
|
||||
public class BrowserLogQuery implements GraphQLQueryResolver {
|
||||
private final ModuleManager moduleManager;
|
||||
|
|
@ -39,11 +41,10 @@ public class BrowserLogQuery implements GraphQLQueryResolver {
|
|||
});
|
||||
}
|
||||
|
||||
public BrowserErrorLogs queryBrowserErrorLogs(BrowserErrorLogQueryCondition condition) throws IOException {
|
||||
|
||||
return getQueryService().queryBrowserErrorLogs(
|
||||
public CompletableFuture<BrowserErrorLogs> queryBrowserErrorLogs(BrowserErrorLogQueryCondition condition) {
|
||||
return queryAsync(() -> getQueryService().queryBrowserErrorLogs(
|
||||
condition.getServiceId(), condition.getServiceVersionId(), condition.getPagePathId(),
|
||||
condition.getCategory(), condition.getQueryDuration(), condition.getPaging()
|
||||
);
|
||||
));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -19,6 +19,7 @@
|
|||
package org.apache.skywalking.oap.query.graphql.resolver;
|
||||
|
||||
import graphql.kickstart.tools.GraphQLQueryResolver;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import org.apache.skywalking.oap.server.core.CoreModule;
|
||||
import org.apache.skywalking.oap.server.core.profiling.continuous.ContinuousProfilingQueryService;
|
||||
import org.apache.skywalking.oap.server.core.profiling.continuous.storage.ContinuousProfilingTargetType;
|
||||
|
|
@ -26,9 +27,10 @@ import org.apache.skywalking.oap.server.core.query.type.ContinuousProfilingMonit
|
|||
import org.apache.skywalking.oap.server.core.query.type.ContinuousProfilingPolicyTarget;
|
||||
import org.apache.skywalking.oap.server.library.module.ModuleManager;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
|
||||
import static org.apache.skywalking.oap.query.graphql.resolver.AsyncQueryUtils.queryAsync;
|
||||
|
||||
public class ContinuousProfilingQuery implements GraphQLQueryResolver {
|
||||
|
||||
private final ModuleManager moduleManager;
|
||||
|
|
@ -46,12 +48,11 @@ public class ContinuousProfilingQuery implements GraphQLQueryResolver {
|
|||
return queryService;
|
||||
}
|
||||
|
||||
public List<ContinuousProfilingPolicyTarget> queryContinuousProfilingServiceTargets(String serviceId) throws IOException {
|
||||
return getQueryService().queryContinuousProfilingServiceTargets(serviceId);
|
||||
public CompletableFuture<List<ContinuousProfilingPolicyTarget>> queryContinuousProfilingServiceTargets(String serviceId) {
|
||||
return queryAsync(() -> getQueryService().queryContinuousProfilingServiceTargets(serviceId));
|
||||
}
|
||||
|
||||
public List<ContinuousProfilingMonitoringInstance> queryContinuousProfilingMonitoringInstances(String serviceId, ContinuousProfilingTargetType target) throws IOException {
|
||||
return getQueryService().queryContinuousProfilingMonitoringInstances(serviceId, target);
|
||||
public CompletableFuture<List<ContinuousProfilingMonitoringInstance>> queryContinuousProfilingMonitoringInstances(String serviceId, ContinuousProfilingTargetType target) {
|
||||
return queryAsync(() -> getQueryService().queryContinuousProfilingMonitoringInstances(serviceId, target));
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -19,6 +19,8 @@
|
|||
package org.apache.skywalking.oap.query.graphql.resolver;
|
||||
|
||||
import graphql.kickstart.tools.GraphQLQueryResolver;
|
||||
import java.util.Objects;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import org.apache.skywalking.oap.server.core.CoreModule;
|
||||
import org.apache.skywalking.oap.server.core.profiling.ebpf.EBPFProfilingQueryService;
|
||||
import org.apache.skywalking.oap.server.core.profiling.ebpf.storage.EBPFProfilingTargetType;
|
||||
|
|
@ -32,10 +34,10 @@ import org.apache.skywalking.oap.server.core.query.type.EBPFProfilingTask;
|
|||
import org.apache.skywalking.oap.server.core.query.type.EBPFProfilingTaskPrepare;
|
||||
import org.apache.skywalking.oap.server.library.module.ModuleManager;
|
||||
import org.apache.skywalking.oap.server.library.util.StringUtil;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
|
||||
import static org.apache.skywalking.oap.query.graphql.resolver.AsyncQueryUtils.queryAsync;
|
||||
|
||||
public class EBPFProcessProfilingQuery implements GraphQLQueryResolver {
|
||||
|
||||
private final ModuleManager moduleManager;
|
||||
|
|
@ -54,30 +56,34 @@ public class EBPFProcessProfilingQuery implements GraphQLQueryResolver {
|
|||
return queryService;
|
||||
}
|
||||
|
||||
public EBPFProfilingTaskPrepare queryPrepareCreateEBPFProfilingTaskData(String serviceId) throws IOException {
|
||||
public CompletableFuture<EBPFProfilingTaskPrepare> queryPrepareCreateEBPFProfilingTaskData(String serviceId) {
|
||||
if (StringUtil.isEmpty(serviceId)) {
|
||||
throw new IllegalArgumentException("please provide the service id");
|
||||
}
|
||||
return getQueryService().queryPrepareCreateEBPFProfilingTaskData(serviceId);
|
||||
return queryAsync(() -> getQueryService().queryPrepareCreateEBPFProfilingTaskData(serviceId));
|
||||
}
|
||||
|
||||
public List<EBPFProfilingTask> queryEBPFProfilingTasks(String serviceId, String serviceInstanceId, List<EBPFProfilingTargetType> targets, EBPFProfilingTriggerType triggerType, Duration duration) throws IOException {
|
||||
public CompletableFuture<List<EBPFProfilingTask>> queryEBPFProfilingTasks(String serviceId, String serviceInstanceId, List<EBPFProfilingTargetType> targets, EBPFProfilingTriggerType triggerType, Duration duration) {
|
||||
if (StringUtil.isEmpty(serviceId) && StringUtil.isEmpty(serviceInstanceId)) {
|
||||
throw new IllegalArgumentException("please provide the service id or instance id");
|
||||
}
|
||||
if (triggerType == null) {
|
||||
triggerType = EBPFProfilingTriggerType.FIXED_TIME;
|
||||
}
|
||||
return getQueryService().queryEBPFProfilingTasks(serviceId, serviceInstanceId, targets, triggerType, duration);
|
||||
|
||||
return queryAsync(() -> getQueryService().queryEBPFProfilingTasks(serviceId, serviceInstanceId, targets,
|
||||
Objects.requireNonNullElse(
|
||||
triggerType,
|
||||
EBPFProfilingTriggerType.FIXED_TIME
|
||||
),
|
||||
duration
|
||||
));
|
||||
}
|
||||
|
||||
public List<EBPFProfilingSchedule> queryEBPFProfilingSchedules(String taskId) throws Exception {
|
||||
return getQueryService().queryEBPFProfilingSchedules(taskId);
|
||||
public CompletableFuture<List<EBPFProfilingSchedule>> queryEBPFProfilingSchedules(String taskId) {
|
||||
return queryAsync(() -> getQueryService().queryEBPFProfilingSchedules(taskId));
|
||||
}
|
||||
|
||||
public EBPFProfilingAnalyzation analysisEBPFProfilingResult(List<String> scheduleIdList,
|
||||
public CompletableFuture<EBPFProfilingAnalyzation> analysisEBPFProfilingResult(List<String> scheduleIdList,
|
||||
List<EBPFProfilingAnalyzeTimeRange> timeRanges,
|
||||
EBPFProfilingAnalyzeAggregateType aggregateType) throws IOException {
|
||||
return getQueryService().getEBPFProfilingAnalyzation(scheduleIdList, timeRanges, aggregateType);
|
||||
EBPFProfilingAnalyzeAggregateType aggregateType) {
|
||||
return queryAsync(() -> getQueryService().getEBPFProfilingAnalyzation(scheduleIdList, timeRanges, aggregateType));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -19,12 +19,15 @@
|
|||
package org.apache.skywalking.oap.query.graphql.resolver;
|
||||
|
||||
import graphql.kickstart.tools.GraphQLQueryResolver;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import org.apache.skywalking.oap.server.core.CoreModule;
|
||||
import org.apache.skywalking.oap.server.core.query.EventQueryService;
|
||||
import org.apache.skywalking.oap.server.core.query.type.event.EventQueryCondition;
|
||||
import org.apache.skywalking.oap.server.core.query.type.event.Events;
|
||||
import org.apache.skywalking.oap.server.library.module.ModuleManager;
|
||||
|
||||
import static org.apache.skywalking.oap.query.graphql.resolver.AsyncQueryUtils.queryAsync;
|
||||
|
||||
public class EventQuery implements GraphQLQueryResolver {
|
||||
private EventQueryService queryService;
|
||||
|
||||
|
|
@ -45,7 +48,7 @@ public class EventQuery implements GraphQLQueryResolver {
|
|||
return queryService;
|
||||
}
|
||||
|
||||
public Events queryEvents(final EventQueryCondition condition) throws Exception {
|
||||
return queryService().queryEvents(condition);
|
||||
public CompletableFuture<Events> queryEvents(final EventQueryCondition condition) {
|
||||
return queryAsync(() -> queryService().queryEvents(condition));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -20,6 +20,7 @@ package org.apache.skywalking.oap.query.graphql.resolver;
|
|||
|
||||
import graphql.kickstart.tools.GraphQLQueryResolver;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import org.apache.skywalking.oap.server.core.CoreModule;
|
||||
import org.apache.skywalking.oap.server.core.query.HierarchyQueryService;
|
||||
import org.apache.skywalking.oap.server.core.query.type.InstanceHierarchy;
|
||||
|
|
@ -27,6 +28,8 @@ import org.apache.skywalking.oap.server.core.query.type.LayerLevel;
|
|||
import org.apache.skywalking.oap.server.core.query.type.ServiceHierarchy;
|
||||
import org.apache.skywalking.oap.server.library.module.ModuleManager;
|
||||
|
||||
import static org.apache.skywalking.oap.query.graphql.resolver.AsyncQueryUtils.queryAsync;
|
||||
|
||||
public class HierarchyQuery implements GraphQLQueryResolver {
|
||||
private final ModuleManager moduleManager;
|
||||
private HierarchyQueryService hierarchyQueryService;
|
||||
|
|
@ -44,15 +47,15 @@ public class HierarchyQuery implements GraphQLQueryResolver {
|
|||
return hierarchyQueryService;
|
||||
}
|
||||
|
||||
public ServiceHierarchy getServiceHierarchy(String serviceId, String layer) throws Exception {
|
||||
return getHierarchyQueryService().getServiceHierarchy(serviceId, layer);
|
||||
public CompletableFuture<ServiceHierarchy> getServiceHierarchy(String serviceId, String layer) {
|
||||
return queryAsync(() -> getHierarchyQueryService().getServiceHierarchy(serviceId, layer));
|
||||
}
|
||||
|
||||
public InstanceHierarchy getInstanceHierarchy(String instanceId, String layer) throws Exception {
|
||||
return getHierarchyQueryService().getInstanceHierarchy(instanceId, layer);
|
||||
public CompletableFuture<InstanceHierarchy> getInstanceHierarchy(String instanceId, String layer) {
|
||||
return queryAsync(() -> getHierarchyQueryService().getInstanceHierarchy(instanceId, layer));
|
||||
}
|
||||
|
||||
public List<LayerLevel> listLayerLevels() throws Exception {
|
||||
return getHierarchyQueryService().listLayerLevels();
|
||||
public CompletableFuture<List<LayerLevel>> listLayerLevels() {
|
||||
return queryAsync(() -> getHierarchyQueryService().listLayerLevels());
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -21,6 +21,7 @@ package org.apache.skywalking.oap.query.graphql.resolver;
|
|||
import graphql.kickstart.tools.GraphQLQueryResolver;
|
||||
import java.io.IOException;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import org.apache.skywalking.oap.server.core.CoreModule;
|
||||
import org.apache.skywalking.oap.server.core.UnexpectedException;
|
||||
import org.apache.skywalking.oap.server.core.analysis.manual.searchtag.TagType;
|
||||
|
|
@ -37,6 +38,7 @@ import org.apache.skywalking.oap.server.library.util.CollectionUtils;
|
|||
import org.apache.skywalking.oap.server.library.util.StringUtil;
|
||||
|
||||
import static java.util.Objects.isNull;
|
||||
import static org.apache.skywalking.oap.query.graphql.resolver.AsyncQueryUtils.queryAsync;
|
||||
import static org.apache.skywalking.oap.server.core.query.type.debugging.DebuggingTraceContext.TRACE_CONTEXT;
|
||||
|
||||
public class LogQuery implements GraphQLQueryResolver {
|
||||
|
|
@ -66,21 +68,24 @@ public class LogQuery implements GraphQLQueryResolver {
|
|||
return getQueryService().supportQueryLogsByKeywords();
|
||||
}
|
||||
|
||||
public Logs queryLogs(LogQueryCondition condition, boolean debug) throws IOException {
|
||||
DebuggingTraceContext traceContext = new DebuggingTraceContext("LogQueryCondition: " + condition, debug, false);
|
||||
DebuggingTraceContext.TRACE_CONTEXT.set(traceContext);
|
||||
DebuggingSpan span = traceContext.createSpan("Query logs");
|
||||
try {
|
||||
Logs logs = invokeQueryLogs(condition);
|
||||
if (debug) {
|
||||
logs.setDebuggingTrace(traceContext.getExecTrace());
|
||||
public CompletableFuture<Logs> queryLogs(LogQueryCondition condition, boolean debug) {
|
||||
return queryAsync(() -> {
|
||||
DebuggingTraceContext traceContext = new DebuggingTraceContext(
|
||||
"LogQueryCondition: " + condition, debug, false);
|
||||
DebuggingTraceContext.TRACE_CONTEXT.set(traceContext);
|
||||
DebuggingSpan span = traceContext.createSpan("Query logs");
|
||||
try {
|
||||
Logs logs = invokeQueryLogs(condition);
|
||||
if (debug) {
|
||||
logs.setDebuggingTrace(traceContext.getExecTrace());
|
||||
}
|
||||
return logs;
|
||||
} finally {
|
||||
traceContext.stopSpan(span);
|
||||
traceContext.stopTrace();
|
||||
TRACE_CONTEXT.remove();
|
||||
}
|
||||
return logs;
|
||||
} finally {
|
||||
traceContext.stopSpan(span);
|
||||
traceContext.stopTrace();
|
||||
TRACE_CONTEXT.remove();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private Logs invokeQueryLogs(LogQueryCondition condition) throws IOException {
|
||||
|
|
@ -115,11 +120,11 @@ public class LogQuery implements GraphQLQueryResolver {
|
|||
);
|
||||
}
|
||||
|
||||
public Set<String> queryLogTagAutocompleteKeys(final Duration queryDuration) throws IOException {
|
||||
return getTagQueryService().queryTagAutocompleteKeys(TagType.LOG, queryDuration);
|
||||
public CompletableFuture<Set<String>> queryLogTagAutocompleteKeys(final Duration queryDuration) {
|
||||
return queryAsync(() -> getTagQueryService().queryTagAutocompleteKeys(TagType.LOG, queryDuration));
|
||||
}
|
||||
|
||||
public Set<String> queryLogTagAutocompleteValues(final String tagKey, final Duration queryDuration) throws IOException {
|
||||
return getTagQueryService().queryTagAutocompleteValues(TagType.LOG, tagKey, queryDuration);
|
||||
public CompletableFuture<Set<String>> queryLogTagAutocompleteValues(final String tagKey, final Duration queryDuration) {
|
||||
return queryAsync(() -> getTagQueryService().queryTagAutocompleteValues(TagType.LOG, tagKey, queryDuration));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -19,11 +19,11 @@
|
|||
package org.apache.skywalking.oap.query.graphql.resolver;
|
||||
|
||||
import graphql.kickstart.tools.GraphQLQueryResolver;
|
||||
import java.io.IOException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import org.apache.skywalking.oap.query.graphql.type.TimeInfo;
|
||||
import org.apache.skywalking.oap.server.core.CoreModule;
|
||||
import org.apache.skywalking.oap.server.core.analysis.IDManager;
|
||||
|
|
@ -36,6 +36,8 @@ import org.apache.skywalking.oap.server.core.query.type.Service;
|
|||
import org.apache.skywalking.oap.server.core.query.type.ServiceInstance;
|
||||
import org.apache.skywalking.oap.server.library.module.ModuleManager;
|
||||
|
||||
import static org.apache.skywalking.oap.query.graphql.resolver.AsyncQueryUtils.queryAsync;
|
||||
|
||||
/**
|
||||
* Metadata v2 query protocol implementation.
|
||||
*
|
||||
|
|
@ -59,50 +61,50 @@ public class MetadataQueryV2 implements GraphQLQueryResolver {
|
|||
return metadataQueryService;
|
||||
}
|
||||
|
||||
public Set<String> listLayers() throws IOException {
|
||||
return getMetadataQueryService().listLayers();
|
||||
public CompletableFuture<Set<String>> listLayers() {
|
||||
return queryAsync(() -> getMetadataQueryService().listLayers());
|
||||
}
|
||||
|
||||
public List<Service> listServices(final String layer) throws IOException {
|
||||
return getMetadataQueryService().listServices(layer, null);
|
||||
public CompletableFuture<List<Service>> listServices(final String layer) {
|
||||
return queryAsync(() -> getMetadataQueryService().listServices(layer, null));
|
||||
}
|
||||
|
||||
public Service findService(final String serviceName) throws IOException {
|
||||
return getMetadataQueryService().getService(IDManager.ServiceID.buildId(serviceName, true));
|
||||
public CompletableFuture<Service> findService(final String serviceName) {
|
||||
return queryAsync(() -> getMetadataQueryService().getService(IDManager.ServiceID.buildId(serviceName, true)));
|
||||
}
|
||||
|
||||
public Service getService(final String serviceId) throws IOException {
|
||||
return getMetadataQueryService().getService(serviceId);
|
||||
public CompletableFuture<Service> getService(final String serviceId) {
|
||||
return queryAsync(() -> getMetadataQueryService().getService(serviceId));
|
||||
}
|
||||
|
||||
public List<ServiceInstance> listInstances(final Duration duration,
|
||||
final String serviceId) throws IOException {
|
||||
return getMetadataQueryService().listInstances(duration, serviceId);
|
||||
public CompletableFuture<List<ServiceInstance>> listInstances(final Duration duration,
|
||||
final String serviceId) {
|
||||
return queryAsync(() -> getMetadataQueryService().listInstances(duration, serviceId));
|
||||
}
|
||||
|
||||
public ServiceInstance getInstance(final String instanceId) throws IOException {
|
||||
return getMetadataQueryService().getInstance(instanceId);
|
||||
public CompletableFuture<ServiceInstance> getInstance(final String instanceId) {
|
||||
return queryAsync(() -> getMetadataQueryService().getInstance(instanceId));
|
||||
}
|
||||
|
||||
public List<Endpoint> findEndpoint(final String keyword, final String serviceId,
|
||||
final int limit) throws IOException {
|
||||
return getMetadataQueryService().findEndpoint(keyword, serviceId, limit);
|
||||
public CompletableFuture<List<Endpoint>> findEndpoint(final String keyword, final String serviceId,
|
||||
final int limit) {
|
||||
return queryAsync(() -> getMetadataQueryService().findEndpoint(keyword, serviceId, limit));
|
||||
}
|
||||
|
||||
public EndpointInfo getEndpointInfo(final String endpointId) throws IOException {
|
||||
return getMetadataQueryService().getEndpointInfo(endpointId);
|
||||
public CompletableFuture<EndpointInfo> getEndpointInfo(final String endpointId) {
|
||||
return queryAsync(() -> getMetadataQueryService().getEndpointInfo(endpointId));
|
||||
}
|
||||
|
||||
public List<Process> listProcesses(final Duration duration, final String instanceId) throws IOException {
|
||||
return getMetadataQueryService().listProcesses(duration, instanceId);
|
||||
public CompletableFuture<List<Process>> listProcesses(final Duration duration, final String instanceId) {
|
||||
return queryAsync(() -> getMetadataQueryService().listProcesses(duration, instanceId));
|
||||
}
|
||||
|
||||
public Process getProcess(final String processId) throws IOException {
|
||||
return getMetadataQueryService().getProcess(processId);
|
||||
public CompletableFuture<Process> getProcess(final String processId) {
|
||||
return queryAsync(() -> getMetadataQueryService().getProcess(processId));
|
||||
}
|
||||
|
||||
public Long estimateProcessScale(String serviceId, List<String> labels) throws IOException {
|
||||
return getMetadataQueryService().estimateProcessScale(serviceId, labels);
|
||||
public CompletableFuture<Long> estimateProcessScale(String serviceId, List<String> labels) {
|
||||
return queryAsync(() -> getMetadataQueryService().estimateProcessScale(serviceId, labels));
|
||||
}
|
||||
|
||||
public TimeInfo getTimeInfo() {
|
||||
|
|
|
|||
|
|
@ -59,21 +59,17 @@ public class MetricQuery implements GraphQLQueryResolver {
|
|||
condition.setName(metrics.getName());
|
||||
condition.setEntity(new MockEntity(null));
|
||||
|
||||
kv.setValue(query.readMetricsValue(condition, duration));
|
||||
kv.setValue(query.readMetricsValue(condition, duration).join());
|
||||
values.addKVInt(kv);
|
||||
} else {
|
||||
List<KVInt> ints = metrics.getIds().parallelStream().map(id -> {
|
||||
MetricsCondition condition = new MetricsCondition();
|
||||
condition.setName(metrics.getName());
|
||||
condition.setEntity(new MockEntity(id));
|
||||
try {
|
||||
KVInt kv = new KVInt();
|
||||
kv.setId(id);
|
||||
kv.setValue(query.readMetricsValue(condition, duration));
|
||||
return kv;
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
KVInt kv = new KVInt();
|
||||
kv.setId(id);
|
||||
kv.setValue(query.readMetricsValue(condition, duration).join());
|
||||
return kv;
|
||||
}).collect(Collectors.toList());
|
||||
ints.forEach(v -> values.addKVInt(v));
|
||||
|
||||
|
|
@ -88,7 +84,7 @@ public class MetricQuery implements GraphQLQueryResolver {
|
|||
condition.setName(metrics.getName());
|
||||
condition.setEntity(new MockEntity(metrics.getId()));
|
||||
|
||||
final MetricsValues metricsValues = query.readMetricsValues(condition, duration);
|
||||
final MetricsValues metricsValues = query.readMetricsValues(condition, duration).join();
|
||||
return metricsValues.getValues();
|
||||
}
|
||||
|
||||
|
|
@ -103,7 +99,7 @@ public class MetricQuery implements GraphQLQueryResolver {
|
|||
labels.add(String.valueOf(i));
|
||||
}
|
||||
|
||||
final List<MetricsValues> metricsValues = query.readLabeledMetricsValues(condition, labels, duration);
|
||||
final List<MetricsValues> metricsValues = query.readLabeledMetricsValues(condition, labels, duration).join();
|
||||
List<IntValues> response = new ArrayList<>(metricsValues.size());
|
||||
labels.forEach(l -> metricsValues.stream()
|
||||
.filter(m -> m.getLabel().equals(l))
|
||||
|
|
@ -122,7 +118,7 @@ public class MetricQuery implements GraphQLQueryResolver {
|
|||
List<String> labels = new ArrayList<>(linearIndex.size());
|
||||
linearIndex.forEach(i -> labels.add(String.valueOf(i)));
|
||||
|
||||
final List<MetricsValues> metricsValues = query.readLabeledMetricsValues(condition, labels, duration);
|
||||
final List<MetricsValues> metricsValues = query.readLabeledMetricsValues(condition, labels, duration).join();
|
||||
List<IntValues> response = new ArrayList<>(metricsValues.size());
|
||||
labels.forEach(l -> metricsValues.stream()
|
||||
.filter(m -> m.getLabel().equals(l))
|
||||
|
|
@ -137,7 +133,7 @@ public class MetricQuery implements GraphQLQueryResolver {
|
|||
condition.setName(metrics.getName());
|
||||
condition.setEntity(new MockEntity(metrics.getId()));
|
||||
|
||||
final HeatMap heatMap = query.readHeatMap(condition, duration);
|
||||
final HeatMap heatMap = query.readHeatMap(condition, duration).join();
|
||||
|
||||
Thermodynamic thermodynamic = new Thermodynamic();
|
||||
final List<Bucket> buckets = heatMap.getBuckets();
|
||||
|
|
|
|||
|
|
@ -19,6 +19,7 @@
|
|||
package org.apache.skywalking.oap.query.graphql.resolver;
|
||||
|
||||
import graphql.kickstart.tools.GraphQLQueryResolver;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import org.antlr.v4.runtime.misc.ParseCancellationException;
|
||||
import java.text.DecimalFormat;
|
||||
import org.antlr.v4.runtime.CharStreams;
|
||||
|
|
@ -37,6 +38,7 @@ import org.apache.skywalking.oap.server.library.module.ModuleManager;
|
|||
import org.apache.skywalking.mqe.rt.grammar.MQELexer;
|
||||
import org.apache.skywalking.mqe.rt.grammar.MQEParser;
|
||||
|
||||
import static org.apache.skywalking.oap.query.graphql.resolver.AsyncQueryUtils.queryAsync;
|
||||
import static org.apache.skywalking.oap.server.core.query.type.debugging.DebuggingTraceContext.TRACE_CONTEXT;
|
||||
|
||||
public class MetricsExpressionQuery implements GraphQLQueryResolver {
|
||||
|
|
@ -48,53 +50,55 @@ public class MetricsExpressionQuery implements GraphQLQueryResolver {
|
|||
this.valueFormat.setGroupingUsed(false);
|
||||
}
|
||||
|
||||
public ExpressionResult execExpression(String expression,
|
||||
Entity entity,
|
||||
Duration duration,
|
||||
boolean debug,
|
||||
boolean dumpStorageRsp) {
|
||||
DebuggingTraceContext traceContext = new DebuggingTraceContext(
|
||||
"Expression: " + expression + ", Entity: " + entity + ", Duration: " + duration, debug, dumpStorageRsp);
|
||||
TRACE_CONTEXT.set(traceContext);
|
||||
DebuggingSpan span = traceContext.createSpan("MQE query");
|
||||
try {
|
||||
MQEVisitor visitor = new MQEVisitor(moduleManager, entity, duration);
|
||||
DebuggingTrace execTrace = traceContext.getExecTrace();
|
||||
DebuggingSpan syntaxSpan = traceContext.createSpan("MQE syntax analysis");
|
||||
ParseTree tree;
|
||||
public CompletableFuture<ExpressionResult> execExpression(String expression,
|
||||
Entity entity,
|
||||
Duration duration,
|
||||
boolean debug,
|
||||
boolean dumpStorageRsp) {
|
||||
return queryAsync(() -> {
|
||||
DebuggingTraceContext traceContext = new DebuggingTraceContext(
|
||||
"Expression: " + expression + ", Entity: " + entity + ", Duration: " + duration, debug, dumpStorageRsp);
|
||||
TRACE_CONTEXT.set(traceContext);
|
||||
DebuggingSpan span = traceContext.createSpan("MQE query");
|
||||
try {
|
||||
MQELexer lexer = new MQELexer(
|
||||
CharStreams.fromString(expression));
|
||||
lexer.addErrorListener(new ParseErrorListener());
|
||||
MQEParser parser = new MQEParser(new CommonTokenStream(lexer));
|
||||
parser.addErrorListener(new ParseErrorListener());
|
||||
MQEVisitor visitor = new MQEVisitor(moduleManager, entity, duration);
|
||||
DebuggingTrace execTrace = traceContext.getExecTrace();
|
||||
DebuggingSpan syntaxSpan = traceContext.createSpan("MQE syntax analysis");
|
||||
ParseTree tree;
|
||||
try {
|
||||
tree = parser.expression();
|
||||
} catch (ParseCancellationException e) {
|
||||
ExpressionResult errorResult = new ExpressionResult();
|
||||
errorResult.setType(ExpressionResultType.UNKNOWN);
|
||||
errorResult.setError(e.getMessage());
|
||||
return errorResult;
|
||||
}
|
||||
} finally {
|
||||
traceContext.stopSpan(syntaxSpan);
|
||||
}
|
||||
ExpressionResult parseResult = visitor.visit(tree);
|
||||
parseResult.getResults().forEach(mqeValues -> {
|
||||
mqeValues.getValues().forEach(mqeValue -> {
|
||||
if (!mqeValue.isEmptyValue()) {
|
||||
mqeValue.setValue(valueFormat.format(mqeValue.getDoubleValue()));
|
||||
MQELexer lexer = new MQELexer(
|
||||
CharStreams.fromString(expression));
|
||||
lexer.addErrorListener(new ParseErrorListener());
|
||||
MQEParser parser = new MQEParser(new CommonTokenStream(lexer));
|
||||
parser.addErrorListener(new ParseErrorListener());
|
||||
try {
|
||||
tree = parser.expression();
|
||||
} catch (ParseCancellationException e) {
|
||||
ExpressionResult errorResult = new ExpressionResult();
|
||||
errorResult.setType(ExpressionResultType.UNKNOWN);
|
||||
errorResult.setError(e.getMessage());
|
||||
return errorResult;
|
||||
}
|
||||
} finally {
|
||||
traceContext.stopSpan(syntaxSpan);
|
||||
}
|
||||
ExpressionResult parseResult = visitor.visit(tree);
|
||||
parseResult.getResults().forEach(mqeValues -> {
|
||||
mqeValues.getValues().forEach(mqeValue -> {
|
||||
if (!mqeValue.isEmptyValue()) {
|
||||
mqeValue.setValue(valueFormat.format(mqeValue.getDoubleValue()));
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
if (debug) {
|
||||
parseResult.setDebuggingTrace(execTrace);
|
||||
if (debug) {
|
||||
parseResult.setDebuggingTrace(execTrace);
|
||||
}
|
||||
return parseResult;
|
||||
} finally {
|
||||
traceContext.stopSpan(span);
|
||||
traceContext.stopTrace();
|
||||
TRACE_CONTEXT.remove();
|
||||
}
|
||||
return parseResult;
|
||||
} finally {
|
||||
traceContext.stopSpan(span);
|
||||
traceContext.stopTrace();
|
||||
TRACE_CONTEXT.remove();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -19,11 +19,11 @@
|
|||
package org.apache.skywalking.oap.query.graphql.resolver;
|
||||
|
||||
import graphql.kickstart.tools.GraphQLQueryResolver;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import org.apache.skywalking.oap.server.core.Const;
|
||||
|
|
@ -50,6 +50,8 @@ import org.apache.skywalking.oap.server.core.query.type.Record;
|
|||
import org.apache.skywalking.oap.server.core.query.type.SelectedRecord;
|
||||
import org.apache.skywalking.oap.server.library.module.ModuleManager;
|
||||
|
||||
import static org.apache.skywalking.oap.query.graphql.resolver.AsyncQueryUtils.queryAsync;
|
||||
|
||||
/**
|
||||
* Metrics v2 query protocol implementation.
|
||||
*
|
||||
|
|
@ -105,8 +107,8 @@ public class MetricsQuery implements GraphQLQueryResolver {
|
|||
/**
|
||||
* Metrics definition metadata query. Response the metrics type which determines the suitable query methods.
|
||||
*/
|
||||
public MetricsType typeOfMetrics(String name) throws IOException {
|
||||
return MetricsMetadataQueryService.typeOfMetrics(name);
|
||||
public CompletableFuture<MetricsType> typeOfMetrics(String name) {
|
||||
return queryAsync(() -> MetricsMetadataQueryService.typeOfMetrics(name));
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -115,79 +117,43 @@ public class MetricsQuery implements GraphQLQueryResolver {
|
|||
* @param regex to filter the metrics by name, if existing.
|
||||
* @return all available metrics.
|
||||
*/
|
||||
public List<MetricDefinition> listMetrics(String regex) {
|
||||
return getMetricsMetadataQueryService().listMetrics(regex);
|
||||
public CompletableFuture<List<MetricDefinition>> listMetrics(String regex) {
|
||||
return queryAsync(() -> getMetricsMetadataQueryService().listMetrics(regex));
|
||||
}
|
||||
|
||||
/**
|
||||
* Read metrics single value in the duration of required metrics
|
||||
*/
|
||||
public long readMetricsValue(MetricsCondition condition, Duration duration) throws IOException {
|
||||
if (!condition.senseScope() || !condition.getEntity().isValid()) {
|
||||
return 0;
|
||||
}
|
||||
return getMetricsQueryService().readMetricsValue(condition, duration).getValue();
|
||||
public CompletableFuture<Long> readMetricsValue(MetricsCondition condition, Duration duration) {
|
||||
return queryAsync(() -> {
|
||||
if (!condition.senseScope() || !condition.getEntity().isValid()) {
|
||||
return 0L;
|
||||
}
|
||||
return getMetricsQueryService().readMetricsValue(condition, duration).getValue();
|
||||
});
|
||||
}
|
||||
|
||||
public NullableValue readNullableMetricsValue(MetricsCondition condition, Duration duration) throws IOException {
|
||||
if (!condition.senseScope() || !condition.getEntity().isValid()) {
|
||||
return new NullableValue(0, true);
|
||||
}
|
||||
return getMetricsQueryService().readMetricsValue(condition, duration);
|
||||
public CompletableFuture<NullableValue> readNullableMetricsValue(MetricsCondition condition, Duration duration) {
|
||||
return queryAsync(() -> {
|
||||
if (!condition.senseScope() || !condition.getEntity().isValid()) {
|
||||
return new NullableValue(0, true);
|
||||
}
|
||||
return getMetricsQueryService().readMetricsValue(condition, duration);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Read time-series values in the duration of required metrics
|
||||
*/
|
||||
public MetricsValues readMetricsValues(MetricsCondition condition, Duration duration) throws IOException {
|
||||
boolean hasScope = condition.senseScope();
|
||||
if (!hasScope || !condition.getEntity().isValid()) {
|
||||
final List<PointOfTime> pointOfTimes = duration.assembleDurationPoints();
|
||||
String entityId = "UNKNOWN_METRIC_NAME";
|
||||
if (hasScope) {
|
||||
entityId = "ILLEGAL_ENTITY";
|
||||
}
|
||||
MetricsValues values = new MetricsValues();
|
||||
for (PointOfTime pointOfTime : pointOfTimes) {
|
||||
String id = pointOfTime.id(entityId);
|
||||
final KVInt kvInt = new KVInt();
|
||||
kvInt.setId(id);
|
||||
kvInt.setValue(0);
|
||||
kvInt.setEmptyValue(true);
|
||||
values.getValues().addKVInt(kvInt);
|
||||
}
|
||||
return values;
|
||||
}
|
||||
return getMetricsQueryService().readMetricsValues(condition, duration);
|
||||
}
|
||||
|
||||
/**
|
||||
* Read entity list of required metrics and parent entity type.
|
||||
*/
|
||||
public List<SelectedRecord> sortMetrics(TopNCondition condition, Duration duration) throws IOException {
|
||||
if (!condition.senseScope()) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
return getQueryService().sortMetrics(condition, duration);
|
||||
}
|
||||
|
||||
/**
|
||||
* Read value in the given time duration, usually as a linear.
|
||||
*
|
||||
* @param labels the labels you need to query.
|
||||
*/
|
||||
public List<MetricsValues> readLabeledMetricsValues(MetricsCondition condition,
|
||||
List<String> labels,
|
||||
Duration duration) throws IOException {
|
||||
boolean hasScope = condition.senseScope();
|
||||
if (!hasScope || !condition.getEntity().isValid()) {
|
||||
final List<PointOfTime> pointOfTimes = duration.assembleDurationPoints();
|
||||
String entityId = "UNKNOWN_METRIC_NAME";
|
||||
if (hasScope) {
|
||||
entityId = "ILLEGAL_ENTITY";
|
||||
}
|
||||
List<MetricsValues> labeledValues = new ArrayList<>(labels.size());
|
||||
for (String label : labels) {
|
||||
public CompletableFuture<MetricsValues> readMetricsValues(MetricsCondition condition, Duration duration) {
|
||||
return queryAsync(() -> {
|
||||
boolean hasScope = condition.senseScope();
|
||||
if (!hasScope || !condition.getEntity().isValid()) {
|
||||
final List<PointOfTime> pointOfTimes = duration.assembleDurationPoints();
|
||||
String entityId = "UNKNOWN_METRIC_NAME";
|
||||
if (hasScope) {
|
||||
entityId = "ILLEGAL_ENTITY";
|
||||
}
|
||||
MetricsValues values = new MetricsValues();
|
||||
for (PointOfTime pointOfTime : pointOfTimes) {
|
||||
String id = pointOfTime.id(entityId);
|
||||
|
|
@ -197,15 +163,61 @@ public class MetricsQuery implements GraphQLQueryResolver {
|
|||
kvInt.setEmptyValue(true);
|
||||
values.getValues().addKVInt(kvInt);
|
||||
}
|
||||
values.setLabel(label);
|
||||
labeledValues.add(values);
|
||||
return values;
|
||||
}
|
||||
return labeledValues;
|
||||
}
|
||||
List<KeyValue> labelList = new ArrayList<>();
|
||||
String labelValue = labels.stream().reduce((a, b) -> a + Const.COMMA + b).orElse("");
|
||||
labelList.add(new KeyValue(DataLabel.GENERAL_LABEL_NAME, labelValue));
|
||||
return getMetricsQueryService().readLabeledMetricsValues(condition, labelList, duration);
|
||||
return getMetricsQueryService().readMetricsValues(condition, duration);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Read entity list of required metrics and parent entity type.
|
||||
*/
|
||||
public CompletableFuture<List<SelectedRecord>> sortMetrics(TopNCondition condition, Duration duration) {
|
||||
return queryAsync(() -> {
|
||||
if (!condition.senseScope()) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
return getQueryService().sortMetrics(condition, duration);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Read value in the given time duration, usually as a linear.
|
||||
*
|
||||
* @param labels the labels you need to query.
|
||||
*/
|
||||
public CompletableFuture<List<MetricsValues>> readLabeledMetricsValues(MetricsCondition condition,
|
||||
List<String> labels,
|
||||
Duration duration) {
|
||||
return queryAsync(() -> {
|
||||
boolean hasScope = condition.senseScope();
|
||||
if (!hasScope || !condition.getEntity().isValid()) {
|
||||
final List<PointOfTime> pointOfTimes = duration.assembleDurationPoints();
|
||||
String entityId = "UNKNOWN_METRIC_NAME";
|
||||
if (hasScope) {
|
||||
entityId = "ILLEGAL_ENTITY";
|
||||
}
|
||||
List<MetricsValues> labeledValues = new ArrayList<>(labels.size());
|
||||
for (String label : labels) {
|
||||
MetricsValues values = new MetricsValues();
|
||||
for (PointOfTime pointOfTime : pointOfTimes) {
|
||||
String id = pointOfTime.id(entityId);
|
||||
final KVInt kvInt = new KVInt();
|
||||
kvInt.setId(id);
|
||||
kvInt.setValue(0);
|
||||
kvInt.setEmptyValue(true);
|
||||
values.getValues().addKVInt(kvInt);
|
||||
}
|
||||
values.setLabel(label);
|
||||
labeledValues.add(values);
|
||||
}
|
||||
return labeledValues;
|
||||
}
|
||||
List<KeyValue> labelList = new ArrayList<>();
|
||||
String labelValue = labels.stream().reduce((a, b) -> a + Const.COMMA + b).orElse("");
|
||||
labelList.add(new KeyValue(DataLabel.GENERAL_LABEL_NAME, labelValue));
|
||||
return getMetricsQueryService().readLabeledMetricsValues(condition, labelList, duration);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -220,25 +232,27 @@ public class MetricsQuery implements GraphQLQueryResolver {
|
|||
* key = step * maxNumOfSteps, represents [step * maxNumOfSteps, MAX)
|
||||
* </pre>
|
||||
*/
|
||||
public HeatMap readHeatMap(MetricsCondition condition, Duration duration) throws IOException {
|
||||
boolean hasScope = condition.senseScope();
|
||||
if (!hasScope || !condition.getEntity().isValid()) {
|
||||
DataTable emptyData = new DataTable();
|
||||
emptyData.put("0", 0L);
|
||||
final String rawdata = emptyData.toStorageData();
|
||||
final HeatMap heatMap = new HeatMap();
|
||||
final List<PointOfTime> pointOfTimes = duration.assembleDurationPoints();
|
||||
String entityId = "UNKNOWN_METRIC_NAME";
|
||||
if (hasScope) {
|
||||
entityId = "ILLEGAL_ENTITY";
|
||||
public CompletableFuture<HeatMap> readHeatMap(MetricsCondition condition, Duration duration) {
|
||||
return queryAsync(() -> {
|
||||
boolean hasScope = condition.senseScope();
|
||||
if (!hasScope || !condition.getEntity().isValid()) {
|
||||
DataTable emptyData = new DataTable();
|
||||
emptyData.put("0", 0L);
|
||||
final String rawdata = emptyData.toStorageData();
|
||||
final HeatMap heatMap = new HeatMap();
|
||||
final List<PointOfTime> pointOfTimes = duration.assembleDurationPoints();
|
||||
String entityId = "UNKNOWN_METRIC_NAME";
|
||||
if (hasScope) {
|
||||
entityId = "ILLEGAL_ENTITY";
|
||||
}
|
||||
for (PointOfTime pointOfTime : pointOfTimes) {
|
||||
String id = pointOfTime.id(entityId);
|
||||
heatMap.buildColumn(id, rawdata, 0);
|
||||
}
|
||||
return heatMap;
|
||||
}
|
||||
for (PointOfTime pointOfTime : pointOfTimes) {
|
||||
String id = pointOfTime.id(entityId);
|
||||
heatMap.buildColumn(id, rawdata, 0);
|
||||
}
|
||||
return heatMap;
|
||||
}
|
||||
return getMetricsQueryService().readHeatMap(condition, duration);
|
||||
return getMetricsQueryService().readHeatMap(condition, duration);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -247,12 +261,14 @@ public class MetricsQuery implements GraphQLQueryResolver {
|
|||
* @since 9.3.0 This query is replaced by {@link RecordQueryService#readRecords(RecordCondition, Duration)}
|
||||
*/
|
||||
@Deprecated
|
||||
public List<SelectedRecord> readSampledRecords(TopNCondition condition, Duration duration) throws IOException {
|
||||
RecordCondition recordCondition = new RecordCondition(condition);
|
||||
if (!recordCondition.senseScope() || !recordCondition.getParentEntity().isValid()) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
final List<Record> records = getRecordQueryService().readRecords(recordCondition, duration);
|
||||
return records.stream().filter(Objects::nonNull).map(Record::toSelectedRecord).collect(Collectors.toList());
|
||||
public CompletableFuture<List<SelectedRecord>> readSampledRecords(TopNCondition condition, Duration duration) {
|
||||
return queryAsync(() -> {
|
||||
RecordCondition recordCondition = new RecordCondition(condition);
|
||||
if (!recordCondition.senseScope() || !recordCondition.getParentEntity().isValid()) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
final List<Record> records = getRecordQueryService().readRecords(recordCondition, duration);
|
||||
return records.stream().filter(Objects::nonNull).map(Record::toSelectedRecord).collect(Collectors.toList());
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -61,7 +61,7 @@ public class OndemandLogQuery implements GraphQLQueryResolver {
|
|||
public PodContainers listContainers(final OndemandContainergQueryCondition condition)
|
||||
throws IOException {
|
||||
final ServiceInstance instance =
|
||||
metadataQuery.getInstance(condition.getServiceInstanceId());
|
||||
metadataQuery.getInstance(condition.getServiceInstanceId()).join();
|
||||
final Map<String, String> attributesMap = convertInstancePropertiesToMap(instance);
|
||||
final String ns = attributesMap.get(PropertyUtil.NAMESPACE);
|
||||
final String pod = attributesMap.get(PropertyUtil.POD);
|
||||
|
|
@ -71,7 +71,7 @@ public class OndemandLogQuery implements GraphQLQueryResolver {
|
|||
public Logs ondemandPodLogs(final OndemandLogQueryCondition condition)
|
||||
throws IOException {
|
||||
final ServiceInstance instance =
|
||||
metadataQuery.getInstance(condition.getServiceInstanceId());
|
||||
metadataQuery.getInstance(condition.getServiceInstanceId()).join();
|
||||
final Map<String, String> attributesMap = convertInstancePropertiesToMap(instance);
|
||||
final String ns = attributesMap.get(PropertyUtil.NAMESPACE);
|
||||
final String pod = attributesMap.get(PropertyUtil.POD);
|
||||
|
|
|
|||
|
|
@ -19,6 +19,7 @@
|
|||
package org.apache.skywalking.oap.query.graphql.resolver;
|
||||
|
||||
import graphql.kickstart.tools.GraphQLQueryResolver;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import org.apache.skywalking.oap.server.core.CoreModule;
|
||||
import org.apache.skywalking.oap.server.core.profiling.trace.ProfileTaskQueryService;
|
||||
import org.apache.skywalking.oap.server.core.query.input.SegmentProfileAnalyzeQuery;
|
||||
|
|
@ -28,9 +29,10 @@ import org.apache.skywalking.oap.server.core.query.type.ProfileTaskLog;
|
|||
import org.apache.skywalking.oap.server.core.query.type.ProfiledTraceSegments;
|
||||
import org.apache.skywalking.oap.server.library.module.ModuleManager;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
|
||||
import static org.apache.skywalking.oap.query.graphql.resolver.AsyncQueryUtils.queryAsync;
|
||||
|
||||
/**
|
||||
* profile query GraphQL resolver
|
||||
*/
|
||||
|
|
@ -52,20 +54,19 @@ public class ProfileQuery implements GraphQLQueryResolver {
|
|||
return profileTaskQueryService;
|
||||
}
|
||||
|
||||
public List<ProfileTask> getProfileTaskList(final String serviceId, final String endpointName) throws IOException {
|
||||
return getProfileTaskQueryService().getTaskList(serviceId, endpointName);
|
||||
public CompletableFuture<List<ProfileTask>> getProfileTaskList(final String serviceId, final String endpointName) {
|
||||
return queryAsync(() -> getProfileTaskQueryService().getTaskList(serviceId, endpointName));
|
||||
}
|
||||
|
||||
public List<ProfileTaskLog> getProfileTaskLogs(final String taskID) throws IOException {
|
||||
return getProfileTaskQueryService().getProfileTaskLogs(taskID);
|
||||
public CompletableFuture<List<ProfileTaskLog>> getProfileTaskLogs(final String taskID) {
|
||||
return queryAsync(() -> getProfileTaskQueryService().getProfileTaskLogs(taskID));
|
||||
}
|
||||
|
||||
public List<ProfiledTraceSegments> getProfileTaskSegments(String taskId) throws IOException {
|
||||
return getProfileTaskQueryService().getProfileTaskSegments(taskId);
|
||||
public CompletableFuture<List<ProfiledTraceSegments>> getProfileTaskSegments(String taskId) {
|
||||
return queryAsync(() -> getProfileTaskQueryService().getProfileTaskSegments(taskId));
|
||||
}
|
||||
|
||||
public ProfileAnalyzation getSegmentsProfileAnalyze(final List<SegmentProfileAnalyzeQuery> queries) throws IOException {
|
||||
return getProfileTaskQueryService().getProfileAnalyze(queries);
|
||||
public CompletableFuture<ProfileAnalyzation> getSegmentsProfileAnalyze(final List<SegmentProfileAnalyzeQuery> queries) {
|
||||
return queryAsync(() -> getProfileTaskQueryService().getProfileAnalyze(queries));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -20,16 +20,17 @@ package org.apache.skywalking.oap.query.graphql.resolver;
|
|||
|
||||
import graphql.kickstart.tools.GraphQLQueryResolver;
|
||||
import java.util.Collections;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import org.apache.skywalking.oap.server.core.CoreModule;
|
||||
import org.apache.skywalking.oap.server.core.query.RecordQueryService;
|
||||
import org.apache.skywalking.oap.server.core.query.input.Duration;
|
||||
import org.apache.skywalking.oap.server.core.query.input.RecordCondition;
|
||||
import org.apache.skywalking.oap.server.core.query.type.Record;
|
||||
import org.apache.skywalking.oap.server.library.module.ModuleManager;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
|
||||
import static org.apache.skywalking.oap.query.graphql.resolver.AsyncQueryUtils.queryAsync;
|
||||
|
||||
public class RecordsQuery implements GraphQLQueryResolver {
|
||||
private ModuleManager moduleManager;
|
||||
private RecordQueryService recordQueryService;
|
||||
|
|
@ -47,10 +48,12 @@ public class RecordsQuery implements GraphQLQueryResolver {
|
|||
return recordQueryService;
|
||||
}
|
||||
|
||||
public List<Record> readRecords(RecordCondition condition, Duration duration) throws IOException {
|
||||
if (!condition.senseScope() || !condition.getParentEntity().isValid()) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
return getRecordQueryService().readRecords(condition, duration);
|
||||
public CompletableFuture<List<Record>> readRecords(RecordCondition condition, Duration duration) {
|
||||
return queryAsync(() -> {
|
||||
if (!condition.senseScope() || !condition.getParentEntity().isValid()) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
return getRecordQueryService().readRecords(condition, duration);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -52,7 +52,7 @@ public class TopNRecordsQuery implements GraphQLQueryResolver {
|
|||
topNCondition.setOrder(condition.getOrder());
|
||||
topNCondition.setTopN(condition.getTopN());
|
||||
|
||||
final List<SelectedRecord> selectedRecords = query.readSampledRecords(topNCondition, condition.getDuration());
|
||||
final List<SelectedRecord> selectedRecords = query.readSampledRecords(topNCondition, condition.getDuration()).join();
|
||||
List<TopNRecord> list = new ArrayList<>(selectedRecords.size());
|
||||
selectedRecords.forEach(record -> {
|
||||
TopNRecord top = new TopNRecord();
|
||||
|
|
|
|||
|
|
@ -19,9 +19,9 @@
|
|||
package org.apache.skywalking.oap.query.graphql.resolver;
|
||||
|
||||
import graphql.kickstart.tools.GraphQLQueryResolver;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import org.apache.skywalking.oap.server.core.CoreModule;
|
||||
import org.apache.skywalking.oap.server.core.query.TopologyQueryService;
|
||||
import org.apache.skywalking.oap.server.core.query.input.Duration;
|
||||
|
|
@ -33,6 +33,7 @@ import org.apache.skywalking.oap.server.core.query.type.debugging.DebuggingSpan;
|
|||
import org.apache.skywalking.oap.server.core.query.type.debugging.DebuggingTraceContext;
|
||||
import org.apache.skywalking.oap.server.library.module.ModuleManager;
|
||||
|
||||
import static org.apache.skywalking.oap.query.graphql.resolver.AsyncQueryUtils.queryAsync;
|
||||
import static org.apache.skywalking.oap.server.core.query.type.debugging.DebuggingTraceContext.TRACE_CONTEXT;
|
||||
|
||||
public class TopologyQuery implements GraphQLQueryResolver {
|
||||
|
|
@ -51,29 +52,31 @@ public class TopologyQuery implements GraphQLQueryResolver {
|
|||
return queryService;
|
||||
}
|
||||
|
||||
public Topology getGlobalTopology(final Duration duration,
|
||||
final String layer,
|
||||
final boolean debug) throws IOException {
|
||||
DebuggingTraceContext traceContext = new DebuggingTraceContext(
|
||||
"Duration: " + duration + ", Layer: " + layer, debug, false);
|
||||
DebuggingTraceContext.TRACE_CONTEXT.set(traceContext);
|
||||
DebuggingSpan span = traceContext.createSpan("Query global topology");
|
||||
try {
|
||||
Topology topology = getQueryService().getGlobalTopology(duration, layer);
|
||||
if (debug) {
|
||||
topology.setDebuggingTrace(traceContext.getExecTrace());
|
||||
public CompletableFuture<Topology> getGlobalTopology(final Duration duration,
|
||||
final String layer,
|
||||
final boolean debug) {
|
||||
return queryAsync(() -> {
|
||||
DebuggingTraceContext traceContext = new DebuggingTraceContext(
|
||||
"Duration: " + duration + ", Layer: " + layer, debug, false);
|
||||
DebuggingTraceContext.TRACE_CONTEXT.set(traceContext);
|
||||
DebuggingSpan span = traceContext.createSpan("Query global topology");
|
||||
try {
|
||||
Topology topology = getQueryService().getGlobalTopology(duration, layer);
|
||||
if (debug) {
|
||||
topology.setDebuggingTrace(traceContext.getExecTrace());
|
||||
}
|
||||
return topology;
|
||||
} finally {
|
||||
traceContext.stopSpan(span);
|
||||
traceContext.stopTrace();
|
||||
TRACE_CONTEXT.remove();
|
||||
}
|
||||
return topology;
|
||||
} finally {
|
||||
traceContext.stopSpan(span);
|
||||
traceContext.stopTrace();
|
||||
TRACE_CONTEXT.remove();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public Topology getServiceTopology(final String serviceId,
|
||||
final Duration duration,
|
||||
final boolean debug) throws IOException {
|
||||
final boolean debug) {
|
||||
DebuggingTraceContext traceContext = new DebuggingTraceContext(
|
||||
"ServiceId: " + serviceId + "Duration: " + duration, debug, false);
|
||||
DebuggingTraceContext.TRACE_CONTEXT.set(traceContext);
|
||||
|
|
@ -81,108 +84,115 @@ public class TopologyQuery implements GraphQLQueryResolver {
|
|||
try {
|
||||
List<String> selectedServiceList = new ArrayList<>(1);
|
||||
selectedServiceList.add(serviceId);
|
||||
Topology topology = this.getServicesTopology(selectedServiceList, duration, debug);
|
||||
Topology topology = this.getServicesTopology(selectedServiceList, duration, debug).join();
|
||||
if (debug) {
|
||||
topology.setDebuggingTrace(traceContext.getExecTrace());
|
||||
}
|
||||
return topology;
|
||||
} finally {
|
||||
|
||||
traceContext.stopSpan(span);
|
||||
traceContext.stopTrace();
|
||||
TRACE_CONTEXT.remove();
|
||||
}
|
||||
}
|
||||
|
||||
public Topology getServicesTopology(final List<String> serviceIds,
|
||||
public CompletableFuture<Topology> getServicesTopology(final List<String> serviceIds,
|
||||
final Duration duration,
|
||||
final boolean debug) throws IOException {
|
||||
DebuggingTraceContext traceContext = new DebuggingTraceContext(
|
||||
"ServiceIds: " + serviceIds + "Duration: " + duration, debug, false);
|
||||
DebuggingTraceContext.TRACE_CONTEXT.set(traceContext);
|
||||
DebuggingSpan span = traceContext.createSpan("Query service topology");
|
||||
try {
|
||||
Topology topology = getQueryService().getServiceTopology(duration, serviceIds);
|
||||
if (debug) {
|
||||
topology.setDebuggingTrace(traceContext.getExecTrace());
|
||||
final boolean debug) {
|
||||
return queryAsync(() -> {
|
||||
DebuggingTraceContext traceContext = new DebuggingTraceContext(
|
||||
"ServiceIds: " + serviceIds + "Duration: " + duration, debug, false);
|
||||
DebuggingTraceContext.TRACE_CONTEXT.set(traceContext);
|
||||
DebuggingSpan span = traceContext.createSpan("Query service topology");
|
||||
try {
|
||||
Topology topology = getQueryService().getServiceTopology(duration, serviceIds);
|
||||
if (debug) {
|
||||
topology.setDebuggingTrace(traceContext.getExecTrace());
|
||||
}
|
||||
return topology;
|
||||
} finally {
|
||||
traceContext.stopSpan(span);
|
||||
traceContext.stopTrace();
|
||||
TRACE_CONTEXT.remove();
|
||||
}
|
||||
return topology;
|
||||
} finally {
|
||||
traceContext.stopSpan(span);
|
||||
traceContext.stopTrace();
|
||||
TRACE_CONTEXT.remove();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public ServiceInstanceTopology getServiceInstanceTopology(final String clientServiceId,
|
||||
public CompletableFuture<ServiceInstanceTopology> getServiceInstanceTopology(final String clientServiceId,
|
||||
final String serverServiceId,
|
||||
final Duration duration,
|
||||
final boolean debug) throws IOException {
|
||||
DebuggingTraceContext traceContext = new DebuggingTraceContext(
|
||||
"ClientServiceId: " + clientServiceId + ", ServerServiceId: " + serverServiceId + ", Duration: " + duration,
|
||||
debug, false
|
||||
);
|
||||
DebuggingTraceContext.TRACE_CONTEXT.set(traceContext);
|
||||
DebuggingSpan span = traceContext.createSpan("Query service instance topology");
|
||||
try {
|
||||
ServiceInstanceTopology topology = getQueryService().getServiceInstanceTopology(
|
||||
clientServiceId, serverServiceId,
|
||||
duration
|
||||
final boolean debug) {
|
||||
return queryAsync(() -> {
|
||||
DebuggingTraceContext traceContext = new DebuggingTraceContext(
|
||||
"ClientServiceId: " + clientServiceId + ", ServerServiceId: " + serverServiceId + ", Duration: " + duration,
|
||||
debug, false
|
||||
);
|
||||
if (debug) {
|
||||
topology.setDebuggingTrace(traceContext.getExecTrace());
|
||||
DebuggingTraceContext.TRACE_CONTEXT.set(traceContext);
|
||||
DebuggingSpan span = traceContext.createSpan("Query service instance topology");
|
||||
try {
|
||||
ServiceInstanceTopology topology = getQueryService().getServiceInstanceTopology(
|
||||
clientServiceId, serverServiceId,
|
||||
duration
|
||||
);
|
||||
if (debug) {
|
||||
topology.setDebuggingTrace(traceContext.getExecTrace());
|
||||
}
|
||||
return topology;
|
||||
} finally {
|
||||
traceContext.stopSpan(span);
|
||||
traceContext.stopTrace();
|
||||
TRACE_CONTEXT.remove();
|
||||
}
|
||||
return topology;
|
||||
} finally {
|
||||
traceContext.stopSpan(span);
|
||||
traceContext.stopTrace();
|
||||
TRACE_CONTEXT.remove();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Replaced by {@link #getEndpointDependencies(String, Duration, boolean)}
|
||||
*/
|
||||
@Deprecated
|
||||
public Topology getEndpointTopology(final String endpointId, final Duration duration) throws IOException {
|
||||
return getQueryService().getEndpointTopology(duration, endpointId);
|
||||
public CompletableFuture<Topology> getEndpointTopology(final String endpointId, final Duration duration) {
|
||||
return queryAsync(() -> getQueryService().getEndpointTopology(duration, endpointId));
|
||||
}
|
||||
|
||||
public EndpointTopology getEndpointDependencies(final String endpointId,
|
||||
public CompletableFuture<EndpointTopology> getEndpointDependencies(final String endpointId,
|
||||
final Duration duration,
|
||||
final boolean debug) throws IOException {
|
||||
DebuggingTraceContext traceContext = new DebuggingTraceContext(
|
||||
"EndpointId: " + endpointId + ", Duration: " + duration, debug, false);
|
||||
DebuggingTraceContext.TRACE_CONTEXT.set(traceContext);
|
||||
DebuggingSpan span = traceContext.createSpan("Query endpoint dependencies");
|
||||
try {
|
||||
EndpointTopology topology = getQueryService().getEndpointDependencies(duration, endpointId);
|
||||
if (debug) {
|
||||
topology.setDebuggingTrace(traceContext.getExecTrace());
|
||||
final boolean debug) {
|
||||
return queryAsync(() -> {
|
||||
DebuggingTraceContext traceContext = new DebuggingTraceContext(
|
||||
"EndpointId: " + endpointId + ", Duration: " + duration, debug, false);
|
||||
DebuggingTraceContext.TRACE_CONTEXT.set(traceContext);
|
||||
DebuggingSpan span = traceContext.createSpan("Query endpoint dependencies");
|
||||
try {
|
||||
EndpointTopology topology = getQueryService().getEndpointDependencies(duration, endpointId);
|
||||
if (debug) {
|
||||
topology.setDebuggingTrace(traceContext.getExecTrace());
|
||||
}
|
||||
return topology;
|
||||
} finally {
|
||||
traceContext.stopSpan(span);
|
||||
traceContext.stopTrace();
|
||||
TRACE_CONTEXT.remove();
|
||||
}
|
||||
return topology;
|
||||
} finally {
|
||||
traceContext.stopSpan(span);
|
||||
traceContext.stopTrace();
|
||||
TRACE_CONTEXT.remove();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public ProcessTopology getProcessTopology(final String instanceId, final Duration duration, final boolean debug) throws Exception {
|
||||
DebuggingTraceContext traceContext = new DebuggingTraceContext(
|
||||
"InstanceId: " + instanceId + ", Duration: " + duration, debug, false);
|
||||
DebuggingTraceContext.TRACE_CONTEXT.set(traceContext);
|
||||
DebuggingSpan span = traceContext.createSpan("Query process topology");
|
||||
try {
|
||||
ProcessTopology topology = getQueryService().getProcessTopology(instanceId, duration);
|
||||
if (debug) {
|
||||
topology.setDebuggingTrace(traceContext.getExecTrace());
|
||||
public CompletableFuture<ProcessTopology> getProcessTopology(final String instanceId, final Duration duration, final boolean debug) {
|
||||
return queryAsync(() -> {
|
||||
DebuggingTraceContext traceContext = new DebuggingTraceContext(
|
||||
"InstanceId: " + instanceId + ", Duration: " + duration, debug, false);
|
||||
DebuggingTraceContext.TRACE_CONTEXT.set(traceContext);
|
||||
DebuggingSpan span = traceContext.createSpan("Query process topology");
|
||||
try {
|
||||
ProcessTopology topology = getQueryService().getProcessTopology(instanceId, duration);
|
||||
if (debug) {
|
||||
topology.setDebuggingTrace(traceContext.getExecTrace());
|
||||
}
|
||||
return topology;
|
||||
} finally {
|
||||
traceContext.stopSpan(span);
|
||||
traceContext.stopTrace();
|
||||
TRACE_CONTEXT.remove();
|
||||
}
|
||||
return topology;
|
||||
} finally {
|
||||
traceContext.stopSpan(span);
|
||||
traceContext.stopTrace();
|
||||
TRACE_CONTEXT.remove();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -22,6 +22,7 @@ import graphql.kickstart.tools.GraphQLQueryResolver;
|
|||
import com.google.common.base.Strings;
|
||||
import java.io.IOException;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import org.apache.skywalking.oap.server.core.Const;
|
||||
import org.apache.skywalking.oap.server.core.CoreModule;
|
||||
import org.apache.skywalking.oap.server.core.UnexpectedException;
|
||||
|
|
@ -40,6 +41,7 @@ import org.apache.skywalking.oap.server.core.query.type.debugging.DebuggingTrace
|
|||
import org.apache.skywalking.oap.server.library.module.ModuleManager;
|
||||
|
||||
import static java.util.Objects.isNull;
|
||||
import static org.apache.skywalking.oap.query.graphql.resolver.AsyncQueryUtils.queryAsync;
|
||||
import static org.apache.skywalking.oap.server.core.query.type.debugging.DebuggingTraceContext.TRACE_CONTEXT;
|
||||
|
||||
public class TraceQuery implements GraphQLQueryResolver {
|
||||
|
|
@ -66,22 +68,24 @@ public class TraceQuery implements GraphQLQueryResolver {
|
|||
return tagQueryService;
|
||||
}
|
||||
|
||||
public TraceBrief queryBasicTraces(final TraceQueryCondition condition, boolean debug) throws IOException {
|
||||
DebuggingTraceContext traceContext = new DebuggingTraceContext(
|
||||
"TraceQueryCondition: " + condition, debug, false);
|
||||
DebuggingTraceContext.TRACE_CONTEXT.set(traceContext);
|
||||
DebuggingSpan span = traceContext.createSpan("Query basic traces");
|
||||
try {
|
||||
TraceBrief traceBrief = invokeQueryBasicTraces(condition);
|
||||
if (debug) {
|
||||
traceBrief.setDebuggingTrace(traceContext.getExecTrace());
|
||||
public CompletableFuture<TraceBrief> queryBasicTraces(final TraceQueryCondition condition, boolean debug) {
|
||||
return queryAsync(() -> {
|
||||
DebuggingTraceContext traceContext = new DebuggingTraceContext(
|
||||
"TraceQueryCondition: " + condition, debug, false);
|
||||
DebuggingTraceContext.TRACE_CONTEXT.set(traceContext);
|
||||
DebuggingSpan span = traceContext.createSpan("Query basic traces");
|
||||
try {
|
||||
TraceBrief traceBrief = invokeQueryBasicTraces(condition);
|
||||
if (debug) {
|
||||
traceBrief.setDebuggingTrace(traceContext.getExecTrace());
|
||||
}
|
||||
return traceBrief;
|
||||
} finally {
|
||||
traceContext.stopSpan(span);
|
||||
traceContext.stopTrace();
|
||||
TRACE_CONTEXT.remove();
|
||||
}
|
||||
return traceBrief;
|
||||
} finally {
|
||||
traceContext.stopSpan(span);
|
||||
traceContext.stopTrace();
|
||||
TRACE_CONTEXT.remove();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private TraceBrief invokeQueryBasicTraces(final TraceQueryCondition condition) throws IOException {
|
||||
|
|
@ -106,29 +110,31 @@ public class TraceQuery implements GraphQLQueryResolver {
|
|||
);
|
||||
}
|
||||
|
||||
public Trace queryTrace(final String traceId, boolean debug) throws IOException {
|
||||
DebuggingTraceContext traceContext = new DebuggingTraceContext(
|
||||
"TraceId: " + traceId, debug, false);
|
||||
DebuggingTraceContext.TRACE_CONTEXT.set(traceContext);
|
||||
DebuggingSpan span = traceContext.createSpan("Query trace");
|
||||
try {
|
||||
Trace trace = getQueryService().queryTrace(traceId);
|
||||
if (debug) {
|
||||
trace.setDebuggingTrace(traceContext.getExecTrace());
|
||||
public CompletableFuture<Trace> queryTrace(final String traceId, boolean debug) {
|
||||
return queryAsync(() -> {
|
||||
DebuggingTraceContext traceContext = new DebuggingTraceContext(
|
||||
"TraceId: " + traceId, debug, false);
|
||||
DebuggingTraceContext.TRACE_CONTEXT.set(traceContext);
|
||||
DebuggingSpan span = traceContext.createSpan("Query trace");
|
||||
try {
|
||||
Trace trace = getQueryService().queryTrace(traceId);
|
||||
if (debug) {
|
||||
trace.setDebuggingTrace(traceContext.getExecTrace());
|
||||
}
|
||||
return trace;
|
||||
} finally {
|
||||
traceContext.stopSpan(span);
|
||||
traceContext.stopTrace();
|
||||
TRACE_CONTEXT.remove();
|
||||
}
|
||||
return trace;
|
||||
} finally {
|
||||
traceContext.stopSpan(span);
|
||||
traceContext.stopTrace();
|
||||
TRACE_CONTEXT.remove();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public Set<String> queryTraceTagAutocompleteKeys(final Duration queryDuration) throws IOException {
|
||||
return getTagQueryService().queryTagAutocompleteKeys(TagType.TRACE, queryDuration);
|
||||
public CompletableFuture<Set<String>> queryTraceTagAutocompleteKeys(final Duration queryDuration) {
|
||||
return queryAsync(() -> getTagQueryService().queryTagAutocompleteKeys(TagType.TRACE, queryDuration));
|
||||
}
|
||||
|
||||
public Set<String> queryTraceTagAutocompleteValues(final String tagKey, final Duration queryDuration) throws IOException {
|
||||
return getTagQueryService().queryTagAutocompleteValues(TagType.TRACE, tagKey, queryDuration);
|
||||
public CompletableFuture<Set<String>> queryTraceTagAutocompleteValues(final String tagKey, final Duration queryDuration) {
|
||||
return queryAsync(() -> getTagQueryService().queryTagAutocompleteValues(TagType.TRACE, tagKey, queryDuration));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue