Search in sources :

Example 6 with ServiceName

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;
}
Also used : ServiceName(org.apache.skywalking.apm.collector.storage.table.register.ServiceName)

Example 7 with ServiceName

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;
}
Also used : Call(org.apache.skywalking.apm.collector.storage.ui.common.Call) HashMap(java.util.HashMap) Node(org.apache.skywalking.apm.collector.storage.ui.common.Node) VisualUserNode(org.apache.skywalking.apm.collector.storage.ui.common.VisualUserNode) Topology(org.apache.skywalking.apm.collector.storage.ui.common.Topology) LinkedList(java.util.LinkedList) ServiceName(org.apache.skywalking.apm.collector.storage.table.register.ServiceName) VisualUserNode(org.apache.skywalking.apm.collector.storage.ui.common.VisualUserNode) ParseException(java.text.ParseException) HashSet(java.util.HashSet)

Example 8 with ServiceName

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;
}
Also used : ServiceName(org.apache.skywalking.apm.collector.storage.table.register.ServiceName) ParseException(java.text.ParseException) ServiceMetric(org.apache.skywalking.apm.collector.storage.ui.service.ServiceMetric)

Example 9 with ServiceName

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;
}
Also used : ServiceName(org.apache.skywalking.apm.collector.storage.table.register.ServiceName) ParseException(java.text.ParseException) ServiceMetric(org.apache.skywalking.apm.collector.storage.ui.service.ServiceMetric)

Example 10 with ServiceName

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;
}
Also used : JsonArray(com.google.gson.JsonArray) ServiceName(org.apache.skywalking.apm.collector.storage.table.register.ServiceName) LogMessage(org.apache.skywalking.apm.network.proto.LogMessage) JsonObject(com.google.gson.JsonObject) KeyWithStringValue(org.apache.skywalking.apm.network.proto.KeyWithStringValue) TraceSegmentObject(org.apache.skywalking.apm.network.proto.TraceSegmentObject) SpanObject(org.apache.skywalking.apm.network.proto.SpanObject)

Aggregations

ServiceName (org.apache.skywalking.apm.collector.storage.table.register.ServiceName)12 ParseException (java.text.ParseException)3 HashMap (java.util.HashMap)2 ServiceMetric (org.apache.skywalking.apm.collector.storage.ui.service.ServiceMetric)2 JsonArray (com.google.gson.JsonArray)1 JsonObject (com.google.gson.JsonObject)1 ResultSet (java.sql.ResultSet)1 SQLException (java.sql.SQLException)1 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 LinkedList (java.util.LinkedList)1 H2Client (org.apache.skywalking.apm.collector.client.h2.H2Client)1 H2ClientException (org.apache.skywalking.apm.collector.client.h2.H2ClientException)1 Alarm (org.apache.skywalking.apm.collector.storage.ui.alarm.Alarm)1 Call (org.apache.skywalking.apm.collector.storage.ui.common.Call)1 Node (org.apache.skywalking.apm.collector.storage.ui.common.Node)1 Topology (org.apache.skywalking.apm.collector.storage.ui.common.Topology)1 VisualUserNode (org.apache.skywalking.apm.collector.storage.ui.common.VisualUserNode)1 KeyValue (org.apache.skywalking.apm.collector.storage.ui.trace.KeyValue)1 LogEntity (org.apache.skywalking.apm.collector.storage.ui.trace.LogEntity)1