Search in sources :

Example 1 with ServiceName

use of org.apache.skywalking.apm.collector.storage.table.register.ServiceName in project incubator-skywalking by apache.

the class ServiceNameRegisterSerialWorker method onWork.

@Override
protected void onWork(ServiceName serviceName) throws WorkerException {
    logger.debug("register service name: {}, application id: {}", serviceName.getServiceName(), serviceName.getApplicationId());
    int serviceId = serviceIdCacheService.get(serviceName.getApplicationId(), serviceName.getSrcSpanType(), serviceName.getServiceName());
    if (serviceId == 0) {
        ServiceName newServiceName;
        int min = serviceNameRegisterDAO.getMinServiceId();
        if (min == 0) {
            ServiceName noneServiceName = new ServiceName();
            noneServiceName.setId("1");
            noneServiceName.setApplicationId(Const.NONE_APPLICATION_ID);
            noneServiceName.setServiceId(Const.NONE_SERVICE_ID);
            noneServiceName.setServiceName(Const.NONE_SERVICE_NAME);
            noneServiceName.setSrcSpanType(Const.SPAN_TYPE_VIRTUAL);
            serviceNameRegisterDAO.save(noneServiceName);
            newServiceName = new ServiceName();
            newServiceName.setId("-1");
            newServiceName.setApplicationId(serviceName.getApplicationId());
            newServiceName.setServiceId(-1);
            newServiceName.setSrcSpanType(serviceName.getSrcSpanType());
            newServiceName.setServiceName(serviceName.getServiceName());
        } else {
            int max = serviceNameRegisterDAO.getMaxServiceId();
            serviceId = IdAutoIncrement.INSTANCE.increment(min, max);
            newServiceName = new ServiceName();
            newServiceName.setId(String.valueOf(serviceId));
            newServiceName.setApplicationId(serviceName.getApplicationId());
            newServiceName.setServiceId(serviceId);
            newServiceName.setSrcSpanType(serviceName.getSrcSpanType());
            newServiceName.setServiceName(serviceName.getServiceName());
        }
        serviceNameRegisterDAO.save(newServiceName);
    }
}
Also used : ServiceName(org.apache.skywalking.apm.collector.storage.table.register.ServiceName)

Example 2 with ServiceName

use of org.apache.skywalking.apm.collector.storage.table.register.ServiceName in project incubator-skywalking by apache.

the class ServiceMetricAlarmAssertWorker method generateAlarmContent.

@Override
protected void generateAlarmContent(ServiceAlarm alarm, double threshold) {
    ServiceName serviceName = serviceNameCacheService.get(alarm.getServiceId());
    String clientOrServer = "server";
    if (MetricSource.Caller.getValue() == alarm.getSourceValue()) {
        clientOrServer = "client";
    }
    if (AlarmType.ERROR_RATE.getValue() == alarm.getAlarmType()) {
        alarm.setAlarmContent("The success rate of " + serviceName.getServiceName() + ", detected from " + clientOrServer + " side, is lower than " + threshold + " rate.");
    } else if (AlarmType.SLOW_RTT.getValue() == alarm.getAlarmType()) {
        alarm.setAlarmContent("Response time of " + serviceName.getServiceName() + ", detected from " + clientOrServer + " side, is slower than " + threshold + " ms.");
    }
}
Also used : ServiceName(org.apache.skywalking.apm.collector.storage.table.register.ServiceName)

Example 3 with ServiceName

use of org.apache.skywalking.apm.collector.storage.table.register.ServiceName in project incubator-skywalking by apache.

the class ServiceNameEsCacheDAO method get.

@Override
public ServiceName get(int serviceId) {
    GetRequestBuilder getRequestBuilder = getClient().prepareGet(ServiceNameTable.TABLE, String.valueOf(serviceId));
    GetResponse getResponse = getRequestBuilder.get();
    if (getResponse.isExists()) {
        ServiceName serviceName = new ServiceName();
        serviceName.setApplicationId(((Number) getResponse.getSource().get(ServiceNameTable.COLUMN_APPLICATION_ID)).intValue());
        serviceName.setServiceId(serviceId);
        serviceName.setServiceName((String) getResponse.getSource().get(ServiceNameTable.COLUMN_SERVICE_NAME));
        return serviceName;
    }
    return null;
}
Also used : ServiceName(org.apache.skywalking.apm.collector.storage.table.register.ServiceName) GetResponse(org.elasticsearch.action.get.GetResponse) GetRequestBuilder(org.elasticsearch.action.get.GetRequestBuilder)

Example 4 with ServiceName

use of org.apache.skywalking.apm.collector.storage.table.register.ServiceName in project incubator-skywalking by apache.

the class AlarmService method loadServiceAlarmList.

public Alarm loadServiceAlarmList(String keyword, Step step, long startTimeBucket, long endTimeBucket, int limit, int from) throws ParseException {
    logger.debug("keyword: {}, startTimeBucket: {}, endTimeBucket: {}, limit: {}, from: {}", keyword, startTimeBucket, endTimeBucket, limit, from);
    Alarm alarm = serviceAlarmUIDAO.loadAlarmList(keyword, startTimeBucket, endTimeBucket, limit, from);
    List<IApplicationMappingUIDAO.ApplicationMapping> applicationMappings = applicationMappingUIDAO.load(step, startTimeBucket, endTimeBucket);
    Map<Integer, Integer> mappings = new HashMap<>();
    applicationMappings.forEach(applicationMapping -> mappings.put(applicationMapping.getMappingApplicationId(), applicationMapping.getApplicationId()));
    alarm.getItems().forEach(item -> {
        ServiceName serviceName = serviceNameCacheService.get(item.getId());
        String applicationCode = applicationCacheService.getApplicationById(mappings.getOrDefault(serviceName.getApplicationId(), serviceName.getApplicationId())).getApplicationCode();
        switch(item.getCauseType()) {
            case SLOW_RESPONSE:
                item.setTitle("Service " + serviceName.getServiceName() + " of Application " + applicationCode + RESPONSE_TIME_ALARM);
                break;
            case LOW_SUCCESS_RATE:
                item.setTitle("Service " + serviceName.getServiceName() + " of Application  " + applicationCode + SUCCESS_RATE_ALARM);
                break;
        }
    });
    return alarm;
}
Also used : HashMap(java.util.HashMap) ServiceName(org.apache.skywalking.apm.collector.storage.table.register.ServiceName) Alarm(org.apache.skywalking.apm.collector.storage.ui.alarm.Alarm)

