You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@skywalking.apache.org by wu...@apache.org on 2019/02/12 04:19:13 UTC

[incubator-skywalking] branch top-sql updated: Finish new query protocol binding.

This is an automated email from the ASF dual-hosted git repository.

wusheng pushed a commit to branch top-sql
in repository https://gitbox.apache.org/repos/asf/incubator-skywalking.git


The following commit(s) were added to refs/heads/top-sql by this push:
     new 359a59a  Finish new query protocol binding.
359a59a is described below

commit 359a59ab4694cad7b7f6ad69942a78787e1e78e3
Author: Wu Sheng <wu...@foxmail.com>
AuthorDate: Tue Feb 12 12:19:01 2019 +0800

    Finish new query protocol binding.
---
 .../database/DatabaseStatementDispatcher.java      |  2 +-
 .../manual/database/TopNDatabaseStatement.java     | 11 +++---
 .../oap/server/core/analysis/topn/TopN.java        |  2 ++
 .../oap/server/core/query/entity/TopNRecord.java   | 32 +++++++++++++++++
 .../oap/query/graphql/GraphQLQueryProvider.java    |  2 ++
 .../query/graphql/resolver/TopNRecordsQuery.java   | 40 ++++++++++++++++++++++
 .../query/graphql/type/TopNRecordsCondition.java   | 32 +++++++++++++++++
 .../src/main/resources/query-protocol              |  2 +-
 8 files changed, 115 insertions(+), 8 deletions(-)

