diff --git a/apm-protocol/apm-ui-protocol/README.md b/apm-protocol/apm-ui-protocol/README.md new file mode 100644 index 000000000..f58f1ea6d --- /dev/null +++ b/apm-protocol/apm-ui-protocol/README.md @@ -0,0 +1,6 @@ +## Using graphiql + +Graphiql */ˈɡrafək(ə)l/* is interactive in-browser GraphQL IDE which can be used by following steps. + + 1. Run `org.apache.skywalking.apm.ui.protocol.GraphQLInitializer#main` + 1. Access [http://localhost:8080/graphiql](http://localhost:8080/graphiql) diff --git a/apm-protocol/apm-ui-protocol/pom.xml b/apm-protocol/apm-ui-protocol/pom.xml index 9ad10c060..ab829decd 100644 --- a/apm-protocol/apm-ui-protocol/pom.xml +++ b/apm-protocol/apm-ui-protocol/pom.xml @@ -29,5 +29,38 @@ apm-ui-protocol + + + org.springframework.boot + spring-boot-starter-web + 1.5.9.RELEASE + + + org.springframework.boot + spring-boot-starter-actuator + 1.5.9.RELEASE + + + org.springframework.boot + spring-boot-configuration-processor + 1.5.9.RELEASE + + + org.springframework.boot + spring-boot-devtools + 1.5.9.RELEASE + + + + com.graphql-java + graphql-spring-boot-starter + 3.9.2 + + + com.graphql-java + graphiql-spring-boot-starter + 3.9.2 + + diff --git a/apm-protocol/apm-ui-protocol/src/main/java/org/apache/skywalking/apm/ui/protocol/GraphQLInitializer.java b/apm-protocol/apm-ui-protocol/src/main/java/org/apache/skywalking/apm/ui/protocol/GraphQLInitializer.java new file mode 100644 index 000000000..934c06786 --- /dev/null +++ b/apm-protocol/apm-ui-protocol/src/main/java/org/apache/skywalking/apm/ui/protocol/GraphQLInitializer.java @@ -0,0 +1,75 @@ +package org.apache.skywalking.apm.ui.protocol; + +import graphql.schema.GraphQLObjectType; +import graphql.schema.GraphQLSchema; +import graphql.schema.TypeResolver; +import graphql.schema.idl.FieldWiringEnvironment; +import graphql.schema.idl.InterfaceWiringEnvironment; +import graphql.schema.idl.RuntimeWiring; +import graphql.schema.idl.SchemaGenerator; +import graphql.schema.idl.SchemaParser; +import graphql.schema.idl.TypeDefinitionRegistry; +import graphql.schema.idl.WiringFactory; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.boot.web.support.SpringBootServletInitializer; +import org.springframework.context.ApplicationContext; +import org.springframework.context.annotation.Bean; + +import java.io.File; + +/** + * GraphQL server initializer. + * + * @author gaohongtao + */ +@SpringBootApplication +public class GraphQLInitializer extends SpringBootServletInitializer { + + private Logger logger = LoggerFactory.getLogger(GraphQLInitializer.class); + + public static void main(String[] args) throws Exception { + ApplicationContext applicationContext = SpringApplication.run(GraphQLInitializer.class, args); + } + + @Bean + GraphQLSchema schema() { + 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("overview-layer.graphqls"))); + RuntimeWiring wiring = buildRuntimeWiring(); + return schemaGenerator.makeExecutableSchema(typeRegistry, wiring); + } + + private File loadSchema(final String s) { + return new File(GraphQLInitializer.class.getClassLoader().getResource("ui-graphql/" + s).getFile()); + } + + private RuntimeWiring buildRuntimeWiring() { + WiringFactory dynamicWiringFactory = new WiringFactory() { + @Override + public boolean providesTypeResolver(final InterfaceWiringEnvironment environment) { + return true; + } + + @Override + public TypeResolver getTypeResolver(final InterfaceWiringEnvironment environment) { + return env -> GraphQLObjectType.newObject().build(); + } + + @Override + public boolean providesDataFetcher(final FieldWiringEnvironment environment) { + logger.info("data fetcher: {},{}", environment.getFieldDefinition(), environment.getParentType()); + return false; + } + }; + return RuntimeWiring.newRuntimeWiring() + .wiringFactory(dynamicWiringFactory).build(); + } +} diff --git a/apm-protocol/apm-ui-protocol/src/main/resources/application.yml b/apm-protocol/apm-ui-protocol/src/main/resources/application.yml new file mode 100644 index 000000000..0dddee92e --- /dev/null +++ b/apm-protocol/apm-ui-protocol/src/main/resources/application.yml @@ -0,0 +1,20 @@ +# +# Copyright 2017, OpenSkywalking Organization All rights reserved. +# +# Licensed 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. +# +# Project repository: https://github.com/OpenSkywalking/skywalking-ui +# + +server: + port: 8080 diff --git a/apm-protocol/apm-ui-protocol/src/main/resources/ui-graphql/common.graphqls b/apm-protocol/apm-ui-protocol/src/main/resources/ui-graphql/common.graphqls index 91d6ba352..7473866b3 100644 --- a/apm-protocol/apm-ui-protocol/src/main/resources/ui-graphql/common.graphqls +++ b/apm-protocol/apm-ui-protocol/src/main/resources/ui-graphql/common.graphqls @@ -2,6 +2,7 @@ schema { query: Query } +#Root node type Query { version: String } @@ -24,7 +25,7 @@ type Query { # metrics from the following time points expected # 2017-11-08 9:00 -> 2017-11-08 19:00 # there are 11 time points (hours) in the time span. -type Duration{ +input Duration{ start: String! end: String! step: Step! diff --git a/apm-protocol/apm-ui-protocol/src/main/resources/ui-graphql/overview-layer.graphqls b/apm-protocol/apm-ui-protocol/src/main/resources/ui-graphql/overview-layer.graphqls index 1dbc1455b..c101963ff 100644 --- a/apm-protocol/apm-ui-protocol/src/main/resources/ui-graphql/overview-layer.graphqls +++ b/apm-protocol/apm-ui-protocol/src/main/resources/ui-graphql/overview-layer.graphqls @@ -88,7 +88,7 @@ type ConjecturalApp { # The display name of the application # e.g. MySQL, RocketMQ, Kafka, Nginx name: String! - num: int! + num: Int! } type ApplicationBrief { @@ -97,7 +97,7 @@ type ApplicationBrief { type ApplicationInfo { name: String! - tps: int! + tps: Int! } extend type Query { diff --git a/apm-protocol/apm-ui-protocol/src/main/resources/ui-graphql/trace.graphqls b/apm-protocol/apm-ui-protocol/src/main/resources/ui-graphql/trace.graphqls index 75b8b2003..822f7ce8f 100644 --- a/apm-protocol/apm-ui-protocol/src/main/resources/ui-graphql/trace.graphqls +++ b/apm-protocol/apm-ui-protocol/src/main/resources/ui-graphql/trace.graphqls @@ -13,7 +13,7 @@ type BasicTrace { } # Represent the conditions used for query TraceBrief -type TraceQueryCondition { +input TraceQueryCondition { applicationCodes: [String!] traceId: String operationName: String