use of org.apache.skywalking.apm.collector.storage.table.register.ServiceName in project incubator-skywalking by apache.
the class ServiceNameService method getOrCreate.
@Override
public int getOrCreate(int applicationId, int srcSpanType, String serviceName) {
int serviceId = getServiceIdCacheService().get(applicationId, srcSpanType, serviceName);
if (serviceId == 0) {
ServiceName service = new ServiceName();
service.setId("0");
service.setApplicationId(applicationId);
service.setServiceName(serviceName);
service.setSrcSpanType(srcSpanType);
service.setServiceId(0);
getServiceNameRegisterGraph().start(service);
}
return serviceId;
}
use of org.apache.skywalking.apm.collector.storage.table.register.ServiceName in project incubator-skywalking by apache.
the class ServiceTopologyService method getServiceTopology.
public Topology getServiceTopology(Step step, int serviceId, long startTimeBucket, long endTimeBucket, long startSecondTimeBucket, long endSecondTimeBucket) throws ParseException {
logger.debug("startTimeBucket: {}, endTimeBucket: {}", startTimeBucket, endTimeBucket);
List<IApplicationComponentUIDAO.ApplicationComponent> applicationComponents = applicationComponentUIDAO.load(step, startTimeBucket, endTimeBucket);
Map<Integer, String> components = new HashMap<>();
applicationComponents.forEach(component -> components.put(component.getApplicationId(), ComponentsDefine.getInstance().getComponentName(component.getComponentId())));
List<IServiceReferenceMetricUIDAO.ServiceReferenceMetric> referenceMetrics = serviceReferenceMetricUIDAO.getFrontServices(step, startTimeBucket, endTimeBucket, MetricSource.Callee, serviceId);
referenceMetrics.addAll(serviceReferenceMetricUIDAO.getBehindServices(step, startTimeBucket, endTimeBucket, MetricSource.Caller, serviceId));
Set<Integer> nodeIds = new HashSet<>();
List<Call> calls = new LinkedList<>();
referenceMetrics.forEach(referenceMetric -> {
nodeIds.add(referenceMetric.getSource());
nodeIds.add(referenceMetric.getTarget());
Call call = new Call();
call.setSource(referenceMetric.getSource());
call.setTarget(referenceMetric.getTarget());
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();
call.setCallsPerSec(referenceMetric.getCalls() / secondBetweenService.calculate(applicationId, startSecondTimeBucket, endSecondTimeBucket));
} catch (ParseException e) {
logger.error(e.getMessage(), e);
}
call.setAlert(false);
calls.add(call);
});
List<Node> serviceNodes = serviceMetricUIDAO.getServicesMetric(step, startTimeBucket, endTimeBucket, MetricSource.Callee, nodeIds);
Set<Integer> gotNodes = new HashSet<>();
serviceNodes.forEach(serviceNode -> gotNodes.add(serviceNode.getId()));
Set<Integer> callerNodeIds = new HashSet<>();
nodeIds.forEach(nodeId -> {
if (!gotNodes.contains(nodeId)) {
callerNodeIds.add(nodeId);
}
});
serviceNodes.addAll(serviceMetricUIDAO.getServicesMetric(step, startTimeBucket, endTimeBucket, MetricSource.Caller, callerNodeIds));
serviceNodes.forEach(serviceNode -> {
ServiceName serviceName = serviceNameCacheService.get(serviceNode.getId());
serviceNode.setName(serviceName.getServiceName());
});
if (callerNodeIds.contains(Const.NONE_SERVICE_ID)) {
VisualUserNode userNode = new VisualUserNode();
userNode.setId(Const.NONE_SERVICE_ID);
userNode.setName(Const.USER_CODE);
userNode.setType(Const.USER_CODE.toUpperCase());
serviceNodes.add(userNode);
}
Topology topology = new Topology();
topology.setCalls(calls);
topology.setNodes(serviceNodes);
return topology;
}
use of org.apache.skywalking.apm.collector.storage.table.register.ServiceName in project incubator-skywalking by apache.
the class ApplicationService method getSlowService.
public List<ServiceMetric> getSlowService(int applicationId, Step step, long startTimeBucket, long endTimeBucket, long startSecondTimeBucket, long endSecondTimeBucket, Integer topN) throws ParseException {
List<ServiceMetric> slowServices = serviceMetricUIDAO.getSlowService(applicationId, step, startTimeBucket, endTimeBucket, topN, MetricSource.Callee);
slowServices.forEach(slowService -> {
ServiceName serviceName = serviceNameCacheService.get(slowService.getId());
try {
slowService.setCallsPerSec((int) (slowService.getCalls() / secondBetweenService.calculate(serviceName.getApplicationId(), startSecondTimeBucket, endSecondTimeBucket)));
} catch (ParseException e) {
logger.error(e.getMessage(), e);
}
slowService.setName(serviceName.getServiceName());
});
return slowServices;
}
use of org.apache.skywalking.apm.collector.storage.table.register.ServiceName in project incubator-skywalking by apache.
the class ServiceNameService method getSlowService.
public List<ServiceMetric> getSlowService(Step step, long startTimeBucket, long endTimeBucket, long startSecondTimeBucket, long endSecondTimeBucket, Integer topN) throws ParseException {
List<ServiceMetric> slowServices = serviceMetricUIDAO.getSlowService(0, step, startTimeBucket, endTimeBucket, topN, MetricSource.Callee);
slowServices.forEach(slowService -> {
ServiceName serviceName = serviceNameCacheService.get(slowService.getId());
slowService.setName(serviceName.getServiceName());
try {
slowService.setCallsPerSec((int) (slowService.getCalls() / secondBetweenService.calculate(serviceName.getApplicationId(), startSecondTimeBucket, endSecondTimeBucket)));
} catch (ParseException e) {
logger.error(e.getMessage(), e);
}
});
return slowServices;
}
use of org.apache.skywalking.apm.collector.storage.table.register.ServiceName in project incubator-skywalking by apache.
the class SpanService method load.
public JsonObject load(String segmentId, int spanId) {
TraceSegmentObject segmentObject = segmentDAO.load(segmentId);
JsonObject spanJson = new JsonObject();
List<SpanObject> spans = segmentObject.getSpansList();
for (SpanObject spanObject : spans) {
if (spanId == spanObject.getSpanId()) {
String operationName = spanObject.getOperationName();
if (spanObject.getOperationNameId() != 0) {
ServiceName serviceName = serviceNameCacheService.get(spanObject.getOperationNameId());
if (StringUtils.isNotEmpty(serviceName)) {
operationName = serviceName.getServiceName();
}
}
spanJson.addProperty("operationName", operationName);
spanJson.addProperty("startTime", spanObject.getStartTime());
spanJson.addProperty("endTime", spanObject.getEndTime());
JsonArray logsArray = new JsonArray();
List<LogMessage> logs = spanObject.getLogsList();
for (LogMessage logMessage : logs) {
JsonObject logJson = new JsonObject();
logJson.addProperty("time", logMessage.getTime());
JsonArray logInfoArray = new JsonArray();
for (KeyWithStringValue value : logMessage.getDataList()) {
JsonObject valueJson = new JsonObject();
valueJson.addProperty("key", value.getKey());
valueJson.addProperty("value", value.getValue());
logInfoArray.add(valueJson);
}
logJson.add("logInfo", logInfoArray);
logsArray.add(logJson);
}
spanJson.add("logMessage", logsArray);
JsonArray tagsArray = new JsonArray();
JsonObject spanTypeJson = new JsonObject();
spanTypeJson.addProperty("key", "span type");
spanTypeJson.addProperty("value", spanObject.getSpanType().name());
tagsArray.add(spanTypeJson);
JsonObject componentJson = new JsonObject();
componentJson.addProperty("key", "component");
if (spanObject.getComponentId() == 0) {
componentJson.addProperty("value", spanObject.getComponent());
} else {
componentJson.addProperty("value", ComponentsDefine.getInstance().getComponentName(spanObject.getComponentId()));
}
tagsArray.add(componentJson);
JsonObject peerJson = new JsonObject();
peerJson.addProperty("key", "peer");
if (spanObject.getPeerId() == 0) {
peerJson.addProperty("value", spanObject.getPeer());
} else {
peerJson.addProperty("value", applicationCacheService.getApplicationById(spanObject.getPeerId()).getApplicationCode());
}
tagsArray.add(peerJson);
for (KeyWithStringValue tagValue : spanObject.getTagsList()) {
JsonObject tagJson = new JsonObject();
tagJson.addProperty("key", tagValue.getKey());
tagJson.addProperty("value", tagValue.getValue());
tagsArray.add(tagJson);
}
JsonObject isErrorJson = new JsonObject();
isErrorJson.addProperty("key", "is error");
isErrorJson.addProperty("value", spanObject.getIsError());
tagsArray.add(isErrorJson);
spanJson.add("tags", tagsArray);
}
}
return spanJson;
}
Aggregations