Provide the getServiceSLATrend query.
This commit is contained in:
parent
cccba2ec8f
commit
2c6b03bfbb
|
|
@ -27,5 +27,7 @@ import org.apache.skywalking.apm.collector.storage.utils.DurationPoint;
|
|||
* @author peng-yongsheng
|
||||
*/
|
||||
public interface IServiceMetricUIDAO extends DAO {
|
||||
List<Integer> load(int serviceId, Step step, List<DurationPoint> durationPoints);
|
||||
List<Integer> getServiceResponseTimeTrend(int serviceId, Step step, List<DurationPoint> durationPoints);
|
||||
|
||||
List<Integer> getServiceSLATrend(int serviceId, Step step, List<DurationPoint> durationPoints);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -25,4 +25,12 @@ import java.util.List;
|
|||
*/
|
||||
public class SLATrend {
|
||||
private List<Integer> trendList;
|
||||
|
||||
public List<Integer> getTrendList() {
|
||||
return trendList;
|
||||
}
|
||||
|
||||
public void setTrendList(List<Integer> trendList) {
|
||||
this.trendList = trendList;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -42,7 +42,8 @@ public class ServiceMetricEsUIDAO extends EsDAO implements IServiceMetricUIDAO {
|
|||
super(client);
|
||||
}
|
||||
|
||||
@Override public List<Integer> load(int serviceId, Step step, List<DurationPoint> durationPoints) {
|
||||
@Override
|
||||
public List<Integer> getServiceResponseTimeTrend(int serviceId, Step step, List<DurationPoint> durationPoints) {
|
||||
MultiGetRequestBuilder prepareMultiGet = getClient().prepareMultiGet();
|
||||
String tableName = TimePyramidTableNameBuilder.build(step, ServiceMetricTable.TABLE);
|
||||
|
||||
|
|
@ -66,4 +67,27 @@ public class ServiceMetricEsUIDAO extends EsDAO implements IServiceMetricUIDAO {
|
|||
}
|
||||
return trends;
|
||||
}
|
||||
|
||||
@Override public List<Integer> getServiceSLATrend(int serviceId, Step step, List<DurationPoint> durationPoints) {
|
||||
MultiGetRequestBuilder prepareMultiGet = getClient().prepareMultiGet();
|
||||
String tableName = TimePyramidTableNameBuilder.build(step, ServiceMetricTable.TABLE);
|
||||
|
||||
durationPoints.forEach(durationPoint -> {
|
||||
String id = durationPoint.getPoint() + Const.ID_SPLIT + serviceId + Const.ID_SPLIT + MetricSource.Callee.getValue();
|
||||
prepareMultiGet.add(tableName, ServiceMetricTable.TABLE_TYPE, id);
|
||||
});
|
||||
|
||||
List<Integer> trends = new LinkedList<>();
|
||||
MultiGetResponse multiGetResponse = prepareMultiGet.get();
|
||||
for (MultiGetItemResponse response : multiGetResponse.getResponses()) {
|
||||
if (response.getResponse().isExists()) {
|
||||
long calls = ((Number)response.getResponse().getSource().get(ServiceMetricTable.COLUMN_TRANSACTION_CALLS)).longValue();
|
||||
long errorCalls = ((Number)response.getResponse().getSource().get(ServiceMetricTable.COLUMN_TRANSACTION_ERROR_CALLS)).longValue();
|
||||
trends.add((int)(((calls - errorCalls) / calls)) * 10000);
|
||||
} else {
|
||||
trends.add(10000);
|
||||
}
|
||||
}
|
||||
return trends;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -47,7 +47,8 @@ public class ServiceMetricH2UIDAO extends H2DAO implements IServiceMetricUIDAO {
|
|||
super(client);
|
||||
}
|
||||
|
||||
@Override public List<Integer> load(int serviceId, Step step, List<DurationPoint> durationPoints) {
|
||||
@Override
|
||||
public List<Integer> getServiceResponseTimeTrend(int serviceId, Step step, List<DurationPoint> durationPoints) {
|
||||
String tableName = TimePyramidTableNameBuilder.build(step, ServiceMetricTable.TABLE);
|
||||
|
||||
H2Client client = getClient();
|
||||
|
|
@ -75,4 +76,31 @@ public class ServiceMetricH2UIDAO extends H2DAO implements IServiceMetricUIDAO {
|
|||
|
||||
return trends;
|
||||
}
|
||||
|
||||
@Override public List<Integer> getServiceSLATrend(int serviceId, Step step, List<DurationPoint> durationPoints) {
|
||||
String tableName = TimePyramidTableNameBuilder.build(step, ServiceMetricTable.TABLE);
|
||||
|
||||
H2Client client = getClient();
|
||||
String dynamicSql = "select * from {0} where {1} = ?";
|
||||
String sql = SqlBuilder.buildSql(dynamicSql, tableName, ServiceMetricTable.COLUMN_ID);
|
||||
|
||||
List<Integer> trends = new LinkedList<>();
|
||||
durationPoints.forEach(durationPoint -> {
|
||||
String id = durationPoint.getPoint() + Const.ID_SPLIT + serviceId + Const.ID_SPLIT + MetricSource.Callee.getValue();
|
||||
|
||||
try (ResultSet rs = client.executeQuery(sql, new String[] {id})) {
|
||||
if (rs.next()) {
|
||||
long calls = rs.getLong(ServiceMetricTable.COLUMN_TRANSACTION_CALLS);
|
||||
long errorCalls = rs.getLong(ServiceMetricTable.COLUMN_TRANSACTION_ERROR_CALLS);
|
||||
trends.add((int)(((calls - errorCalls) / calls)) * 10000);
|
||||
} else {
|
||||
trends.add(10000);
|
||||
}
|
||||
} catch (SQLException | H2ClientException e) {
|
||||
logger.error(e.getMessage(), e);
|
||||
}
|
||||
});
|
||||
|
||||
return trends;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -65,8 +65,10 @@ public class ServiceQuery implements Query {
|
|||
return null;
|
||||
}
|
||||
|
||||
public SLATrend getServiceSLATrend(int serviceId, Duration duration) {
|
||||
return null;
|
||||
public SLATrend getServiceSLATrend(int serviceId, Duration duration) throws ParseException {
|
||||
long start = DurationUtils.INSTANCE.exchangeToTimeBucket(duration.getStart());
|
||||
long end = DurationUtils.INSTANCE.exchangeToTimeBucket(duration.getEnd());
|
||||
return getServiceNameService().getServiceSLATrend(serviceId, duration.getStep(), start, end);
|
||||
}
|
||||
|
||||
public Topology getServiceTopology(int serviceId, Duration duration) {
|
||||
|
|
|
|||
|
|
@ -25,6 +25,7 @@ import org.apache.skywalking.apm.collector.storage.StorageModule;
|
|||
import org.apache.skywalking.apm.collector.storage.dao.ui.IServiceMetricUIDAO;
|
||||
import org.apache.skywalking.apm.collector.storage.dao.ui.IServiceNameServiceUIDAO;
|
||||
import org.apache.skywalking.apm.collector.storage.ui.common.ResponseTimeTrend;
|
||||
import org.apache.skywalking.apm.collector.storage.ui.common.SLATrend;
|
||||
import org.apache.skywalking.apm.collector.storage.ui.common.Step;
|
||||
import org.apache.skywalking.apm.collector.storage.ui.service.ServiceInfo;
|
||||
import org.apache.skywalking.apm.collector.storage.utils.DurationPoint;
|
||||
|
|
@ -55,7 +56,14 @@ public class ServiceNameService {
|
|||
long end) throws ParseException {
|
||||
ResponseTimeTrend responseTimeTrend = new ResponseTimeTrend();
|
||||
List<DurationPoint> durationPoints = DurationUtils.INSTANCE.getDurationPoints(step, start, end);
|
||||
responseTimeTrend.setTrendList(serviceMetricUIDAO.load(serviceId, step, durationPoints));
|
||||
responseTimeTrend.setTrendList(serviceMetricUIDAO.getServiceResponseTimeTrend(serviceId, step, durationPoints));
|
||||
return responseTimeTrend;
|
||||
}
|
||||
|
||||
public SLATrend getServiceSLATrend(int serviceId, Step step, long start, long end) throws ParseException {
|
||||
SLATrend slaTrend = new SLATrend();
|
||||
List<DurationPoint> durationPoints = DurationUtils.INSTANCE.getDurationPoints(step, start, end);
|
||||
slaTrend.setTrendList(serviceMetricUIDAO.getServiceSLATrend(serviceId, step, durationPoints));
|
||||
return slaTrend;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue