未验证 提交 9b6f8723 编写于 作者: X Xin,Zhang 提交者: GitHub

Merge pull request #870 from peng-yongsheng/fixed/855

Fixed/855
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package org.apache.skywalking.apm.collector.analysis.segment.parser.provider.service;
import com.google.protobuf.InvalidProtocolBufferException;
import java.util.Base64;
import java.util.List;
import org.apache.skywalking.apm.network.proto.SpanObject;
import org.apache.skywalking.apm.network.proto.TraceSegmentObject;
import org.apache.skywalking.apm.network.proto.UniqueId;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* @author peng-yongsheng
*/
public class SegmentBase64Printer {
private static final Logger LOGGER = LoggerFactory.getLogger(SegmentBase64Printer.class);
public static void main(String[] args) throws InvalidProtocolBufferException {
String segmentBase64 = "CgwKCgIBsv/x1L2vgBsSggEQ////////////ARirnsP1niwg9Z7D9Z4sOhhIMi9KREJJL0Nvbm5lY3Rpb24vY2xvc2VKDGxvY2FsaG9zdDotMVABWAFgBHoOCgdkYi50eXBlEgNzcWx6GQoLZGIuaW5zdGFuY2USCmRhdGFTb3VyY2V6DgoMZGIuc3RhdGVtZW50GP///////////wEgAg==";
byte[] binarySegment = Base64.getDecoder().decode(segmentBase64);
TraceSegmentObject segmentObject = TraceSegmentObject.parseFrom(binarySegment);
UniqueId segmentId = segmentObject.getTraceSegmentId();
StringBuilder segmentIdBuilder = new StringBuilder();
for (int i = 0; i < segmentId.getIdPartsList().size(); i++) {
if (i == 0) {
segmentIdBuilder.append(segmentId.getIdPartsList().get(i));
} else {
segmentIdBuilder.append(".").append(segmentId.getIdPartsList().get(i));
}
}
LOGGER.info("SegmentId: {}", segmentIdBuilder.toString());
LOGGER.info("ApplicationId: {}", segmentObject.getApplicationId());
LOGGER.info("ApplicationInstanceId: {}", segmentObject.getApplicationInstanceId());
List<SpanObject> spansList = segmentObject.getSpansList();
LOGGER.info("Spans:");
spansList.forEach(span -> {
LOGGER.info(" Span:");
LOGGER.info(" SpanId: {}", span.getSpanId());
LOGGER.info(" ParentSpanId: {}", span.getParentSpanId());
LOGGER.info(" SpanLayer: {}", span.getSpanLayer());
LOGGER.info(" SpanType: {}", span.getSpanType());
LOGGER.info(" StartTime: {}", span.getStartTime());
LOGGER.info(" EndTime: {}", span.getEndTime());
LOGGER.info(" ComponentId: {}", span.getComponentId());
LOGGER.info(" Component: {}", span.getComponent());
LOGGER.info(" OperationNameId: {}", span.getOperationNameId());
LOGGER.info(" OperationName: {}", span.getOperationName());
LOGGER.info(" PeerId: {}", span.getPeerId());
LOGGER.info(" Peer: {}", span.getPeer());
LOGGER.info(" IsError: {}", span.getIsError());
LOGGER.info(" reference:");
span.getRefsList().forEach(reference -> {
LOGGER.info(" EntryApplicationInstanceId: {}", reference.getEntryApplicationInstanceId());
});
});
}
}
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ Licensed to the Apache Software Foundation (ASF) under one or more
~ contributor license agreements. See the NOTICE file distributed with
~ this work for additional information regarding copyright ownership.
~ The ASF licenses this file to You under the Apache License, Version 2.0
~ (the "License"); you may not use this file except in compliance with
~ the License. You may obtain a copy of the License at
~
~ http://www.apache.org/licenses/LICENSE-2.0
~
~ Unless required by applicable law or agreed to in writing, software
~ distributed under the License is distributed on an "AS IS" BASIS,
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
~ See the License for the specific language governing permissions and
~ limitations under the License.
~
-->
<Configuration status="info">
<Appenders>
<Console name="Console" target="SYSTEM_OUT">
<PatternLayout charset="UTF-8" pattern="%d - %c -%-4r [%t] %-5p %x - %m%n"/>
</Console>
</Appenders>
<Loggers>
<logger name="org.eclipse.jetty" level="INFO"/>
<logger name="org.apache.zookeeper" level="INFO"/>
<logger name="org.elasticsearch.common.network.IfConfig" level="INFO"/>
<logger name="org.apache.skywalking.apm.collector.agent.grpc.provider.handler.JVMMetricsServiceHandler" level="INFO"/>
<logger name="org.apache.skywalking.apm.collector.analysis.worker.timer.PersistenceTimer" level="INFO"/>
<logger name="io.grpc.netty" level="INFO"/>
<Root level="info">
<AppenderRef ref="Console"/>
</Root>
</Loggers>
</Configuration>
......@@ -58,11 +58,11 @@ public class AlarmQuery implements Query {
switch (alarmType) {
case APPLICATION:
return getAlarmService().loadApplicationAlarmList(keyword, startTimeBucket, endTimeBucket, page.getLimit(), page.getFrom());
return getAlarmService().loadApplicationAlarmList(keyword, duration.getStep(), startTimeBucket, endTimeBucket, page.getLimit(), page.getFrom());
case SERVER:
return getAlarmService().loadInstanceAlarmList(keyword, startTimeBucket, endTimeBucket, page.getLimit(), page.getFrom());
return getAlarmService().loadInstanceAlarmList(keyword, duration.getStep(), startTimeBucket, endTimeBucket, page.getLimit(), page.getFrom());
case SERVICE:
return getAlarmService().loadServiceAlarmList(keyword, startTimeBucket, endTimeBucket, page.getLimit(), page.getFrom());
return getAlarmService().loadServiceAlarmList(keyword, duration.getStep(), startTimeBucket, endTimeBucket, page.getLimit(), page.getFrom());
default:
return new Alarm();
}
......
......@@ -65,11 +65,11 @@ public class TraceQuery implements Query {
long endSecondTimeBucket = 0;
String traceId = Const.EMPTY_STRING;
if (ObjectUtils.isNotEmpty(condition.getQueryDuration())) {
if (StringUtils.isNotEmpty(condition.getTraceId())) {
traceId = condition.getTraceId();
} else if (ObjectUtils.isNotEmpty(condition.getQueryDuration())) {
startSecondTimeBucket = DurationUtils.INSTANCE.durationToSecondTimeBucket(condition.getQueryDuration().getStep(), condition.getQueryDuration().getStart());
endSecondTimeBucket = DurationUtils.INSTANCE.durationToSecondTimeBucket(condition.getQueryDuration().getStep(), condition.getQueryDuration().getEnd());
} else if (StringUtils.isNotEmpty(condition.getTraceId())) {
traceId = condition.getTraceId();
} else {
throw new UnexpectedException("The condition must contains either queryDuration or traceId.");
}
......
......@@ -32,6 +32,7 @@ import org.apache.skywalking.apm.collector.core.util.Const;
import org.apache.skywalking.apm.collector.storage.StorageModule;
import org.apache.skywalking.apm.collector.storage.dao.ui.IApplicationAlarmListUIDAO;
import org.apache.skywalking.apm.collector.storage.dao.ui.IApplicationAlarmUIDAO;
import org.apache.skywalking.apm.collector.storage.dao.ui.IApplicationMappingUIDAO;
import org.apache.skywalking.apm.collector.storage.dao.ui.IInstanceAlarmUIDAO;
import org.apache.skywalking.apm.collector.storage.dao.ui.IInstanceUIDAO;
import org.apache.skywalking.apm.collector.storage.dao.ui.IServiceAlarmUIDAO;
......@@ -56,6 +57,7 @@ public class AlarmService {
private final Gson gson = new Gson();
private final IInstanceUIDAO instanceDAO;
private final IApplicationAlarmUIDAO applicationAlarmUIDAO;
private final IApplicationMappingUIDAO applicationMappingUIDAO;
private final IInstanceAlarmUIDAO instanceAlarmUIDAO;
private final IServiceAlarmUIDAO serviceAlarmUIDAO;
private final IApplicationAlarmListUIDAO applicationAlarmListUIDAO;
......@@ -67,6 +69,7 @@ public class AlarmService {
public AlarmService(ModuleManager moduleManager) {
this.instanceDAO = moduleManager.find(StorageModule.NAME).getService(IInstanceUIDAO.class);
this.applicationAlarmUIDAO = moduleManager.find(StorageModule.NAME).getService(IApplicationAlarmUIDAO.class);
this.applicationMappingUIDAO = moduleManager.find(StorageModule.NAME).getService(IApplicationMappingUIDAO.class);
this.instanceAlarmUIDAO = moduleManager.find(StorageModule.NAME).getService(IInstanceAlarmUIDAO.class);
this.serviceAlarmUIDAO = moduleManager.find(StorageModule.NAME).getService(IServiceAlarmUIDAO.class);
this.applicationAlarmListUIDAO = moduleManager.find(StorageModule.NAME).getService(IApplicationAlarmListUIDAO.class);
......@@ -74,12 +77,16 @@ public class AlarmService {
this.serviceNameCacheService = moduleManager.find(CacheModule.NAME).getService(ServiceNameCacheService.class);
}
public Alarm loadApplicationAlarmList(String keyword, long startTimeBucket, long endTimeBucket,
public Alarm loadApplicationAlarmList(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 = applicationAlarmUIDAO.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 -> {
String applicationCode = applicationCacheService.getApplicationById(item.getId()).getApplicationCode();
String applicationCode = applicationCacheService.getApplicationById(mappings.getOrDefault(item.getId(), item.getId())).getApplicationCode();
switch (item.getCauseType()) {
case SLOW_RESPONSE:
item.setTitle("Application " + applicationCode + RESPONSE_TIME_ALARM);
......@@ -92,13 +99,18 @@ public class AlarmService {
return alarm;
}
public Alarm loadInstanceAlarmList(String keyword, long startTimeBucket, long endTimeBucket,
public Alarm loadInstanceAlarmList(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 = instanceAlarmUIDAO.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 -> {
Instance instance = instanceDAO.getInstance(item.getId());
String applicationCode = applicationCacheService.getApplicationById(instance.getApplicationId()).getApplicationCode();
String applicationCode = applicationCacheService.getApplicationById(mappings.getOrDefault(instance.getApplicationId(), instance.getApplicationId())).getApplicationCode();
String serverName = buildServerName(instance.getOsInfo());
switch (item.getCauseType()) {
case SLOW_RESPONSE:
......@@ -113,13 +125,18 @@ public class AlarmService {
return alarm;
}
public Alarm loadServiceAlarmList(String keyword, long startTimeBucket, long endTimeBucket,
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(serviceName.getApplicationId()).getApplicationCode();
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);
......@@ -146,7 +163,11 @@ public class AlarmService {
AlarmTrend alarmTrend = new AlarmTrend();
durationPoints.forEach(durationPoint -> {
alarmTrend.getNumOfAlarmRate().add((trendsMap.getOrDefault(durationPoint.getPoint(), 0) * 10000) / (applications.size()));
if (applications.size() == 0) {
alarmTrend.getNumOfAlarmRate().add(0);
} else {
alarmTrend.getNumOfAlarmRate().add((trendsMap.getOrDefault(durationPoint.getPoint(), 0) * 10000) / (applications.size()));
}
});
return alarmTrend;
}
......
......@@ -82,6 +82,6 @@ public class ApplicationTopologyService {
TopologyBuilder builder = new TopologyBuilder(moduleManager);
return builder.build(applicationComponents, applicationMappings, applicationMetrics, callerReferenceMetric, calleeReferenceMetric, startTimeBucket, endTimeBucket, startSecondTimeBucket, endSecondTimeBucket);
return builder.build(applicationComponents, applicationMappings, applicationMetrics, callerReferenceMetric, calleeReferenceMetric, step, startTimeBucket, endTimeBucket, startSecondTimeBucket, endSecondTimeBucket);
}
}
......@@ -72,6 +72,6 @@ public class ClusterTopologyService {
TopologyBuilder builder = new TopologyBuilder(moduleManager);
return builder.build(applicationComponents, applicationMappings, applicationMetrics, callerReferenceMetric, calleeReferenceMetric, startTimeBucket, endTimeBucket, startSecondTimeBucket, endSecondTimeBucket);
return builder.build(applicationComponents, applicationMappings, applicationMetrics, callerReferenceMetric, calleeReferenceMetric, step, startTimeBucket, endTimeBucket, startSecondTimeBucket, endSecondTimeBucket);
}
}
......@@ -26,6 +26,7 @@ import java.util.LinkedList;
import java.util.List;
import org.apache.skywalking.apm.collector.cache.CacheModule;
import org.apache.skywalking.apm.collector.cache.service.ApplicationCacheService;
import org.apache.skywalking.apm.collector.cache.service.InstanceCacheService;
import org.apache.skywalking.apm.collector.core.module.ModuleManager;
import org.apache.skywalking.apm.collector.core.util.Const;
import org.apache.skywalking.apm.collector.core.util.StringUtils;
......@@ -59,6 +60,7 @@ public class ServerService {
private final IGCMetricUIDAO gcMetricUIDAO;
private final IMemoryMetricUIDAO memoryMetricUIDAO;
private final ApplicationCacheService applicationCacheService;
private final InstanceCacheService instanceCacheService;
private final SecondBetweenService secondBetweenService;
public ServerService(ModuleManager moduleManager) {
......@@ -68,6 +70,7 @@ public class ServerService {
this.gcMetricUIDAO = moduleManager.find(StorageModule.NAME).getService(IGCMetricUIDAO.class);
this.memoryMetricUIDAO = moduleManager.find(StorageModule.NAME).getService(IMemoryMetricUIDAO.class);
this.applicationCacheService = moduleManager.find(CacheModule.NAME).getService(ApplicationCacheService.class);
this.instanceCacheService = moduleManager.find(CacheModule.NAME).getService(InstanceCacheService.class);
this.secondBetweenService = new SecondBetweenService(moduleManager);
}
......@@ -105,7 +108,8 @@ public class ServerService {
List<AppServerInfo> serverThroughput = instanceMetricUIDAO.getServerThroughput(applicationId, step, startTimeBucket, endTimeBucket, secondBetween, topN, MetricSource.Callee);
serverThroughput.forEach(appServerInfo -> {
String applicationCode = applicationCacheService.getApplicationById(applicationId).getApplicationCode();
appServerInfo.setApplicationId(instanceCacheService.getApplicationId(appServerInfo.getId()));
String applicationCode = applicationCacheService.getApplicationById(appServerInfo.getApplicationId()).getApplicationCode();
appServerInfo.setApplicationCode(applicationCode);
Instance instance = instanceUIDAO.getInstance(appServerInfo.getId());
appServerInfo.setOsInfo(instance.getOsInfo());
......
......@@ -20,9 +20,11 @@ package org.apache.skywalking.apm.collector.ui.service;
import java.text.ParseException;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Set;
import org.apache.skywalking.apm.collector.cache.CacheModule;
import org.apache.skywalking.apm.collector.cache.service.ApplicationCacheService;
import org.apache.skywalking.apm.collector.core.module.ModuleManager;
......@@ -38,6 +40,7 @@ import org.apache.skywalking.apm.collector.storage.ui.application.ApplicationNod
import org.apache.skywalking.apm.collector.storage.ui.application.ConjecturalNode;
import org.apache.skywalking.apm.collector.storage.ui.common.Call;
import org.apache.skywalking.apm.collector.storage.ui.common.Node;
import org.apache.skywalking.apm.collector.storage.ui.common.Step;
import org.apache.skywalking.apm.collector.storage.ui.common.Topology;
import org.apache.skywalking.apm.collector.storage.ui.common.VisualUserNode;
import org.apache.skywalking.apm.collector.ui.utils.ApdexCalculator;
......@@ -70,7 +73,7 @@ class TopologyBuilder {
List<IApplicationMetricUIDAO.ApplicationMetric> applicationMetrics,
List<IApplicationReferenceMetricUIDAO.ApplicationReferenceMetric> callerReferenceMetric,
List<IApplicationReferenceMetricUIDAO.ApplicationReferenceMetric> calleeReferenceMetric,
long startTimeBucket, long endTimeBucket, long startSecondTimeBucket, long endSecondTimeBucket) {
Step step, long startTimeBucket, long endTimeBucket, long startSecondTimeBucket, long endSecondTimeBucket) {
Map<Integer, String> components = changeNodeComp2Map(applicationComponents);
Map<Integer, Integer> mappings = changeMapping2Map(applicationMappings);
......@@ -95,7 +98,7 @@ class TopologyBuilder {
applicationNode.setApdex(ApdexCalculator.INSTANCE.calculate(applicationMetric.getSatisfiedCount(), applicationMetric.getToleratingCount(), applicationMetric.getFrustratedCount()));
applicationNode.setAlarm(false);
try {
Alarm alarm = alarmService.loadApplicationAlarmList(Const.EMPTY_STRING, startTimeBucket, endTimeBucket, 1, 0);
Alarm alarm = alarmService.loadApplicationAlarmList(Const.EMPTY_STRING, step, startTimeBucket, endTimeBucket, 1, 0);
if (alarm.getItems().size() > 0) {
applicationNode.setAlarm(true);
}
......@@ -105,14 +108,14 @@ class TopologyBuilder {
applicationNode.setNumOfServer(serverService.getAllServer(applicationId, startSecondTimeBucket, endSecondTimeBucket).size());
try {
Alarm alarm = alarmService.loadInstanceAlarmList(Const.EMPTY_STRING, startTimeBucket, endTimeBucket, 1000, 0);
Alarm alarm = alarmService.loadInstanceAlarmList(Const.EMPTY_STRING, step, startTimeBucket, endTimeBucket, 1000, 0);
applicationNode.setNumOfServerAlarm(alarm.getItems().size());
} catch (ParseException e) {
logger.error(e.getMessage(), e);
}
try {
Alarm alarm = alarmService.loadServiceAlarmList(Const.EMPTY_STRING, startTimeBucket, endTimeBucket, 1000, 0);
Alarm alarm = alarmService.loadServiceAlarmList(Const.EMPTY_STRING, step, startTimeBucket, endTimeBucket, 1000, 0);
applicationNode.setNumOfServiceAlarm(alarm.getItems().size());
} catch (ParseException e) {
logger.error(e.getMessage(), e);
......@@ -133,6 +136,17 @@ class TopologyBuilder {
nodes.add(conjecturalNode);
}
Set<Integer> nodeIds = buildNodeIds(nodes);
if (!nodeIds.contains(source.getApplicationId())) {
ApplicationNode applicationNode = new ApplicationNode();
applicationNode.setId(source.getApplicationId());
applicationNode.setName(source.getApplicationCode());
applicationNode.setType(components.getOrDefault(source.getApplicationId(), Const.UNKNOWN));
applicationNode.setApdex(100);
applicationNode.setSla(100);
nodes.add(applicationNode);
}
Call call = new Call();
call.setSource(source.getApplicationId());
call.setSourceName(source.getApplicationCode());
......@@ -198,6 +212,12 @@ class TopologyBuilder {
return topology;
}
private Set<Integer> buildNodeIds(List<Node> nodes) {
Set<Integer> nodeIds = new HashSet<>();
nodes.forEach(node -> nodeIds.add(node.getId()));
return nodeIds;
}
private List<IApplicationReferenceMetricUIDAO.ApplicationReferenceMetric> calleeReferenceMetricFilter(
List<IApplicationReferenceMetricUIDAO.ApplicationReferenceMetric> calleeReferenceMetric) {
List<IApplicationReferenceMetricUIDAO.ApplicationReferenceMetric> filteredMetrics = new LinkedList<>();
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册