Provide the getServerTPSTrend query.
This commit is contained in:
parent
703a591bec
commit
86e05bc381
|
|
@ -18,10 +18,10 @@
|
|||
|
||||
package org.apache.skywalking.apm.collector.storage.dao;
|
||||
|
||||
import com.google.gson.JsonArray;
|
||||
import java.util.List;
|
||||
import org.apache.skywalking.apm.collector.storage.base.dao.DAO;
|
||||
import org.apache.skywalking.apm.collector.storage.ui.common.Step;
|
||||
import org.apache.skywalking.apm.collector.storage.utils.DurationPoint;
|
||||
|
||||
/**
|
||||
* @author peng-yongsheng
|
||||
|
|
@ -31,11 +31,11 @@ public interface IInstanceMetricUIDAO extends DAO {
|
|||
|
||||
long getTpsMetric(int instanceId, long timeBucket);
|
||||
|
||||
JsonArray getTpsMetric(int instanceId, long startTimeBucket, long endTimeBucket);
|
||||
List<Integer> getServerTPSTrend(int instanceId, Step step, List<DurationPoint> durationPoints);
|
||||
|
||||
long getRespTimeMetric(int instanceId, long timeBucket);
|
||||
|
||||
List<Integer> getResponseTimeTrend(int instanceId, Step step, Long[] timeBuckets);
|
||||
List<Integer> getResponseTimeTrend(int instanceId, Step step, List<DurationPoint> durationPoints);
|
||||
|
||||
class InstanceMetric {
|
||||
private final int instanceId;
|
||||
|
|
|
|||
|
|
@ -25,4 +25,12 @@ import java.util.List;
|
|||
*/
|
||||
public class ThroughputTrend {
|
||||
private List<Integer> trendList;
|
||||
|
||||
public List<Integer> getTrendList() {
|
||||
return trendList;
|
||||
}
|
||||
|
||||
public void setTrendList(List<Integer> trendList) {
|
||||
this.trendList = trendList;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,40 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
*/
|
||||
|
||||
package org.apache.skywalking.apm.collector.storage.utils;
|
||||
|
||||
/**
|
||||
* @author peng-yongsheng
|
||||
*/
|
||||
public class DurationPoint {
|
||||
private long point;
|
||||
private long secondsBetween;
|
||||
|
||||
public DurationPoint(long point, long secondsBetween) {
|
||||
this.point = point;
|
||||
this.secondsBetween = secondsBetween;
|
||||
}
|
||||
|
||||
public long getPoint() {
|
||||
return point;
|
||||
}
|
||||
|
||||
public long getSecondsBetween() {
|
||||
return secondsBetween;
|
||||
}
|
||||
}
|
||||
|
|
@ -18,7 +18,6 @@
|
|||
|
||||
package org.apache.skywalking.apm.collector.storage.es.dao;
|
||||
|
||||
import com.google.gson.JsonArray;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import org.apache.skywalking.apm.collector.client.elasticsearch.ElasticSearchClient;
|
||||
|
|
@ -28,6 +27,7 @@ import org.apache.skywalking.apm.collector.storage.es.base.dao.EsDAO;
|
|||
import org.apache.skywalking.apm.collector.storage.table.MetricSource;
|
||||
import org.apache.skywalking.apm.collector.storage.table.instance.InstanceMetricTable;
|
||||
import org.apache.skywalking.apm.collector.storage.ui.common.Step;
|
||||
import org.apache.skywalking.apm.collector.storage.utils.DurationPoint;
|
||||
import org.apache.skywalking.apm.collector.storage.utils.TimePyramidTableNameBuilder;
|
||||
import org.elasticsearch.action.get.GetResponse;
|
||||
import org.elasticsearch.action.get.MultiGetItemResponse;
|
||||
|
|
@ -83,27 +83,28 @@ public class InstanceMetricEsUIDAO extends EsDAO implements IInstanceMetricUIDAO
|
|||
return 0;
|
||||
}
|
||||
|
||||
@Override public JsonArray getTpsMetric(int instanceId, long startTimeBucket, long endTimeBucket) {
|
||||
@Override public List<Integer> getServerTPSTrend(int instanceId, Step step, List<DurationPoint> durationPoints) {
|
||||
MultiGetRequestBuilder prepareMultiGet = getClient().prepareMultiGet();
|
||||
String tableName = TimePyramidTableNameBuilder.build(step, InstanceMetricTable.TABLE);
|
||||
|
||||
long timeBucket = startTimeBucket;
|
||||
do {
|
||||
String id = timeBucket + Const.ID_SPLIT + instanceId;
|
||||
prepareMultiGet.add(InstanceMetricTable.TABLE, InstanceMetricTable.TABLE_TYPE, id);
|
||||
// timeBucket = TimeBucketUtils.INSTANCE.addSecondForSecondTimeBucket(TimeBucketUtils.TimeBucketType.SECOND, timeBucket, 1);
|
||||
}
|
||||
while (timeBucket <= endTimeBucket);
|
||||
durationPoints.forEach(durationPoint -> {
|
||||
String id = durationPoint.getPoint() + Const.ID_SPLIT + instanceId + Const.ID_SPLIT + MetricSource.Callee.getValue();
|
||||
prepareMultiGet.add(tableName, InstanceMetricTable.TABLE_TYPE, id);
|
||||
});
|
||||
|
||||
JsonArray metrics = new JsonArray();
|
||||
List<Integer> throughputTrend = new LinkedList<>();
|
||||
MultiGetResponse multiGetResponse = prepareMultiGet.get();
|
||||
for (MultiGetItemResponse response : multiGetResponse.getResponses()) {
|
||||
|
||||
for (int i = 0; i < multiGetResponse.getResponses().length; i++) {
|
||||
MultiGetItemResponse response = multiGetResponse.getResponses()[i];
|
||||
if (response.getResponse().isExists()) {
|
||||
metrics.add(((Number)response.getResponse().getSource().get(InstanceMetricTable.COLUMN_TRANSACTION_CALLS)).longValue());
|
||||
long callTimes = ((Number)response.getResponse().getSource().get(InstanceMetricTable.COLUMN_TRANSACTION_CALLS)).longValue();
|
||||
throughputTrend.add((int)(callTimes / durationPoints.get(i).getSecondsBetween()));
|
||||
} else {
|
||||
metrics.add(0);
|
||||
throughputTrend.add(0);
|
||||
}
|
||||
}
|
||||
return metrics;
|
||||
return throughputTrend;
|
||||
}
|
||||
|
||||
@Override public long getRespTimeMetric(int instanceId, long timeBucket) {
|
||||
|
|
@ -118,14 +119,14 @@ public class InstanceMetricEsUIDAO extends EsDAO implements IInstanceMetricUIDAO
|
|||
return 0;
|
||||
}
|
||||
|
||||
@Override public List<Integer> getResponseTimeTrend(int instanceId, Step step, Long[] timeBuckets) {
|
||||
@Override public List<Integer> getResponseTimeTrend(int instanceId, Step step, List<DurationPoint> durationPoints) {
|
||||
MultiGetRequestBuilder prepareMultiGet = getClient().prepareMultiGet();
|
||||
String tableName = TimePyramidTableNameBuilder.build(step, InstanceMetricTable.TABLE);
|
||||
|
||||
for (long timeBucket : timeBuckets) {
|
||||
String id = timeBucket + Const.ID_SPLIT + instanceId + Const.ID_SPLIT + MetricSource.Callee.getValue();
|
||||
durationPoints.forEach(durationPoint -> {
|
||||
String id = durationPoint.getPoint() + Const.ID_SPLIT + instanceId + Const.ID_SPLIT + MetricSource.Callee.getValue();
|
||||
prepareMultiGet.add(tableName, InstanceMetricTable.TABLE_TYPE, id);
|
||||
}
|
||||
});
|
||||
|
||||
List<Integer> responseTimeTrends = new LinkedList<>();
|
||||
MultiGetResponse multiGetResponse = prepareMultiGet.get();
|
||||
|
|
|
|||
|
|
@ -18,10 +18,8 @@
|
|||
|
||||
package org.apache.skywalking.apm.collector.storage.h2.dao;
|
||||
|
||||
import com.google.gson.JsonArray;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import org.apache.skywalking.apm.collector.client.h2.H2Client;
|
||||
|
|
@ -33,6 +31,7 @@ import org.apache.skywalking.apm.collector.storage.h2.base.dao.H2DAO;
|
|||
import org.apache.skywalking.apm.collector.storage.table.MetricSource;
|
||||
import org.apache.skywalking.apm.collector.storage.table.instance.InstanceMetricTable;
|
||||
import org.apache.skywalking.apm.collector.storage.ui.common.Step;
|
||||
import org.apache.skywalking.apm.collector.storage.utils.DurationPoint;
|
||||
import org.apache.skywalking.apm.collector.storage.utils.TimePyramidTableNameBuilder;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
|
@ -55,7 +54,7 @@ public class InstanceMetricH2UIDAO extends H2DAO implements IInstanceMetricUIDAO
|
|||
logger.info("the inst performance inst id = {}", instanceId);
|
||||
String sql = SqlBuilder.buildSql(GET_INSTANCE_METRIC_SQL, InstanceMetricTable.TABLE, InstanceMetricTable.COLUMN_INSTANCE_ID, InstanceMetricTable.COLUMN_TIME_BUCKET);
|
||||
StringBuilder builder = new StringBuilder();
|
||||
for (int i = 0; i < timeBuckets.length; i++) {
|
||||
for (long timeBucket : timeBuckets) {
|
||||
builder.append("?,");
|
||||
}
|
||||
builder.delete(builder.length() - 1, builder.length());
|
||||
|
|
@ -93,34 +92,29 @@ public class InstanceMetricH2UIDAO extends H2DAO implements IInstanceMetricUIDAO
|
|||
return 0;
|
||||
}
|
||||
|
||||
@Override public JsonArray getTpsMetric(int instanceId, long startTimeBucket, long endTimeBucket) {
|
||||
logger.info("getTpsMetric instanceId = {}, startTimeBucket = {}, endTimeBucket = {}", instanceId, startTimeBucket, endTimeBucket);
|
||||
@Override
|
||||
public List<Integer> getServerTPSTrend(int instanceId, Step step, List<DurationPoint> durationPoints) {
|
||||
H2Client client = getClient();
|
||||
String sql = SqlBuilder.buildSql(GET_TPS_METRIC_SQL, InstanceMetricTable.TABLE, InstanceMetricTable.COLUMN_ID);
|
||||
String tableName = TimePyramidTableNameBuilder.build(step, InstanceMetricTable.TABLE);
|
||||
|
||||
long timeBucket = startTimeBucket;
|
||||
List<String> idList = new ArrayList<>();
|
||||
do {
|
||||
String id = timeBucket + Const.ID_SPLIT + instanceId;
|
||||
// timeBucket = TimeBucketUtils.INSTANCE.addSecondForSecondTimeBucket(TimeBucketUtils.TimeBucketType.SECOND, timeBucket, 1);
|
||||
idList.add(id);
|
||||
}
|
||||
while (timeBucket <= endTimeBucket);
|
||||
String sql = SqlBuilder.buildSql(GET_TPS_METRIC_SQL, tableName, InstanceMetricTable.COLUMN_ID);
|
||||
|
||||
JsonArray metrics = new JsonArray();
|
||||
idList.forEach(id -> {
|
||||
List<Integer> throughputTrend = new LinkedList<>();
|
||||
durationPoints.forEach(durationPoint -> {
|
||||
String id = durationPoint.getPoint() + Const.ID_SPLIT + instanceId + Const.ID_SPLIT + MetricSource.Callee.getValue();
|
||||
try (ResultSet rs = client.executeQuery(sql, new Object[] {id})) {
|
||||
if (rs.next()) {
|
||||
long calls = rs.getLong(InstanceMetricTable.COLUMN_TRANSACTION_CALLS);
|
||||
metrics.add(calls);
|
||||
long callTimes = rs.getLong(InstanceMetricTable.COLUMN_TRANSACTION_CALLS);
|
||||
throughputTrend.add((int)(callTimes / durationPoint.getSecondsBetween()));
|
||||
} else {
|
||||
metrics.add(0);
|
||||
throughputTrend.add(0);
|
||||
}
|
||||
} catch (SQLException | H2ClientException e) {
|
||||
logger.error(e.getMessage(), e);
|
||||
}
|
||||
});
|
||||
return metrics;
|
||||
|
||||
return throughputTrend;
|
||||
}
|
||||
|
||||
@Override public long getRespTimeMetric(int instanceId, long timeBucket) {
|
||||
|
|
@ -139,15 +133,15 @@ public class InstanceMetricH2UIDAO extends H2DAO implements IInstanceMetricUIDAO
|
|||
return 0;
|
||||
}
|
||||
|
||||
@Override public List<Integer> getResponseTimeTrend(int instanceId, Step step, Long[] timeBuckets) {
|
||||
@Override public List<Integer> getResponseTimeTrend(int instanceId, Step step, List<DurationPoint> durationPoints) {
|
||||
H2Client client = getClient();
|
||||
|
||||
String tableName = TimePyramidTableNameBuilder.build(step, InstanceMetricTable.TABLE);
|
||||
String sql = SqlBuilder.buildSql(GET_TPS_METRIC_SQL, tableName, InstanceMetricTable.COLUMN_ID);
|
||||
|
||||
List<Integer> responseTimeTrends = new LinkedList<>();
|
||||
for (long timeBucket : timeBuckets) {
|
||||
String id = timeBucket + Const.ID_SPLIT + instanceId + Const.ID_SPLIT + MetricSource.Callee.getValue();
|
||||
durationPoints.forEach(durationPoint -> {
|
||||
String id = durationPoint.getPoint() + Const.ID_SPLIT + instanceId + Const.ID_SPLIT + MetricSource.Callee.getValue();
|
||||
try (ResultSet rs = client.executeQuery(sql, new Object[] {id})) {
|
||||
if (rs.next()) {
|
||||
long callTimes = rs.getLong(InstanceMetricTable.COLUMN_TRANSACTION_CALLS);
|
||||
|
|
@ -161,7 +155,7 @@ public class InstanceMetricH2UIDAO extends H2DAO implements IInstanceMetricUIDAO
|
|||
} catch (SQLException | H2ClientException e) {
|
||||
logger.error(e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
});
|
||||
return responseTimeTrends;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -70,8 +70,10 @@ public class ServerQuery implements Query {
|
|||
return getServerService().getServerResponseTimeTrend(serverId, duration.getStep(), start, end);
|
||||
}
|
||||
|
||||
public ThroughputTrend getServerTPSTrend(int serverId, Duration duration) {
|
||||
return null;
|
||||
public ThroughputTrend getServerTPSTrend(int serverId, Duration duration) throws ParseException {
|
||||
long start = DurationUtils.INSTANCE.exchangeToTimeBucket(duration.getStart());
|
||||
long end = DurationUtils.INSTANCE.exchangeToTimeBucket(duration.getEnd());
|
||||
return getServerService().getServerTPSTrend(serverId, duration.getStep(), start, end);
|
||||
}
|
||||
|
||||
public CPUTrend getCPUTrend(int serverId, Duration duration) {
|
||||
|
|
|
|||
|
|
@ -112,7 +112,6 @@ public class InstanceJVMService {
|
|||
} else if (metricType.toLowerCase().equals(MetricType.gc.name())) {
|
||||
metrics.add(MetricType.gc.name(), gcMetricDAO.getMetric(instanceId, startTimeBucket, endTimeBucket));
|
||||
} else if (metricType.toLowerCase().equals(MetricType.tps.name())) {
|
||||
metrics.add(MetricType.tps.name(), instanceMetricUIDAO.getTpsMetric(instanceId, startTimeBucket, endTimeBucket));
|
||||
} else if (metricType.toLowerCase().equals(MetricType.resptime.name())) {
|
||||
} else if (metricType.toLowerCase().equals(MetricType.heapmemory.name())) {
|
||||
metrics.add(MetricType.heapmemory.name(), memoryMetricDAO.getMetric(instanceId, startTimeBucket, endTimeBucket, true));
|
||||
|
|
|
|||
|
|
@ -32,7 +32,9 @@ import org.apache.skywalking.apm.collector.storage.dao.IInstanceMetricUIDAO;
|
|||
import org.apache.skywalking.apm.collector.storage.dao.IInstanceUIDAO;
|
||||
import org.apache.skywalking.apm.collector.storage.ui.common.ResponseTimeTrend;
|
||||
import org.apache.skywalking.apm.collector.storage.ui.common.Step;
|
||||
import org.apache.skywalking.apm.collector.storage.ui.common.ThroughputTrend;
|
||||
import org.apache.skywalking.apm.collector.storage.ui.server.AppServerInfo;
|
||||
import org.apache.skywalking.apm.collector.storage.utils.DurationPoint;
|
||||
import org.apache.skywalking.apm.collector.ui.utils.DurationUtils;
|
||||
|
||||
/**
|
||||
|
|
@ -70,12 +72,20 @@ public class ServerService {
|
|||
public ResponseTimeTrend getServerResponseTimeTrend(int instanceId, Step step, long start,
|
||||
long end) throws ParseException {
|
||||
ResponseTimeTrend responseTimeTrend = new ResponseTimeTrend();
|
||||
Long[] timeBuckets = DurationUtils.INSTANCE.getDurationPoints(step, start, end);
|
||||
List<Integer> trends = instanceMetricUIDAO.getResponseTimeTrend(instanceId, step, timeBuckets);
|
||||
List<DurationPoint> durationPoints = DurationUtils.INSTANCE.getDurationPoints(step, start, end);
|
||||
List<Integer> trends = instanceMetricUIDAO.getResponseTimeTrend(instanceId, step, durationPoints);
|
||||
responseTimeTrend.setTrendList(trends);
|
||||
return responseTimeTrend;
|
||||
}
|
||||
|
||||
public ThroughputTrend getServerTPSTrend(int instanceId, Step step, long start, long end) throws ParseException {
|
||||
ThroughputTrend throughputTrend = new ThroughputTrend();
|
||||
List<DurationPoint> durationPoints = DurationUtils.INSTANCE.getDurationPoints(step, start, end);
|
||||
List<Integer> trends = instanceMetricUIDAO.getServerTPSTrend(instanceId, step, durationPoints);
|
||||
throughputTrend.setTrendList(trends);
|
||||
return throughputTrend;
|
||||
}
|
||||
|
||||
private void buildAppServerInfo(List<AppServerInfo> serverInfos) {
|
||||
serverInfos.forEach(serverInfo -> {
|
||||
if (StringUtils.isNotEmpty(serverInfo.getOsInfo())) {
|
||||
|
|
|
|||
|
|
@ -26,6 +26,7 @@ import org.apache.skywalking.apm.collector.core.UnexpectedException;
|
|||
import org.apache.skywalking.apm.collector.core.util.Const;
|
||||
import org.apache.skywalking.apm.collector.core.util.TimeBucketUtils;
|
||||
import org.apache.skywalking.apm.collector.storage.ui.common.Step;
|
||||
import org.apache.skywalking.apm.collector.storage.utils.DurationPoint;
|
||||
import org.joda.time.DateTime;
|
||||
import org.joda.time.Seconds;
|
||||
|
||||
|
|
@ -92,6 +93,23 @@ public enum DurationUtils {
|
|||
return Seconds.secondsBetween(new DateTime(startDate), new DateTime(endDate)).getSeconds();
|
||||
}
|
||||
|
||||
public long secondsBetween(Step step, DateTime dateTime) throws ParseException {
|
||||
switch (step) {
|
||||
case MONTH:
|
||||
return dateTime.dayOfMonth().getMaximumValue() * 24 * 60 * 60;
|
||||
case DAY:
|
||||
return 24 * 60 * 60;
|
||||
case HOUR:
|
||||
return 60 * 60;
|
||||
case MINUTE:
|
||||
return 60;
|
||||
case SECOND:
|
||||
return 1;
|
||||
default:
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
public DateTime parseToDateTime(Step step, long time) throws ParseException {
|
||||
DateTime dateTime = null;
|
||||
|
||||
|
|
@ -121,11 +139,11 @@ public enum DurationUtils {
|
|||
return dateTime;
|
||||
}
|
||||
|
||||
public Long[] getDurationPoints(Step step, long start, long end) throws ParseException {
|
||||
public List<DurationPoint> getDurationPoints(Step step, long start, long end) throws ParseException {
|
||||
DateTime dateTime = parseToDateTime(step, start);
|
||||
|
||||
List<Long> durations = new LinkedList<>();
|
||||
durations.add(start);
|
||||
List<DurationPoint> durations = new LinkedList<>();
|
||||
durations.add(new DurationPoint(start, secondsBetween(step, dateTime)));
|
||||
|
||||
int i = 0;
|
||||
do {
|
||||
|
|
@ -133,27 +151,27 @@ public enum DurationUtils {
|
|||
case MONTH:
|
||||
dateTime = dateTime.plusMonths(1);
|
||||
String timeBucket = TimeBucketUtils.MONTH_DATE_FORMAT.format(dateTime.toDate());
|
||||
durations.add(Long.valueOf(timeBucket));
|
||||
durations.add(new DurationPoint(Long.valueOf(timeBucket), secondsBetween(step, dateTime)));
|
||||
break;
|
||||
case DAY:
|
||||
dateTime = dateTime.plusDays(1);
|
||||
timeBucket = TimeBucketUtils.DAY_DATE_FORMAT.format(dateTime.toDate());
|
||||
durations.add(Long.valueOf(timeBucket));
|
||||
durations.add(new DurationPoint(Long.valueOf(timeBucket), secondsBetween(step, dateTime)));
|
||||
break;
|
||||
case HOUR:
|
||||
dateTime = dateTime.plusHours(1);
|
||||
timeBucket = TimeBucketUtils.HOUR_DATE_FORMAT.format(dateTime.toDate());
|
||||
durations.add(Long.valueOf(timeBucket));
|
||||
durations.add(new DurationPoint(Long.valueOf(timeBucket), secondsBetween(step, dateTime)));
|
||||
break;
|
||||
case MINUTE:
|
||||
dateTime = dateTime.plusMinutes(1);
|
||||
timeBucket = TimeBucketUtils.MINUTE_DATE_FORMAT.format(dateTime.toDate());
|
||||
durations.add(Long.valueOf(timeBucket));
|
||||
durations.add(new DurationPoint(Long.valueOf(timeBucket), secondsBetween(step, dateTime)));
|
||||
break;
|
||||
case SECOND:
|
||||
dateTime = dateTime.plusSeconds(1);
|
||||
timeBucket = TimeBucketUtils.SECOND_DATE_FORMAT.format(dateTime.toDate());
|
||||
durations.add(Long.valueOf(timeBucket));
|
||||
durations.add(new DurationPoint(Long.valueOf(timeBucket), secondsBetween(step, dateTime)));
|
||||
break;
|
||||
}
|
||||
i++;
|
||||
|
|
@ -161,8 +179,8 @@ public enum DurationUtils {
|
|||
throw new UnexpectedException("Duration data error, step: " + step.name() + ", start: " + start + ", end: " + end);
|
||||
}
|
||||
}
|
||||
while (end != durations.get(durations.size() - 1));
|
||||
while (end != durations.get(durations.size() - 1).getPoint());
|
||||
|
||||
return durations.toArray(new Long[durations.size()]);
|
||||
return durations;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -19,8 +19,10 @@
|
|||
package org.apache.skywalking.apm.collector.ui.utils;
|
||||
|
||||
import java.text.ParseException;
|
||||
import java.util.List;
|
||||
import org.apache.skywalking.apm.collector.core.UnexpectedException;
|
||||
import org.apache.skywalking.apm.collector.storage.ui.common.Step;
|
||||
import org.apache.skywalking.apm.collector.storage.utils.DurationPoint;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
|
|
@ -35,20 +37,72 @@ public class DurationUtilsTestCase {
|
|||
|
||||
@Test
|
||||
public void testGetDurationPoints() throws ParseException {
|
||||
Long[] durationPoints = DurationUtils.INSTANCE.getDurationPoints(Step.MONTH, 201710, 201803);
|
||||
Assert.assertArrayEquals(new Long[] {201710L, 201711L, 201712L, 201801L, 201802L, 201803L}, durationPoints);
|
||||
List<DurationPoint> durationPoints = DurationUtils.INSTANCE.getDurationPoints(Step.MONTH, 201710, 201803);
|
||||
Assert.assertEquals(6, durationPoints.size());
|
||||
Assert.assertEquals(201710L, durationPoints.get(0).getPoint());
|
||||
Assert.assertEquals(2678400, durationPoints.get(0).getSecondsBetween());
|
||||
Assert.assertEquals(201711L, durationPoints.get(1).getPoint());
|
||||
Assert.assertEquals(2592000, durationPoints.get(1).getSecondsBetween());
|
||||
Assert.assertEquals(201712L, durationPoints.get(2).getPoint());
|
||||
Assert.assertEquals(2678400, durationPoints.get(2).getSecondsBetween());
|
||||
Assert.assertEquals(201801L, durationPoints.get(3).getPoint());
|
||||
Assert.assertEquals(2678400, durationPoints.get(3).getSecondsBetween());
|
||||
Assert.assertEquals(201802L, durationPoints.get(4).getPoint());
|
||||
Assert.assertEquals(2419200, durationPoints.get(4).getSecondsBetween());
|
||||
Assert.assertEquals(201803L, durationPoints.get(5).getPoint());
|
||||
Assert.assertEquals(2678400, durationPoints.get(5).getSecondsBetween());
|
||||
|
||||
durationPoints = DurationUtils.INSTANCE.getDurationPoints(Step.DAY, 20180129, 20180202);
|
||||
Assert.assertArrayEquals(new Long[] {20180129L, 20180130L, 20180131L, 20180201L, 20180202L}, durationPoints);
|
||||
Assert.assertEquals(5, durationPoints.size());
|
||||
Assert.assertEquals(20180129L, durationPoints.get(0).getPoint());
|
||||
Assert.assertEquals(86400, durationPoints.get(0).getSecondsBetween());
|
||||
Assert.assertEquals(20180130L, durationPoints.get(1).getPoint());
|
||||
Assert.assertEquals(86400, durationPoints.get(1).getSecondsBetween());
|
||||
Assert.assertEquals(20180131L, durationPoints.get(2).getPoint());
|
||||
Assert.assertEquals(86400, durationPoints.get(2).getSecondsBetween());
|
||||
Assert.assertEquals(20180201L, durationPoints.get(3).getPoint());
|
||||
Assert.assertEquals(86400, durationPoints.get(3).getSecondsBetween());
|
||||
Assert.assertEquals(20180202L, durationPoints.get(4).getPoint());
|
||||
Assert.assertEquals(86400, durationPoints.get(4).getSecondsBetween());
|
||||
|
||||
durationPoints = DurationUtils.INSTANCE.getDurationPoints(Step.HOUR, 2018012922, 2018013002);
|
||||
Assert.assertArrayEquals(new Long[] {2018012922L, 2018012923L, 2018013000L, 2018013001L, 2018013002L}, durationPoints);
|
||||
Assert.assertEquals(5, durationPoints.size());
|
||||
Assert.assertEquals(2018012922L, durationPoints.get(0).getPoint());
|
||||
Assert.assertEquals(3600, durationPoints.get(0).getSecondsBetween());
|
||||
Assert.assertEquals(2018012923L, durationPoints.get(1).getPoint());
|
||||
Assert.assertEquals(3600, durationPoints.get(1).getSecondsBetween());
|
||||
Assert.assertEquals(2018013000L, durationPoints.get(2).getPoint());
|
||||
Assert.assertEquals(3600, durationPoints.get(2).getSecondsBetween());
|
||||
Assert.assertEquals(2018013001L, durationPoints.get(3).getPoint());
|
||||
Assert.assertEquals(3600, durationPoints.get(3).getSecondsBetween());
|
||||
Assert.assertEquals(2018013002L, durationPoints.get(4).getPoint());
|
||||
Assert.assertEquals(3600, durationPoints.get(4).getSecondsBetween());
|
||||
|
||||
durationPoints = DurationUtils.INSTANCE.getDurationPoints(Step.MINUTE, 201801292258L, 201801292302L);
|
||||
Assert.assertArrayEquals(new Long[] {201801292258L, 201801292259L, 201801292300L, 201801292301L, 201801292302L}, durationPoints);
|
||||
Assert.assertEquals(5, durationPoints.size());
|
||||
Assert.assertEquals(201801292258L, durationPoints.get(0).getPoint());
|
||||
Assert.assertEquals(60, durationPoints.get(0).getSecondsBetween());
|
||||
Assert.assertEquals(201801292259L, durationPoints.get(1).getPoint());
|
||||
Assert.assertEquals(60, durationPoints.get(1).getSecondsBetween());
|
||||
Assert.assertEquals(201801292300L, durationPoints.get(2).getPoint());
|
||||
Assert.assertEquals(60, durationPoints.get(2).getSecondsBetween());
|
||||
Assert.assertEquals(201801292301L, durationPoints.get(3).getPoint());
|
||||
Assert.assertEquals(60, durationPoints.get(3).getSecondsBetween());
|
||||
Assert.assertEquals(201801292302L, durationPoints.get(4).getPoint());
|
||||
Assert.assertEquals(60, durationPoints.get(4).getSecondsBetween());
|
||||
|
||||
durationPoints = DurationUtils.INSTANCE.getDurationPoints(Step.SECOND, 20180129225858L, 20180129225902L);
|
||||
Assert.assertArrayEquals(new Long[] {20180129225858L, 20180129225859L, 20180129225900L, 20180129225901L, 20180129225902L}, durationPoints);
|
||||
Assert.assertEquals(5, durationPoints.size());
|
||||
Assert.assertEquals(20180129225858L, durationPoints.get(0).getPoint());
|
||||
Assert.assertEquals(1, durationPoints.get(0).getSecondsBetween());
|
||||
Assert.assertEquals(20180129225859L, durationPoints.get(1).getPoint());
|
||||
Assert.assertEquals(1, durationPoints.get(1).getSecondsBetween());
|
||||
Assert.assertEquals(20180129225900L, durationPoints.get(2).getPoint());
|
||||
Assert.assertEquals(1, durationPoints.get(2).getSecondsBetween());
|
||||
Assert.assertEquals(20180129225901L, durationPoints.get(3).getPoint());
|
||||
Assert.assertEquals(1, durationPoints.get(3).getSecondsBetween());
|
||||
Assert.assertEquals(20180129225902L, durationPoints.get(4).getPoint());
|
||||
Assert.assertEquals(1, durationPoints.get(4).getSecondsBetween());
|
||||
}
|
||||
|
||||
@Test(expected = UnexpectedException.class)
|
||||
|
|
|
|||
Loading…
Reference in New Issue