diff --git a/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/analysis/manual/database/DatabaseStatementDispatcher.java b/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/analysis/manual/database/DatabaseStatementDispatcher.java
index 628751a..f36cca5 100644
--- a/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/analysis/manual/database/DatabaseStatementDispatcher.java
+++ b/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/analysis/manual/database/DatabaseStatementDispatcher.java
@@ -29,7 +29,7 @@ public class DatabaseStatementDispatcher implements SourceDispatcher<DatabaseSlo
     @Override public void dispatch(DatabaseSlowStatement source) {
         TopNDatabaseStatement statement = new TopNDatabaseStatement();
         statement.setId(source.getId());
-        statement.setDatabaseServiceId(source.getDatabaseServiceId());
+        statement.setServiceId(source.getDatabaseServiceId());
         statement.setLatency(source.getLatency());
         statement.setStatement(source.getStatement());
         statement.setTimeBucket(source.getTimeBucket());
diff --git a/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/analysis/manual/database/TopNDatabaseStatement.java b/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/analysis/manual/database/TopNDatabaseStatement.java
index c40a6bb..e43d89a 100644
--- a/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/analysis/manual/database/TopNDatabaseStatement.java
+++ b/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/analysis/manual/database/TopNDatabaseStatement.java
@@ -36,10 +36,9 @@ import org.apache.skywalking.oap.server.core.storage.annotation.*;
 @StorageEntity(name = TopNDatabaseStatement.INDEX_NAME, builder = TopNDatabaseStatement.Builder.class, source = Scope.DatabaseSlowStatement)
 public class TopNDatabaseStatement extends TopN {
     public static final String INDEX_NAME = "top_n_database_statement";
-    public static final String DATABASE_SERVICE_ID = "db_service_id";
+
 
     @Setter private String id;
-    @Getter @Setter @Column(columnName = DATABASE_SERVICE_ID) private int databaseServiceId;
 
     @Override public String id() {
         return id;
@@ -51,11 +50,11 @@ public class TopNDatabaseStatement extends TopN {
         if (o == null || getClass() != o.getClass())
             return false;
         TopNDatabaseStatement statement = (TopNDatabaseStatement)o;
-        return databaseServiceId == statement.databaseServiceId;
+        return getServiceId() == statement.getServiceId();
     }
 
     @Override public int hashCode() {
-        return Objects.hash(databaseServiceId);
+        return Objects.hash(getServiceId());
     }
 
     public static class Builder implements StorageBuilder<TopNDatabaseStatement> {
@@ -65,7 +64,7 @@ public class TopNDatabaseStatement extends TopN {
             statement.setStatement((String)dbMap.get(STATEMENT));
             statement.setTraceId((String)dbMap.get(TRACE_ID));
             statement.setLatency(((Number)dbMap.get(LATENCY)).longValue());
-            statement.setDatabaseServiceId(((Number)dbMap.get(DATABASE_SERVICE_ID)).intValue());
+            statement.setServiceId(((Number)dbMap.get(SERVICE_ID)).intValue());
             return statement;
         }
 
@@ -74,7 +73,7 @@ public class TopNDatabaseStatement extends TopN {
             map.put(STATEMENT, storageData.getStatement());
             map.put(TRACE_ID, storageData.getTraceId());
             map.put(LATENCY, storageData.getLatency());
-            map.put(DATABASE_SERVICE_ID, storageData.getDatabaseServiceId());
+            map.put(SERVICE_ID, storageData.getServiceId());
             return map;
         }
     }
diff --git a/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/analysis/topn/TopN.java b/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/analysis/topn/TopN.java
index 1071203..fae8298 100644
--- a/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/analysis/topn/TopN.java
+++ b/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/analysis/topn/TopN.java
@@ -32,10 +32,12 @@ public abstract class TopN extends Record implements ComparableStorageData {
     public static final String STATEMENT = "statement";
     public static final String LATENCY = "latency";
     public static final String TRACE_ID = "trace_id";
+    public static final String SERVICE_ID = "service_id";
 
     @Getter @Setter @Column(columnName = STATEMENT) private String statement;
     @Getter @Setter @Column(columnName = LATENCY) private long latency;
     @Getter @Setter @Column(columnName = TRACE_ID) private String traceId;
+    @Getter @Setter @Column(columnName = SERVICE_ID) private int serviceId;
 
     @Override public int compareTo(Object o) {
         TopN target = (TopN)o;
diff --git a/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/query/entity/TopNRecord.java b/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/query/entity/TopNRecord.java
new file mode 100644
index 0000000..e8baa5d
--- /dev/null
+++ b/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/query/entity/TopNRecord.java
@@ -0,0 +1,32 @@
+/*
+ * 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.server.core.query.entity;
+
+import lombok.*;
+
+/**
+ * @author wusheng
+ */
+@Setter
+@Getter
+public class TopNRecord {
+    private String statement;
+    private long latency;
+    private String traceId;
+}
diff --git a/oap-server/server-query-plugin/query-graphql-plugin/src/main/java/org/apache/skywalking/oap/query/graphql/GraphQLQueryProvider.java b/oap-server/server-query-plugin/query-graphql-plugin/src/main/java/org/apache/skywalking/oap/query/graphql/GraphQLQueryProvider.java
index c834daf..d940141 100644
--- a/oap-server/server-query-plugin/query-graphql-plugin/src/main/java/org/apache/skywalking/oap/query/graphql/GraphQLQueryProvider.java
+++ b/oap-server/server-query-plugin/query-graphql-plugin/src/main/java/org/apache/skywalking/oap/query/graphql/GraphQLQueryProvider.java
@@ -66,6 +66,8 @@ public class GraphQLQueryProvider extends ModuleProvider {
             .resolvers(new AggregationQuery(getManager()))
             .file("query-protocol/alarm.graphqls")
             .resolvers(new AlarmQuery(getManager()))
+            .file("query-protocol/top-n-records.graphqls")
+            .resolvers(new TopNRecordsQuery(getManager()))
             .build()
             .makeExecutableSchema();
         this.graphQL = GraphQL.newGraphQL(schema).build();
diff --git a/oap-server/server-query-plugin/query-graphql-plugin/src/main/java/org/apache/skywalking/oap/query/graphql/resolver/TopNRecordsQuery.java b/oap-server/server-query-plugin/query-graphql-plugin/src/main/java/org/apache/skywalking/oap/query/graphql/resolver/TopNRecordsQuery.java
new file mode 100644
index 0000000..fc9f784
--- /dev/null
+++ b/oap-server/server-query-plugin/query-graphql-plugin/src/main/java/org/apache/skywalking/oap/query/graphql/resolver/TopNRecordsQuery.java
@@ -0,0 +1,40 @@
+/*
+ * 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 com.coxautodev.graphql.tools.GraphQLQueryResolver;
+import java.util.List;
+import org.apache.skywalking.oap.query.graphql.type.TopNRecordsCondition;
+import org.apache.skywalking.oap.server.core.query.entity.TopNRecord;
+import org.apache.skywalking.oap.server.library.module.ModuleManager;
+
+/**
+ * @author wusheng
+ */
+public class TopNRecordsQuery implements GraphQLQueryResolver {
+    private final ModuleManager moduleManager;
+
+    public TopNRecordsQuery(ModuleManager moduleManager) {
+        this.moduleManager = moduleManager;
+    }
+
+    public List<TopNRecord> getTopNRecords(TopNRecordsCondition condition) {
+        return null;
+    }
+}
diff --git a/oap-server/server-query-plugin/query-graphql-plugin/src/main/java/org/apache/skywalking/oap/query/graphql/type/TopNRecordsCondition.java b/oap-server/server-query-plugin/query-graphql-plugin/src/main/java/org/apache/skywalking/oap/query/graphql/type/TopNRecordsCondition.java
new file mode 100644
index 0000000..0d20eaa
--- /dev/null
+++ b/oap-server/server-query-plugin/query-graphql-plugin/src/main/java/org/apache/skywalking/oap/query/graphql/type/TopNRecordsCondition.java
@@ -0,0 +1,32 @@
+/*
+ * 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.type;
+
+import lombok.*;
+import org.apache.skywalking.oap.server.core.query.entity.Order;
+
+@Getter
+@Setter
+public class TopNRecordsCondition {
+    private String serviceId;
+    private String metricName;
+    private int topN;
+    private Order order;
+    private Duration duration;
+}
diff --git a/oap-server/server-query-plugin/query-graphql-plugin/src/main/resources/query-protocol b/oap-server/server-query-plugin/query-graphql-plugin/src/main/resources/query-protocol
index 85b81e2..6f11e3b 160000
--- a/oap-server/server-query-plugin/query-graphql-plugin/src/main/resources/query-protocol
+++ b/oap-server/server-query-plugin/query-graphql-plugin/src/main/resources/query-protocol
@@ -1 +1 @@
-Subproject commit 85b81e2e34efb0b670d039154feca336c9203700
+Subproject commit 6f11e3b829bba4d3532477e968291cf657f0ac0b