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 2020/04/19 15:35:48 UTC

[skywalking] branch metrics updated: Make compiling passed, and doing UT testing.

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

wusheng pushed a commit to branch metrics
in repository https://gitbox.apache.org/repos/asf/skywalking.git


The following commit(s) were added to refs/heads/metrics by this push:
     new e3246ee  Make compiling passed, and doing UT testing.
e3246ee is described below

commit e3246ee653a1a0c18ce0877ded0f37b001cc9bf4
Author: Wu Sheng <wu...@foxmail.com>
AuthorDate: Sun Apr 19 23:35:00 2020 +0800

    Make compiling passed, and doing UT testing.
---
 .../oap/server/core/analysis/TimeBucket.java       |   8 -
 .../server/core/analysis/metrics/DataTable.java    |  10 +-
 .../core/analysis/metrics/PercentileMetrics.java   |  11 +-
 .../server/core/query/MetadataQueryService.java    |  12 -
 .../server/core/query/TopologyQueryService.java    |  30 +--
 .../oap/server/core/query/type/ClusterBrief.java   |  32 ---
 .../core/storage/query/IAggregationQueryDAO.java   |   2 +-
 .../core/storage/query/ITopologyQueryDAO.java      |  14 +-
 .../oap/query/graphql/resolver/AlarmQuery.java     |  13 +-
 .../oap/query/graphql/resolver/LogQuery.java       |  10 +-
 .../oap/query/graphql/resolver/MetadataQuery.java  |  34 +--
 .../oap/query/graphql/resolver/Mutation.java       |   2 +-
 .../oap/query/graphql/resolver/Query.java          |   2 +-
 .../oap/query/graphql/resolver/TopologyQuery.java  |  31 +--
 .../storage/plugin/elasticsearch/base/EsDAO.java   |  10 -
 .../elasticsearch/query/AggregationQueryEsDAO.java |   8 +-
 .../elasticsearch/query/TopNRecordsQueryEsDAO.java |   8 +-
 .../elasticsearch/query/TopologyQueryEsDAO.java    |  16 +-
 .../query/AggregationQueryEs7DAO.java              |   8 +-
 .../storage/plugin/influxdb/InfluxClient.java      |   8 -
 .../plugin/influxdb/query/AggregationQuery.java    | 108 +++------
 .../influxdb/query/InfluxMetadataQueryDAO.java     | 146 ------------
 .../plugin/influxdb/query/MetadataQuery.java       |  45 +---
 .../plugin/influxdb/query/MetricsQuery.java        | 251 +++++++++------------
 .../plugin/influxdb/query/TopNRecordsQuery.java    |  42 ++--
 .../plugin/influxdb/query/TopologyQuery.java       |  16 +-
 .../plugin/jdbc/h2/dao/H2TopNRecordsQueryDAO.java  |  13 +-
 .../plugin/jdbc/h2/dao/H2TopologyQueryDAO.java     |  16 +-
 28 files changed, 270 insertions(+), 636 deletions(-)

