avoid "by zero" exception when all request are error (#1022)
* avoid "by zero" exception when all request are error * update pr about "by zero" exception * update pr about "by zero" exception add 3 file change * update pr about "by zero" exception add 1 file change * update pr about "by zero" exception to solution 1
This commit is contained in:
parent
bcf97b60bd
commit
8834f30e3a
|
|
@ -73,10 +73,8 @@ public class ServiceMetricEsUIDAO extends EsDAO implements IServiceMetricUIDAO {
|
|||
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();
|
||||
long durationSum = ((Number) response.getResponse().getSource().get(ServiceMetricTable.COLUMN_TRANSACTION_DURATION_SUM)).longValue();
|
||||
long errorDurationSum = ((Number) response.getResponse().getSource().get(ServiceMetricTable.COLUMN_TRANSACTION_ERROR_DURATION_SUM)).longValue();
|
||||
trends.add((int) ((durationSum - errorDurationSum) / (calls - errorCalls)));
|
||||
trends.add((int) (durationSum / calls));
|
||||
} else {
|
||||
trends.add(0);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -90,10 +90,8 @@ public class InstanceMetricH2UIDAO extends H2DAO implements IInstanceMetricUIDAO
|
|||
try (ResultSet rs = client.executeQuery(sql, new Object[] {id})) {
|
||||
if (rs.next()) {
|
||||
long callTimes = rs.getLong(InstanceMetricTable.COLUMN_TRANSACTION_CALLS);
|
||||
long errorCallTimes = rs.getLong(InstanceMetricTable.COLUMN_TRANSACTION_ERROR_CALLS);
|
||||
long durationSum = rs.getLong(InstanceMetricTable.COLUMN_TRANSACTION_DURATION_SUM);
|
||||
long errorDurationSum = rs.getLong(InstanceMetricTable.COLUMN_BUSINESS_TRANSACTION_ERROR_DURATION_SUM);
|
||||
responseTimeTrends.add((int)((durationSum - errorDurationSum) / (callTimes - errorCallTimes)));
|
||||
responseTimeTrends.add((int) (durationSum / callTimes));
|
||||
} else {
|
||||
responseTimeTrends.add(0);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -65,10 +65,8 @@ public class ServiceMetricH2UIDAO extends H2DAO implements IServiceMetricUIDAO {
|
|||
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);
|
||||
long durationSum = rs.getLong(ServiceMetricTable.COLUMN_TRANSACTION_DURATION_SUM);
|
||||
long errorDurationSum = rs.getLong(ServiceMetricTable.COLUMN_TRANSACTION_ERROR_DURATION_SUM);
|
||||
trends.add((int)((durationSum - errorDurationSum) / (calls - errorCalls)));
|
||||
trends.add((int) (durationSum / calls));
|
||||
} else {
|
||||
trends.add(0);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -86,7 +86,7 @@ public class ServiceTopologyService {
|
|||
Call call = new Call();
|
||||
call.setSource(referenceMetric.getSource());
|
||||
call.setTarget(referenceMetric.getTarget());
|
||||
call.setAvgResponseTime((referenceMetric.getDurations() - referenceMetric.getErrorDurations()) / (referenceMetric.getCalls() - referenceMetric.getErrorCalls()));
|
||||
call.setAvgResponseTime(referenceMetric.getDurations() / referenceMetric.getCalls());
|
||||
call.setCallType(components.getOrDefault(serviceNameCacheService.get(referenceMetric.getTarget()).getApplicationId(), Const.UNKNOWN));
|
||||
try {
|
||||
int applicationId = serviceNameCacheService.get(referenceMetric.getTarget()).getApplicationId();
|
||||
|
|
|
|||
|
|
@ -97,7 +97,7 @@ class TopologyBuilder {
|
|||
} catch (ParseException e) {
|
||||
logger.error(e.getMessage(), e);
|
||||
}
|
||||
applicationNode.setAvgResponseTime((applicationMetric.getDurations() - applicationMetric.getErrorDurations()) / (applicationMetric.getCalls() - applicationMetric.getErrorCalls()));
|
||||
applicationNode.setAvgResponseTime(applicationMetric.getDurations() / applicationMetric.getCalls());
|
||||
applicationNode.setApdex(ApdexCalculator.INSTANCE.calculate(applicationMetric.getSatisfiedCount(), applicationMetric.getToleratingCount(), applicationMetric.getFrustratedCount()));
|
||||
applicationNode.setAlarm(false);
|
||||
try {
|
||||
|
|
@ -168,7 +168,7 @@ class TopologyBuilder {
|
|||
} catch (ParseException e) {
|
||||
logger.error(e.getMessage(), e);
|
||||
}
|
||||
call.setAvgResponseTime((referenceMetric.getDurations() - referenceMetric.getErrorDurations()) / (referenceMetric.getCalls() - referenceMetric.getErrorCalls()));
|
||||
call.setAvgResponseTime(referenceMetric.getDurations() / referenceMetric.getCalls());
|
||||
calls.add(call);
|
||||
});
|
||||
|
||||
|
|
@ -215,7 +215,7 @@ class TopologyBuilder {
|
|||
} catch (ParseException e) {
|
||||
logger.error(e.getMessage(), e);
|
||||
}
|
||||
call.setAvgResponseTime((referenceMetric.getDurations() - referenceMetric.getErrorDurations()) / (referenceMetric.getCalls() - referenceMetric.getErrorCalls()));
|
||||
call.setAvgResponseTime(referenceMetric.getDurations() / referenceMetric.getCalls());
|
||||
calls.add(call);
|
||||
});
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue