From 282b59312bade113f1ab35a0aed71b286cc94a8d Mon Sep 17 00:00:00 2001 From: Wu Sheng Date: Fri, 27 Jul 2018 13:39:01 +0800 Subject: [PATCH] v6 query protocol. --- .../{common.graphql => common.graphqls} | 14 +++ .../main/resources/ui-graphql-v6/jvm.graphqls | 41 ++++++ .../{metric.graphql => metric.graphqls} | 20 ++- .../{overview.graphql => overview.graphqls} | 25 +++- .../{topology.graphql => topology.graphqls} | 0 .../resources/ui-graphql-v6/trace.graphql | 0 .../resources/ui-graphql-v6/trace.graphqls | 118 ++++++++++++++++++ .../apm/ui/protocol/GraphQLv6ScriptTest.java | 55 ++++++++ 8 files changed, 266 insertions(+), 7 deletions(-) rename apm-protocol/apm-ui-protocol/src/main/resources/ui-graphql-v6/{common.graphql => common.graphqls} (91%) create mode 100644 apm-protocol/apm-ui-protocol/src/main/resources/ui-graphql-v6/jvm.graphqls rename apm-protocol/apm-ui-protocol/src/main/resources/ui-graphql-v6/{metric.graphql => metric.graphqls} (88%) rename apm-protocol/apm-ui-protocol/src/main/resources/ui-graphql-v6/{overview.graphql => overview.graphqls} (64%) rename apm-protocol/apm-ui-protocol/src/main/resources/ui-graphql-v6/{topology.graphql => topology.graphqls} (100%) delete mode 100644 apm-protocol/apm-ui-protocol/src/main/resources/ui-graphql-v6/trace.graphql create mode 100644 apm-protocol/apm-ui-protocol/src/main/resources/ui-graphql-v6/trace.graphqls create mode 100644 apm-protocol/apm-ui-protocol/src/test/java/org/apache/skywalking/apm/ui/protocol/GraphQLv6ScriptTest.java diff --git a/apm-protocol/apm-ui-protocol/src/main/resources/ui-graphql-v6/common.graphql b/apm-protocol/apm-ui-protocol/src/main/resources/ui-graphql-v6/common.graphqls similarity index 91% rename from apm-protocol/apm-ui-protocol/src/main/resources/ui-graphql-v6/common.graphql rename to apm-protocol/apm-ui-protocol/src/main/resources/ui-graphql-v6/common.graphqls index d1cf27095a..b0a87857d1 100644 --- a/apm-protocol/apm-ui-protocol/src/main/resources/ui-graphql-v6/common.graphql +++ b/apm-protocol/apm-ui-protocol/src/main/resources/ui-graphql-v6/common.graphqls @@ -60,6 +60,11 @@ enum Step { SECOND } +enum Order { + ASC + DES +} + input Pagination { # pageNum starts in 1, the default is 1. pageNum: Int @@ -68,3 +73,12 @@ input Pagination { needTotal: Boolean } +enum Language { + # For not language based agent, the language is impossible to tell. + UNKNOWN + JAVA + DOTNET + NODEJS + PYTHON + RUBY +} diff --git a/apm-protocol/apm-ui-protocol/src/main/resources/ui-graphql-v6/jvm.graphqls b/apm-protocol/apm-ui-protocol/src/main/resources/ui-graphql-v6/jvm.graphqls new file mode 100644 index 0000000000..eb098d4447 --- /dev/null +++ b/apm-protocol/apm-ui-protocol/src/main/resources/ui-graphql-v6/jvm.graphqls @@ -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. + +type CPUTrend { + cost: [Int!]! +} + +# The gc trend represents the numbers and time of Garbage Collector execution +type GCTrend { + youngGCCount: [Int!]! + oldGCount: [Int!]! + youngGCTime: [Int!]! + oldGCTime: [Int!]! +} + +# The memory used and max limit in heap and noheap space. +type MemoryTrend { + heap: [Int!]! + maxHeap: [Int!]! + noheap: [Int!]! + maxNoheap: [Int!]! +} + +extend type Query { + getJVMCPUTrend(serviceInstanceId: ID!, duration: Duration!): CPUTrend + getJVMGCTrend(serviceInstanceId: ID!, duration: Duration!): GCTrend + getJVMMemoryTrend(serviceInstanceId: ID!, duration: Duration!): MemoryTrend +} \ No newline at end of file diff --git a/apm-protocol/apm-ui-protocol/src/main/resources/ui-graphql-v6/metric.graphql b/apm-protocol/apm-ui-protocol/src/main/resources/ui-graphql-v6/metric.graphqls similarity index 88% rename from apm-protocol/apm-ui-protocol/src/main/resources/ui-graphql-v6/metric.graphql rename to apm-protocol/apm-ui-protocol/src/main/resources/ui-graphql-v6/metric.graphqls index c0de3a7886..f63cc1507b 100644 --- a/apm-protocol/apm-ui-protocol/src/main/resources/ui-graphql-v6/metric.graphql +++ b/apm-protocol/apm-ui-protocol/src/main/resources/ui-graphql-v6/metric.graphqls @@ -23,12 +23,6 @@ input MetricCondition { # Id in this metric type. # In the above case, the id should be endpoint id. id: ID - topN: TopN -} - -# TopN filter -input TopN { - n: Int! } type LinearIntValues { @@ -60,7 +54,21 @@ type Thermodynamic { axisYStep: Int! } +# Match the metric by name, order by metric value(such as: avg, percent) +input MetricTopNCondition { + name: String! + topN: Int! + order: Order! +} + +type MetricEntity { + name: String! + id: ID! + value: Int! +} + extend type Query { getLinearIntValues(metric: MetricCondition!, duration: Duration!): LinearIntValues getThermodynamic(metric: MetricCondition!, duration: Duration!): Thermodynamic + getTopN(metric: MetricTopNCondition!): [MetricEntity!]! } \ No newline at end of file diff --git a/apm-protocol/apm-ui-protocol/src/main/resources/ui-graphql-v6/overview.graphql b/apm-protocol/apm-ui-protocol/src/main/resources/ui-graphql-v6/overview.graphqls similarity index 64% rename from apm-protocol/apm-ui-protocol/src/main/resources/ui-graphql-v6/overview.graphql rename to apm-protocol/apm-ui-protocol/src/main/resources/ui-graphql-v6/overview.graphqls index 69986581b0..42ad5de075 100644 --- a/apm-protocol/apm-ui-protocol/src/main/resources/ui-graphql-v6/overview.graphql +++ b/apm-protocol/apm-ui-protocol/src/main/resources/ui-graphql-v6/overview.graphqls @@ -34,12 +34,35 @@ type Service { } type ServiceInstance { + id: ID! + name: String! + attributes: [Attribute!]! + language: Language! +} + +type Attribute { + name: String! + value: String! +} +type Endpoint { + id: ID! + name: String! } extend type Query { getGlobalBrief(duration: Duration!): ClusterBrief getAlarmTrend(duration: Duration!): AlarmTrend - getAllService(duration: Duration!): [Service!]! + # Service related meta info. + getAllServices(duration: Duration!): [Service!]! + searchServices(duration: Duration!, keyword: String!): [Service!]! + + # Service intance query + getServiceInstances(duration: Duration!, id: ID!): [ServiceInstance!]! + + # Endpoint query + # Consider there are huge numbers of endpoint, + # must use endpoint owner's service id, keyword and top N filter to do query. + searchEndpoint(keyword: String!, serviceId: ID!, topNFilter: MetricTopNCondition!): [Endpoint!]! } \ No newline at end of file diff --git a/apm-protocol/apm-ui-protocol/src/main/resources/ui-graphql-v6/topology.graphql b/apm-protocol/apm-ui-protocol/src/main/resources/ui-graphql-v6/topology.graphqls similarity index 100% rename from apm-protocol/apm-ui-protocol/src/main/resources/ui-graphql-v6/topology.graphql rename to apm-protocol/apm-ui-protocol/src/main/resources/ui-graphql-v6/topology.graphqls diff --git a/apm-protocol/apm-ui-protocol/src/main/resources/ui-graphql-v6/trace.graphql b/apm-protocol/apm-ui-protocol/src/main/resources/ui-graphql-v6/trace.graphql deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/apm-protocol/apm-ui-protocol/src/main/resources/ui-graphql-v6/trace.graphqls b/apm-protocol/apm-ui-protocol/src/main/resources/ui-graphql-v6/trace.graphqls new file mode 100644 index 0000000000..72ccf98033 --- /dev/null +++ b/apm-protocol/apm-ui-protocol/src/main/resources/ui-graphql-v6/trace.graphqls @@ -0,0 +1,118 @@ +# 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. + +# The list of traces +type TraceBrief { + traces: [BasicTrace!]! + total: Int! +} + +# Trace basic info +type BasicTrace { + segmentId: String! + operationNames: [String!]! + duration: Int! + start: String! + isError: Boolean + traceIds: [String!]! +} + +# Represent the conditions used for query TraceBrief +input TraceQueryCondition { + # The value of 0 means all application. + applicationId: Int + traceId: String + operationName: String + # The time range of traces started + queryDuration: Duration + # The mix time of trace + minTraceDuration: Int + # The max time of trace + maxTraceDuration: Int + traceState: TraceState! + queryOrder: QueryOrder! + paging: Pagination! +} + +enum TraceState { + ALL + SUCCESS + ERROR +} + +enum QueryOrder { + BY_START_TIME + BY_DURATION +} + +# The trace represents a distributed trace, includes all segments and spans. +type Trace { + spans: [Span!]! +} + +type Span { + traceId: ID! + segmentId: ID! + spanId: Int! + parentSpanId: Int! + refs: [Ref!]! + applicationCode: String! + startTime: Long! + endTime: Long! + operationName: String + # There are three span types: Local, Entry and Exit + type: String! + # Peer network id, e.g. host+port, ip+port + peer: String + component: String + isError: Boolean + # There are 5 layers: Unknown, Database, RPCFramework, Http, MQ and Cache + layer: String + tags: [KeyValue!]! + logs: [LogEntity!]! +} + +# Ref represents the link between the segment and its parents. +# The parent(ref) may not exists, which means batch process. +# The UI should display a list, representing the other trace IDs. +type Ref { + traceId: ID! + parentSegmentId: ID! + parentSpanId: Int! + # Ref type represents why did the ref happen. + # Include: 1) CrossProcess 2) CrossThread + type: RefType! +} + +enum RefType { + CROSS_PROCESS, + CROSS_THREAD +} + +type KeyValue { + key: String! + value: String +} + +type LogEntity { + time: Long! + data: [KeyValue!] +} + +extend type Query { + queryBasicTraces(condition: TraceQueryCondition): TraceBrief + queryTrace(traceId: ID!): Trace +} diff --git a/apm-protocol/apm-ui-protocol/src/test/java/org/apache/skywalking/apm/ui/protocol/GraphQLv6ScriptTest.java b/apm-protocol/apm-ui-protocol/src/test/java/org/apache/skywalking/apm/ui/protocol/GraphQLv6ScriptTest.java new file mode 100644 index 0000000000..71cead4f6f --- /dev/null +++ b/apm-protocol/apm-ui-protocol/src/test/java/org/apache/skywalking/apm/ui/protocol/GraphQLv6ScriptTest.java @@ -0,0 +1,55 @@ +/* + * 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.apm.ui.protocol; + +import graphql.schema.idl.EchoingWiringFactory; +import graphql.schema.idl.RuntimeWiring; +import graphql.schema.idl.SchemaGenerator; +import graphql.schema.idl.SchemaParser; +import graphql.schema.idl.TypeDefinitionRegistry; +import java.io.File; +import org.junit.Test; + +import static org.junit.Assert.assertTrue; + +public class GraphQLv6ScriptTest { + @Test + public void assertScriptFormat() { + SchemaParser schemaParser = new SchemaParser(); + SchemaGenerator schemaGenerator = new SchemaGenerator(); + + TypeDefinitionRegistry typeRegistry = new TypeDefinitionRegistry(); + typeRegistry.merge(schemaParser.parse(loadSchema("common.graphqls"))); + typeRegistry.merge(schemaParser.parse(loadSchema("trace.graphqls"))); + typeRegistry.merge(schemaParser.parse(loadSchema("metric.graphqls"))); + typeRegistry.merge(schemaParser.parse(loadSchema("overview.graphqls"))); + typeRegistry.merge(schemaParser.parse(loadSchema("topology.graphqls"))); + typeRegistry.merge(schemaParser.parse(loadSchema("jvm.graphqls"))); + RuntimeWiring wiring = buildRuntimeWiring(); + assertTrue(schemaGenerator.makeExecutableSchema(typeRegistry, wiring).getAllTypesAsList().size() > 0); + } + + private File loadSchema(final String s) { + return new File(GraphQLScriptTest.class.getClassLoader().getResource("ui-graphql-v6/" + s).getFile()); + } + + private RuntimeWiring buildRuntimeWiring() { + return RuntimeWiring.newRuntimeWiring().wiringFactory(new EchoingWiringFactory()).build(); + } +} -- GitLab