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);
}
}
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.");
}
}
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;
}
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;
}
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;
}
Aggregations