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/01/29 15:51:34 UTC
[incubator-skywalking] branch top-sql updated: Add scope and new
manual dispatcher.
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 4f4bd62 Add scope and new manual dispatcher.
4f4bd62 is described below
commit 4f4bd6284dda1a748245eee1153ebe4da68eb9ec
Author: Wu Sheng <wu...@foxmail.com>
AuthorDate: Tue Jan 29 23:51:23 2019 +0800
Add scope and new manual dispatcher.
---
.../database/DatabaseStatementDispatcher.java | 39 +++++++++++++
.../manual/database/TopNDatabaseStatement.java | 68 ++++++++++++++++++++++
.../oap/server/core/analysis/topn/TopN.java | 5 ++
.../server/core/analysis/worker/TopNProcess.java | 5 ++
.../{Scope.java => DatabaseSlowStatement.java} | 28 +++++----
.../skywalking/oap/server/core/source/Scope.java | 2 +-
6 files changed, 136 insertions(+), 11 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
new file mode 100644
index 0000000..8e8037e
--- /dev/null
+++ b/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/analysis/manual/database/DatabaseStatementDispatcher.java
@@ -0,0 +1,39 @@
+/*
+ * 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.analysis.manual.database;
+
+import org.apache.skywalking.oap.server.core.analysis.SourceDispatcher;
+import org.apache.skywalking.oap.server.core.analysis.worker.TopNProcess;
+import org.apache.skywalking.oap.server.core.source.DatabaseSlowStatement;
+
+/**
+ * @author wusheng
+ */
+public class DatabaseStatementDispatcher implements SourceDispatcher<DatabaseSlowStatement> {
+ @Override public void dispatch(DatabaseSlowStatement source) {
+ TopNDatabaseStatement statement = new TopNDatabaseStatement();
+ statement.setDatabaseServiceId(source.getDatabaseServiceId());
+ statement.setDuration(source.getDuration());
+ statement.setStatement(source.getStatement());
+ statement.setTimeBucket(source.getTimeBucket());
+ statement.setTraceId(source.getTraceId());
+
+ TopNProcess.INSTANCE.in(statement);
+ }
+}
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
new file mode 100644
index 0000000..c528d02
--- /dev/null
+++ b/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/analysis/manual/database/TopNDatabaseStatement.java
@@ -0,0 +1,68 @@
+/*
+ * 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.analysis.manual.database;
+
+import java.util.*;
+import lombok.*;
+import org.apache.skywalking.oap.server.core.Const;
+import org.apache.skywalking.oap.server.core.analysis.topn.TopN;
+import org.apache.skywalking.oap.server.core.analysis.topn.annotation.TopNType;
+import org.apache.skywalking.oap.server.core.source.Scope;
+import org.apache.skywalking.oap.server.core.storage.StorageBuilder;
+import org.apache.skywalking.oap.server.core.storage.annotation.*;
+
+/**
+ * Database TopN statement, including Database SQL statement, mongoDB and Redis commands.
+ *
+ * @author wusheng
+ */
+@TopNType
+@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";
+
+ @Getter @Setter @Column(columnName = DATABASE_SERVICE_ID) private int databaseServiceId;
+ private final long recordNanoSec = System.nanoTime();
+
+ @Override public String id() {
+ return TIME_BUCKET + Const.ID_SPLIT + recordNanoSec;
+ }
+
+ public static class Builder implements StorageBuilder<TopNDatabaseStatement> {
+
+ @Override public TopNDatabaseStatement map2Data(Map<String, Object> dbMap) {
+ TopNDatabaseStatement statement = new TopNDatabaseStatement();
+ statement.setStatement((String)dbMap.get(STATEMENT));
+ statement.setTraceId((String)dbMap.get(TRACE_ID));
+ statement.setDuration(((Number)dbMap.get(DURATION)).longValue());
+ statement.setDatabaseServiceId(((Number)dbMap.get(DATABASE_SERVICE_ID)).intValue());
+ return statement;
+ }
+
+ @Override public Map<String, Object> data2Map(TopNDatabaseStatement storageData) {
+ Map<String, Object> map = new HashMap<>();
+ map.put(STATEMENT, storageData.getStatement());
+ map.put(TRACE_ID, storageData.getTraceId());
+ map.put(DURATION, storageData.getDuration());
+ map.put(DATABASE_SERVICE_ID, storageData.getDatabaseServiceId());
+ 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 caaafd9..125ac71 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
@@ -36,4 +36,9 @@ public abstract class TopN extends Record implements ComparableStorageData {
@Getter @Setter @Column(columnName = STATEMENT) private String statement;
@Getter @Setter @Column(columnName = DURATION) private long duration;
@Getter @Setter @Column(columnName = TRACE_ID) private String traceId;
+
+ @Override public int compareTo(Object o) {
+ TopN target = (TopN)o;
+ return (int)(duration - target.duration);
+ }
}
diff --git a/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/analysis/worker/TopNProcess.java b/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/analysis/worker/TopNProcess.java
index f93a985..98d8326 100644
--- a/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/analysis/worker/TopNProcess.java
+++ b/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/analysis/worker/TopNProcess.java
@@ -18,6 +18,7 @@
package org.apache.skywalking.oap.server.core.analysis.worker;
+import org.apache.skywalking.oap.server.core.analysis.manual.database.TopNDatabaseStatement;
import org.apache.skywalking.oap.server.core.analysis.topn.TopN;
import org.apache.skywalking.oap.server.core.storage.StorageBuilder;
import org.apache.skywalking.oap.server.core.storage.annotation.StorageEntityAnnotationUtils;
@@ -36,4 +37,8 @@ public enum TopNProcess {
String modelName = StorageEntityAnnotationUtils.getModelName(topN);
Class<? extends StorageBuilder> builderClass = StorageEntityAnnotationUtils.getBuilder(topN);
}
+
+ public void in(TopNDatabaseStatement statement) {
+
+ }
}
diff --git a/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/source/Scope.java b/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/source/DatabaseSlowStatement.java
similarity index 59%
copy from oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/source/Scope.java
copy to oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/source/DatabaseSlowStatement.java
index d162f3e..4d56262 100644
--- a/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/source/Scope.java
+++ b/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/source/DatabaseSlowStatement.java
@@ -18,18 +18,26 @@
package org.apache.skywalking.oap.server.core.source;
+import lombok.*;
+import org.apache.skywalking.oap.server.core.Const;
+import org.apache.skywalking.oap.server.core.source.annotation.SourceType;
+
/**
- * @author peng-yongsheng, wusheng
+ * @author wusheng
*/
-public enum Scope {
- All, Service, ServiceInstance, Endpoint, ServiceRelation, ServiceInstanceRelation, EndpointRelation, NetworkAddress,
- ServiceInstanceJVMCPU, ServiceInstanceJVMMemory, ServiceInstanceJVMMemoryPool, ServiceInstanceJVMGC,
- Segment, Alarm, ServiceInventory, ServiceInstanceInventory, EndpointInventory, DatabaseAccess;
+@SourceType
+public class DatabaseSlowStatement extends Source {
+ @Getter @Setter private int databaseServiceId;
+ @Getter @Setter private String statement;
+ @Getter @Setter private long duration;
+ @Getter @Setter private String traceId;
+
+ @Override public Scope scope() {
+ return Scope.DatabaseSlowStatement;
+ }
- public static Scope valueOf(int ordinal) {
- if (ordinal < 0 || ordinal >= values().length) {
- throw new IndexOutOfBoundsException("Invalid ordinal");
- }
- return values()[ordinal];
+ @Override public String getEntityId() {
+ return Const.EMPTY_STRING;
}
+
}
diff --git a/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/source/Scope.java b/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/source/Scope.java
index d162f3e..fd66299 100644
--- a/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/source/Scope.java
+++ b/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/source/Scope.java
@@ -24,7 +24,7 @@ package org.apache.skywalking.oap.server.core.source;
public enum Scope {
All, Service, ServiceInstance, Endpoint, ServiceRelation, ServiceInstanceRelation, EndpointRelation, NetworkAddress,
ServiceInstanceJVMCPU, ServiceInstanceJVMMemory, ServiceInstanceJVMMemoryPool, ServiceInstanceJVMGC,
- Segment, Alarm, ServiceInventory, ServiceInstanceInventory, EndpointInventory, DatabaseAccess;
+ Segment, Alarm, ServiceInventory, ServiceInstanceInventory, EndpointInventory, DatabaseAccess, DatabaseSlowStatement;
public static Scope valueOf(int ordinal) {
if (ordinal < 0 || ordinal >= values().length) {