diff --git a/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/analysis/TimeBucket.java b/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/analysis/TimeBucket.java
index df604a7..59ea7c4 100644
--- a/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/analysis/TimeBucket.java
+++ b/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/analysis/TimeBucket.java
@@ -95,14 +95,6 @@ public class TimeBucket {
     }
 
     /**
-     * The format of timeBucket in month Unit is "yyyyMM", so which means the TimeBucket must be between 100000 and
-     * 999999.
-     */
-    public static boolean isMonthBucket(long timeBucket) {
-        return timeBucket < 999999L && timeBucket > 100000L;
-    }
-
-    /**
      * Convert TimeBucket to Timestamp in millisecond.
      *
      * @param timeBucket   long
diff --git a/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/analysis/metrics/DataTable.java b/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/analysis/metrics/DataTable.java
index dc677b8..ecc4850 100644
--- a/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/analysis/metrics/DataTable.java
+++ b/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/analysis/metrics/DataTable.java
@@ -102,6 +102,14 @@ public class DataTable implements StorageDataComplexObject<DataTable> {
 
     @Override
     public void append(DataTable dataTable) {
-        dataTable.data.forEach(this.data::put);
+        dataTable.data.forEach((key, value) -> {
+            Long current = this.data.get(key);
+            if (current == null) {
+                current = value;
+            } else {
+                current += value;
+            }
+            this.data.put(key, current);
+        });
     }
 }
diff --git a/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/analysis/metrics/PercentileMetrics.java b/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/analysis/metrics/PercentileMetrics.java
index f2ede3a..ac3889d 100644
--- a/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/analysis/metrics/PercentileMetrics.java
+++ b/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/analysis/metrics/PercentileMetrics.java
@@ -96,7 +96,6 @@ public abstract class PercentileMetrics extends Metrics implements MultiIntValue
 
     @Override
     public final void calculate() {
-
         if (!isCalculated) {
             long total = dataset.sumOfValues();
 
@@ -109,15 +108,15 @@ public abstract class PercentileMetrics extends Metrics implements MultiIntValue
             final List<String> sortedKeys = dataset.sortedKeys(Comparator.comparingInt(Integer::parseInt));
 
             int loopIndex = 0;
-            for (String index : sortedKeys) {
-                final Long value = dataset.get(index);
+            for (String key : sortedKeys) {
+                final Long value = dataset.get(key);
 
                 count += value;
-                for (int i = loopIndex; i < roofs.length; i++) {
-                    int roof = roofs[i];
+                for (int rankIdx = loopIndex; rankIdx < roofs.length; rankIdx++) {
+                    int roof = roofs[rankIdx];
 
                     if (count >= roof) {
-                        percentileValues.put(index, Long.parseLong(index) * precision);
+                        percentileValues.put(String.valueOf(rankIdx), Long.parseLong(key) * precision);
                         loopIndex++;
                     } else {
                         break;
diff --git a/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/query/MetadataQueryService.java b/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/query/MetadataQueryService.java
index 0726ba4..b373fe4 100644
--- a/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/query/MetadataQueryService.java
+++ b/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/query/MetadataQueryService.java
@@ -21,13 +21,11 @@ package org.apache.skywalking.oap.server.core.query;
 import java.io.IOException;
 import java.util.List;
 import org.apache.skywalking.oap.server.core.analysis.IDManager;
-import org.apache.skywalking.oap.server.core.query.type.ClusterBrief;
 import org.apache.skywalking.oap.server.core.query.type.Database;
 import org.apache.skywalking.oap.server.core.query.type.Endpoint;
 import org.apache.skywalking.oap.server.core.query.type.EndpointInfo;
 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.core.analysis.NodeType;
 import org.apache.skywalking.oap.server.core.storage.StorageModule;
 import org.apache.skywalking.oap.server.core.storage.query.IMetadataQueryDAO;
 import org.apache.skywalking.oap.server.library.module.ModuleManager;
@@ -48,16 +46,6 @@ public class MetadataQueryService implements org.apache.skywalking.oap.server.li
         return metadataQueryDAO;
     }
 
-    public ClusterBrief getGlobalBrief(final long startTimestamp, final long endTimestamp) throws IOException {
-        ClusterBrief clusterBrief = new ClusterBrief();
-        clusterBrief.setNumOfService(getMetadataQueryDAO().numOfService(startTimestamp, endTimestamp));
-        clusterBrief.setNumOfEndpoint(getMetadataQueryDAO().numOfEndpoint());
-        clusterBrief.setNumOfDatabase(getMetadataQueryDAO().numOfConjectural(NodeType.Database.value()));
-        clusterBrief.setNumOfCache(getMetadataQueryDAO().numOfConjectural(NodeType.Cache.value()));
-        clusterBrief.setNumOfMQ(getMetadataQueryDAO().numOfConjectural(NodeType.MQ.value()));
-        return clusterBrief;
-    }
-
     public List<Service> getAllServices(final long startTimestamp, final long endTimestamp) throws IOException {
         return getMetadataQueryDAO().getAllServices(startTimestamp, endTimestamp);
     }
diff --git a/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/query/TopologyQueryService.java b/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/query/TopologyQueryService.java
index 8598cf1..4b0ee5b 100644
--- a/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/query/TopologyQueryService.java
+++ b/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/query/TopologyQueryService.java
@@ -27,7 +27,6 @@ import java.util.Set;
 import lombok.extern.slf4j.Slf4j;
 import org.apache.skywalking.oap.server.core.Const;
 import org.apache.skywalking.oap.server.core.CoreModule;
-import org.apache.skywalking.oap.server.core.analysis.DownSampling;
 import org.apache.skywalking.oap.server.core.analysis.IDManager;
 import org.apache.skywalking.oap.server.core.config.IComponentLibraryCatalogService;
 import org.apache.skywalking.oap.server.core.query.type.Call;
@@ -67,24 +66,23 @@ public class TopologyQueryService implements Service {
         return componentLibraryCatalogService;
     }
 
-    public Topology getGlobalTopology(final DownSampling downsampling, final long startTB,
+    public Topology getGlobalTopology(final long startTB,
                                       final long endTB) throws IOException {
-        log.debug("Downsampling: {}, startTimeBucket: {}, endTimeBucket: {}", downsampling, startTB, endTB);
         List<Call.CallDetail> serviceRelationServerCalls = getTopologyQueryDAO().loadServiceRelationsDetectedAtServerSide(
-            downsampling, startTB, endTB);
+            startTB, endTB);
         List<Call.CallDetail> serviceRelationClientCalls = getTopologyQueryDAO().loadServiceRelationDetectedAtClientSide(
-            downsampling, startTB, endTB);
+            startTB, endTB);
 
         ServiceTopologyBuilder builder = new ServiceTopologyBuilder(moduleManager);
         return builder.build(serviceRelationClientCalls, serviceRelationServerCalls);
     }
 
-    public Topology getServiceTopology(final DownSampling downsampling, final long startTB, final long endTB,
+    public Topology getServiceTopology(final long startTB, final long endTB,
                                        final List<String> serviceIds) throws IOException {
         List<Call.CallDetail> serviceRelationClientCalls = getTopologyQueryDAO().loadServiceRelationDetectedAtClientSide(
-            downsampling, startTB, endTB, serviceIds);
+            startTB, endTB, serviceIds);
         List<Call.CallDetail> serviceRelationServerCalls = getTopologyQueryDAO().loadServiceRelationsDetectedAtServerSide(
-            downsampling, startTB, endTB, serviceIds);
+            startTB, endTB, serviceIds);
 
         ServiceTopologyBuilder builder = new ServiceTopologyBuilder(moduleManager);
         Topology topology = builder.build(serviceRelationClientCalls, serviceRelationServerCalls);
@@ -105,7 +103,7 @@ public class TopologyQueryService implements Service {
         if (CollectionUtils.isNotEmpty(outScopeSourceServiceIds)) {
             // If exist, query them as the server side to get the target's component.
             List<Call.CallDetail> sourceCalls = getTopologyQueryDAO().loadServiceRelationsDetectedAtServerSide(
-                downsampling, startTB, endTB, outScopeSourceServiceIds);
+                startTB, endTB, outScopeSourceServiceIds);
             topology.getNodes().forEach(node -> {
                 if (Strings.isNullOrEmpty(node.getType())) {
                     for (Call.CallDetail call : sourceCalls) {
@@ -123,27 +121,21 @@ public class TopologyQueryService implements Service {
 
     public ServiceInstanceTopology getServiceInstanceTopology(final String clientServiceId,
                                                               final String serverServiceId,
-                                                              final DownSampling downsampling,
                                                               final long startTB,
                                                               final long endTB) throws IOException {
-        log.debug(
-            "ClientServiceId: {}, ServerServiceId: {}, Downsampling: {}, startTimeBucket: {}, endTimeBucket: {}",
-            clientServiceId, serverServiceId, downsampling, startTB, endTB
-        );
-
         List<Call.CallDetail> serviceInstanceRelationClientCalls = getTopologyQueryDAO().loadInstanceRelationDetectedAtClientSide(
-            clientServiceId, serverServiceId, downsampling, startTB, endTB);
+            clientServiceId, serverServiceId, startTB, endTB);
         List<Call.CallDetail> serviceInstanceRelationServerCalls = getTopologyQueryDAO().loadInstanceRelationDetectedAtServerSide(
-            clientServiceId, serverServiceId, downsampling, startTB, endTB);
+            clientServiceId, serverServiceId, startTB, endTB);
 
         ServiceInstanceTopologyBuilder builder = new ServiceInstanceTopologyBuilder(moduleManager);
         return builder.build(serviceInstanceRelationClientCalls, serviceInstanceRelationServerCalls);
     }
 
-    public Topology getEndpointTopology(final DownSampling downsampling, final long startTB, final long endTB,
+    public Topology getEndpointTopology(final long startTB, final long endTB,
                                         final String endpointId) throws IOException {
         List<Call.CallDetail> serverSideCalls = getTopologyQueryDAO().loadEndpointRelation(
-            downsampling, startTB, endTB, endpointId);
+            startTB, endTB, endpointId);
 
         Topology topology = new Topology();
         serverSideCalls.forEach(callDetail -> {
diff --git a/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/query/type/ClusterBrief.java b/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/query/type/ClusterBrief.java
deleted file mode 100644
index c6d1118..0000000
--- a/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/query/type/ClusterBrief.java
+++ /dev/null
@@ -1,32 +0,0 @@
-/*
- * 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.type;
-
-import lombok.Getter;
-import lombok.Setter;
-
-@Getter
-@Setter
-public class ClusterBrief {
-    private int numOfService;
-    private int numOfEndpoint;
-    private int numOfDatabase;
-    private int numOfCache;
-    private int numOfMQ;
-}
diff --git a/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/storage/query/IAggregationQueryDAO.java b/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/storage/query/IAggregationQueryDAO.java
index e520d3c..5f31903 100644
--- a/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/storage/query/IAggregationQueryDAO.java
+++ b/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/storage/query/IAggregationQueryDAO.java
@@ -32,7 +32,7 @@ import org.apache.skywalking.oap.server.core.storage.DAO;
  * @since 8.0.0
  */
 public interface IAggregationQueryDAO extends DAO {
-    List<SelectedRecord> sortMetrics(TopNCondition metrics,
+    List<SelectedRecord> sortMetrics(TopNCondition condition,
                                      String valueColumnName,
                                      Duration duration,
                                      List<KeyValue> additionalConditions) throws IOException;
diff --git a/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/storage/query/ITopologyQueryDAO.java b/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/storage/query/ITopologyQueryDAO.java
index 255ab13..c54a28b 100644
--- a/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/storage/query/ITopologyQueryDAO.java
+++ b/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/storage/query/ITopologyQueryDAO.java
@@ -20,7 +20,6 @@ package org.apache.skywalking.oap.server.core.storage.query;
 
 import java.io.IOException;
 import java.util.List;
-import org.apache.skywalking.oap.server.core.analysis.DownSampling;
 import org.apache.skywalking.oap.server.core.analysis.manual.relation.instance.ServiceInstanceRelationClientSideMetrics;
 import org.apache.skywalking.oap.server.core.analysis.manual.relation.instance.ServiceInstanceRelationServerSideMetrics;
 import org.apache.skywalking.oap.server.core.analysis.manual.relation.service.ServiceRelationClientSideMetrics;
@@ -32,25 +31,25 @@ public interface ITopologyQueryDAO extends Service {
     /**
      * Query {@link ServiceRelationServerSideMetrics} through the given conditions
      */
-    List<Call.CallDetail> loadServiceRelationsDetectedAtServerSide(DownSampling downsampling, long startTB, long endTB,
+    List<Call.CallDetail> loadServiceRelationsDetectedAtServerSide(long startTB, long endTB,
                                                                    List<String> serviceIds) throws IOException;
 
     /**
      * Query {@link ServiceRelationClientSideMetrics} through the given conditions
      */
-    List<Call.CallDetail> loadServiceRelationDetectedAtClientSide(DownSampling downsampling, long startTB, long endTB,
+    List<Call.CallDetail> loadServiceRelationDetectedAtClientSide(long startTB, long endTB,
                                                                   List<String> serviceIds) throws IOException;
 
     /**
      * Query {@link ServiceRelationServerSideMetrics} globally, without given serviceIds
      */
-    List<Call.CallDetail> loadServiceRelationsDetectedAtServerSide(DownSampling downsampling, long startTB,
+    List<Call.CallDetail> loadServiceRelationsDetectedAtServerSide(long startTB,
                                                                    long endTB) throws IOException;
 
     /**
      * Query {@link ServiceRelationClientSideMetrics} globally, without given serviceIds
      */
-    List<Call.CallDetail> loadServiceRelationDetectedAtClientSide(DownSampling downsampling, long startTB,
+    List<Call.CallDetail> loadServiceRelationDetectedAtClientSide(long startTB,
                                                                   long endTB) throws IOException;
 
     /**
@@ -59,7 +58,6 @@ public interface ITopologyQueryDAO extends Service {
      */
     List<Call.CallDetail> loadInstanceRelationDetectedAtServerSide(String clientServiceId,
                                                                    String serverServiceId,
-                                                                   DownSampling downsampling,
                                                                    long startTB,
                                                                    long endTB) throws IOException;
 
@@ -69,15 +67,13 @@ public interface ITopologyQueryDAO extends Service {
      */
     List<Call.CallDetail> loadInstanceRelationDetectedAtClientSide(String clientServiceId,
                                                                    String serverServiceId,
-                                                                   DownSampling downsampling,
                                                                    long startTB,
                                                                    long endTB) throws IOException;
 
     /**
      * Query the endpoint relationship. Endpoint dependency is not detected from server side agent.
      */
-    List<Call.CallDetail> loadEndpointRelation(DownSampling downsampling,
-                                               long startTB,
+    List<Call.CallDetail> loadEndpointRelation(long startTB,
                                                long endTB,
                                                String destEndpointId) throws IOException;
 }
diff --git a/oap-server/server-query-plugin/query-graphql-plugin/src/main/java/org/apache/skywalking/oap/query/graphql/resolver/AlarmQuery.java b/oap-server/server-query-plugin/query-graphql-plugin/src/main/java/org/apache/skywalking/oap/query/graphql/resolver/AlarmQuery.java
index 293dc6d..fe38bb9 100644
--- a/oap-server/server-query-plugin/query-graphql-plugin/src/main/java/org/apache/skywalking/oap/query/graphql/resolver/AlarmQuery.java
+++ b/oap-server/server-query-plugin/query-graphql-plugin/src/main/java/org/apache/skywalking/oap/query/graphql/resolver/AlarmQuery.java
@@ -20,14 +20,13 @@ package org.apache.skywalking.oap.query.graphql.resolver;
 
 import com.coxautodev.graphql.tools.GraphQLQueryResolver;
 import java.io.IOException;
-import org.apache.skywalking.oap.server.core.query.input.Duration;
 import org.apache.skywalking.oap.server.core.CoreModule;
 import org.apache.skywalking.oap.server.core.query.AlarmQueryService;
-import org.apache.skywalking.oap.server.core.query.DurationUtils;
+import org.apache.skywalking.oap.server.core.query.enumeration.Scope;
+import org.apache.skywalking.oap.server.core.query.input.Duration;
 import org.apache.skywalking.oap.server.core.query.type.AlarmTrend;
 import org.apache.skywalking.oap.server.core.query.type.Alarms;
 import org.apache.skywalking.oap.server.core.query.type.Pagination;
-import org.apache.skywalking.oap.server.core.query.enumeration.Scope;
 import org.apache.skywalking.oap.server.library.module.ModuleManager;
 
 public class AlarmQuery implements GraphQLQueryResolver {
@@ -51,15 +50,13 @@ public class AlarmQuery implements GraphQLQueryResolver {
     }
 
     public Alarms getAlarm(final Duration duration, final Scope scope, final String keyword,
-        final Pagination paging) throws IOException {
-        long startTimeBucket = DurationUtils.INSTANCE.startTimeDurationToSecondTimeBucket(duration.getStep(), duration.getStart());
-        long endTimeBucket = DurationUtils.INSTANCE.endTimeDurationToSecondTimeBucket(duration.getStep(), duration.getEnd());
-
+                           final Pagination paging) throws IOException {
         Integer scopeId = null;
         if (scope != null) {
             scopeId = scope.getScopeId();
         }
 
-        return getQueryService().getAlarm(scopeId, keyword, paging, startTimeBucket, endTimeBucket);
+        return getQueryService().getAlarm(
+            scopeId, keyword, paging, duration.getStartTimeBucket(), duration.getEndTimeBucket());
     }
 }
diff --git a/oap-server/server-query-plugin/query-graphql-plugin/src/main/java/org/apache/skywalking/oap/query/graphql/resolver/LogQuery.java b/oap-server/server-query-plugin/query-graphql-plugin/src/main/java/org/apache/skywalking/oap/query/graphql/resolver/LogQuery.java
index 06c5a8d..156cb0c 100644
--- a/oap-server/server-query-plugin/query-graphql-plugin/src/main/java/org/apache/skywalking/oap/query/graphql/resolver/LogQuery.java
+++ b/oap-server/server-query-plugin/query-graphql-plugin/src/main/java/org/apache/skywalking/oap/query/graphql/resolver/LogQuery.java
@@ -20,10 +20,9 @@ package org.apache.skywalking.oap.query.graphql.resolver;
 
 import com.coxautodev.graphql.tools.GraphQLQueryResolver;
 import java.io.IOException;
-import org.apache.skywalking.oap.server.core.query.input.LogQueryCondition;
 import org.apache.skywalking.oap.server.core.CoreModule;
-import org.apache.skywalking.oap.server.core.query.DurationUtils;
 import org.apache.skywalking.oap.server.core.query.LogQueryService;
+import org.apache.skywalking.oap.server.core.query.input.LogQueryCondition;
 import org.apache.skywalking.oap.server.core.query.type.Logs;
 import org.apache.skywalking.oap.server.library.module.ModuleManager;
 
@@ -52,7 +51,10 @@ public class LogQuery implements GraphQLQueryResolver {
             endSecondTB = condition.getQueryDuration().getEndTimeBucketInSec();
         }
 
-        return getQueryService().queryLogs(condition.getMetricName(), condition.getServiceId(), condition.getServiceInstanceId(), condition
-            .getEndpointId(), condition.getTraceId(), condition.getState(), condition.getStateCode(), condition.getPaging(), startSecondTB, endSecondTB);
+        return getQueryService().queryLogs(
+            condition.getMetricName(), condition.getServiceId(), condition.getServiceInstanceId(), condition
+                .getEndpointId(), condition.getTraceId(), condition.getState(), condition.getStateCode(),
+            condition.getPaging(), startSecondTB, endSecondTB
+        );
     }
 }
diff --git a/oap-server/server-query-plugin/query-graphql-plugin/src/main/java/org/apache/skywalking/oap/query/graphql/resolver/MetadataQuery.java b/oap-server/server-query-plugin/query-graphql-plugin/src/main/java/org/apache/skywalking/oap/query/graphql/resolver/MetadataQuery.java
index 1d70814..fc35840 100644
--- a/oap-server/server-query-plugin/query-graphql-plugin/src/main/java/org/apache/skywalking/oap/query/graphql/resolver/MetadataQuery.java
+++ b/oap-server/server-query-plugin/query-graphql-plugin/src/main/java/org/apache/skywalking/oap/query/graphql/resolver/MetadataQuery.java
@@ -24,12 +24,10 @@ import java.text.ParseException;
 import java.text.SimpleDateFormat;
 import java.util.Date;
 import java.util.List;
-import org.apache.skywalking.oap.server.core.query.input.Duration;
 import org.apache.skywalking.oap.query.graphql.type.TimeInfo;
 import org.apache.skywalking.oap.server.core.CoreModule;
-import org.apache.skywalking.oap.server.core.query.DurationUtils;
 import org.apache.skywalking.oap.server.core.query.MetadataQueryService;
-import org.apache.skywalking.oap.server.core.query.type.ClusterBrief;
+import org.apache.skywalking.oap.server.core.query.input.Duration;
 import org.apache.skywalking.oap.server.core.query.type.Database;
 import org.apache.skywalking.oap.server.core.query.type.Endpoint;
 import org.apache.skywalking.oap.server.core.query.type.EndpointInfo;
@@ -55,33 +53,19 @@ public class MetadataQuery implements GraphQLQueryResolver {
         return metadataQueryService;
     }
 
-    public ClusterBrief getGlobalBrief(final Duration duration) throws IOException, ParseException {
-        long startTimestamp = DurationUtils.INSTANCE.startTimeToTimestamp(duration.getStep(), duration.getStart());
-        long endTimestamp = DurationUtils.INSTANCE.endTimeToTimestamp(duration.getStep(), duration.getEnd());
-
-        return getMetadataQueryService().getGlobalBrief(startTimestamp, endTimestamp);
-    }
-
     public List<Service> getAllServices(final Duration duration) throws IOException, ParseException {
-        long startTimestamp = DurationUtils.INSTANCE.startTimeToTimestamp(duration.getStep(), duration.getStart());
-        long endTimestamp = DurationUtils.INSTANCE.endTimeToTimestamp(duration.getStep(), duration.getEnd());
-
-        return getMetadataQueryService().getAllServices(startTimestamp, endTimestamp);
+        return getMetadataQueryService().getAllServices(duration.getStartTimeBucket(), duration.getEndTimeBucket());
     }
 
     public List<Service> getAllBrowserServices(final Duration duration) throws IOException, ParseException {
-        long startTimestamp = DurationUtils.INSTANCE.startTimeToTimestamp(duration.getStep(), duration.getStart());
-        long endTimestamp = DurationUtils.INSTANCE.endTimeToTimestamp(duration.getStep(), duration.getEnd());
-
-        return getMetadataQueryService().getAllBrowserServices(startTimestamp, endTimestamp);
+        return getMetadataQueryService().getAllBrowserServices(
+            duration.getStartTimeBucket(), duration.getEndTimeBucket());
     }
 
     public List<Service> searchServices(final Duration duration,
                                         final String keyword) throws IOException, ParseException {
-        long startTimestamp = DurationUtils.INSTANCE.startTimeToTimestamp(duration.getStep(), duration.getStart());
-        long endTimestamp = DurationUtils.INSTANCE.endTimeToTimestamp(duration.getStep(), duration.getEnd());
-
-        return getMetadataQueryService().searchServices(startTimestamp, endTimestamp, keyword);
+        return getMetadataQueryService().searchServices(
+            duration.getStartTimeBucket(), duration.getEndTimeBucket(), keyword);
     }
 
     public Service searchService(final String serviceCode) throws IOException {
@@ -90,10 +74,8 @@ public class MetadataQuery implements GraphQLQueryResolver {
 
     public List<ServiceInstance> getServiceInstances(final Duration duration,
                                                      final String serviceId) throws IOException, ParseException {
-        long startTimestamp = DurationUtils.INSTANCE.startTimeToTimestamp(duration.getStep(), duration.getStart());
-        long endTimestamp = DurationUtils.INSTANCE.endTimeToTimestamp(duration.getStep(), duration.getEnd());
-
-        return getMetadataQueryService().getServiceInstances(startTimestamp, endTimestamp, serviceId);
+        return getMetadataQueryService().getServiceInstances(
+            duration.getStartTimeBucket(), duration.getEndTimeBucket(), serviceId);
     }
 
     public List<Endpoint> searchEndpoint(final String keyword, final String serviceId,
diff --git a/oap-server/server-query-plugin/query-graphql-plugin/src/main/java/org/apache/skywalking/oap/query/graphql/resolver/Mutation.java b/oap-server/server-query-plugin/query-graphql-plugin/src/main/java/org/apache/skywalking/oap/query/graphql/resolver/Mutation.java
index cf3abdb..239588f 100644
--- a/oap-server/server-query-plugin/query-graphql-plugin/src/main/java/org/apache/skywalking/oap/query/graphql/resolver/Mutation.java
+++ b/oap-server/server-query-plugin/query-graphql-plugin/src/main/java/org/apache/skywalking/oap/query/graphql/resolver/Mutation.java
@@ -24,5 +24,5 @@ import com.coxautodev.graphql.tools.GraphQLMutationResolver;
  * Root mutation resolver.
  */
 public class Mutation implements GraphQLMutationResolver {
-    private String version;
+    private String version = "8.0";
 }
diff --git a/oap-server/server-query-plugin/query-graphql-plugin/src/main/java/org/apache/skywalking/oap/query/graphql/resolver/Query.java b/oap-server/server-query-plugin/query-graphql-plugin/src/main/java/org/apache/skywalking/oap/query/graphql/resolver/Query.java
index 8f4a018..947e303 100644
--- a/oap-server/server-query-plugin/query-graphql-plugin/src/main/java/org/apache/skywalking/oap/query/graphql/resolver/Query.java
+++ b/oap-server/server-query-plugin/query-graphql-plugin/src/main/java/org/apache/skywalking/oap/query/graphql/resolver/Query.java
@@ -24,5 +24,5 @@ import com.coxautodev.graphql.tools.GraphQLQueryResolver;
  * Root Query Resolver.
  */
 public class Query implements GraphQLQueryResolver {
-    private String version = "6.0";
+    private String version = "8.0";
 }
diff --git a/oap-server/server-query-plugin/query-graphql-plugin/src/main/java/org/apache/skywalking/oap/query/graphql/resolver/TopologyQuery.java b/oap-server/server-query-plugin/query-graphql-plugin/src/main/java/org/apache/skywalking/oap/query/graphql/resolver/TopologyQuery.java
index 00b669e..333c962 100644
--- a/oap-server/server-query-plugin/query-graphql-plugin/src/main/java/org/apache/skywalking/oap/query/graphql/resolver/TopologyQuery.java
+++ b/oap-server/server-query-plugin/query-graphql-plugin/src/main/java/org/apache/skywalking/oap/query/graphql/resolver/TopologyQuery.java
@@ -22,11 +22,9 @@ import com.coxautodev.graphql.tools.GraphQLQueryResolver;
 import java.io.IOException;
 import java.util.ArrayList;
 import java.util.List;
-import org.apache.skywalking.oap.server.core.query.input.Duration;
 import org.apache.skywalking.oap.server.core.CoreModule;
-import org.apache.skywalking.oap.server.core.query.DurationUtils;
-import org.apache.skywalking.oap.server.core.query.StepToDownSampling;
 import org.apache.skywalking.oap.server.core.query.TopologyQueryService;
+import org.apache.skywalking.oap.server.core.query.input.Duration;
 import org.apache.skywalking.oap.server.core.query.type.ServiceInstanceTopology;
 import org.apache.skywalking.oap.server.core.query.type.Topology;
 import org.apache.skywalking.oap.server.library.module.ModuleManager;
@@ -48,11 +46,7 @@ public class TopologyQuery implements GraphQLQueryResolver {
     }
 
     public Topology getGlobalTopology(final Duration duration) throws IOException {
-        long startTimeBucket = DurationUtils.INSTANCE.convertToTimeBucket(duration.getStart());
-        long endTimeBucket = DurationUtils.INSTANCE.convertToTimeBucket(duration.getEnd());
-
-        return getQueryService().getGlobalTopology(
-            StepToDownSampling.transform(duration.getStep()), startTimeBucket, endTimeBucket);
+        return getQueryService().getGlobalTopology(duration.getStartTimeBucket(), duration.getEndTimeBucket());
     }
 
     public Topology getServiceTopology(final String serviceId, final Duration duration) throws IOException {
@@ -62,30 +56,21 @@ public class TopologyQuery implements GraphQLQueryResolver {
     }
 
     public Topology getServicesTopology(final List<String> serviceIds, final Duration duration) throws IOException {
-        long startTimeBucket = DurationUtils.INSTANCE.convertToTimeBucket(duration.getStart());
-        long endTimeBucket = DurationUtils.INSTANCE.convertToTimeBucket(duration.getEnd());
-
         return getQueryService().getServiceTopology(
-            StepToDownSampling.transform(duration.getStep()), startTimeBucket, endTimeBucket, serviceIds);
+            duration.getStartTimeBucket(), duration.getEndTimeBucket(), serviceIds);
     }
 
-    public ServiceInstanceTopology getServiceInstanceTopology(final String clientServiceId, final String serverServiceId,
+    public ServiceInstanceTopology getServiceInstanceTopology(final String clientServiceId,
+                                                              final String serverServiceId,
                                                               final Duration duration) throws IOException {
-        long startTimeBucket = DurationUtils.INSTANCE.convertToTimeBucket(duration.getStart());
-        long endTimeBucket = DurationUtils.INSTANCE.convertToTimeBucket(duration.getEnd());
-
         return getQueryService().getServiceInstanceTopology(
-            clientServiceId, serverServiceId, StepToDownSampling.transform(duration
-                                                                               .getStep()), startTimeBucket,
-            endTimeBucket
+            clientServiceId, serverServiceId,
+            duration.getStartTimeBucket(), duration.getEndTimeBucket()
         );
     }
 
     public Topology getEndpointTopology(final String endpointId, final Duration duration) throws IOException {
-        long startTimeBucket = DurationUtils.INSTANCE.convertToTimeBucket(duration.getStart());
-        long endTimeBucket = DurationUtils.INSTANCE.convertToTimeBucket(duration.getEnd());
-
         return getQueryService().getEndpointTopology(
-            StepToDownSampling.transform(duration.getStep()), startTimeBucket, endTimeBucket, endpointId);
+            duration.getStartTimeBucket(), duration.getEndTimeBucket(), endpointId);
     }
 }
diff --git a/oap-server/server-storage-plugin/storage-elasticsearch-plugin/src/main/java/org/apache/skywalking/oap/server/storage/plugin/elasticsearch/base/EsDAO.java b/oap-server/server-storage-plugin/storage-elasticsearch-plugin/src/main/java/org/apache/skywalking/oap/server/storage/plugin/elasticsearch/base/EsDAO.java
index 01ad815..396e71c 100644
--- a/oap-server/server-storage-plugin/storage-elasticsearch-plugin/src/main/java/org/apache/skywalking/oap/server/storage/plugin/elasticsearch/base/EsDAO.java
+++ b/oap-server/server-storage-plugin/storage-elasticsearch-plugin/src/main/java/org/apache/skywalking/oap/server/storage/plugin/elasticsearch/base/EsDAO.java
@@ -19,22 +19,12 @@
 package org.apache.skywalking.oap.server.storage.plugin.elasticsearch.base;
 
 import java.io.IOException;
-import java.util.ArrayList;
-import java.util.List;
 import java.util.Map;
-import org.apache.skywalking.oap.server.core.analysis.metrics.Metrics;
-import org.apache.skywalking.oap.server.core.query.PointOfTime;
-import org.apache.skywalking.oap.server.core.query.input.Duration;
-import org.apache.skywalking.oap.server.core.query.input.MetricsCondition;
 import org.apache.skywalking.oap.server.core.storage.AbstractDAO;
 import org.apache.skywalking.oap.server.core.storage.type.StorageDataComplexObject;
 import org.apache.skywalking.oap.server.library.client.elasticsearch.ElasticSearchClient;
 import org.elasticsearch.common.xcontent.XContentBuilder;
 import org.elasticsearch.common.xcontent.XContentFactory;
-import org.elasticsearch.index.query.BoolQueryBuilder;
-import org.elasticsearch.index.query.QueryBuilders;
-import org.elasticsearch.index.query.RangeQueryBuilder;
-import org.elasticsearch.search.builder.SearchSourceBuilder;
 
 public abstract class EsDAO extends AbstractDAO<ElasticSearchClient> {
 
diff --git a/oap-server/server-storage-plugin/storage-elasticsearch-plugin/src/main/java/org/apache/skywalking/oap/server/storage/plugin/elasticsearch/query/AggregationQueryEsDAO.java b/oap-server/server-storage-plugin/storage-elasticsearch-plugin/src/main/java/org/apache/skywalking/oap/server/storage/plugin/elasticsearch/query/AggregationQueryEsDAO.java
index 546a6e2..c1d4ce3 100644
--- a/oap-server/server-storage-plugin/storage-elasticsearch-plugin/src/main/java/org/apache/skywalking/oap/server/storage/plugin/elasticsearch/query/AggregationQueryEsDAO.java
+++ b/oap-server/server-storage-plugin/storage-elasticsearch-plugin/src/main/java/org/apache/skywalking/oap/server/storage/plugin/elasticsearch/query/AggregationQueryEsDAO.java
@@ -45,7 +45,7 @@ public class AggregationQueryEsDAO extends EsDAO implements IAggregationQueryDAO
     }
 
     @Override
-    public List<SelectedRecord> sortMetrics(final TopNCondition metrics,
+    public List<SelectedRecord> sortMetrics(final TopNCondition condition,
                                             final String valueColumnName,
                                             final Duration duration,
                                             final List<KeyValue> additionalConditions) throws IOException {
@@ -55,7 +55,7 @@ public class AggregationQueryEsDAO extends EsDAO implements IAggregationQueryDAO
                                          .gte(duration.getStartTimeBucket()));
 
         boolean asc = false;
-        if (metrics.getOrder().equals(Order.ASC)) {
+        if (condition.getOrder().equals(Order.ASC)) {
             asc = true;
         }
 
@@ -63,11 +63,11 @@ public class AggregationQueryEsDAO extends EsDAO implements IAggregationQueryDAO
             AggregationBuilders.terms(Metrics.ENTITY_ID)
                                .field(Metrics.ENTITY_ID)
                                .order(BucketOrder.aggregation(valueColumnName, asc))
-                               .size(metrics.getTopN())
+                               .size(condition.getTopN())
                                .subAggregation(AggregationBuilders.avg(valueColumnName).field(valueColumnName))
         );
 
-        SearchResponse response = getClient().search(metrics.getName(), sourceBuilder);
+        SearchResponse response = getClient().search(condition.getName(), sourceBuilder);
 
         List<SelectedRecord> topNList = new ArrayList<>();
         Terms idTerms = response.getAggregations().get(Metrics.ENTITY_ID);
diff --git a/oap-server/server-storage-plugin/storage-elasticsearch-plugin/src/main/java/org/apache/skywalking/oap/server/storage/plugin/elasticsearch/query/TopNRecordsQueryEsDAO.java b/oap-server/server-storage-plugin/storage-elasticsearch-plugin/src/main/java/org/apache/skywalking/oap/server/storage/plugin/elasticsearch/query/TopNRecordsQueryEsDAO.java
index 41eb8f6..7b324a7 100644
--- a/oap-server/server-storage-plugin/storage-elasticsearch-plugin/src/main/java/org/apache/skywalking/oap/server/storage/plugin/elasticsearch/query/TopNRecordsQueryEsDAO.java
+++ b/oap-server/server-storage-plugin/storage-elasticsearch-plugin/src/main/java/org/apache/skywalking/oap/server/storage/plugin/elasticsearch/query/TopNRecordsQueryEsDAO.java
@@ -21,6 +21,7 @@ package org.apache.skywalking.oap.server.storage.plugin.elasticsearch.query;
 import java.io.IOException;
 import java.util.ArrayList;
 import java.util.List;
+import org.apache.skywalking.apm.util.StringUtil;
 import org.apache.skywalking.oap.server.core.analysis.IDManager;
 import org.apache.skywalking.oap.server.core.analysis.topn.TopN;
 import org.apache.skywalking.oap.server.core.query.enumeration.Order;
@@ -50,8 +51,11 @@ public class TopNRecordsQueryEsDAO extends EsDAO implements ITopNRecordsQueryDAO
         boolQueryBuilder.must().add(QueryBuilders.rangeQuery(TopN.TIME_BUCKET)
                                                  .gte(duration.getStartTimeBucket())
                                                  .lte(duration.getEndTimeBucket()));
-        final String serviceId = IDManager.ServiceID.buildId(condition.getParentService(), condition.isNormal());
-        boolQueryBuilder.must().add(QueryBuilders.termQuery(TopN.SERVICE_ID, serviceId));
+
+        if (StringUtil.isNotEmpty(condition.getParentService())) {
+            final String serviceId = IDManager.ServiceID.buildId(condition.getParentService(), condition.isNormal());
+            boolQueryBuilder.must().add(QueryBuilders.termQuery(TopN.SERVICE_ID, serviceId));
+        }
 
         sourceBuilder.query(boolQueryBuilder);
         sourceBuilder.size(condition.getTopN())
diff --git a/oap-server/server-storage-plugin/storage-elasticsearch-plugin/src/main/java/org/apache/skywalking/oap/server/storage/plugin/elasticsearch/query/TopologyQueryEsDAO.java b/oap-server/server-storage-plugin/storage-elasticsearch-plugin/src/main/java/org/apache/skywalking/oap/server/storage/plugin/elasticsearch/query/TopologyQueryEsDAO.java
index 7c4f699..21fd086 100644
--- a/oap-server/server-storage-plugin/storage-elasticsearch-plugin/src/main/java/org/apache/skywalking/oap/server/storage/plugin/elasticsearch/query/TopologyQueryEsDAO.java
+++ b/oap-server/server-storage-plugin/storage-elasticsearch-plugin/src/main/java/org/apache/skywalking/oap/server/storage/plugin/elasticsearch/query/TopologyQueryEsDAO.java
@@ -22,7 +22,6 @@ import java.io.IOException;
 import java.util.ArrayList;
 import java.util.List;
 import org.apache.skywalking.oap.server.core.UnexpectedException;
-import org.apache.skywalking.oap.server.core.analysis.DownSampling;
 import org.apache.skywalking.oap.server.core.analysis.manual.relation.endpoint.EndpointRelationServerSideMetrics;
 import org.apache.skywalking.oap.server.core.analysis.manual.relation.instance.ServiceInstanceRelationClientSideMetrics;
 import org.apache.skywalking.oap.server.core.analysis.manual.relation.instance.ServiceInstanceRelationServerSideMetrics;
@@ -49,8 +48,7 @@ public class TopologyQueryEsDAO extends EsDAO implements ITopologyQueryDAO {
     }
 
     @Override
-    public List<Call.CallDetail> loadServiceRelationsDetectedAtServerSide(DownSampling downsampling,
-                                                                          long startTB,
+    public List<Call.CallDetail> loadServiceRelationsDetectedAtServerSide(long startTB,
                                                                           long endTB,
                                                                           List<String> serviceIds) throws IOException {
         if (CollectionUtils.isEmpty(serviceIds)) {
@@ -65,8 +63,7 @@ public class TopologyQueryEsDAO extends EsDAO implements ITopologyQueryDAO {
     }
 
     @Override
-    public List<Call.CallDetail> loadServiceRelationDetectedAtClientSide(DownSampling downsampling,
-                                                                         long startTB,
+    public List<Call.CallDetail> loadServiceRelationDetectedAtClientSide(long startTB,
                                                                          long endTB,
                                                                          List<String> serviceIds) throws IOException {
         if (CollectionUtils.isEmpty(serviceIds)) {
@@ -81,7 +78,7 @@ public class TopologyQueryEsDAO extends EsDAO implements ITopologyQueryDAO {
     }
 
     @Override
-    public List<Call.CallDetail> loadServiceRelationsDetectedAtServerSide(DownSampling downsampling, long startTB,
+    public List<Call.CallDetail> loadServiceRelationsDetectedAtServerSide(long startTB,
                                                                           long endTB) throws IOException {
         SearchSourceBuilder sourceBuilder = SearchSourceBuilder.searchSource();
         sourceBuilder.query(QueryBuilders.rangeQuery(ServiceRelationServerSideMetrics.TIME_BUCKET)
@@ -93,7 +90,7 @@ public class TopologyQueryEsDAO extends EsDAO implements ITopologyQueryDAO {
     }
 
     @Override
-    public List<Call.CallDetail> loadServiceRelationDetectedAtClientSide(DownSampling downsampling, long startTB,
+    public List<Call.CallDetail> loadServiceRelationDetectedAtClientSide(long startTB,
                                                                          long endTB) throws IOException {
         SearchSourceBuilder sourceBuilder = SearchSourceBuilder.searchSource();
         sourceBuilder.query(QueryBuilders.rangeQuery(ServiceRelationServerSideMetrics.TIME_BUCKET)
@@ -107,7 +104,6 @@ public class TopologyQueryEsDAO extends EsDAO implements ITopologyQueryDAO {
     @Override
     public List<Call.CallDetail> loadInstanceRelationDetectedAtServerSide(String clientServiceId,
                                                                           String serverServiceId,
-                                                                          DownSampling downsampling,
                                                                           long startTB,
                                                                           long endTB) throws IOException {
         SearchSourceBuilder sourceBuilder = SearchSourceBuilder.searchSource();
@@ -121,7 +117,6 @@ public class TopologyQueryEsDAO extends EsDAO implements ITopologyQueryDAO {
     @Override
     public List<Call.CallDetail> loadInstanceRelationDetectedAtClientSide(String clientServiceId,
                                                                           String serverServiceId,
-                                                                          DownSampling downsampling,
                                                                           long startTB,
                                                                           long endTB) throws IOException {
         SearchSourceBuilder sourceBuilder = SearchSourceBuilder.searchSource();
@@ -161,8 +156,7 @@ public class TopologyQueryEsDAO extends EsDAO implements ITopologyQueryDAO {
     }
 
     @Override
-    public List<Call.CallDetail> loadEndpointRelation(DownSampling downsampling,
-                                                      long startTB,
+    public List<Call.CallDetail> loadEndpointRelation(long startTB,
                                                       long endTB,
                                                       String destEndpointId) throws IOException {
         SearchSourceBuilder sourceBuilder = SearchSourceBuilder.searchSource();
diff --git a/oap-server/server-storage-plugin/storage-elasticsearch7-plugin/src/main/java/org/apache/skywalking/oap/server/storage/plugin/elasticsearch7/query/AggregationQueryEs7DAO.java b/oap-server/server-storage-plugin/storage-elasticsearch7-plugin/src/main/java/org/apache/skywalking/oap/server/storage/plugin/elasticsearch7/query/AggregationQueryEs7DAO.java
index 82f72da..f5b9e37 100644
--- a/oap-server/server-storage-plugin/storage-elasticsearch7-plugin/src/main/java/org/apache/skywalking/oap/server/storage/plugin/elasticsearch7/query/AggregationQueryEs7DAO.java
+++ b/oap-server/server-storage-plugin/storage-elasticsearch7-plugin/src/main/java/org/apache/skywalking/oap/server/storage/plugin/elasticsearch7/query/AggregationQueryEs7DAO.java
@@ -47,7 +47,7 @@ public class AggregationQueryEs7DAO extends AggregationQueryEsDAO {
     }
 
     @Override
-    public List<SelectedRecord> sortMetrics(final TopNCondition metrics,
+    public List<SelectedRecord> sortMetrics(final TopNCondition condition,
                                             final String valueColumnName,
                                             final Duration duration,
                                             final List<KeyValue> additionalConditions) throws IOException {
@@ -57,7 +57,7 @@ public class AggregationQueryEs7DAO extends AggregationQueryEsDAO {
                                          .gte(duration.getStartTimeBucket()));
 
         boolean asc = false;
-        if (metrics.getOrder().equals(Order.ASC)) {
+        if (condition.getOrder().equals(Order.ASC)) {
             asc = true;
         }
 
@@ -65,11 +65,11 @@ public class AggregationQueryEs7DAO extends AggregationQueryEsDAO {
             AggregationBuilders.terms(Metrics.ENTITY_ID)
                                .field(Metrics.ENTITY_ID)
                                .order(BucketOrder.aggregation(valueColumnName, asc))
-                               .size(metrics.getTopN())
+                               .size(condition.getTopN())
                                .subAggregation(AggregationBuilders.avg(valueColumnName).field(valueColumnName))
         );
 
-        SearchResponse response = getClient().search(metrics.getName(), sourceBuilder);
+        SearchResponse response = getClient().search(condition.getName(), sourceBuilder);
 
         List<SelectedRecord> topNList = new ArrayList<>();
         Terms idTerms = response.getAggregations().get(Metrics.ENTITY_ID);
diff --git a/oap-server/server-storage-plugin/storage-influxdb-plugin/src/main/java/org/apache/skywalking/oap/server/storage/plugin/influxdb/InfluxClient.java b/oap-server/server-storage-plugin/storage-influxdb-plugin/src/main/java/org/apache/skywalking/oap/server/storage/plugin/influxdb/InfluxClient.java
index fe96dd4..d12bd4c 100644
--- a/oap-server/server-storage-plugin/storage-influxdb-plugin/src/main/java/org/apache/skywalking/oap/server/storage/plugin/influxdb/InfluxClient.java
+++ b/oap-server/server-storage-plugin/storage-influxdb-plugin/src/main/java/org/apache/skywalking/oap/server/storage/plugin/influxdb/InfluxClient.java
@@ -24,7 +24,6 @@ import java.util.Objects;
 import java.util.concurrent.TimeUnit;
 import lombok.extern.slf4j.Slf4j;
 import okhttp3.OkHttpClient;
-import org.apache.skywalking.oap.server.core.analysis.DownSampling;
 import org.apache.skywalking.oap.server.core.analysis.TimeBucket;
 import org.apache.skywalking.oap.server.library.client.Client;
 import org.apache.skywalking.oap.server.library.util.CollectionUtils;
@@ -196,13 +195,6 @@ public class InfluxClient implements Client {
     /**
      * Convert to InfluxDB {@link TimeInterval}.
      */
-    public static TimeInterval timeInterval(long timeBucket, DownSampling downsampling) {
-        return ti(TimeBucket.getTimestamp(timeBucket, downsampling), "ms");
-    }
-
-    /**
-     * Convert to InfluxDB {@link TimeInterval}.
-     */
     public static TimeInterval timeInterval(long timeBucket) {
         return ti(TimeBucket.getTimestamp(timeBucket), "ms");
     }
diff --git a/oap-server/server-storage-plugin/storage-influxdb-plugin/src/main/java/org/apache/skywalking/oap/server/storage/plugin/influxdb/query/AggregationQuery.java b/oap-server/server-storage-plugin/storage-influxdb-plugin/src/main/java/org/apache/skywalking/oap/server/storage/plugin/influxdb/query/AggregationQuery.java
index 48cd1ef..cdd94f4 100644
--- a/oap-server/server-storage-plugin/storage-influxdb-plugin/src/main/java/org/apache/skywalking/oap/server/storage/plugin/influxdb/query/AggregationQuery.java
+++ b/oap-server/server-storage-plugin/storage-influxdb-plugin/src/main/java/org/apache/skywalking/oap/server/storage/plugin/influxdb/query/AggregationQuery.java
@@ -24,15 +24,18 @@ import java.util.Collections;
 import java.util.Comparator;
 import java.util.List;
 import lombok.extern.slf4j.Slf4j;
-import org.apache.skywalking.oap.server.core.analysis.DownSampling;
-import org.apache.skywalking.oap.server.core.query.entity.Order;
-import org.apache.skywalking.oap.server.core.query.entity.TopNEntity;
+import org.apache.skywalking.oap.server.core.query.enumeration.Order;
+import org.apache.skywalking.oap.server.core.query.input.Duration;
+import org.apache.skywalking.oap.server.core.query.input.TopNCondition;
+import org.apache.skywalking.oap.server.core.query.type.KeyValue;
+import org.apache.skywalking.oap.server.core.query.type.SelectedRecord;
 import org.apache.skywalking.oap.server.core.storage.query.IAggregationQueryDAO;
 import org.apache.skywalking.oap.server.storage.plugin.influxdb.InfluxClient;
 import org.apache.skywalking.oap.server.storage.plugin.influxdb.InfluxConstants;
 import org.influxdb.dto.QueryResult;
 import org.influxdb.querybuilder.SelectQueryImpl;
 import org.influxdb.querybuilder.SelectSubQueryImpl;
+import org.influxdb.querybuilder.WhereSubQueryImpl;
 
 import static org.influxdb.querybuilder.BuiltQuery.QueryBuilder.eq;
 import static org.influxdb.querybuilder.BuiltQuery.QueryBuilder.gte;
@@ -48,60 +51,38 @@ public class AggregationQuery implements IAggregationQueryDAO {
     }
 
     @Override
-    public List<TopNEntity> getServiceTopN(String indName, String valueCName, int topN, DownSampling downsampling,
-                                           long startTB, long endTB, Order order) throws IOException {
-        return getTopNEntity(downsampling, indName, subQuery(indName, valueCName, startTB, endTB), order, topN);
-    }
-
-    @Override
-    public List<TopNEntity> getAllServiceInstanceTopN(String indName, String valueCName, int topN,
-                                                      DownSampling downsampling,
-                                                      long startTB, long endTB, Order order) throws IOException {
-        return getTopNEntity(downsampling, indName, subQuery(indName, valueCName, startTB, endTB), order, topN);
-    }
-
-    @Override
-    public List<TopNEntity> getServiceInstanceTopN(String serviceId, String indName, String valueCName, int topN,
-                                                   DownSampling downsampling,
-                                                   long startTB, long endTB, Order order) throws IOException {
-        return getTopNEntity(
-            downsampling, indName,
-            subQuery(InfluxConstants.TagName.SERVICE_ID, serviceId, indName, valueCName, startTB, endTB), order, topN
-        );
-    }
-
-    @Override
-    public List<TopNEntity> getAllEndpointTopN(String indName, String valueCName, int topN, DownSampling downsampling,
-                                               long startTB, long endTB, Order order) throws IOException {
-        return getTopNEntity(downsampling, indName, subQuery(indName, valueCName, startTB, endTB), order, topN);
-    }
+    public List<SelectedRecord> sortMetrics(final TopNCondition condition,
+                                            final String valueColumnName,
+                                            final Duration duration,
+                                            final List<KeyValue> additionalConditions) throws IOException {
+        String measurement = condition.getName();
 
-    @Override
-    public List<TopNEntity> getEndpointTopN(String serviceId, String indName, String valueCName, int topN,
-                                            DownSampling downsampling,
-                                            long startTB, long endTB, Order order) throws IOException {
-        return getTopNEntity(
-            downsampling, indName,
-            subQuery(InfluxConstants.TagName.SERVICE_ID, serviceId, indName, valueCName, startTB, endTB), order, topN
-        );
-    }
-
-    private List<TopNEntity> getTopNEntity(DownSampling downsampling,
-                                           String measurement,
-                                           SelectSubQueryImpl<SelectQueryImpl> subQuery,
-                                           Order order,
-                                           int topN) throws IOException {
         // Have to re-sort here. Because the function, top()/bottom(), get the result ordered by the `time`.
-        Comparator<TopNEntity> comparator = DESCENDING;
+        Comparator<SelectedRecord> comparator = DESCENDING;
         String functionName = InfluxConstants.SORT_DES;
-        if (order == Order.ASC) {
+        if (condition.getOrder().equals(Order.ASC)) {
             functionName = InfluxConstants.SORT_ASC;
             comparator = ASCENDING;
         }
 
-        SelectQueryImpl query = select().function(functionName, "mean", topN).as("value")
+        SelectQueryImpl query = select().function(functionName, "mean", condition.getTopN()).as("value")
                                         .column(InfluxConstants.TagName.ENTITY_ID)
                                         .from(client.getDatabase(), measurement);
+
+        WhereSubQueryImpl<SelectSubQueryImpl<SelectQueryImpl>, SelectQueryImpl> where = select()
+            .fromSubQuery(client.getDatabase())
+            .mean(valueColumnName)
+            .from(condition.getName()).where();
+        if (additionalConditions != null) {
+            additionalConditions.forEach(moreCondition -> {
+                where.and(eq(moreCondition.getKey(), moreCondition.getValue()));
+            });
+        }
+        final SelectSubQueryImpl<SelectQueryImpl> subQuery = where
+            .and(gte(InfluxClient.TIME, InfluxClient.timeInterval(duration.getStartTimeBucket())))
+            .and(lte(InfluxClient.TIME, InfluxClient.timeInterval(duration.getEndTimeBucket())))
+            .groupBy(InfluxConstants.TagName.ENTITY_ID);
+
         query.setSubQuery(subQuery);
 
         List<QueryResult.Series> series = client.queryForSeries(query);
@@ -113,11 +94,11 @@ public class AggregationQuery implements IAggregationQueryDAO {
         }
 
         List<List<Object>> dataset = series.get(0).getValues();
-        List<TopNEntity> entities = Lists.newArrayListWithCapacity(dataset.size());
+        List<SelectedRecord> entities = Lists.newArrayListWithCapacity(dataset.size());
         dataset.forEach(values -> {
-            final TopNEntity entity = new TopNEntity();
+            final SelectedRecord entity = new SelectedRecord();
             entity.setId((String) values.get(2));
-            entity.setValue(((Double) values.get(1)).longValue());
+            entity.setValue(((Double) values.get(1)).longValue() + "");
             entities.add(entity);
         });
 
@@ -125,26 +106,9 @@ public class AggregationQuery implements IAggregationQueryDAO {
         return entities;
     }
 
-    private SelectSubQueryImpl<SelectQueryImpl> subQuery(String serviceColumnName, String serviceId, String name,
-                                                         String columnName,
-                                                         long startTB, long endTB) {
-        return select().fromSubQuery(client.getDatabase()).mean(columnName).from(name)
-                       .where()
-                       .and(eq(serviceColumnName, serviceId))
-                       .and(gte(InfluxClient.TIME, InfluxClient.timeInterval(startTB)))
-                       .and(lte(InfluxClient.TIME, InfluxClient.timeInterval(endTB)))
-                       .groupBy(InfluxConstants.TagName.ENTITY_ID);
-    }
-
-    private SelectSubQueryImpl<SelectQueryImpl> subQuery(String name, String columnName, long startTB, long endTB) {
-        return select().fromSubQuery(client.getDatabase()).mean(columnName).from(name)
-                       .where()
-                       .and(gte(InfluxClient.TIME, InfluxClient.timeInterval(startTB)))
-                       .and(lte(InfluxClient.TIME, InfluxClient.timeInterval(endTB)))
-                       .groupBy(InfluxConstants.TagName.ENTITY_ID);
-    }
-
-    private static final Comparator<TopNEntity> ASCENDING = Comparator.comparingLong(TopNEntity::getValue);
+    private static final Comparator<SelectedRecord> ASCENDING = (a, b) -> Long.compare(
+        Long.parseLong(a.getValue()), Long.parseLong(b.getValue()));
 
-    private static final Comparator<TopNEntity> DESCENDING = (a, b) -> Long.compare(b.getValue(), a.getValue());
+    private static final Comparator<SelectedRecord> DESCENDING = (a, b) -> Long.compare(
+        Long.parseLong(b.getValue()), Long.parseLong(a.getValue()));
 }
diff --git a/oap-server/server-storage-plugin/storage-influxdb-plugin/src/main/java/org/apache/skywalking/oap/server/storage/plugin/influxdb/query/InfluxMetadataQueryDAO.java b/oap-server/server-storage-plugin/storage-influxdb-plugin/src/main/java/org/apache/skywalking/oap/server/storage/plugin/influxdb/query/InfluxMetadataQueryDAO.java
deleted file mode 100644
index 3ca0c3e..0000000
--- a/oap-server/server-storage-plugin/storage-influxdb-plugin/src/main/java/org/apache/skywalking/oap/server/storage/plugin/influxdb/query/InfluxMetadataQueryDAO.java
+++ /dev/null
@@ -1,146 +0,0 @@
-/*
- * 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.storage.plugin.influxdb.query;
-
-import com.google.common.base.Strings;
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.List;
-import org.apache.skywalking.oap.server.core.analysis.IDManager;
-import org.apache.skywalking.oap.server.core.analysis.manual.endpoint.EndpointTraffic;
-import org.apache.skywalking.oap.server.core.query.type.Database;
-import org.apache.skywalking.oap.server.core.query.type.Endpoint;
-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.core.storage.query.IMetadataQueryDAO;
-import org.apache.skywalking.oap.server.storage.plugin.influxdb.InfluxClient;
-import org.apache.skywalking.oap.server.storage.plugin.influxdb.base.MetricsDAO;
-import org.influxdb.dto.Query;
-import org.influxdb.dto.QueryResult;
-import org.influxdb.querybuilder.SelectQueryImpl;
-import org.influxdb.querybuilder.WhereQueryImpl;
-
-import static org.influxdb.querybuilder.BuiltQuery.QueryBuilder.contains;
-import static org.influxdb.querybuilder.BuiltQuery.QueryBuilder.eq;
-import static org.influxdb.querybuilder.BuiltQuery.QueryBuilder.select;
-
-public class InfluxMetadataQueryDAO implements IMetadataQueryDAO {
-    private InfluxClient client;
-    // 'name' is InfluxDB keyword, so escapes it
-    private static final String ENDPOINT_NAME = '\"' + EndpointTraffic.NAME + '\"';
-
-    public InfluxMetadataQueryDAO(final InfluxClient client) {
-        this.client = client;
-    }
-
-    @Override
-    public int numOfService(final long startTimestamp, final long endTimestamp) throws IOException {
-        return 0;
-    }
-
-    @Override
-    public int numOfEndpoint() throws IOException {
-        final SelectQueryImpl selectQuery = select()
-            .count(EndpointTraffic.ENTITY_ID)
-            .from(client.getDatabase(), EndpointTraffic.INDEX_NAME);
-
-        Query query = new Query(selectQuery.getCommand());
-
-        final QueryResult.Series series = client.queryForSingleSeries(query);
-        if (series == null) {
-            return 0;
-        }
-
-        return ((Number) series.getValues().get(0).get(1)).intValue();
-    }
-
-    @Override
-    public int numOfConjectural(final int nodeTypeValue) throws IOException {
-        return 0;
-    }
-
-    @Override
-    public List<Service> getAllServices(final long startTimestamp, final long endTimestamp) throws IOException {
-        return null;
-    }
-
-    @Override
-    public List<Service> getAllBrowserServices(final long startTimestamp, final long endTimestamp) throws IOException {
-        return null;
-    }
-
-    @Override
-    public List<Database> getAllDatabases() throws IOException {
-        return null;
-    }
-
-    @Override
-    public List<Service> searchServices(final long startTimestamp,
-                                        final long endTimestamp,
-                                        final String keyword) throws IOException {
-        return null;
-    }
-
-    @Override
-    public Service searchService(final String serviceCode) throws IOException {
-        return null;
-    }
-
-    @Override
-    public List<Endpoint> searchEndpoint(final String keyword,
-                                         final String serviceId,
-                                         final int limit) throws IOException {
-        WhereQueryImpl<SelectQueryImpl> endpointQuery = select()
-            .column(EndpointTraffic.SERVICE_ID)
-            .column(ENDPOINT_NAME)
-            .from(client.getDatabase(), EndpointTraffic.INDEX_NAME)
-            .where();
-        endpointQuery.where(eq(MetricsDAO.TAG_ENDPOINT_OWNER_SERVICE, String.valueOf(serviceId)));
-        if (!Strings.isNullOrEmpty(keyword)) {
-            endpointQuery.where(contains(MetricsDAO.TAG_ENDPOINT_NAME, keyword.replaceAll("/", "\\\\/")));
-        }
-        endpointQuery.limit(limit);
-
-        Query query = new Query(endpointQuery.getCommand());
-
-        final QueryResult.Series series = client.queryForSingleSeries(query);
-
-        List<Endpoint> list = new ArrayList<>(limit);
-        if (series != null) {
-            series.getValues().forEach(values -> {
-                EndpointTraffic endpointTraffic = new EndpointTraffic();
-                endpointTraffic.setServiceId((String) values.get(1));
-                endpointTraffic.setName((String) values.get(2));
-
-                Endpoint endpoint = new Endpoint();
-                endpoint.setId(IDManager.EndpointID.buildId(endpointTraffic.getServiceId(), endpointTraffic.getName()));
-                endpoint.setName(endpointTraffic.getName());
-                list.add(endpoint);
-            });
-        }
-        return list;
-    }
-
-    @Override
-    public List<ServiceInstance> getServiceInstances(final long startTimestamp,
-                                                     final long endTimestamp,
-                                                     final String serviceId) throws IOException {
-        return null;
-    }
-}
diff --git a/oap-server/server-storage-plugin/storage-influxdb-plugin/src/main/java/org/apache/skywalking/oap/server/storage/plugin/influxdb/query/MetadataQuery.java b/oap-server/server-storage-plugin/storage-influxdb-plugin/src/main/java/org/apache/skywalking/oap/server/storage/plugin/influxdb/query/MetadataQuery.java
index bd04197..4c20e08 100644
--- a/oap-server/server-storage-plugin/storage-influxdb-plugin/src/main/java/org/apache/skywalking/oap/server/storage/plugin/influxdb/query/MetadataQuery.java
+++ b/oap-server/server-storage-plugin/storage-influxdb-plugin/src/main/java/org/apache/skywalking/oap/server/storage/plugin/influxdb/query/MetadataQuery.java
@@ -35,13 +35,12 @@ import org.apache.skywalking.oap.server.core.analysis.TimeBucket;
 import org.apache.skywalking.oap.server.core.analysis.manual.endpoint.EndpointTraffic;
 import org.apache.skywalking.oap.server.core.analysis.manual.instance.InstanceTraffic;
 import org.apache.skywalking.oap.server.core.analysis.manual.service.ServiceTraffic;
-import org.apache.skywalking.oap.server.core.query.entity.Attribute;
-import org.apache.skywalking.oap.server.core.query.entity.Database;
-import org.apache.skywalking.oap.server.core.query.entity.Endpoint;
-import org.apache.skywalking.oap.server.core.query.entity.Language;
-import org.apache.skywalking.oap.server.core.query.entity.LanguageTrans;
-import org.apache.skywalking.oap.server.core.query.entity.Service;
-import org.apache.skywalking.oap.server.core.query.entity.ServiceInstance;
+import org.apache.skywalking.oap.server.core.query.enumeration.Language;
+import org.apache.skywalking.oap.server.core.query.type.Attribute;
+import org.apache.skywalking.oap.server.core.query.type.Database;
+import org.apache.skywalking.oap.server.core.query.type.Endpoint;
+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.core.storage.query.IMetadataQueryDAO;
 import org.apache.skywalking.oap.server.storage.plugin.influxdb.InfluxClient;
 import org.apache.skywalking.oap.server.storage.plugin.influxdb.InfluxConstants;
@@ -70,36 +69,6 @@ public class MetadataQuery implements IMetadataQueryDAO {
     }
 
     @Override
-    public int numOfService(final long startTimestamp, final long endTimestamp) throws IOException {
-        WhereQueryImpl query = select().raw("count(distinct " + ID_COLUMN + ")")
-                                       .from(client.getDatabase(), ServiceTraffic.INDEX_NAME)
-                                       .where()
-                                       .and(
-                                           eq(InfluxConstants.TagName.NODE_TYPE, String.valueOf(NodeType.Normal.value())
-                                           ));
-        return client.getCounter(query);
-    }
-
-    @Override
-    public int numOfEndpoint() throws IOException {
-        SelectQueryImpl query = select()
-            .raw("count(distinct " + ID_COLUMN + ")")
-            .from(client.getDatabase(), EndpointTraffic.INDEX_NAME);
-        return client.getCounter(query);
-    }
-
-    @Override
-    public int numOfConjectural(final int nodeTypeValue) throws IOException {
-        WhereQueryImpl<SelectQueryImpl> query = select().raw("count(distinct " + ID_COLUMN + ")")
-                                                        .from(client.getDatabase(), ServiceTraffic.INDEX_NAME)
-                                                        .where(eq(
-                                                            InfluxConstants.TagName.NODE_TYPE,
-                                                            String.valueOf(nodeTypeValue)
-                                                        ));
-        return client.getCounter(query);
-    }
-
-    @Override
     public List<Service> getAllServices(final long startTimestamp, final long endTimestamp) throws IOException {
         SelectSubQueryImpl<SelectQueryImpl> subQuery = select()
             .fromSubQuery(client.getDatabase())
@@ -256,7 +225,7 @@ public class MetadataQuery implements IMetadataQueryDAO {
                     String key = property.getKey();
                     String value = property.getValue().getAsString();
                     if (key.equals(InstanceTraffic.PropertyUtil.LANGUAGE)) {
-                        serviceInstance.setLanguage(LanguageTrans.INSTANCE.value(value));
+                        serviceInstance.setLanguage(Language.value(value));
                     } else {
                         serviceInstance.getAttributes().add(new Attribute(key, value));
                     }
diff --git a/oap-server/server-storage-plugin/storage-influxdb-plugin/src/main/java/org/apache/skywalking/oap/server/storage/plugin/influxdb/query/MetricsQuery.java b/oap-server/server-storage-plugin/storage-influxdb-plugin/src/main/java/org/apache/skywalking/oap/server/storage/plugin/influxdb/query/MetricsQuery.java
index a28f1c6..4635c23 100644
--- a/oap-server/server-storage-plugin/storage-influxdb-plugin/src/main/java/org/apache/skywalking/oap/server/storage/plugin/influxdb/query/MetricsQuery.java
+++ b/oap-server/server-storage-plugin/storage-influxdb-plugin/src/main/java/org/apache/skywalking/oap/server/storage/plugin/influxdb/query/MetricsQuery.java
@@ -26,16 +26,17 @@ import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 import lombok.extern.slf4j.Slf4j;
-import org.apache.skywalking.oap.server.core.analysis.DownSampling;
-import org.apache.skywalking.oap.server.core.analysis.metrics.IntKeyLongValue;
-import org.apache.skywalking.oap.server.core.analysis.metrics.IntKeyLongValueHashMap;
-import org.apache.skywalking.oap.server.core.analysis.metrics.ThermodynamicMetrics;
-import org.apache.skywalking.oap.server.core.query.entity.IntValues;
-import org.apache.skywalking.oap.server.core.query.entity.KVInt;
-import org.apache.skywalking.oap.server.core.query.entity.Thermodynamic;
+import org.apache.skywalking.oap.server.core.analysis.metrics.DataTable;
+import org.apache.skywalking.oap.server.core.analysis.metrics.Metrics;
+import org.apache.skywalking.oap.server.core.query.PointOfTime;
+import org.apache.skywalking.oap.server.core.query.input.Duration;
+import org.apache.skywalking.oap.server.core.query.input.MetricsCondition;
 import org.apache.skywalking.oap.server.core.query.sql.Function;
-import org.apache.skywalking.oap.server.core.query.sql.KeyValues;
-import org.apache.skywalking.oap.server.core.query.sql.Where;
+import org.apache.skywalking.oap.server.core.query.type.HeatMap;
+import org.apache.skywalking.oap.server.core.query.type.IntValues;
+import org.apache.skywalking.oap.server.core.query.type.KVInt;
+import org.apache.skywalking.oap.server.core.query.type.MetricsValues;
+import org.apache.skywalking.oap.server.core.storage.annotation.ValueColumnMetadata;
 import org.apache.skywalking.oap.server.core.storage.model.ModelColumn;
 import org.apache.skywalking.oap.server.core.storage.query.IMetricsQueryDAO;
 import org.apache.skywalking.oap.server.library.util.CollectionUtils;
@@ -63,15 +64,19 @@ public class MetricsQuery implements IMetricsQueryDAO {
     }
 
     @Override
-    public IntValues getValues(String measurement, DownSampling downsampling, long startTB, long endTB,
-                               Where where, String valueCName, Function function) throws IOException {
+    public int readMetricsValue(final MetricsCondition condition,
+                                final String valueColumnName,
+                                final Duration duration) throws IOException {
+        final Function function = ValueColumnMetadata.INSTANCE.getValueFunction(condition.getName());
+        final String measurement = condition.getName();
+
         SelectionQueryImpl query = select();
         switch (function) {
             case Avg:
-                query.mean(valueCName);
+                query.mean(valueColumnName);
                 break;
             default:
-                query.sum(valueCName);
+                query.sum(valueColumnName);
         }
         WhereQueryImpl<SelectQueryImpl> queryWhereQuery = query.from(client.getDatabase(), measurement).where();
 
@@ -81,69 +86,47 @@ public class MetricsQuery implements IMetricsQueryDAO {
         }
 
         List<String> ids = new ArrayList<>(20);
-        List<KeyValues> whereKeyValues = where.getKeyValues();
-        if (!whereKeyValues.isEmpty()) {
+
+        final String entityId = condition.getEntity().buildId();
+        if (entityId != null) {
             StringBuilder clauseBuilder = new StringBuilder();
-            for (KeyValues kv : whereKeyValues) {
-                final List<String> values = kv.getValues();
-                ids.addAll(values);
-
-                Class<?> type = columnTypes.get(kv.getKey());
-                if (values.size() == 1) {
-                    String value = kv.getValues().get(0);
-                    if (type == String.class) {
-                        value = "'" + value + "'";
-                    }
-                    clauseBuilder.append(kv.getKey()).append("=").append(value).append(" OR ");
-                } else {
-                    if (type == String.class) {
-                        clauseBuilder.append(kv.getKey())
-                                     .append(" =~ /")
-                                     .append(Joiner.on("|").join(values))
-                                     .append("/ OR ");
-                    } else {
-                        for (String value : values) {
-                            clauseBuilder.append(kv.getKey()).append(" = '").append(value).append("' OR ");
-                        }
-                    }
-                }
-            }
-            queryWhereQuery.where(clauseBuilder.substring(0, clauseBuilder.length() - 4));
+            clauseBuilder.append(Metrics.ENTITY_ID).append("=").append(entityId);
+            queryWhereQuery.where(clauseBuilder.toString());
         }
+
         queryWhereQuery
-            .and(gte(InfluxClient.TIME, InfluxClient.timeInterval(startTB, downsampling)))
-            .and(lte(InfluxClient.TIME, InfluxClient.timeInterval(endTB, downsampling)))
+            .and(gte(InfluxClient.TIME, InfluxClient.timeInterval(duration.getStartTimeBucket())))
+            .and(lte(InfluxClient.TIME, InfluxClient.timeInterval(duration.getEndTimeBucket())))
             .groupBy(InfluxConstants.TagName.ENTITY_ID);
 
-        IntValues intValues = new IntValues();
         List<QueryResult.Series> seriesList = client.queryForSeries(queryWhereQuery);
         if (log.isDebugEnabled()) {
             log.debug("SQL: {} result set: {}", queryWhereQuery.getCommand(), seriesList);
         }
         if (CollectionUtils.isNotEmpty(seriesList)) {
             for (QueryResult.Series series : seriesList) {
-                KVInt kv = new KVInt();
-                kv.setId(series.getTags().get(InfluxConstants.TagName.ENTITY_ID));
                 Number value = (Number) series.getValues().get(0).get(1);
-                kv.setValue(value.longValue());
-
-                intValues.addKVInt(kv);
+                return value.intValue();
             }
         }
 
-        return orderWithDefault0(intValues, ids);
+        return ValueColumnMetadata.INSTANCE.getDefaultValue(condition.getName());
     }
 
     @Override
-    public IntValues getLinearIntValues(String measurement,
-                                        DownSampling downsampling,
-                                        List<String> ids,
-                                        String valueCName)
-        throws IOException {
+    public MetricsValues readMetricsValues(final MetricsCondition condition,
+                                           final String valueColumnName,
+                                           final Duration duration) throws IOException {
+        final List<PointOfTime> pointOfTimes = duration.assembleDurationPoints();
+        List<String> ids = new ArrayList<>(pointOfTimes.size());
+        pointOfTimes.forEach(pointOfTime -> {
+            ids.add(pointOfTime.id(condition.getEntity().buildId()));
+        });
+
         WhereQueryImpl<SelectQueryImpl> query = select()
             .column(ID_COLUMN)
-            .column(valueCName)
-            .from(client.getDatabase(), measurement)
+            .column(valueColumnName)
+            .from(client.getDatabase(), condition.getName())
             .where();
 
         if (CollectionUtils.isNotEmpty(ids)) {
@@ -158,7 +141,10 @@ public class MetricsQuery implements IMetricsQueryDAO {
             log.debug("SQL: {} result set: {}", query.getCommand(), seriesList);
         }
 
-        IntValues intValues = new IntValues();
+        MetricsValues metricsValues = new MetricsValues();
+        // Label is null, because in readMetricsValues, no label parameter.
+        final IntValues intValues = metricsValues.getValues();
+
         if (CollectionUtils.isNotEmpty(seriesList)) {
             seriesList.get(0).getValues().forEach(values -> {
                 KVInt kv = new KVInt();
@@ -167,36 +153,27 @@ public class MetricsQuery implements IMetricsQueryDAO {
                 intValues.addKVInt(kv);
             });
         }
-        return orderWithDefault0(intValues, ids);
+        metricsValues.setValues(
+            Util.sortValues(intValues, ids, ValueColumnMetadata.INSTANCE.getDefaultValue(condition.getName()))
+        );
+        return metricsValues;
     }
 
-    /**
-     * Make sure the order is same as the expected order, and keep default value as 0.
-     *
-     * @param origin        IntValues
-     * @param expectedOrder List
-     * @return
-     */
-    private IntValues orderWithDefault0(IntValues origin, List<String> expectedOrder) {
-        IntValues intValues = new IntValues();
-
-        expectedOrder.forEach(id -> {
-            KVInt e = new KVInt();
-            e.setId(id);
-            e.setValue(origin.findValue(id, 0));
-            intValues.addKVInt(e);
+    @Override
+    public List<MetricsValues> readLabeledMetricsValues(final MetricsCondition condition,
+                                                        final String valueColumnName,
+                                                        final List<String> labels,
+                                                        final Duration duration) throws IOException {
+        final List<PointOfTime> pointOfTimes = duration.assembleDurationPoints();
+        List<String> ids = new ArrayList<>(pointOfTimes.size());
+        pointOfTimes.forEach(pointOfTime -> {
+            ids.add(pointOfTime.id(condition.getEntity().buildId()));
         });
 
-        return intValues;
-    }
-
-    @Override
-    public IntValues[] getMultipleLinearIntValues(String measurement, DownSampling downsampling, List<String> ids,
-                                                  List<Integer> linearIndex, String valueCName) throws IOException {
         WhereQueryImpl<SelectQueryImpl> query = select()
             .column("id")
-            .column(valueCName)
-            .from(client.getDatabase(), measurement)
+            .column(valueColumnName)
+            .from(client.getDatabase(), condition.getName())
             .where();
 
         if (CollectionUtils.isNotEmpty(ids)) {
@@ -210,53 +187,53 @@ public class MetricsQuery implements IMetricsQueryDAO {
         if (log.isDebugEnabled()) {
             log.debug("SQL: {} result set: {}", query.getCommand(), series);
         }
-        IntValues[] intValues = new IntValues[linearIndex.size()];
-        for (int i = 0; i < intValues.length; i++) {
-            intValues[i] = new IntValues();
-        }
-        if (CollectionUtils.isEmpty(series)) {
-            return intValues;
-        }
-        series.get(0).getValues().forEach(values -> {
-            IntKeyLongValueHashMap multipleValues = new IntKeyLongValueHashMap(5);
-            multipleValues.toObject((String) values.get(2));
 
-            final String id = (String) values.get(1);
-            for (int i = 0; i < intValues.length; i++) {
-                Integer index = linearIndex.get(i);
-                KVInt kv = new KVInt();
-                kv.setId(id);
-                kv.setValue(multipleValues.get(index).getValue());
-                intValues[i].addKVInt(kv);
-            }
+        Map<String, MetricsValues> labeledValues = new HashMap<>(labels.size());
+        labels.forEach(label -> {
+            MetricsValues labelValue = new MetricsValues();
+            labelValue.setLabel(label);
+
+            labeledValues.put(label, labelValue);
         });
-        return orderWithDefault0(intValues, ids);
-    }
 
-    /**
-     * Make sure the order is same as the expected order, and keep default value as 0.
-     *
-     * @param origin        IntValues[]
-     * @param expectedOrder List
-     * @return
-     */
-    private IntValues[] orderWithDefault0(IntValues[] origin, List<String> expectedOrder) {
-        for (int i = 0; i < origin.length; i++) {
-            origin[i] = orderWithDefault0(origin[i], expectedOrder);
+        if (!CollectionUtils.isEmpty(series)) {
+            series.get(0).getValues().forEach(values -> {
+                final String id = (String) values.get(1);
+                DataTable multipleValues = new DataTable(5);
+                multipleValues.toObject((String) values.get(2));
+
+                labels.forEach(label -> {
+                    final Long data = multipleValues.get(label);
+                    final IntValues intValues = labeledValues.get(label).getValues();
+                    KVInt kv = new KVInt();
+                    kv.setId(id);
+                    kv.setValue(data);
+                    intValues.addKVInt(kv);
+                });
+            });
         }
-        return origin;
+
+        return Util.sortValues(
+            new ArrayList<>(labeledValues.values()),
+            ids,
+            ValueColumnMetadata.INSTANCE.getDefaultValue(condition.getName())
+        );
     }
 
     @Override
-    public Thermodynamic getThermodynamic(String measurement, DownSampling downsampling, List<String> ids,
-                                          String valueCName)
-        throws IOException {
+    public HeatMap readHeatMap(final MetricsCondition condition,
+                               final String valueColumnName,
+                               final Duration duration) throws IOException {
+        final List<PointOfTime> pointOfTimes = duration.assembleDurationPoints();
+        List<String> ids = new ArrayList<>(pointOfTimes.size());
+        pointOfTimes.forEach(pointOfTime -> {
+            ids.add(pointOfTime.id(condition.getEntity().buildId()));
+        });
+
         WhereQueryImpl<SelectQueryImpl> query = select()
-            .column(ThermodynamicMetrics.STEP)
-            .column(ThermodynamicMetrics.NUM_OF_STEPS)
-            .column(ThermodynamicMetrics.DETAIL_GROUP)
             .column(ID_COLUMN)
-            .from(client.getDatabase(), measurement)
+            .column(valueColumnName)
+            .from(client.getDatabase(), condition.getName())
             .where(contains(ID_COLUMN, Joiner.on("|").join(ids)));
         Map<String, List<Long>> thermodynamicValueMatrix = new HashMap<>();
 
@@ -264,38 +241,16 @@ public class MetricsQuery implements IMetricsQueryDAO {
         if (log.isDebugEnabled()) {
             log.debug("SQL: {} result set: {}", query.getCommand(), series);
         }
-        if (series == null) {
-            return new Thermodynamic();
-        }
 
-        int numOfSteps = 0, axisYStep = 0;
-        List<List<Long>> thermodynamicValueCollection = new ArrayList<>();
-        Thermodynamic thermodynamic = new Thermodynamic();
-        for (List<Object> values : series.getValues()) {
-            numOfSteps = (int) values.get(2) + 1;
-            axisYStep = (int) values.get(1);
-            IntKeyLongValueHashMap intKeyLongValues = new IntKeyLongValueHashMap(5);
-            intKeyLongValues.toObject((String) values.get(3));
-            List<Long> axisYValues = new ArrayList<>(numOfSteps);
-            for (int i = 0; i < numOfSteps; i++) {
-                axisYValues.add(0L);
+        HeatMap heatMap = new HeatMap();
+        if (series != null) {
+            for (List<Object> values : series.getValues()) {
+                heatMap.buildColumn(values.get(1).toString(), values.get(2).toString());
             }
-            for (IntKeyLongValue intKeyLongValue : intKeyLongValues.values()) {
-                axisYValues.set(intKeyLongValue.getKey(), intKeyLongValue.getValue());
-            }
-            thermodynamicValueMatrix.put((String) values.get(4), axisYValues);
         }
-        // try to add default values when there is no data in that time bucket.
-        ids.forEach(id -> {
-            if (thermodynamicValueMatrix.containsKey(id)) {
-                thermodynamicValueCollection.add(thermodynamicValueMatrix.get(id));
-            } else {
-                thermodynamicValueCollection.add(new ArrayList<>());
-            }
-        });
-        thermodynamic.fromMatrixData(thermodynamicValueCollection, numOfSteps);
-        thermodynamic.setAxisYStep(axisYStep);
 
-        return thermodynamic;
+        heatMap.fixMissingColumns(ids);
+
+        return heatMap;
     }
 }
\ No newline at end of file
diff --git a/oap-server/server-storage-plugin/storage-influxdb-plugin/src/main/java/org/apache/skywalking/oap/server/storage/plugin/influxdb/query/TopNRecordsQuery.java b/oap-server/server-storage-plugin/storage-influxdb-plugin/src/main/java/org/apache/skywalking/oap/server/storage/plugin/influxdb/query/TopNRecordsQuery.java
index 17f2390..ba7a592 100644
--- a/oap-server/server-storage-plugin/storage-influxdb-plugin/src/main/java/org/apache/skywalking/oap/server/storage/plugin/influxdb/query/TopNRecordsQuery.java
+++ b/oap-server/server-storage-plugin/storage-influxdb-plugin/src/main/java/org/apache/skywalking/oap/server/storage/plugin/influxdb/query/TopNRecordsQuery.java
@@ -25,9 +25,12 @@ import java.util.Comparator;
 import java.util.List;
 import lombok.extern.slf4j.Slf4j;
 import org.apache.skywalking.apm.util.StringUtil;
+import org.apache.skywalking.oap.server.core.analysis.IDManager;
 import org.apache.skywalking.oap.server.core.analysis.topn.TopN;
 import org.apache.skywalking.oap.server.core.query.enumeration.Order;
-import org.apache.skywalking.oap.server.core.query.type.TopNRecord;
+import org.apache.skywalking.oap.server.core.query.input.Duration;
+import org.apache.skywalking.oap.server.core.query.input.TopNCondition;
+import org.apache.skywalking.oap.server.core.query.type.SelectedRecord;
 import org.apache.skywalking.oap.server.core.storage.query.ITopNRecordsQueryDAO;
 import org.apache.skywalking.oap.server.storage.plugin.influxdb.InfluxClient;
 import org.apache.skywalking.oap.server.storage.plugin.influxdb.InfluxConstants;
@@ -48,26 +51,27 @@ public class TopNRecordsQuery implements ITopNRecordsQueryDAO {
     }
 
     @Override
-    public List<TopNRecord> getTopNRecords(long startSecondTB, long endSecondTB, String metricName,
-                                           String serviceId, int topN, Order order) throws IOException {
+    public List<SelectedRecord> readSampledRecords(final TopNCondition condition,
+                                                   final Duration duration) throws IOException {
         String function = InfluxConstants.SORT_ASC;
         // Have to re-sort here. Because the function, top()/bottom(), get the result ordered by the `time`.
-        Comparator<TopNRecord> comparator = Comparator.comparingLong(TopNRecord::getLatency);
-        if (order.equals(Order.DES)) {
+        Comparator<SelectedRecord> comparator = ASCENDING;
+        if (condition.getOrder().equals(Order.DES)) {
             function = InfluxConstants.SORT_DES;
-            comparator = (a, b) -> Long.compare(b.getLatency(), a.getLatency());
+            comparator = DESCENDING;
         }
 
         WhereQueryImpl query = select()
-            .function(function, TopN.LATENCY, topN)
+            .function(function, TopN.LATENCY, condition.getTopN())
             .column(TopN.STATEMENT)
             .column(TopN.TRACE_ID)
-            .from(client.getDatabase(), metricName)
+            .from(client.getDatabase(), condition.getName())
             .where()
-            .and(gte(TopN.TIME_BUCKET, startSecondTB))
-            .and(lte(TopN.TIME_BUCKET, endSecondTB));
+            .and(gte(TopN.TIME_BUCKET, duration.getStartTimeBucket()))
+            .and(lte(TopN.TIME_BUCKET, duration.getEndTimeBucket()));
 
-        if (StringUtil.isNotEmpty(serviceId)) {
+        if (StringUtil.isNotEmpty(condition.getParentService())) {
+            final String serviceId = IDManager.ServiceID.buildId(condition.getParentService(), condition.isNormal());
             query.and(eq(InfluxConstants.TagName.SERVICE_ID, serviceId));
         }
 
@@ -79,16 +83,22 @@ public class TopNRecordsQuery implements ITopNRecordsQueryDAO {
             return Collections.emptyList();
         }
 
-        final List<TopNRecord> records = new ArrayList<>();
+        final List<SelectedRecord> records = new ArrayList<>();
         series.getValues().forEach(values -> {
-            TopNRecord record = new TopNRecord();
-            record.setLatency((long) values.get(1));
-            record.setTraceId((String) values.get(3));
-            record.setStatement((String) values.get(2));
+            SelectedRecord record = new SelectedRecord();
+            record.setValue(String.valueOf((long) values.get(1)));
+            record.setRefId((String) values.get(3));
+            record.setName((String) values.get(2));
             records.add(record);
         });
 
         Collections.sort(records, comparator); // re-sort by self, because of the result order by time.
         return records;
     }
+
+    private static final Comparator<SelectedRecord> ASCENDING = (a, b) -> Long.compare(
+        Long.parseLong(a.getValue()), Long.parseLong(b.getValue()));
+
+    private static final Comparator<SelectedRecord> DESCENDING = (a, b) -> Long.compare(
+        Long.parseLong(b.getValue()), Long.parseLong(a.getValue()));
 }
diff --git a/oap-server/server-storage-plugin/storage-influxdb-plugin/src/main/java/org/apache/skywalking/oap/server/storage/plugin/influxdb/query/TopologyQuery.java b/oap-server/server-storage-plugin/storage-influxdb-plugin/src/main/java/org/apache/skywalking/oap/server/storage/plugin/influxdb/query/TopologyQuery.java
index 67b6f4a..d659de3 100644
--- a/oap-server/server-storage-plugin/storage-influxdb-plugin/src/main/java/org/apache/skywalking/oap/server/storage/plugin/influxdb/query/TopologyQuery.java
+++ b/oap-server/server-storage-plugin/storage-influxdb-plugin/src/main/java/org/apache/skywalking/oap/server/storage/plugin/influxdb/query/TopologyQuery.java
@@ -23,13 +23,12 @@ import java.util.ArrayList;
 import java.util.Collections;
 import java.util.List;
 import lombok.extern.slf4j.Slf4j;
-import org.apache.skywalking.oap.server.core.analysis.DownSampling;
 import org.apache.skywalking.oap.server.core.analysis.manual.relation.endpoint.EndpointRelationServerSideMetrics;
 import org.apache.skywalking.oap.server.core.analysis.manual.relation.instance.ServiceInstanceRelationClientSideMetrics;
 import org.apache.skywalking.oap.server.core.analysis.manual.relation.instance.ServiceInstanceRelationServerSideMetrics;
 import org.apache.skywalking.oap.server.core.analysis.manual.relation.service.ServiceRelationClientSideMetrics;
 import org.apache.skywalking.oap.server.core.analysis.manual.relation.service.ServiceRelationServerSideMetrics;
-import org.apache.skywalking.oap.server.core.query.entity.Call;
+import org.apache.skywalking.oap.server.core.query.type.Call;
 import org.apache.skywalking.oap.server.core.source.DetectPoint;
 import org.apache.skywalking.oap.server.core.storage.query.ITopologyQueryDAO;
 import org.apache.skywalking.oap.server.storage.plugin.influxdb.InfluxClient;
@@ -55,7 +54,7 @@ public class TopologyQuery implements ITopologyQueryDAO {
     }
 
     @Override
-    public List<Call.CallDetail> loadServiceRelationsDetectedAtServerSide(DownSampling downsampling, long startTB,
+    public List<Call.CallDetail> loadServiceRelationsDetectedAtServerSide(long startTB,
                                                                           long endTB,
                                                                           List<String> serviceIds) throws IOException {
         String measurement = ServiceRelationServerSideMetrics.INDEX_NAME;
@@ -72,7 +71,7 @@ public class TopologyQuery implements ITopologyQueryDAO {
     }
 
     @Override
-    public List<Call.CallDetail> loadServiceRelationDetectedAtClientSide(DownSampling downsampling, long startTB,
+    public List<Call.CallDetail> loadServiceRelationDetectedAtClientSide(long startTB,
                                                                          long endTB,
                                                                          List<String> serviceIds) throws IOException {
         String measurement = ServiceRelationClientSideMetrics.INDEX_NAME;
@@ -88,7 +87,7 @@ public class TopologyQuery implements ITopologyQueryDAO {
     }
 
     @Override
-    public List<Call.CallDetail> loadServiceRelationsDetectedAtServerSide(DownSampling downsampling, long startTB,
+    public List<Call.CallDetail> loadServiceRelationsDetectedAtServerSide(long startTB,
                                                                           long endTB) throws IOException {
         String measurement = ServiceRelationServerSideMetrics.INDEX_NAME;
         WhereSubQueryImpl<SelectSubQueryImpl<SelectQueryImpl>, SelectQueryImpl> subQuery = buildServiceCallsQuery(
@@ -103,7 +102,7 @@ public class TopologyQuery implements ITopologyQueryDAO {
     }
 
     @Override
-    public List<Call.CallDetail> loadServiceRelationDetectedAtClientSide(DownSampling downsampling, long startTB,
+    public List<Call.CallDetail> loadServiceRelationDetectedAtClientSide(long startTB,
                                                                          long endTB) throws IOException {
         String tableName = ServiceRelationClientSideMetrics.INDEX_NAME;
         WhereSubQueryImpl<SelectSubQueryImpl<SelectQueryImpl>, SelectQueryImpl> subQuery = buildServiceCallsQuery(
@@ -120,7 +119,6 @@ public class TopologyQuery implements ITopologyQueryDAO {
     @Override
     public List<Call.CallDetail> loadInstanceRelationDetectedAtServerSide(String clientServiceId,
                                                                           String serverServiceId,
-                                                                          DownSampling downsampling,
                                                                           long startTB,
                                                                           long endTB) throws IOException {
         String measurement = ServiceInstanceRelationServerSideMetrics.INDEX_NAME;
@@ -138,7 +136,6 @@ public class TopologyQuery implements ITopologyQueryDAO {
     @Override
     public List<Call.CallDetail> loadInstanceRelationDetectedAtClientSide(String clientServiceId,
                                                                           String serverServiceId,
-                                                                          DownSampling downsampling,
                                                                           long startTB,
                                                                           long endTB) throws IOException {
         String measurement = ServiceInstanceRelationClientSideMetrics.INDEX_NAME;
@@ -154,8 +151,7 @@ public class TopologyQuery implements ITopologyQueryDAO {
     }
 
     @Override
-    public List<Call.CallDetail> loadEndpointRelation(DownSampling downsampling,
-                                                      long startTB,
+    public List<Call.CallDetail> loadEndpointRelation(long startTB,
                                                       long endTB,
                                                       String destEndpointId) throws IOException {
         String measurement = EndpointRelationServerSideMetrics.INDEX_NAME;
diff --git a/oap-server/server-storage-plugin/storage-jdbc-hikaricp-plugin/src/main/java/org/apache/skywalking/oap/server/storage/plugin/jdbc/h2/dao/H2TopNRecordsQueryDAO.java b/oap-server/server-storage-plugin/storage-jdbc-hikaricp-plugin/src/main/java/org/apache/skywalking/oap/server/storage/plugin/jdbc/h2/dao/H2TopNRecordsQueryDAO.java
index baa1fda..2f9a22d 100644
--- a/oap-server/server-storage-plugin/storage-jdbc-hikaricp-plugin/src/main/java/org/apache/skywalking/oap/server/storage/plugin/jdbc/h2/dao/H2TopNRecordsQueryDAO.java
+++ b/oap-server/server-storage-plugin/storage-jdbc-hikaricp-plugin/src/main/java/org/apache/skywalking/oap/server/storage/plugin/jdbc/h2/dao/H2TopNRecordsQueryDAO.java
@@ -24,13 +24,13 @@ import java.sql.ResultSet;
 import java.sql.SQLException;
 import java.util.ArrayList;
 import java.util.List;
+import org.apache.skywalking.apm.util.StringUtil;
 import org.apache.skywalking.oap.server.core.analysis.IDManager;
 import org.apache.skywalking.oap.server.core.analysis.topn.TopN;
 import org.apache.skywalking.oap.server.core.query.enumeration.Order;
 import org.apache.skywalking.oap.server.core.query.input.Duration;
 import org.apache.skywalking.oap.server.core.query.input.TopNCondition;
 import org.apache.skywalking.oap.server.core.query.type.SelectedRecord;
-import org.apache.skywalking.oap.server.core.query.type.TopNRecord;
 import org.apache.skywalking.oap.server.core.storage.query.ITopNRecordsQueryDAO;
 import org.apache.skywalking.oap.server.library.client.jdbc.hikaricp.JDBCHikariCPClient;
 
@@ -47,9 +47,11 @@ public class H2TopNRecordsQueryDAO implements ITopNRecordsQueryDAO {
         StringBuilder sql = new StringBuilder("select * from " + condition.getName() + " where ");
         List<Object> parameters = new ArrayList<>(10);
 
-        sql.append(" service_id = ? ");
-        final String serviceId = IDManager.ServiceID.buildId(condition.getParentService(), condition.isNormal());
-        parameters.add(serviceId);
+        if (StringUtil.isNotEmpty(condition.getParentService())) {
+            sql.append(" service_id = ? ");
+            final String serviceId = IDManager.ServiceID.buildId(condition.getParentService(), condition.isNormal());
+            parameters.add(serviceId);
+        }
 
         sql.append(" and ").append(TopN.TIME_BUCKET).append(" >= ?");
         parameters.add(duration.getStartTimeBucket());
@@ -66,7 +68,8 @@ public class H2TopNRecordsQueryDAO implements ITopNRecordsQueryDAO {
 
         List<SelectedRecord> results = new ArrayList<>();
         try (Connection connection = h2Client.getConnection()) {
-            try (ResultSet resultSet = h2Client.executeQuery(connection, sql.toString(), parameters.toArray(new Object[0]))) {
+            try (ResultSet resultSet = h2Client.executeQuery(
+                connection, sql.toString(), parameters.toArray(new Object[0]))) {
                 while (resultSet.next()) {
                     SelectedRecord record = new SelectedRecord();
                     record.setName(resultSet.getString(TopN.STATEMENT));
diff --git a/oap-server/server-storage-plugin/storage-jdbc-hikaricp-plugin/src/main/java/org/apache/skywalking/oap/server/storage/plugin/jdbc/h2/dao/H2TopologyQueryDAO.java b/oap-server/server-storage-plugin/storage-jdbc-hikaricp-plugin/src/main/java/org/apache/skywalking/oap/server/storage/plugin/jdbc/h2/dao/H2TopologyQueryDAO.java
index 42ef362..8a5e9eb 100644
--- a/oap-server/server-storage-plugin/storage-jdbc-hikaricp-plugin/src/main/java/org/apache/skywalking/oap/server/storage/plugin/jdbc/h2/dao/H2TopologyQueryDAO.java
+++ b/oap-server/server-storage-plugin/storage-jdbc-hikaricp-plugin/src/main/java/org/apache/skywalking/oap/server/storage/plugin/jdbc/h2/dao/H2TopologyQueryDAO.java
@@ -24,7 +24,6 @@ import java.sql.ResultSet;
 import java.sql.SQLException;
 import java.util.ArrayList;
 import java.util.List;
-import org.apache.skywalking.oap.server.core.analysis.DownSampling;
 import org.apache.skywalking.oap.server.core.analysis.manual.relation.endpoint.EndpointRelationServerSideMetrics;
 import org.apache.skywalking.oap.server.core.analysis.manual.relation.instance.ServiceInstanceRelationClientSideMetrics;
 import org.apache.skywalking.oap.server.core.analysis.manual.relation.instance.ServiceInstanceRelationServerSideMetrics;
@@ -44,8 +43,7 @@ public class H2TopologyQueryDAO implements ITopologyQueryDAO {
     }
 
     @Override
-    public List<Call.CallDetail> loadServiceRelationsDetectedAtServerSide(DownSampling downsampling,
-                                                                          long startTB,
+    public List<Call.CallDetail> loadServiceRelationsDetectedAtServerSide(long startTB,
                                                                           long endTB,
                                                                           List<String> serviceIds) throws IOException {
         return loadServiceCalls(
@@ -56,8 +54,7 @@ public class H2TopologyQueryDAO implements ITopologyQueryDAO {
     }
 
     @Override
-    public List<Call.CallDetail> loadServiceRelationDetectedAtClientSide(DownSampling downsampling,
-                                                                         long startTB,
+    public List<Call.CallDetail> loadServiceRelationDetectedAtClientSide(long startTB,
                                                                          long endTB,
                                                                          List<String> serviceIds) throws IOException {
         return loadServiceCalls(
@@ -68,7 +65,7 @@ public class H2TopologyQueryDAO implements ITopologyQueryDAO {
     }
 
     @Override
-    public List<Call.CallDetail> loadServiceRelationsDetectedAtServerSide(DownSampling downsampling, long startTB,
+    public List<Call.CallDetail> loadServiceRelationsDetectedAtServerSide(long startTB,
                                                                           long endTB) throws IOException {
         return loadServiceCalls(
             ServiceRelationServerSideMetrics.INDEX_NAME, startTB, endTB,
@@ -78,7 +75,7 @@ public class H2TopologyQueryDAO implements ITopologyQueryDAO {
     }
 
     @Override
-    public List<Call.CallDetail> loadServiceRelationDetectedAtClientSide(DownSampling downsampling, long startTB,
+    public List<Call.CallDetail> loadServiceRelationDetectedAtClientSide(long startTB,
                                                                          long endTB) throws IOException {
         return loadServiceCalls(
             ServiceRelationClientSideMetrics.INDEX_NAME, startTB, endTB,
@@ -90,7 +87,6 @@ public class H2TopologyQueryDAO implements ITopologyQueryDAO {
     @Override
     public List<Call.CallDetail> loadInstanceRelationDetectedAtServerSide(String clientServiceId,
                                                                           String serverServiceId,
-                                                                          DownSampling downsampling,
                                                                           long startTB,
                                                                           long endTB) throws IOException {
         return loadServiceInstanceCalls(
@@ -104,7 +100,6 @@ public class H2TopologyQueryDAO implements ITopologyQueryDAO {
     @Override
     public List<Call.CallDetail> loadInstanceRelationDetectedAtClientSide(String clientServiceId,
                                                                           String serverServiceId,
-                                                                          DownSampling downsampling,
                                                                           long startTB,
                                                                           long endTB) throws IOException {
         return loadServiceInstanceCalls(
@@ -116,8 +111,7 @@ public class H2TopologyQueryDAO implements ITopologyQueryDAO {
     }
 
     @Override
-    public List<Call.CallDetail> loadEndpointRelation(DownSampling downsampling,
-                                                      long startTB,
+    public List<Call.CallDetail> loadEndpointRelation(long startTB,
                                                       long endTB,
                                                       String destEndpointId) throws IOException {
         List<Call.CallDetail> calls = loadEndpointFromSide(