Example 5 with ServiceName

use of org.apache.skywalking.apm.collector.storage.table.register.ServiceName in project incubator-skywalking by apache.

the class TraceStackService method buildSpanList.

private List<Span> buildSpanList(String traceId, String segmentId, int applicationId, List<SpanObject> spanObjects) {
    List<Span> spans = new ArrayList<>();
    spanObjects.forEach(spanObject -> {
        Span span = new Span();
        span.setTraceId(traceId);
        span.setSegmentId(segmentId);
        span.setSpanId(spanObject.getSpanId());
        span.setParentSpanId(spanObject.getParentSpanId());
        span.setStartTime(spanObject.getStartTime());
        span.setEndTime(spanObject.getEndTime());
        span.setError(spanObject.getIsError());
        span.setLayer(spanObject.getSpanLayer().name());
        span.setType(spanObject.getSpanType().name());
        String segmentSpanId = segmentId + Const.SEGMENT_SPAN_SPLIT + String.valueOf(spanObject.getSpanId());
        span.setSegmentSpanId(segmentSpanId);
        String segmentParentSpanId = segmentId + Const.SEGMENT_SPAN_SPLIT + String.valueOf(spanObject.getParentSpanId());
        span.setSegmentParentSpanId(segmentParentSpanId);
        if (spanObject.getPeerId() == 0) {
            span.setPeer(spanObject.getPeer());
        } else {
            span.setPeer(networkAddressCacheService.getAddress(spanObject.getPeerId()));
        }
        String operationName = spanObject.getOperationName();
        if (spanObject.getOperationNameId() != 0) {
            ServiceName serviceName = serviceNameCacheService.get(spanObject.getOperationNameId());
            if (ObjectUtils.isNotEmpty(serviceName)) {
                operationName = serviceName.getServiceName();
            } else {
                operationName = Const.EMPTY_STRING;
            }
        }
        span.setOperationName(operationName);
        String applicationCode = applicationCacheService.getApplicationById(applicationId).getApplicationCode();
        span.setApplicationCode(applicationCode);
        if (spanObject.getComponentId() == 0) {
            span.setComponent(spanObject.getComponent());
        } else {
            span.setComponent(ComponentsDefine.getInstance().getComponentName(spanObject.getComponentId()));
        }
        spanObject.getRefsList().forEach(reference -> {
            Ref ref = new Ref();
            ref.setTraceId(traceId);
            switch(reference.getRefType()) {
                case CrossThread:
                    ref.setType(RefType.CROSS_THREAD);
                    break;
                case CrossProcess:
                    ref.setType(RefType.CROSS_PROCESS);
                    break;
            }
            ref.setParentSpanId(reference.getParentSpanId());
            UniqueId uniqueId = reference.getParentTraceSegmentId();
            StringBuilder segmentIdBuilder = new StringBuilder();
            for (int i = 0; i < uniqueId.getIdPartsList().size(); i++) {
                if (i == 0) {
                    segmentIdBuilder.append(String.valueOf(uniqueId.getIdPartsList().get(i)));
                } else {
                    segmentIdBuilder.append(".").append(String.valueOf(uniqueId.getIdPartsList().get(i)));
                }
            }
            ref.setParentSegmentId(segmentIdBuilder.toString());
            span.setSegmentParentSpanId(ref.getParentSegmentId() + Const.SEGMENT_SPAN_SPLIT + String.valueOf(ref.getParentSpanId()));
            span.getRefs().add(ref);
        });
        spanObject.getTagsList().forEach(tag -> {
            KeyValue keyValue = new KeyValue();
            keyValue.setKey(tag.getKey());
            keyValue.setValue(tag.getValue());
            span.getTags().add(keyValue);
        });
        spanObject.getLogsList().forEach(log -> {
            LogEntity logEntity = new LogEntity();
            logEntity.setTime(log.getTime());
            log.getDataList().forEach(data -> {
                KeyValue keyValue = new KeyValue();
                keyValue.setKey(data.getKey());
                keyValue.setValue(data.getValue());
                logEntity.getData().add(keyValue);
            });
            span.getLogs().add(logEntity);
        });
        spans.add(span);
    });
    return spans;
}
Also used : UniqueId(org.apache.skywalking.apm.network.proto.UniqueId) Ref(org.apache.skywalking.apm.collector.storage.ui.trace.Ref) KeyValue(org.apache.skywalking.apm.collector.storage.ui.trace.KeyValue) ServiceName(org.apache.skywalking.apm.collector.storage.table.register.ServiceName) ArrayList(java.util.ArrayList) Span(org.apache.skywalking.apm.collector.storage.ui.trace.Span) LogEntity(org.apache.skywalking.apm.collector.storage.ui.trace.LogEntity)

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