提交 fc322e1a 编写于 作者: 彭勇升 pengys 提交者: wu-sheng

Feature/1064 (#1093)

* Sample of DAO javadoc.

#1064

* Part of UI DAO documents commit.

* Describe all DAO in UI module .

#1064

* The class be tested was deleted.

* Fixed compile failure.

* Fixed CI failure cause of special character.

* gte -> gt
lte -> le

#1064
上级 4ce798c1
......@@ -23,10 +23,27 @@ import org.apache.skywalking.apm.collector.storage.base.dao.DAO;
import org.apache.skywalking.apm.collector.storage.ui.common.Step;
/**
* Interface to be implemented for execute database query operation
* from {@link org.apache.skywalking.apm.collector.storage.table.alarm.ApplicationAlarmListTable#TABLE}.
*
* @author peng-yongsheng
* @see org.apache.skywalking.apm.collector.storage.StorageModule
*/
public interface IApplicationAlarmListUIDAO extends DAO {
/**
* <p>SQL as: select TIME_BUCKET, APPLICATION_ID, count(APPLICATION_ID) from APPLICATION_ALARM_LIST
* where TIME_BUCKET ge ${startTimeBucket} and TIME_BUCKET le ${endTimeBucket}
* group by TIME_BUCKET, APPLICATION_ID
*
* <p>Use {@link org.apache.skywalking.apm.collector.storage.utils.TimePyramidTableNameBuilder#build(Step, String)}
* to generate table name which mixed with step name.
*
* @param step the step which represent time formats
* @param startTimeBucket start time bucket
* @param endTimeBucket end time bucket
* @return not nullable result list
*/
List<AlarmTrend> getAlarmedApplicationNum(Step step, long startTimeBucket, long endTimeBucket);
class AlarmTrend {
......
......@@ -23,9 +23,28 @@ import org.apache.skywalking.apm.collector.storage.base.dao.DAO;
import org.apache.skywalking.apm.collector.storage.ui.alarm.Alarm;
/**
* Interface to be implemented for execute database query operation
* from {@link org.apache.skywalking.apm.collector.storage.table.alarm.ApplicationAlarmTable#TABLE}.
*
* @author peng-yongsheng
* @see org.apache.skywalking.apm.collector.storage.StorageModule
*/
public interface IApplicationAlarmUIDAO extends DAO {
Alarm loadAlarmList(String keyword, long startTimeBucket, long endTimeBucket, int limit, int from) throws ParseException;
/**
* <p>SQL as: select APPLICATION_ID, ALARM_CONTENT, LAST_TIME_BUCKET, ALARM_TYPE from APPLICATION_ALARM
* where LAST_TIME_BUCKET ge ${startTimeBucket} and LAST_TIME_BUCKET le ${endTimeBucket}
* and ALARM_CONTENT like '%{keyword}%'
* <p>Note: keyword maybe not given
*
* @param keyword fuzzy query
* @param startTimeBucket start time bucket
* @param endTimeBucket end time bucket
* @param limit limits the number of rows returned by the query
* @param from specified how many rows to skip
* @return application alarm items
* @throws ParseException alarm time parse exception
*/
Alarm loadAlarmList(String keyword, long startTimeBucket, long endTimeBucket, int limit,
int from) throws ParseException;
}
......@@ -23,10 +23,29 @@ import org.apache.skywalking.apm.collector.storage.base.dao.DAO;
import org.apache.skywalking.apm.collector.storage.ui.common.Step;
/**
* Interface to be implemented for execute database query operation
* from {@link org.apache.skywalking.apm.collector.storage.table.application.ApplicationComponentTable#TABLE}.
*
* @author peng-yongsheng
* @see org.apache.skywalking.apm.collector.storage.StorageModule
*/
public interface IApplicationComponentUIDAO extends DAO {
/**
* Returns application components that collected between start time bucket
* and end time bucket.
*
* <p>SQL as: select COMPONENT_ID, APPLICATION_ID from APPLICATION_COMPONENT
* where TIME_BUCKET ge ${startTimeBucket} and TIME_BUCKET le ${endTimeBucket}
* group by COMPONENT_ID, APPLICATION_ID
* <p>Use {@link org.apache.skywalking.apm.collector.storage.utils.TimePyramidTableNameBuilder#build(Step, String)}
* to generate table name which mixed with step name.
*
* @param step the step which represent time formats
* @param startTimeBucket start time bucket
* @param endTimeBucket end time bucket
* @return not nullable result list
*/
List<ApplicationComponent> load(Step step, long startTimeBucket, long endTimeBucket);
class ApplicationComponent {
......
......@@ -23,9 +23,33 @@ import org.apache.skywalking.apm.collector.storage.base.dao.DAO;
import org.apache.skywalking.apm.collector.storage.ui.common.Step;
/**
* Interface to be implemented for execute database query operation
* from {@link org.apache.skywalking.apm.collector.storage.table.application.ApplicationComponentTable#TABLE}.
*
* @author peng-yongsheng
* @see org.apache.skywalking.apm.collector.storage.table.application.ApplicationComponentTable
* @see org.apache.skywalking.apm.collector.storage.StorageModule
*/
public interface IApplicationMappingUIDAO extends DAO {
/**
* Returns application mapping data that collected between start time bucket
* and end time bucket. The application id was registered from server side,
* mapping application id was register from client side. So, this returned
* collection can be use to distinguished the application reference metrics
* which aggregated from server side or client side.
*
* <p>SQL as: select APPLICATION_ID, MAPPING_APPLICATION_ID from APPLICATION_MAPPING
* where TIME_BUCKET ge ${startTimeBucket} and TIME_BUCKET le ${endTimeBucket}
* group by APPLICATION_ID, MAPPING_APPLICATION_ID
* <p>Use {@link org.apache.skywalking.apm.collector.storage.utils.TimePyramidTableNameBuilder#build(Step, String)}
* to generate table name which mixed with step name.
*
* @param step the step which represent time formats
* @param startTimeBucket start time bucket
* @param endTimeBucket end time bucket
* @return not nullable result list
*/
List<ApplicationMapping> load(Step step, long startTimeBucket, long endTimeBucket);
class ApplicationMapping {
......
......@@ -25,12 +25,61 @@ import org.apache.skywalking.apm.collector.storage.ui.common.Step;
import org.apache.skywalking.apm.collector.storage.ui.overview.ApplicationTPS;
/**
* Interface to be implemented for execute database query operation
* from {@link org.apache.skywalking.apm.collector.storage.table.application.ApplicationMetricTable#TABLE}.
*
* @author peng-yongsheng
* @see org.apache.skywalking.apm.collector.storage.table.application.ApplicationMetricTable
* @see org.apache.skywalking.apm.collector.storage.StorageModule
*/
public interface IApplicationMetricUIDAO extends DAO {
/**
* Returns the top n application throughput between start time bucket
* and end time bucket.
*
* <p>SQL as: select APPLICATION_ID, sum(TRANSACTION_CALLS) / betweenSecond as tps
* from APPLICATION_METRIC
* where TIME_BUCKET ge ${startTimeBucket} and TIME_BUCKET le ${endTimeBucket}
* and SOURCE_VALUE = ${metricSource}
* group by APPLICATION_ID
* order by tps desc
* <p>Use {@link org.apache.skywalking.apm.collector.storage.utils.TimePyramidTableNameBuilder#build(Step, String)}
* to generate table name which mixed with step name.
* <p>Note: SQL should be "select APPLICATION_ID, 0 as tps" when betweenSecond
* equal 0.
*
* @param step the step which represent time formats
* @param startTimeBucket start time bucket
* @param endTimeBucket end time bucket
* @param betweenSecond the seconds between start time bucket and end time bucket
* @param topN how many rows should return
* @param metricSource source of this metric, server side or client side
* @return not nullable result list
*/
List<ApplicationTPS> getTopNApplicationThroughput(Step step, long startTimeBucket, long endTimeBucket,
int betweenSecond, int topN, MetricSource metricSource);
/**
* Returns aggregated application metrics that collected between start time bucket
* and end time bucket.
*
* <p>SQL as: select APPLICATION_ID, sum(TRANSACTION_CALLS), sum(TRANSACTION_ERROR_CALLS),
* sum(TRANSACTION_DURATION_SUM), sum(TRANSACTION_ERROR_DURATION_SUM),
* sum(SATISFIED_COUNT), sum(TOLERATING_COUNT), sum(FRUSTRATED_COUNT)
* from APPLICATION_METRIC
* where TIME_BUCKET ge ${startTimeBucket} and TIME_BUCKET le ${endTimeBucket}
* and SOURCE_VALUE = ${metricSource}
* group by APPLICATION_ID
* <p>Use {@link org.apache.skywalking.apm.collector.storage.utils.TimePyramidTableNameBuilder#build(Step, String)}
* to generate table name which mixed with step name.
*
* @param step the step which represent time formats
* @param startTimeBucket start time bucket
* @param endTimeBucket end time bucket
* @param metricSource source of this metric, server side or client side
* @return not nullable result list
*/
List<ApplicationMetric> getApplications(Step step, long startTimeBucket, long endTimeBucket,
MetricSource metricSource);
......
......@@ -24,10 +24,37 @@ import org.apache.skywalking.apm.collector.storage.table.MetricSource;
import org.apache.skywalking.apm.collector.storage.ui.common.Step;
/**
* Interface to be implemented for execute database query operation
* from {@link org.apache.skywalking.apm.collector.storage.table.application.ApplicationReferenceMetricTable#TABLE}.
*
* @author peng-yongsheng
* @see org.apache.skywalking.apm.collector.storage.table.application.ApplicationReferenceMetricTable
* @see org.apache.skywalking.apm.collector.storage.StorageModule
*/
public interface IApplicationReferenceMetricUIDAO extends DAO {
/**
* Returns aggregated application reference metrics that collected between
* start time bucket and end time bucket.
*
* <p>SQL as: select FRONT_APPLICATION_ID, BEHIND_APPLICATION_ID,
* sum(TRANSACTION_CALLS), sum(TRANSACTION_ERROR_CALLS), sum(TRANSACTION_DURATION_SUM), sum(TRANSACTION_ERROR_DURATION_SUM)
* from APPLICATION_REFERENCE_METRIC
* where TIME_BUCKET ge ${startTimeBucket} and TIME_BUCKET le ${endTimeBucket}
* and SOURCE_VALUE = ${metricSource}
* and ( FRONT_APPLICATION_ID in (${applicationIds}) or BEHIND_APPLICATION_ID in (${applicationIds}) )
* group by FRONT_APPLICATION_ID, BEHIND_APPLICATION_ID
* <p>Use {@link org.apache.skywalking.apm.collector.storage.utils.TimePyramidTableNameBuilder#build(Step, String)}
* to generate table name which mixed with step name.
* <p>Note: ${applicationIds} may not be given
*
* @param step the step which represent time formats
* @param startTimeBucket start time bucket
* @param endTimeBucket end time bucket
* @param metricSource source of this metric, server side or client side
* @param applicationIds source or target application ids,
* @return not nullable result list
*/
List<ApplicationReferenceMetric> getReferences(Step step, long startTimeBucket, long endTimeBucket,
MetricSource metricSource, Integer... applicationIds);
......
......@@ -20,12 +20,39 @@ package org.apache.skywalking.apm.collector.storage.dao.ui;
import java.util.List;
import org.apache.skywalking.apm.collector.storage.base.dao.DAO;
import org.apache.skywalking.apm.collector.storage.table.jvm.CpuMetricTable;
import org.apache.skywalking.apm.collector.storage.ui.common.Step;
import org.apache.skywalking.apm.collector.storage.utils.DurationPoint;
/**
* Interface to be implemented for execute database query operation
* from {@link CpuMetricTable#TABLE}.
*
* @author peng-yongsheng
* @see org.apache.skywalking.apm.collector.storage.table.jvm.CpuMetricTable
* @see org.apache.skywalking.apm.collector.storage.StorageModule
*/
public interface ICpuMetricUIDAO extends DAO {
/**
* CPU Trend describes the trend of CPU in the given duration, which represents by the
* DurationPoint list in the `step` Unit.
* <p>SQL as: select USAGE_PERCENT, TIMES from CPU_METRIC where ID in (durationPoints),
* rule of ID generation is "${durationPoint}_${instanceId}".
* <p>The average usage percent formula is "( USAGE_PERCENT * 100 ) / TIMES", in order
* to avoid the result includes decimal value, cast the class to {@link Integer}.
* <p>Every element in return list must match DurationPoint list, which also means that,
* the two list must be in same size, and index match.
* <p>If some element of the return list can't be found, the implementor must set 0 as
* default value.
* <p>Use {@link org.apache.skywalking.apm.collector.storage.utils.TimePyramidTableNameBuilder#build(Step, String)}
* to generate table name which mixed with step name.
*
* @param instanceId the owner id of this cpu metrics
* @param step the step which represent time formats
* @param durationPoints the time points in the time span
* @return every duration points average cpu usage percent metrics.
* @see org.apache.skywalking.apm.collector.storage.ui.common.Step
*/
List<Integer> getCPUTrend(int instanceId, Step step, List<DurationPoint> durationPoints);
}
......@@ -20,14 +20,63 @@ package org.apache.skywalking.apm.collector.storage.dao.ui;
import java.util.List;
import org.apache.skywalking.apm.collector.storage.base.dao.DAO;
import org.apache.skywalking.apm.collector.storage.table.jvm.GCMetricTable;
import org.apache.skywalking.apm.collector.storage.ui.common.Step;
import org.apache.skywalking.apm.collector.storage.utils.DurationPoint;
/**
* Interface to be implemented for execute database query operation
* from {@link GCMetricTable#TABLE}.
*
* @author peng-yongsheng
* @see org.apache.skywalking.apm.collector.storage.table.jvm.GCMetricTable
* @see org.apache.skywalking.apm.collector.storage.StorageModule
*/
public interface IGCMetricUIDAO extends DAO {
/**
* Young GC Trend describes the trend of young generation garbage collection in the given
* duration, which represents by the DurationPoint list in the `step` Unit.
* <p>SQL as: select COUNT, TIMES from GC_METRIC where ID in (durationPoints), rule of
* ID generation is "${durationPoint}_${instanceId}_${gcPhrase}",
* {@link org.apache.skywalking.apm.network.proto.GCPhrase#NEW_VALUE}
* <p>The average young generation GC count percent formula is "COUNT / TIMES".
* <p>Every element in return list must match DurationPoint list, which also means that,
* the two list must be in same size, and index match.
* <p>If some element of the return list can't be found, the implementor must set 0 as
* default value.
* <p>Use {@link org.apache.skywalking.apm.collector.storage.utils.TimePyramidTableNameBuilder#build(Step, String)}
* to generate table name which mixed with step name.
*
* @param instanceId the owner id of this GC metrics
* @param step the step which represent time formats
* @param durationPoints the time points in the time span
* @return every duration points average young generation GC count percent metrics.
* @see org.apache.skywalking.apm.collector.storage.ui.common.Step
* @see org.apache.skywalking.apm.network.proto.GCPhrase
*/
List<Integer> getYoungGCTrend(int instanceId, Step step, List<DurationPoint> durationPoints);
/**
* Old GC Trend describes the trend of old generation garbage collection in the given
* duration, which represents by the DurationPoint list in the `step` Unit.
* <p>SQL as: select COUNT, TIMES from GC_METRIC where ID in (durationPoints), rule of
* ID generation is "${durationPoint}_${instanceId}_${gcPhrase}",
* {@link org.apache.skywalking.apm.network.proto.GCPhrase#OLD_VALUE}
* <p>The average old generation GC count percent formula is "COUNT / TIMES".
* <p>Every element in return list must match DurationPoint list, which also means that,
* the two list must be in same size, and index match.
* <p>If some element of the return list can't be found, the implementor must set 0 as
* default value.
* <p>Use {@link org.apache.skywalking.apm.collector.storage.utils.TimePyramidTableNameBuilder#build(Step, String)}
* to generate table name which mixed with step name.
*
* @param instanceId the owner id of this GC metrics
* @param step the step which represent time formats
* @param durationPoints the time points in the time span
* @return every duration points average old generation GC count percent metrics.
* @see org.apache.skywalking.apm.collector.storage.ui.common.Step
* @see org.apache.skywalking.apm.network.proto.GCPhrase
*/
List<Integer> getOldGCTrend(int instanceId, Step step, List<DurationPoint> durationPoints);
}
......@@ -22,10 +22,32 @@ import java.util.List;
import org.apache.skywalking.apm.collector.storage.base.dao.DAO;
/**
* Interface to be implemented for execute database query operation
* from {@link org.apache.skywalking.apm.collector.storage.table.global.GlobalTraceTable#TABLE}.
*
* @author peng-yongsheng
* @see org.apache.skywalking.apm.collector.storage.table.global.GlobalTraceTable
* @see org.apache.skywalking.apm.collector.storage.StorageModule
*/
public interface IGlobalTraceUIDAO extends DAO {
/**
* Returns global trace ids by query operation with given segment id.
* Generally, only one global trace id will be found, but found more
* than one id when given segment id been in a batch process.
* <p>SQL as: select TRACE_ID from GLOBAL_TRACE where SEGMENT_ID = ${segmentId},
*
* @param segmentId argument to bind to the query
* @return not nullable result list containing global trace ids.
*/
List<String> getGlobalTraceId(String segmentId);
/**
* Returns segment ids by query operation with given global trace id.
* <p>SQL as: select SEGMENT_ID from GLOBAL_TRACE where TRACE_ID = ${globalTraceId},
*
* @param globalTraceId argument to bind to the query
* @return not nullable result list containing segment ids.
*/
List<String> getSegmentIds(String globalTraceId);
}
......@@ -23,9 +23,28 @@ import org.apache.skywalking.apm.collector.storage.base.dao.DAO;
import org.apache.skywalking.apm.collector.storage.ui.alarm.Alarm;
/**
* Interface to be implemented for execute database query operation
* from {@link org.apache.skywalking.apm.collector.storage.table.alarm.InstanceAlarmTable#TABLE}.
*
* @author peng-yongsheng
* @see org.apache.skywalking.apm.collector.storage.StorageModule
*/
public interface IInstanceAlarmUIDAO extends DAO {
Alarm loadAlarmList(String keyword, long startTimeBucket, long endTimeBucket, int limit, int from) throws ParseException;
/**
* <p>SQL as: select INSTANCE_ID, ALARM_CONTENT, LAST_TIME_BUCKET, ALARM_TYPE from INSTANCE_ALARM
* where LAST_TIME_BUCKET ge ${startTimeBucket} and LAST_TIME_BUCKET le ${endTimeBucket}
* and ALARM_CONTENT like '%{keyword}%'
* <p>Note: keyword maybe not given
*
* @param keyword fuzzy query
* @param startTimeBucket start time bucket
* @param endTimeBucket end time bucket
* @param limit limits the number of rows returned by the query
* @param from specified how many rows to skip
* @return instance alarm items
* @throws ParseException alarm time parse exception
*/
Alarm loadAlarmList(String keyword, long startTimeBucket, long endTimeBucket, int limit,
int from) throws ParseException;
}
......@@ -26,14 +26,76 @@ import org.apache.skywalking.apm.collector.storage.ui.server.AppServerInfo;
import org.apache.skywalking.apm.collector.storage.utils.DurationPoint;
/**
* Interface to be implemented for execute database query operation
* from {@link org.apache.skywalking.apm.collector.storage.table.instance.InstanceMetricTable#TABLE}.
*
* @author peng-yongsheng
* @see org.apache.skywalking.apm.collector.storage.table.instance.InstanceMetricTable
* @see org.apache.skywalking.apm.collector.storage.StorageModule
*/
public interface IInstanceMetricUIDAO extends DAO {
/**
* Returns the top n instance throughput between start time bucket
* and end time bucket.
*
* <p>SQL as: select APPLICATION_ID, sum(TRANSACTION_CALLS) / ${secondBetween} as tps
* from INSTANCE_METRIC
* where TIME_BUCKET ge ${startTimeBucket} and TIME_BUCKET le ${endTimeBucket}
* and SOURCE_VALUE = ${metricSource}
* and APPLICATION_ID = ${applicationId}
* group by INSTANCE_ID
* order by tps desc
*
* <p>Use {@link org.apache.skywalking.apm.collector.storage.utils.TimePyramidTableNameBuilder#build(Step, String)}
* to generate table name which mixed with step name.
* <p>Note: ${applicationId} may not be given
*
* @param applicationId owner of instances
* @param step the step which represent time formats
* @param startTimeBucket start time bucket
* @param endTimeBucket end time bucket
* @param secondBetween the seconds between start time bucket and end time bucket
* @param topN how many rows should return
* @param metricSource source of this metric, server side or client side
* @return not nullable result list
*/
List<AppServerInfo> getServerThroughput(int applicationId, Step step, long startTimeBucket, long endTimeBucket,
int secondBetween, int topN, MetricSource metricSource);
/**
* Server TPS Trend describes the trend of instance throughout in the given duration,
* which represents by the DurationPoint list in the `step` Unit.
*
* <p>SQL as: select TRANSACTION_CALLS from INSTANCE_METRIC where ID in (durationPoints),
* rule of ID generation is "${durationPoint}_${instanceId}_${MetricSource.Callee}".
*
* <p>The formula is "TRANSACTION_CALLS * durationPoint#secondsBetween"
*
* <p>Use {@link org.apache.skywalking.apm.collector.storage.utils.TimePyramidTableNameBuilder#build(Step, String)}
* to generate table name which mixed with step name.
*
* @param instanceId which instance should be query
* @param step the step which represent time formats
* @param durationPoints the time points in the time span
* @return every duration points average instance throughput metrics.
*/
List<Integer> getServerTPSTrend(int instanceId, Step step, List<DurationPoint> durationPoints);
/**
* Response time Trend describes the trend of instance average response time in the given duration,
* which represents by the DurationPoint list in the `step` Unit.
*
* <p>SQL as: select TRANSACTION_DURATION_SUM / TRANSACTION_CALLS from INSTANCE_METRIC where ID in (durationPoints),
* rule of ID generation is "${durationPoint}_${instanceId}_${MetricSource.Callee}".
*
* <p>Use {@link org.apache.skywalking.apm.collector.storage.utils.TimePyramidTableNameBuilder#build(Step, String)}
* to generate table name which mixed with step name.
*
* @param instanceId which instance should be query
* @param step the step which represent time formats
* @param durationPoints the time points in the time span
* @return every duration points average instance response time metrics.
*/
List<Integer> getResponseTimeTrend(int instanceId, Step step, List<DurationPoint> durationPoints);
}
......@@ -19,28 +19,103 @@
package org.apache.skywalking.apm.collector.storage.dao.ui;
import java.util.List;
import org.apache.skywalking.apm.collector.core.util.BooleanUtils;
import org.apache.skywalking.apm.collector.storage.base.dao.DAO;
import org.apache.skywalking.apm.collector.storage.table.register.Instance;
import org.apache.skywalking.apm.collector.storage.ui.application.Application;
import org.apache.skywalking.apm.collector.storage.ui.server.AppServerInfo;
/**
* Interface to be implemented for execute database query operation
* from {@link org.apache.skywalking.apm.collector.storage.table.register.InstanceTable#TABLE}.
*
* @author peng-yongsheng
* @see org.apache.skywalking.apm.collector.storage.table.register.InstanceTable
* @see org.apache.skywalking.apm.collector.storage.StorageModule
*/
public interface IInstanceUIDAO extends DAO {
Long lastHeartBeatTime();
Long instanceLastHeartBeatTime(long applicationInstanceId);
/**
* Returns applications by query operation with given arguments.
* <p>SQL as: select APPLICATION_ID, count(APPLICATION_ID) from INSTANCE
* where IS_ADDRESS = {@link BooleanUtils#FALSE} and
* (( HEARTBEAT_TIME ge ${endSecondTimeBucket} and REGISTER_TIME le ${endSecondTimeBucket})
* or
* (REGISTER_TIME le ${endSecondTimeBucket} and HEARTBEAT_TIME ge ${startSecondTimeBucket}))
* and APPLICATION_ID in (${applicationIds})
* group by APPLICATION_ID
* <p>Note: ${applicationIds} may not be given
*
* @param startSecondTimeBucket start time format pattern is "yyyyMMddHHmmss"
* @param endSecondTimeBucket end time format pattern is "yyyyMMddHHmmss"
* @param applicationIds owner ids of instances
* @return not nullable result list containing application ids and number of instance.
*/
List<Application> getApplications(long startSecondTimeBucket, long endSecondTimeBucket, int... applicationIds);
/**
* Returns the detail of instance by given instance id.
* <p>SQL as: select * from INSTANCE where INSTANCE_ID = ${instanceId}
*
* @param instanceId argument to bind to the query
* @return the single instance object, may be null if not exist
*/
Instance getInstance(int instanceId);
/**
* Returns the detail of instances by given arguments.
* <p>SQL as: select * from INSTANCE
* where IS_ADDRESS = {@link BooleanUtils#FALSE} and
* (( HEARTBEAT_TIME ge ${endSecondTimeBucket} and REGISTER_TIME le ${endSecondTimeBucket})
* or
* (REGISTER_TIME le ${endSecondTimeBucket} and HEARTBEAT_TIME ge ${startSecondTimeBucket}))
* and OS_INFO like '%${keyword}%'
* <p>Note: ${keyword} may not be given
*
* @param keyword any words contains in OS information, use fuzzy search
* @param startSecondTimeBucket start time format pattern is "yyyyMMddHHmmss"
* @param endSecondTimeBucket end time format pattern is "yyyyMMddHHmmss"
* @return not nullable result list containing detail of instances.
*/
List<AppServerInfo> searchServer(String keyword, long startSecondTimeBucket, long endSecondTimeBucket);
/**
* Returns the detail of instances by given arguments.
* <p>SQL as: select * from INSTANCE where
* where IS_ADDRESS = {@link BooleanUtils#FALSE} and
* (( HEARTBEAT_TIME ge ${endSecondTimeBucket} and REGISTER_TIME le ${endSecondTimeBucket})
* or
* (REGISTER_TIME le ${endSecondTimeBucket} and HEARTBEAT_TIME ge ${startSecondTimeBucket}))
* and APPLICATION_ID = ${applicationId}
*
* @param applicationId owner of instances
* @param startSecondTimeBucket start time format pattern is "yyyyMMddHHmmss"
* @param endSecondTimeBucket end time format pattern is "yyyyMMddHHmmss"
* @return not nullable result list containing detail of instances.
*/
List<AppServerInfo> getAllServer(int applicationId, long startSecondTimeBucket, long endSecondTimeBucket);
/**
* Returns the earliest register time in all instances which
* belonged to the given application id.
* <p>SQL as: select REGISTER_TIME from INSTANCE where
* and APPLICATION_ID = ${applicationId}
* order by REGISTER_TIME asc
*
* @param applicationId owner of instances
* @return the earliest register time
*/
long getEarliestRegisterTime(int applicationId);
/**
* Returns the latest heart beat time in all instances which
* belonged to the given application id.
* <p>SQL as: select HEARTBEAT_TIME from INSTANCE where
* and APPLICATION_ID = ${applicationId}
* order by HEARTBEAT_TIME desc
*
* @param applicationId owner of instances
* @return the latest heart beat time
*/
long getLatestHeartBeatTime(int applicationId);
}
......@@ -21,15 +21,64 @@ package org.apache.skywalking.apm.collector.storage.dao.ui;
import java.util.LinkedList;
import java.util.List;
import org.apache.skywalking.apm.collector.storage.base.dao.DAO;
import org.apache.skywalking.apm.collector.storage.table.jvm.MemoryMetricTable;
import org.apache.skywalking.apm.collector.storage.ui.common.Step;
import org.apache.skywalking.apm.collector.storage.utils.DurationPoint;
/**
* Interface to be implemented for execute database query operation
* from {@link MemoryMetricTable#TABLE}.
*
* @author peng-yongsheng
* @see org.apache.skywalking.apm.collector.storage.table.jvm.MemoryMetricTable
* @see org.apache.skywalking.apm.collector.storage.StorageModule
*/
public interface IMemoryMetricUIDAO extends DAO {
/**
* Heap memory Trend describes the trend of Memory in the given duration, which
* represents by the DurationPoint list in the `step` Unit.
* <p>SQL as: select MAX, USED, TIMES from MEMORY_METRIC where ID in (durationPoints),
* rule of ID generation is "${durationPoint}_${instanceId}_${isHeap}".
* {@link org.apache.skywalking.apm.collector.core.util.BooleanUtils#TRUE}
* <p>The average usage percent formula is "MAX / TIMES" and "USED / TIMES"
* <p>Every element in return list must match DurationPoint list, which also means that,
* the two list must be in same size, and index match.
* <p>If some element of the return list can't be found, the implementor must set 0 as
* default value.
* <p>Use {@link org.apache.skywalking.apm.collector.storage.utils.TimePyramidTableNameBuilder#build(Step, String)}
* to generate table name which mixed with step name.
*
* @param instanceId the owner id of this memory metrics
* @param step the step which represent time formats
* @param durationPoints the time points in the time span
* @return every duration points average heap memory max and usage percent metrics.
* @see org.apache.skywalking.apm.collector.storage.ui.common.Step
* @see org.apache.skywalking.apm.collector.core.util.BooleanUtils
*/
Trend getHeapMemoryTrend(int instanceId, Step step, List<DurationPoint> durationPoints);
/**
* Non heap memory Trend describes the trend of Memory in the given duration, which
* represents by the DurationPoint list in the `step` Unit.
* <p>SQL as: select MAX, USED, TIMES from MEMORY_METRIC where ID in (durationPoints),
* rule of ID generation is "${durationPoint}_${instanceId}_${isHeap}".
* {@link org.apache.skywalking.apm.collector.core.util.BooleanUtils#FALSE}
* <p>The average usage percent formula is "MAX / TIMES" and "USED / TIMES"
* <p>Every element in return list must match DurationPoint list, which also means that,
* the two list must be in same size, and index match.
* <p>If some element of the return list can't be found, the implementor must set 0 as
* default value.
* <p>Use {@link org.apache.skywalking.apm.collector.storage.utils.TimePyramidTableNameBuilder#build(Step, String)}
* to generate table name which mixed with step name.
*
* @param instanceId the owner id of this memory metrics
* @param step the step which represent time formats
* @param durationPoints the time points in the time span
* @return every duration points average non heap memory max and usage percent metrics.
* @see org.apache.skywalking.apm.collector.storage.ui.common.Step
* @see org.apache.skywalking.apm.collector.core.util.BooleanUtils
*/
Trend getNoHeapMemoryTrend(int instanceId, Step step, List<DurationPoint> durationPoints);
class Trend {
......@@ -45,16 +94,8 @@ public interface IMemoryMetricUIDAO extends DAO {
return metrics;
}
public void setMetrics(List<Integer> metrics) {
this.metrics = metrics;
}
public List<Integer> getMaxMetrics() {
return maxMetrics;
}
public void setMaxMetrics(List<Integer> maxMetrics) {
this.maxMetrics = maxMetrics;
}
}
}
......@@ -23,10 +23,32 @@ import org.apache.skywalking.apm.collector.storage.base.dao.DAO;
import org.apache.skywalking.apm.collector.storage.ui.overview.ConjecturalApp;
/**
* Interface to be implemented for execute database query operation
* from {@link org.apache.skywalking.apm.collector.storage.table.register.NetworkAddressTable#TABLE}.
*
* @author peng-yongsheng
* @see org.apache.skywalking.apm.collector.storage.table.register.NetworkAddressTable
* @see org.apache.skywalking.apm.collector.storage.StorageModule
*/
public interface INetworkAddressUIDAO extends DAO {
int getNumOfSpanLayer(int spanLayer);
/**
* <p>SQL as: select count(NETWORK_ADDRESS) from network_address
* where SRC_SPAN_LAYER = ${srcSpanLayer}
*
* @param srcSpanLayer the source layer of this network address register from
* @return count of network address register from the given source span layer
*/
int getNumOfSpanLayer(int srcSpanLayer);
/**
* Returns the conjectural applications and the application count in every server type.
*
* <p>SQL as: select SERVER_TYPE, count(SERVER_TYPE) from network_address
* where SRC_SPAN_LAYER in (SpanLayer.Database_VALUE, SpanLayer.Cache_VALUE, SpanLayer.MQ_VALUE)
* group by SERVER_TYPE
*
* @return not nullable result list
*/
List<ConjecturalApp> getConjecturalApps();
}
......@@ -22,9 +22,38 @@ import org.apache.skywalking.apm.collector.storage.base.dao.DAO;
import org.apache.skywalking.apm.collector.storage.ui.trace.TraceBrief;
/**
* Interface to be implemented for execute database query operation
* from {@link org.apache.skywalking.apm.collector.storage.table.segment.SegmentDurationTable#TABLE}.
*
* @author peng-yongsheng
* @see org.apache.skywalking.apm.collector.storage.table.segment.SegmentDurationTable
* @see org.apache.skywalking.apm.collector.storage.StorageModule
*/
public interface ISegmentDurationUIDAO extends DAO {
/**
* <p>SQL as: select SEGMENT_ID, START_TIME, SERVICE_NAME, DURATION, IS_ERROR
* from SEGMENT_DURATION
* where TIME_BUCKET ge ${startSecondTimeBucket} and TIME_BUCKET le ${endSecondTimeBucket}
* and DURATION ge ${minDuration} and DURATION le ${maxDuration}
* and SERVICE_NAME like '%${operationName}%'
* and SEGMENT_ID in (${segmentIds})
* and APPLICATION_ID = ${applicationId}
* LIMIT ${limit} OFFSET ${from}
*
* <p>Note: Every conditions maybe not given except limit and from condition.
*
* @param startSecondTimeBucket start time format pattern is "yyyyMMddHHmmss"
* @param endSecondTimeBucket end time format pattern is "yyyyMMddHHmmss"
* @param minDuration a range condition for query, segment duration greater than given value
* @param maxDuration a range condition for query, segment duration less than given value
* @param operationName the entry span's operation name, provide fuzzy query
* @param applicationId owner id of segment
* @param limit limits the number of rows returned by the query
* @param from specified how many rows to skip
* @param segmentIds mutual exclusion on other condition
* @return not nullable result list
*/
TraceBrief loadTop(long startSecondTimeBucket, long endSecondTimeBucket, long minDuration, long maxDuration,
String operationName, int applicationId, int limit, int from, String... segmentIds);
}
......@@ -22,8 +22,21 @@ import org.apache.skywalking.apm.collector.storage.base.dao.DAO;
import org.apache.skywalking.apm.network.proto.TraceSegmentObject;
/**
* Interface to be implemented for execute database query operation
* from {@link org.apache.skywalking.apm.collector.storage.table.segment.SegmentTable}.
*
* @author peng-yongsheng
* @see org.apache.skywalking.apm.collector.storage.table.segment.SegmentTable
* @see org.apache.skywalking.apm.collector.storage.StorageModule
*/
public interface ISegmentUIDAO extends DAO {
/**
* <p>SQL as: select DATA_BINARY from SEGMENT where SEGMENT_ID = ${segmentId},
*
* @param segmentId argument to bind to the query
* @return detail of segment which deserialize into proto buffer object,
* {@link TraceSegmentObject#parseFrom(byte[])}
*/
TraceSegmentObject load(String segmentId);
}
......@@ -23,9 +23,28 @@ import org.apache.skywalking.apm.collector.storage.base.dao.DAO;
import org.apache.skywalking.apm.collector.storage.ui.alarm.Alarm;
/**
* Interface to be implemented for execute database query operation
* from {@link org.apache.skywalking.apm.collector.storage.table.alarm.ServiceAlarmTable#TABLE}.
*
* @author peng-yongsheng
* @see org.apache.skywalking.apm.collector.storage.StorageModule
*/
public interface IServiceAlarmUIDAO extends DAO {
Alarm loadAlarmList(String keyword, long startTimeBucket, long endTimeBucket, int limit, int from) throws ParseException;
/**
* <p>SQL as: select SERVICE_ID, ALARM_CONTENT, LAST_TIME_BUCKET, ALARM_TYPE from SERVICE_ALARM
* where LAST_TIME_BUCKET ge ${startTimeBucket} and LAST_TIME_BUCKET le ${endTimeBucket}
* and ALARM_CONTENT like '%{keyword}%'
* <p>Note: keyword maybe not given
*
* @param keyword fuzzy query
* @param startTimeBucket start time bucket
* @param endTimeBucket end time bucket
* @param limit limits the number of rows returned by the query
* @param from specified how many rows to skip
* @return service alarm items
* @throws ParseException alarm time parse exception
*/
Alarm loadAlarmList(String keyword, long startTimeBucket, long endTimeBucket, int limit,
int from) throws ParseException;
}
......@@ -28,18 +28,114 @@ import org.apache.skywalking.apm.collector.storage.ui.service.ServiceMetric;
import org.apache.skywalking.apm.collector.storage.utils.DurationPoint;
/**
* Interface to be implemented for execute database query operation
* from {@link org.apache.skywalking.apm.collector.storage.table.service.ServiceMetricTable#TABLE}.
*
* @author peng-yongsheng
* @see org.apache.skywalking.apm.collector.storage.table.service.ServiceMetricTable
* @see org.apache.skywalking.apm.collector.storage.StorageModule
*/
public interface IServiceMetricUIDAO extends DAO {
/**
* Service Response Time Trend describes the trend of Service metric in the given duration
* , which represents by the DurationPoint list in the `step` Unit.
*
* <p>SQL as: select TRANSACTION_DURATION_SUM / TRANSACTION_CALLS from SERVICE_METRIC
* where ID in (${durationPoints})
*
* <p>rule of ID generation is "${durationPoint}_${serviceId}_${MetricSource.Callee}"
* <p>Use {@link org.apache.skywalking.apm.collector.storage.utils.TimePyramidTableNameBuilder#build(Step, String)}
* to generate table name which mixed with step name.
*
* @param serviceId query condition
* @param step the step which represent time formats
* @param durationPoints the time points in the time span
* @return every duration points average response time metrics.
*/
List<Integer> getServiceResponseTimeTrend(int serviceId, Step step, List<DurationPoint> durationPoints);
/**
* Service TPS Trend describes the trend of Service metric in the given duration
* , which represents by the DurationPoint list in the `step` Unit.
*
* <p>SQL as: select TRANSACTION_CALLS / ${durationPoint#secondsBetween} from SERVICE_METRIC
* where ID in (${durationPoints})
*
* <p>rule of ID generation is "${durationPoint}_${serviceId}_${MetricSource.Callee}"
* <p>Use {@link org.apache.skywalking.apm.collector.storage.utils.TimePyramidTableNameBuilder#build(Step, String)}
* to generate table name which mixed with step name.
*
* @param serviceId query condition
* @param step the step which represent time formats
* @param durationPoints the time points in the time span
* @return every duration points average throughout metrics.
*/
List<Integer> getServiceTPSTrend(int serviceId, Step step, List<DurationPoint> durationPoints);
/**
* Service SLA Trend describes the trend of Service SLA metrics in the given duration
* , which represents by the DurationPoint list in the `step` Unit.
*
* <p>SQL as: select (( TRANSACTION_CALLS - TRANSACTION_ERROR_CALLS ) * 10000) / TRANSACTION_CALLS
* from SERVICE_METRIC where ID in (${durationPoints})
*
* <p>rule of ID generation is "${durationPoint}_${serviceId}_${MetricSource.Callee}"
* <p>Use {@link org.apache.skywalking.apm.collector.storage.utils.TimePyramidTableNameBuilder#build(Step, String)}
* to generate table name which mixed with step name.
*
* @param serviceId query condition
* @param step the step which represent time formats
* @param durationPoints the time points in the time span
* @return every duration points service SLA metrics.
*/
List<Integer> getServiceSLATrend(int serviceId, Step step, List<DurationPoint> durationPoints);
List<Node> getServicesMetric(Step step, long startTime, long endTime,
/**
* <p>SQL as: select SERVICE_ID, sum(TRANSACTION_CALLS), sum(TRANSACTION_ERROR_CALLS)
* from SERVICE_METRIC
* where TIME_BUCKET ge ${startTimeBucket} and TIME_BUCKET le ${endTimeBucket}
* and SOURCE_VALUE = ${metricSource} and SERVICE_ID in (${serviceIds})
* group by SERVICE_ID
*
* <p>The SLA formula is "( TRANSACTION_CALLS - TRANSACTION_ERROR_CALLS ) * 10000 ) / TRANSACTION_CALLS"
*
* <p>Use {@link org.apache.skywalking.apm.collector.storage.utils.TimePyramidTableNameBuilder#build(Step, String)}
* to generate table name which mixed with step name.
*
* @param step the step which represent time formats
* @param startTimeBucket start time bucket
* @param endTimeBucket end time bucket
* @param metricSource source of this metric, server side or client side
* @param serviceIds query condition
* @return not nullable result list
*/
List<Node> getServicesMetric(Step step, long startTimeBucket, long endTimeBucket,
MetricSource metricSource, Collection<Integer> serviceIds);
/**
* Returns the top n slow services that collected between start time bucket
* and end time bucket.
*
* <p>SQL as: select SERVICE_ID, TRANSACTION_CALLS, TRANSACTION_AVERAGE_DURATION
* from SERVICE_METRIC where ID in (${durationPoints})
* where TIME_BUCKET ge ${startTimeBucket} and TIME_BUCKET le ${endTimeBucket}
* and SOURCE_VALUE = ${metricSource}
* and APPLICATION_ID = ${applicationId}
* order by TRANSACTION_AVERAGE_DURATION desc
* limit ${topN}
*
* <p>Use {@link org.apache.skywalking.apm.collector.storage.utils.TimePyramidTableNameBuilder#build(Step, String)}
* to generate table name which mixed with step name.
*
* @param applicationId query condition
* @param step the step which represent time formats
* @param startTimeBucket start time bucket
* @param endTimeBucket end time bucket
* @param topN how many rows should return
* @param metricSource source of this metric, server side or client side
* @return not nullable result list
*/
List<ServiceMetric> getSlowService(int applicationId, Step step, long startTimeBucket, long endTimeBucket,
Integer topN, MetricSource metricSource);
}
......@@ -23,10 +23,35 @@ import org.apache.skywalking.apm.collector.storage.base.dao.DAO;
import org.apache.skywalking.apm.collector.storage.ui.service.ServiceInfo;
/**
* Interface to be implemented for execute database query operation
* from {@link org.apache.skywalking.apm.collector.storage.table.register.ServiceNameTable#TABLE}.
*
* @author peng-yongsheng
* @see org.apache.skywalking.apm.collector.storage.table.register.ServiceNameTable
* @see org.apache.skywalking.apm.collector.storage.StorageModule
*/
public interface IServiceNameServiceUIDAO extends DAO {
/**
* Returns count of service name which register by entry span.
*
* <p>SQL as: select count(SERVICE_NAME) from SERVICE_NAME
* where SRC_SPAN_TYPE = SpanType.Entry_VALUE
*
* @return count of service names
*/
int getCount();
/**
* <p>SQL as: select SERVICE_ID, SERVICE_NAME from SERVICE_NAME
* where SRC_SPAN_TYPE = SpanType.Entry_VALUE
* and SERVICE_NAME like '%{keyword}%'
*
* <p> Note: keyword might not given
*
* @param keyword fuzzy query condition
* @param topN how many rows should return
* @return not nullable result list
*/
List<ServiceInfo> searchService(String keyword, int topN);
}
......@@ -24,13 +24,62 @@ import org.apache.skywalking.apm.collector.storage.table.MetricSource;
import org.apache.skywalking.apm.collector.storage.ui.common.Step;
/**
* Interface to be implemented for execute database query operation
* from {@link org.apache.skywalking.apm.collector.storage.table.service.ServiceReferenceMetricTable#TABLE}.
*
* @author peng-yongsheng
* @see org.apache.skywalking.apm.collector.storage.table.service.ServiceReferenceMetricTable
* @see org.apache.skywalking.apm.collector.storage.StorageModule
*/
public interface IServiceReferenceMetricUIDAO extends DAO {
/**
* Returns the service reference metrics which call the given service id
* that collected between start time bucket and end time bucket.
*
* <p>SQL as: select FRONT_SERVICE_ID, sum(TRANSACTION_CALLS), sum(TRANSACTION_ERROR_CALLS),
* sum(TRANSACTION_DURATION_SUM), sum(TRANSACTION_ERROR_DURATION_SUM)
* from SERVICE_REFERENCE_METRIC
* where TIME_BUCKET ge ${startTimeBucket} and TIME_BUCKET le ${endTimeBucket}
* and SOURCE_VALUE = ${metricSource}
* and BEHIND_SERVICE_ID = ${behindServiceId}
* group by FRONT_SERVICE_ID
*
* <p>Use {@link org.apache.skywalking.apm.collector.storage.utils.TimePyramidTableNameBuilder#build(Step, String)}
* to generate table name which mixed with step name.
*
* @param step the step which represent time formats
* @param startTimeBucket start time bucket
* @param endTimeBucket end time bucket
* @param metricSource source of this metric, server side or client side
* @param behindServiceId the callee service id
* @return not nullable result list
*/
List<ServiceReferenceMetric> getFrontServices(Step step, long startTimeBucket, long endTimeBucket,
MetricSource metricSource, int behindServiceId);
/**
* Returns the service reference metrics which call from the given service id
* that collected between start time bucket and end time bucket.
*
* <p>SQL as: select FRONT_SERVICE_ID, sum(TRANSACTION_CALLS), sum(TRANSACTION_ERROR_CALLS),
* sum(TRANSACTION_DURATION_SUM), sum(TRANSACTION_ERROR_DURATION_SUM)
* from SERVICE_REFERENCE_METRIC
* where TIME_BUCKET ge ${startTimeBucket} and TIME_BUCKET le ${endTimeBucket}
* and SOURCE_VALUE = ${metricSource}
* and BEHIND_SERVICE_ID = ${frontServiceId}
* group by BEHIND_SERVICE_ID
*
* <p>Use {@link org.apache.skywalking.apm.collector.storage.utils.TimePyramidTableNameBuilder#build(Step, String)}
* to generate table name which mixed with step name.
*
* @param step the step which represent time formats
* @param startTimeBucket start time bucket
* @param endTimeBucket end time bucket
* @param metricSource source of this metric, server side or client side
* @param frontServiceId the caller service id
* @return not nullable result list
*/
List<ServiceReferenceMetric> getBehindServices(Step step, long startTimeBucket, long endTimeBucket,
MetricSource metricSource, int frontServiceId);
......
......@@ -23,7 +23,6 @@ import java.util.List;
import org.apache.skywalking.apm.collector.client.elasticsearch.ElasticSearchClient;
import org.apache.skywalking.apm.collector.core.util.BooleanUtils;
import org.apache.skywalking.apm.collector.core.util.StringUtils;
import org.apache.skywalking.apm.collector.core.util.TimeBucketUtils;
import org.apache.skywalking.apm.collector.storage.dao.ui.IInstanceUIDAO;
import org.apache.skywalking.apm.collector.storage.es.base.dao.EsDAO;
import org.apache.skywalking.apm.collector.storage.table.register.Instance;
......@@ -35,10 +34,8 @@ import org.elasticsearch.action.get.GetResponse;
import org.elasticsearch.action.search.SearchRequestBuilder;
import org.elasticsearch.action.search.SearchResponse;
import org.elasticsearch.action.search.SearchType;
import org.elasticsearch.index.query.AbstractQueryBuilder;
import org.elasticsearch.index.query.BoolQueryBuilder;
import org.elasticsearch.index.query.QueryBuilders;
import org.elasticsearch.index.query.RangeQueryBuilder;
import org.elasticsearch.search.SearchHit;
import org.elasticsearch.search.aggregations.AggregationBuilders;
import org.elasticsearch.search.aggregations.bucket.terms.Terms;
......@@ -59,44 +56,6 @@ public class InstanceEsUIDAO extends EsDAO implements IInstanceUIDAO {
super(client);
}
@Override public Long lastHeartBeatTime() {
long fiveMinuteBefore = System.currentTimeMillis() - 5 * 60 * 1000;
fiveMinuteBefore = TimeBucketUtils.INSTANCE.getSecondTimeBucket(fiveMinuteBefore);
RangeQueryBuilder rangeQueryBuilder = QueryBuilders.rangeQuery(InstanceTable.HEARTBEAT_TIME.getName()).gt(fiveMinuteBefore);
return heartBeatTime(rangeQueryBuilder);
}
@Override public Long instanceLastHeartBeatTime(long applicationInstanceId) {
long fiveMinuteBefore = System.currentTimeMillis() - 5 * 60 * 1000;
fiveMinuteBefore = TimeBucketUtils.INSTANCE.getSecondTimeBucket(fiveMinuteBefore);
BoolQueryBuilder boolQueryBuilder = new BoolQueryBuilder();
boolQueryBuilder.must(QueryBuilders.rangeQuery(InstanceTable.HEARTBEAT_TIME.getName()).gt(fiveMinuteBefore));
boolQueryBuilder.must(QueryBuilders.termQuery(InstanceTable.INSTANCE_ID.getName(), applicationInstanceId));
return heartBeatTime(boolQueryBuilder);
}
private Long heartBeatTime(AbstractQueryBuilder queryBuilder) {
SearchRequestBuilder searchRequestBuilder = getClient().prepareSearch(InstanceTable.TABLE);
searchRequestBuilder.setTypes(InstanceTable.TABLE_TYPE);
searchRequestBuilder.setSearchType(SearchType.DFS_QUERY_THEN_FETCH);
searchRequestBuilder.setQuery(queryBuilder);
searchRequestBuilder.setSize(1);
searchRequestBuilder.setFetchSource(InstanceTable.HEARTBEAT_TIME.getName(), null);
searchRequestBuilder.addSort(SortBuilders.fieldSort(InstanceTable.HEARTBEAT_TIME.getName()).sortMode(SortMode.MAX));
SearchResponse searchResponse = searchRequestBuilder.execute().actionGet();
SearchHit[] searchHits = searchResponse.getHits().getHits();
Long heartBeatTime = 0L;
for (SearchHit searchHit : searchHits) {
heartBeatTime = (Long)searchHit.getSource().get(InstanceTable.HEARTBEAT_TIME.getName());
logger.debug("heartBeatTime: {}", heartBeatTime);
heartBeatTime = heartBeatTime - 5;
}
return heartBeatTime;
}
@Override public List<Application> getApplications(long startSecondTimeBucket, long endSecondTimeBucket,
int... applicationIds) {
logger.debug("application list get, start time: {}, end time: {}", startSecondTimeBucket, endSecondTimeBucket);
......
......@@ -18,6 +18,8 @@
package org.apache.skywalking.apm.collector.storage.es.dao.ui;
import java.util.LinkedList;
import java.util.List;
import org.apache.skywalking.apm.collector.client.elasticsearch.ElasticSearchClient;
import org.apache.skywalking.apm.collector.core.util.Const;
import org.apache.skywalking.apm.collector.storage.dao.ui.IInstanceMetricUIDAO;
......@@ -42,9 +44,6 @@ import org.elasticsearch.search.aggregations.bucket.terms.Terms;
import org.elasticsearch.search.aggregations.bucket.terms.TermsAggregationBuilder;
import org.elasticsearch.search.aggregations.metrics.sum.Sum;
import java.util.LinkedList;
import java.util.List;
/**
* @author peng-yongsheng
*/
......@@ -56,7 +55,7 @@ public class InstanceMetricEsUIDAO extends EsDAO implements IInstanceMetricUIDAO
@Override
public List<AppServerInfo> getServerThroughput(int applicationId, Step step, long startTimeBucket,
long endTimeBucket, int secondBetween, int topN, MetricSource metricSource) {
long endTimeBucket, int secondBetween, int topN, MetricSource metricSource) {
String tableName = TimePyramidTableNameBuilder.build(step, InstanceMetricTable.TABLE);
SearchRequestBuilder searchRequestBuilder = getClient().prepareSearch(tableName);
......@@ -84,8 +83,8 @@ public class InstanceMetricEsUIDAO extends EsDAO implements IInstanceMetricUIDAO
instanceIdTerms.getBuckets().forEach(instanceIdTerm -> {
int instanceId = instanceIdTerm.getKeyAsNumber().intValue();
Sum callSum = instanceIdTerm.getAggregations().get(ApplicationMetricTable.TRANSACTION_CALLS.getName());
long calls = (long) callSum.getValue();
int callsPerSec = (int) (secondBetween == 0 ? 0 : calls / secondBetween);
long calls = (long)callSum.getValue();
int callsPerSec = (int)(secondBetween == 0 ? 0 : calls / secondBetween);
AppServerInfo appServerInfo = new AppServerInfo();
appServerInfo.setId(instanceId);
......@@ -122,8 +121,8 @@ public class InstanceMetricEsUIDAO extends EsDAO implements IInstanceMetricUIDAO
for (int i = 0; i < multiGetResponse.getResponses().length; i++) {
MultiGetItemResponse response = multiGetResponse.getResponses()[i];
if (response.getResponse().isExists()) {
long callTimes = ((Number) response.getResponse().getSource().get(InstanceMetricTable.TRANSACTION_CALLS.getName())).longValue();
throughputTrend.add((int) (callTimes / durationPoints.get(i).getSecondsBetween()));
long callTimes = ((Number)response.getResponse().getSource().get(InstanceMetricTable.TRANSACTION_CALLS.getName())).longValue();
throughputTrend.add((int)(callTimes / durationPoints.get(i).getSecondsBetween()));
} else {
throughputTrend.add(0);
}
......@@ -143,21 +142,13 @@ public class InstanceMetricEsUIDAO extends EsDAO implements IInstanceMetricUIDAO
});
List<Integer> responseTimeTrends = new LinkedList<>();
MultiGetResponse multiGetResponse = prepareMultiGet.get();
for (MultiGetItemResponse response : multiGetResponse.getResponses()) {
if (response.getResponse().isExists()) {
long callTimes = ((Number)response.getResponse().getSource().get(InstanceMetricTable.TRANSACTION_CALLS.getName())).longValue();
long errorCallTimes = ((Number)response.getResponse().getSource().get(InstanceMetricTable.TRANSACTION_ERROR_CALLS.getName())).longValue();
long durationSum = ((Number)response.getResponse().getSource().get(InstanceMetricTable.TRANSACTION_DURATION_SUM.getName())).longValue();
long errorDurationSum = ((Number)response.getResponse().getSource().get(InstanceMetricTable.BUSINESS_TRANSACTION_ERROR_DURATION_SUM.getName())).longValue();
long correctCallTimes = callTimes - errorCallTimes;
if (correctCallTimes != 0L) {
responseTimeTrends.add((int)((durationSum - errorDurationSum) / correctCallTimes));
} else {
responseTimeTrends.add(0);
}
responseTimeTrends.add((int)(durationSum / callTimes));
} else {
responseTimeTrends.add(0);
}
......
......@@ -43,11 +43,11 @@ public class NetworkAddressEsUIDAO extends EsDAO implements INetworkAddressUIDAO
super(client);
}
@Override public int getNumOfSpanLayer(int spanLayer) {
@Override public int getNumOfSpanLayer(int srcSpanLayer) {
SearchRequestBuilder searchRequestBuilder = getClient().prepareSearch(NetworkAddressTable.TABLE);
searchRequestBuilder.setTypes(NetworkAddressTable.TABLE_TYPE);
searchRequestBuilder.setSearchType(SearchType.DFS_QUERY_THEN_FETCH);
searchRequestBuilder.setQuery(QueryBuilders.termQuery(NetworkAddressTable.SRC_SPAN_LAYER.getName(), spanLayer));
searchRequestBuilder.setQuery(QueryBuilders.termQuery(NetworkAddressTable.SRC_SPAN_LAYER.getName(), srcSpanLayer));
searchRequestBuilder.setSize(0);
SearchResponse searchResponse = searchRequestBuilder.execute().actionGet();
......
......@@ -139,7 +139,7 @@ public class ServiceMetricEsUIDAO extends EsDAO implements IServiceMetricUIDAO {
}
@Override
public List<Node> getServicesMetric(Step step, long startTime, long endTime, MetricSource metricSource,
public List<Node> getServicesMetric(Step step, long startTimeBucket, long endTimeBucket, MetricSource metricSource,
Collection<Integer> serviceIds) {
String tableName = TimePyramidTableNameBuilder.build(step, ServiceMetricTable.TABLE);
......@@ -148,7 +148,7 @@ public class ServiceMetricEsUIDAO extends EsDAO implements IServiceMetricUIDAO {
searchRequestBuilder.setSearchType(SearchType.DFS_QUERY_THEN_FETCH);
BoolQueryBuilder boolQuery = QueryBuilders.boolQuery();
boolQuery.must().add(QueryBuilders.rangeQuery(ServiceMetricTable.TIME_BUCKET.getName()).gte(startTime).lte(endTime));
boolQuery.must().add(QueryBuilders.rangeQuery(ServiceMetricTable.TIME_BUCKET.getName()).gte(startTimeBucket).lte(endTimeBucket));
boolQuery.must().add(QueryBuilders.termsQuery(ServiceMetricTable.SERVICE_ID.getName(), serviceIds));
boolQuery.must().add(QueryBuilders.termQuery(ServiceMetricTable.SOURCE_VALUE.getName(), metricSource.getValue()));
......
......@@ -25,7 +25,6 @@ import java.util.List;
import org.apache.skywalking.apm.collector.client.h2.H2Client;
import org.apache.skywalking.apm.collector.client.h2.H2ClientException;
import org.apache.skywalking.apm.collector.core.util.BooleanUtils;
import org.apache.skywalking.apm.collector.core.util.TimeBucketUtils;
import org.apache.skywalking.apm.collector.storage.base.sql.SqlBuilder;
import org.apache.skywalking.apm.collector.storage.dao.ui.IInstanceUIDAO;
import org.apache.skywalking.apm.collector.storage.h2.base.dao.H2DAO;
......@@ -47,46 +46,9 @@ public class InstanceH2UIDAO extends H2DAO implements IInstanceUIDAO {
super(client);
}
private static final String GET_LAST_HEARTBEAT_TIME_SQL = "select {0} from {1} where {2} > ? limit 1";
private static final String GET_INST_LAST_HEARTBEAT_TIME_SQL = "select {0} from {1} where {2} > ? and {3} = ? limit 1";
private static final String GET_INSTANCE_SQL = "select * from {0} where {1} = ?";
private static final String GET_APPLICATIONS_SQL = "select {3}, count({0}) as cnt from {1} where {2} >= ? group by {3} limit 100";
@Override
public Long lastHeartBeatTime() {
H2Client client = getClient();
long fiveMinuteBefore = System.currentTimeMillis() - 5 * 60 * 1000;
fiveMinuteBefore = TimeBucketUtils.INSTANCE.getSecondTimeBucket(fiveMinuteBefore);
String sql = SqlBuilder.buildSql(GET_LAST_HEARTBEAT_TIME_SQL, InstanceTable.HEARTBEAT_TIME.getName(), InstanceTable.TABLE, InstanceTable.HEARTBEAT_TIME.getName());
Object[] params = new Object[] {fiveMinuteBefore};
try (ResultSet rs = client.executeQuery(sql, params)) {
if (rs.next()) {
return rs.getLong(1);
}
} catch (SQLException | H2ClientException e) {
logger.error(e.getMessage(), e);
}
return 0L;
}
@Override
public Long instanceLastHeartBeatTime(long applicationInstanceId) {
H2Client client = getClient();
long fiveMinuteBefore = System.currentTimeMillis() - 5 * 60 * 1000;
fiveMinuteBefore = TimeBucketUtils.INSTANCE.getSecondTimeBucket(fiveMinuteBefore);
String sql = SqlBuilder.buildSql(GET_INST_LAST_HEARTBEAT_TIME_SQL, InstanceTable.HEARTBEAT_TIME.getName(), InstanceTable.TABLE,
InstanceTable.HEARTBEAT_TIME.getName(), InstanceTable.INSTANCE_ID.getName());
Object[] params = new Object[] {fiveMinuteBefore, applicationInstanceId};
try (ResultSet rs = client.executeQuery(sql, params)) {
if (rs.next()) {
return rs.getLong(1);
}
} catch (SQLException | H2ClientException e) {
logger.error(e.getMessage(), e);
}
return 0L;
}
@Override
public List<Application> getApplications(long startSecondTimeBucket, long endSecondTimeBucket,
int... applicationIds) {
......
......@@ -42,10 +42,10 @@ public class NetworkAddressH2UIDAO extends H2DAO implements INetworkAddressUIDAO
super(client);
}
@Override public int getNumOfSpanLayer(int spanLayer) {
@Override public int getNumOfSpanLayer(int srcSpanLayer) {
String dynamicSql = "select count({0}) as cnt from {1} where {2} = ?";
String sql = SqlBuilder.buildSql(dynamicSql, NetworkAddressTable.NETWORK_ADDRESS.getName(), NetworkAddressTable.TABLE, NetworkAddressTable.SRC_SPAN_LAYER.getName());
Object[] params = new Object[] {spanLayer};
Object[] params = new Object[] {srcSpanLayer};
try (ResultSet rs = getClient().executeQuery(sql, params)) {
if (rs.next()) {
......
......@@ -109,7 +109,7 @@ public class ServiceMetricH2UIDAO extends H2DAO implements IServiceMetricUIDAO {
return trends;
}
@Override public List<Node> getServicesMetric(Step step, long startTime, long endTime, MetricSource metricSource,
@Override public List<Node> getServicesMetric(Step step, long startTimeBucket, long endTimeBucket, MetricSource metricSource,
Collection<Integer> serviceIds) {
return null;
}
......
/*
* 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.ui.service;
import org.apache.skywalking.apm.collector.core.module.ModuleManager;
import org.apache.skywalking.apm.collector.storage.StorageModule;
import org.apache.skywalking.apm.collector.storage.dao.ui.IInstanceUIDAO;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* @author peng-yongsheng
*/
public class TimeSynchronousService {
private static final Logger logger = LoggerFactory.getLogger(TimeSynchronousService.class);
private final IInstanceUIDAO instanceDAO;
public TimeSynchronousService(ModuleManager moduleManager) {
this.instanceDAO = moduleManager.find(StorageModule.NAME).getService(IInstanceUIDAO.class);
}
public Long allInstanceLastTime() {
return instanceDAO.lastHeartBeatTime();
}
public Long instanceLastTime(int applicationInstanceId) {
return instanceDAO.instanceLastHeartBeatTime(applicationInstanceId);
}
}
......@@ -20,11 +20,19 @@ package org.apache.skywalking.apm.collector.ui.service;
import com.google.gson.Gson;
import com.google.gson.JsonArray;
import com.google.gson.JsonObject;
import java.text.ParseException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import org.apache.skywalking.apm.collector.cache.service.ApplicationCacheService;
import org.apache.skywalking.apm.collector.cache.service.InstanceCacheService;
import org.apache.skywalking.apm.collector.core.module.MockModule;
import org.apache.skywalking.apm.collector.core.module.ModuleManager;
import org.apache.skywalking.apm.collector.storage.dao.ui.*;
import org.apache.skywalking.apm.collector.storage.dao.ui.ICpuMetricUIDAO;
import org.apache.skywalking.apm.collector.storage.dao.ui.IGCMetricUIDAO;
import org.apache.skywalking.apm.collector.storage.dao.ui.IInstanceMetricUIDAO;
import org.apache.skywalking.apm.collector.storage.dao.ui.IInstanceUIDAO;
import org.apache.skywalking.apm.collector.storage.dao.ui.IMemoryMetricUIDAO;
import org.apache.skywalking.apm.collector.storage.table.register.Application;
import org.apache.skywalking.apm.collector.storage.table.register.Instance;
import org.apache.skywalking.apm.collector.storage.ui.common.Duration;
......@@ -42,12 +50,10 @@ import org.junit.Test;
import org.mockito.Mockito;
import org.mockito.internal.util.reflection.Whitebox;
import java.text.ParseException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import static org.mockito.Matchers.*;
import static org.mockito.Matchers.anyInt;
import static org.mockito.Matchers.anyLong;
import static org.mockito.Matchers.anyObject;
import static org.mockito.Matchers.anyString;
import static org.mockito.Mockito.mock;
import static org.powermock.api.mockito.PowerMockito.when;
......@@ -71,7 +77,6 @@ public class ServerServiceTest {
private long startTimeBucket;
private long endTimeBucket;
@Before
public void setUp() throws Exception {
ModuleManager moduleManager = mock(ModuleManager.class);
......@@ -192,14 +197,14 @@ public class ServerServiceTest {
public void getMemoryTrend() throws ParseException {
when(memoryMetricUIDAO.getHeapMemoryTrend(anyInt(), anyObject(), anyObject())).then(invocation -> {
IMemoryMetricUIDAO.Trend trend = new IMemoryMetricUIDAO.Trend();
trend.setMaxMetrics(Collections.singletonList(1));
trend.setMetrics(Collections.singletonList(2));
trend.getMaxMetrics().addAll(Collections.singletonList(1));
trend.getMetrics().addAll(Collections.singletonList(2));
return trend;
});
when(memoryMetricUIDAO.getNoHeapMemoryTrend(anyInt(), anyObject(), anyObject())).then(invocation -> {
IMemoryMetricUIDAO.Trend trend = new IMemoryMetricUIDAO.Trend();
trend.setMaxMetrics(Collections.singletonList(1));
trend.setMetrics(Collections.singletonList(2));
trend.getMaxMetrics().addAll(Collections.singletonList(1));
trend.getMetrics().addAll(Collections.singletonList(2));
return trend;
});
MemoryTrend memoryTrend = serverService.getMemoryTrend(1, duration.getStep(), startTimeBucket, endTimeBucket);
......
/*
* 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.ui.service;
import org.apache.skywalking.apm.collector.core.module.MockModule;
import org.apache.skywalking.apm.collector.core.module.ModuleManager;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import static org.mockito.Matchers.anyString;
import static org.mockito.Mockito.mock;
import static org.powermock.api.mockito.PowerMockito.when;
/**
* @author lican
*/
public class TimeSynchronousServiceTest {
private TimeSynchronousService timeSynchronousService;
@Before
public void setUp() throws Exception {
ModuleManager moduleManager = mock(ModuleManager.class);
when(moduleManager.find(anyString())).then(invocation -> new MockModule());
timeSynchronousService = new TimeSynchronousService(moduleManager);
}
@Test
public void allInstanceLastTime() {
Long aLong = timeSynchronousService.allInstanceLastTime();
Assert.assertEquals((long) aLong, 0L);
}
@Test
public void instanceLastTime() {
Long aLong = timeSynchronousService.instanceLastTime(-1);
Assert.assertEquals((long) aLong, 0L);
}
}
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册