提交 9a6520fb 编写于 作者: P peng-yongsheng

Provide the application topology query, but only completed es storage.

上级 e755bba3
......@@ -46,6 +46,23 @@
}
],
"lo": []
},
{
"si": 1,
"tv": 1,
"lv": 1,
"ps": 0,
"st": 1501858094726,
"et": 1501858095804,
"ci": 9,
"cn": "",
"oi": 0,
"on": "mongodb://[username:password@]host1[:port1][,host2[:port2],...[,hostN[:portN]]][/[database][?options]]",
"pi": 0,
"pn": "localhost:27017",
"ie": false,
"to": [],
"lo": []
}
]
}
......
......@@ -18,7 +18,7 @@
package org.apache.skywalking.apm.collector.analysis.alarm.provider.worker;
import org.apache.skywalking.apm.collector.analysis.metric.define.MetricSource;
import org.apache.skywalking.apm.collector.storage.table.MetricSource;
import org.apache.skywalking.apm.collector.analysis.worker.model.base.AbstractLocalAsyncWorker;
import org.apache.skywalking.apm.collector.analysis.worker.model.base.WorkerException;
import org.apache.skywalking.apm.collector.core.data.StreamData;
......
......@@ -31,7 +31,7 @@ public class ApplicationComponentCopy {
newApplicationComponent.setMetricId(applicationComponent.getMetricId());
newApplicationComponent.setComponentId(applicationComponent.getComponentId());
newApplicationComponent.setPeerId(applicationComponent.getPeerId());
newApplicationComponent.setApplicationId(applicationComponent.getApplicationId());
newApplicationComponent.setTimeBucket(newApplicationComponent.getTimeBucket());
return newApplicationComponent;
}
......
......@@ -27,6 +27,8 @@ import org.apache.skywalking.apm.collector.analysis.segment.parser.define.listen
import org.apache.skywalking.apm.collector.analysis.segment.parser.define.listener.FirstSpanListener;
import org.apache.skywalking.apm.collector.analysis.segment.parser.define.listener.SpanListener;
import org.apache.skywalking.apm.collector.analysis.segment.parser.define.listener.SpanListenerFactory;
import org.apache.skywalking.apm.collector.cache.CacheModule;
import org.apache.skywalking.apm.collector.cache.service.ApplicationCacheService;
import org.apache.skywalking.apm.collector.core.graph.Graph;
import org.apache.skywalking.apm.collector.core.graph.GraphManager;
import org.apache.skywalking.apm.collector.core.module.ModuleManager;
......@@ -39,17 +41,24 @@ import org.apache.skywalking.apm.collector.storage.table.application.Application
*/
public class ApplicationComponentSpanListener implements EntrySpanListener, ExitSpanListener, FirstSpanListener {
private final ApplicationCacheService applicationCacheService;
private List<ApplicationComponent> applicationComponents = new ArrayList<>();
private long timeBucket;
ApplicationComponentSpanListener(ModuleManager moduleManager) {
this.applicationCacheService = moduleManager.find(CacheModule.NAME).getService(ApplicationCacheService.class);
}
@Override
public void parseExit(SpanDecorator spanDecorator, int applicationId, int instanceId, String segmentId) {
String metricId = spanDecorator.getPeerId() + Const.ID_SPLIT + String.valueOf(spanDecorator.getComponentId());
int applicationIdFromPeerId = applicationCacheService.getApplicationIdByAddressId(spanDecorator.getPeerId());
String metricId = applicationIdFromPeerId + Const.ID_SPLIT + String.valueOf(spanDecorator.getComponentId());
ApplicationComponent applicationComponent = new ApplicationComponent();
applicationComponent.setMetricId(metricId);
applicationComponent.setComponentId(spanDecorator.getComponentId());
applicationComponent.setPeerId(spanDecorator.getPeerId());
applicationComponent.setApplicationId(applicationIdFromPeerId);
applicationComponents.add(applicationComponent);
}
......@@ -60,7 +69,7 @@ public class ApplicationComponentSpanListener implements EntrySpanListener, Exit
ApplicationComponent applicationComponent = new ApplicationComponent();
applicationComponent.setMetricId(metricId);
applicationComponent.setComponentId(spanDecorator.getComponentId());
applicationComponent.setPeerId(applicationId);
applicationComponent.setApplicationId(applicationId);
applicationComponents.add(applicationComponent);
}
......@@ -82,7 +91,7 @@ public class ApplicationComponentSpanListener implements EntrySpanListener, Exit
public static class Factory implements SpanListenerFactory {
@Override public SpanListener create(ModuleManager moduleManager) {
return new ApplicationComponentSpanListener();
return new ApplicationComponentSpanListener(moduleManager);
}
}
}
......@@ -32,7 +32,7 @@ public class ApplicationMappingCopy {
newApplicationMapping.setTimeBucket(applicationMapping.getTimeBucket());
newApplicationMapping.setApplicationId(applicationMapping.getApplicationId());
newApplicationMapping.setAddressId(applicationMapping.getAddressId());
newApplicationMapping.setMappingApplicationId(applicationMapping.getMappingApplicationId());
return newApplicationMapping;
}
}
......@@ -26,6 +26,8 @@ import org.apache.skywalking.apm.collector.analysis.segment.parser.define.listen
import org.apache.skywalking.apm.collector.analysis.segment.parser.define.listener.FirstSpanListener;
import org.apache.skywalking.apm.collector.analysis.segment.parser.define.listener.SpanListener;
import org.apache.skywalking.apm.collector.analysis.segment.parser.define.listener.SpanListenerFactory;
import org.apache.skywalking.apm.collector.cache.CacheModule;
import org.apache.skywalking.apm.collector.cache.service.ApplicationCacheService;
import org.apache.skywalking.apm.collector.core.graph.Graph;
import org.apache.skywalking.apm.collector.core.graph.GraphManager;
import org.apache.skywalking.apm.collector.core.module.ModuleManager;
......@@ -42,18 +44,26 @@ public class ApplicationMappingSpanListener implements FirstSpanListener, EntryS
private final Logger logger = LoggerFactory.getLogger(ApplicationMappingSpanListener.class);
private final ApplicationCacheService applicationCacheService;
private List<ApplicationMapping> applicationMappings = new LinkedList<>();
private long timeBucket;
ApplicationMappingSpanListener(ModuleManager moduleManager) {
this.applicationCacheService = moduleManager.find(CacheModule.NAME).getService(ApplicationCacheService.class);
}
@Override public void parseEntry(SpanDecorator spanDecorator, int applicationId, int instanceId, String segmentId) {
logger.debug("application mapping listener parse reference");
if (spanDecorator.getRefsCount() > 0) {
for (int i = 0; i < spanDecorator.getRefsCount(); i++) {
ApplicationMapping applicationMapping = new ApplicationMapping();
applicationMapping.setApplicationId(applicationId);
applicationMapping.setAddressId(spanDecorator.getRefs(i).getNetworkAddressId());
String metricId = String.valueOf(applicationId) + Const.ID_SPLIT + String.valueOf(applicationMapping.getAddressId());
int addressId = spanDecorator.getRefs(i).getNetworkAddressId();
int mappingApplicationId = applicationCacheService.getApplicationIdByAddressId(addressId);
applicationMapping.setMappingApplicationId(mappingApplicationId);
String metricId = String.valueOf(applicationId) + Const.ID_SPLIT + String.valueOf(applicationMapping.getMappingApplicationId());
applicationMapping.setMetricId(metricId);
applicationMappings.add(applicationMapping);
}
......@@ -79,7 +89,7 @@ public class ApplicationMappingSpanListener implements FirstSpanListener, EntryS
public static class Factory implements SpanListenerFactory {
@Override public SpanListener create(ModuleManager moduleManager) {
return new ApplicationMappingSpanListener();
return new ApplicationMappingSpanListener(moduleManager);
}
}
}
......@@ -20,7 +20,7 @@ package org.apache.skywalking.apm.collector.analysis.metric.provider.worker.serv
import java.util.LinkedList;
import java.util.List;
import org.apache.skywalking.apm.collector.analysis.metric.define.MetricSource;
import org.apache.skywalking.apm.collector.storage.table.MetricSource;
import org.apache.skywalking.apm.collector.analysis.metric.define.graph.MetricGraphIdDefine;
import org.apache.skywalking.apm.collector.analysis.segment.parser.define.decorator.ReferenceDecorator;
import org.apache.skywalking.apm.collector.analysis.segment.parser.define.decorator.SpanDecorator;
......
......@@ -19,7 +19,6 @@
package org.apache.skywalking.apm.collector.analysis.segment.parser.provider.parser.standardization;
import org.apache.skywalking.apm.collector.analysis.register.define.AnalysisRegisterModule;
import org.apache.skywalking.apm.collector.analysis.register.define.service.IApplicationIDService;
import org.apache.skywalking.apm.collector.analysis.register.define.service.INetworkAddressIDService;
import org.apache.skywalking.apm.collector.analysis.register.define.service.IServiceNameService;
import org.apache.skywalking.apm.collector.analysis.segment.parser.define.decorator.ReferenceDecorator;
......@@ -39,7 +38,6 @@ public class ReferenceIdExchanger implements IdExchanger<ReferenceDecorator> {
private final Logger logger = LoggerFactory.getLogger(ReferenceIdExchanger.class);
private static ReferenceIdExchanger EXCHANGER;
private final IApplicationIDService applicationIDService;
private final IServiceNameService serviceNameService;
private final InstanceCacheService instanceCacheService;
private final INetworkAddressIDService networkAddressIDService;
......@@ -52,7 +50,6 @@ public class ReferenceIdExchanger implements IdExchanger<ReferenceDecorator> {
}
private ReferenceIdExchanger(ModuleManager moduleManager) {
this.applicationIDService = moduleManager.find(AnalysisRegisterModule.NAME).getService(IApplicationIDService.class);
this.serviceNameService = moduleManager.find(AnalysisRegisterModule.NAME).getService(IServiceNameService.class);
this.networkAddressIDService = moduleManager.find(AnalysisRegisterModule.NAME).getService(INetworkAddressIDService.class);
this.instanceCacheService = moduleManager.find(CacheModule.NAME).getService(InstanceCacheService.class);
......
......@@ -19,6 +19,7 @@
package org.apache.skywalking.apm.collector.cache.service;
import org.apache.skywalking.apm.collector.core.module.Service;
import org.apache.skywalking.apm.collector.storage.table.register.Application;
/**
* @author peng-yongsheng
......@@ -26,7 +27,7 @@ import org.apache.skywalking.apm.collector.core.module.Service;
public interface ApplicationCacheService extends Service {
int getApplicationIdByCode(String applicationCode);
String getApplicationCodeById(int applicationId);
Application getApplicationById(int applicationId);
int getApplicationIdByAddressId(int addressId);
}
......@@ -22,11 +22,10 @@ import com.google.common.cache.Cache;
import com.google.common.cache.CacheBuilder;
import org.apache.skywalking.apm.collector.cache.service.ApplicationCacheService;
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.ObjectUtils;
import org.apache.skywalking.apm.collector.core.util.StringUtils;
import org.apache.skywalking.apm.collector.storage.StorageModule;
import org.apache.skywalking.apm.collector.storage.dao.cache.IApplicationCacheDAO;
import org.apache.skywalking.apm.collector.storage.table.register.Application;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
......@@ -70,23 +69,23 @@ public class ApplicationCacheGuavaService implements ApplicationCacheService {
return applicationId;
}
private final Cache<Integer, String> idCache = CacheBuilder.newBuilder().maximumSize(1000).build();
private final Cache<Integer, Application> applicationCache = CacheBuilder.newBuilder().maximumSize(1000).build();
@Override public String getApplicationCodeById(int applicationId) {
String applicationCode = Const.EMPTY_STRING;
@Override public Application getApplicationById(int applicationId) {
Application application = null;
try {
applicationCode = idCache.get(applicationId, () -> getApplicationCacheDAO().getApplicationCode(applicationId));
application = applicationCache.get(applicationId, () -> getApplicationCacheDAO().getApplication(applicationId));
} catch (Throwable e) {
logger.error(e.getMessage(), e);
}
if (StringUtils.isEmpty(applicationCode)) {
applicationCode = getApplicationCacheDAO().getApplicationCode(applicationId);
if (StringUtils.isNotEmpty(applicationCode)) {
codeCache.put(applicationCode, applicationId);
if (ObjectUtils.isEmpty(application)) {
application = getApplicationCacheDAO().getApplication(applicationId);
if (ObjectUtils.isNotEmpty(application)) {
applicationCache.put(applicationId, application);
}
}
return applicationCode;
return application;
}
private final Cache<Integer, Integer> addressIdCache = CacheBuilder.newBuilder().maximumSize(1000).build();
......
......@@ -36,5 +36,10 @@
<artifactId>gson</artifactId>
<version>2.8.1</version>
</dependency>
<dependency>
<groupId>joda-time</groupId>
<artifactId>joda-time</artifactId>
<version>2.9.9</version>
</dependency>
</dependencies>
</project>
......@@ -27,37 +27,37 @@ import java.util.Calendar;
public enum TimeBucketUtils {
INSTANCE;
private final SimpleDateFormat monthDateFormat = new SimpleDateFormat("yyyyMM");
private final SimpleDateFormat dayDateFormat = new SimpleDateFormat("yyyyMMdd");
private final SimpleDateFormat hourDateFormat = new SimpleDateFormat("yyyyMMddHH");
private final SimpleDateFormat minuteDateFormat = new SimpleDateFormat("yyyyMMddHHmm");
private final SimpleDateFormat secondDateFormat = new SimpleDateFormat("yyyyMMddHHmmss");
public static final SimpleDateFormat MONTH_DATE_FORMAT = new SimpleDateFormat("yyyyMM");
public static final SimpleDateFormat DAY_DATE_FORMAT = new SimpleDateFormat("yyyyMMdd");
public static final SimpleDateFormat HOUR_DATE_FORMAT = new SimpleDateFormat("yyyyMMddHH");
public static final SimpleDateFormat MINUTE_DATE_FORMAT = new SimpleDateFormat("yyyyMMddHHmm");
public static final SimpleDateFormat SECOND_DATE_FORMAT = new SimpleDateFormat("yyyyMMddHHmmss");
public long getMinuteTimeBucket(long time) {
Calendar calendar = Calendar.getInstance();
calendar.setTimeInMillis(time);
String timeStr = minuteDateFormat.format(calendar.getTime());
String timeStr = MINUTE_DATE_FORMAT.format(calendar.getTime());
return Long.valueOf(timeStr);
}
public long getSecondTimeBucket(long time) {
Calendar calendar = Calendar.getInstance();
calendar.setTimeInMillis(time);
String timeStr = secondDateFormat.format(calendar.getTime());
String timeStr = SECOND_DATE_FORMAT.format(calendar.getTime());
return Long.valueOf(timeStr);
}
public long getHourTimeBucket(long time) {
Calendar calendar = Calendar.getInstance();
calendar.setTimeInMillis(time);
String timeStr = hourDateFormat.format(calendar.getTime()) + "00";
String timeStr = HOUR_DATE_FORMAT.format(calendar.getTime()) + "00";
return Long.valueOf(timeStr);
}
public long getDayTimeBucket(long time) {
Calendar calendar = Calendar.getInstance();
calendar.setTimeInMillis(time);
String timeStr = dayDateFormat.format(calendar.getTime()) + "0000";
String timeStr = DAY_DATE_FORMAT.format(calendar.getTime()) + "0000";
return Long.valueOf(timeStr);
}
......
......@@ -18,12 +18,35 @@
package org.apache.skywalking.apm.collector.storage.dao;
import com.google.gson.JsonArray;
import java.util.List;
import org.apache.skywalking.apm.collector.storage.base.dao.DAO;
import org.apache.skywalking.apm.collector.storage.ui.common.Step;
/**
* @author peng-yongsheng
*/
public interface IApplicationComponentUIDAO extends DAO {
JsonArray load(long startTime, long endTime);
List<ApplicationComponent> load(Step step, long startTime, long endTime);
class ApplicationComponent {
private int componentId;
private int applicationId;
public int getComponentId() {
return componentId;
}
public void setComponentId(int componentId) {
this.componentId = componentId;
}
public int getApplicationId() {
return applicationId;
}
public void setApplicationId(int applicationId) {
this.applicationId = applicationId;
}
}
}
......@@ -18,12 +18,34 @@
package org.apache.skywalking.apm.collector.storage.dao;
import com.google.gson.JsonArray;
import java.util.List;
import org.apache.skywalking.apm.collector.storage.base.dao.DAO;
import org.apache.skywalking.apm.collector.storage.ui.common.Step;
/**
* @author peng-yongsheng
*/
public interface IApplicationMappingUIDAO extends DAO {
JsonArray load(long startTime, long endTime);
List<ApplicationMapping> load(Step step, long startTime, long endTime);
class ApplicationMapping {
private int applicationId;
private int mappingApplicationId;
public int getApplicationId() {
return applicationId;
}
public void setApplicationId(int applicationId) {
this.applicationId = applicationId;
}
public int getMappingApplicationId() {
return mappingApplicationId;
}
public void setMappingApplicationId(int mappingApplicationId) {
this.mappingApplicationId = mappingApplicationId;
}
}
}
......@@ -18,12 +18,19 @@
package org.apache.skywalking.apm.collector.storage.dao;
import com.google.gson.JsonArray;
import java.util.List;
import org.apache.skywalking.apm.collector.storage.base.dao.DAO;
import org.apache.skywalking.apm.collector.storage.table.MetricSource;
import org.apache.skywalking.apm.collector.storage.ui.common.Call;
import org.apache.skywalking.apm.collector.storage.ui.common.Step;
/**
* @author peng-yongsheng
*/
public interface IApplicationReferenceMetricUIDAO extends DAO {
JsonArray load(long startTime, long endTime);
List<Call> getFrontApplications(Step step, int applicationId, long startTime, long endTime,
MetricSource metricSource);
List<Call> getBehindApplications(Step step, int applicationId, long startTime, long endTime,
MetricSource metricSource);
}
......@@ -31,7 +31,7 @@ public interface IInstanceUIDAO extends DAO {
Long instanceLastHeartBeatTime(long applicationInstanceId);
List<Application> getApplications(long startTime, long endTime);
List<Application> getApplications(long startTime, long endTime, int... applicationIds);
Instance getInstance(int instanceId);
......
......@@ -19,6 +19,7 @@
package org.apache.skywalking.apm.collector.storage.dao.cache;
import org.apache.skywalking.apm.collector.storage.base.dao.DAO;
import org.apache.skywalking.apm.collector.storage.table.register.Application;
/**
* @author peng-yongsheng
......@@ -26,7 +27,7 @@ import org.apache.skywalking.apm.collector.storage.base.dao.DAO;
public interface IApplicationCacheDAO extends DAO {
int getApplicationIdByCode(String applicationCode);
String getApplicationCode(int applicationId);
Application getApplication(int applicationId);
int getApplicationIdByAddressId(int addressId);
}
/*
* 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.storage.table;
/**
* @author peng-yongsheng
*/
public enum MetricSource {
Caller(0), Callee(1);
private final int value;
private MetricSource(int value) {
this.value = value;
}
public int getValue() {
return value;
}
}
......@@ -41,7 +41,7 @@ public class ApplicationComponent extends StreamData {
private static final Column[] INTEGER_COLUMNS = {
new Column(ApplicationComponentTable.COLUMN_COMPONENT_ID, new CoverOperation()),
new Column(ApplicationComponentTable.COLUMN_PEER_ID, new CoverOperation()),
new Column(ApplicationComponentTable.COLUMN_APPLICATION_ID, new CoverOperation()),
};
private static final Column[] BYTE_COLUMNS = {};
......@@ -82,11 +82,11 @@ public class ApplicationComponent extends StreamData {
setDataInteger(0, componentId);
}
public Integer getPeerId() {
public Integer getApplicationId() {
return getDataInteger(1);
}
public void setPeerId(Integer peerId) {
setDataInteger(1, peerId);
public void setApplicationId(Integer applicationId) {
setDataInteger(1, applicationId);
}
}
......@@ -16,7 +16,6 @@
*
*/
package org.apache.skywalking.apm.collector.storage.table.application;
import org.apache.skywalking.apm.collector.core.data.CommonTable;
......@@ -27,5 +26,5 @@ import org.apache.skywalking.apm.collector.core.data.CommonTable;
public class ApplicationComponentTable extends CommonTable {
public static final String TABLE = "application_component";
public static final String COLUMN_COMPONENT_ID = "component_id";
public static final String COLUMN_PEER_ID = "peer_id";
public static final String COLUMN_APPLICATION_ID = "application_id";
}
......@@ -41,7 +41,7 @@ public class ApplicationMapping extends StreamData {
private static final Column[] INTEGER_COLUMNS = {
new Column(ApplicationMappingTable.COLUMN_APPLICATION_ID, new CoverOperation()),
new Column(ApplicationMappingTable.COLUMN_ADDRESS_ID, new CoverOperation()),
new Column(ApplicationMappingTable.COLUMN_MAPPING_APPLICATION_ID, new CoverOperation()),
};
private static final Column[] BYTE_COLUMNS = {};
......@@ -74,12 +74,12 @@ public class ApplicationMapping extends StreamData {
setDataInteger(0, applicationId);
}
public int getAddressId() {
public int getMappingApplicationId() {
return getDataInteger(1);
}
public void setAddressId(int addressId) {
setDataInteger(1, addressId);
public void setMappingApplicationId(int mappingApplicationId) {
setDataInteger(1, mappingApplicationId);
}
public long getTimeBucket() {
......
......@@ -16,7 +16,6 @@
*
*/
package org.apache.skywalking.apm.collector.storage.table.application;
import org.apache.skywalking.apm.collector.core.data.CommonTable;
......@@ -27,5 +26,5 @@ import org.apache.skywalking.apm.collector.core.data.CommonTable;
public class ApplicationMappingTable extends CommonTable {
public static final String TABLE = "application_mapping";
public static final String COLUMN_APPLICATION_ID = "application_id";
public static final String COLUMN_ADDRESS_ID = "address_id";
public static final String COLUMN_MAPPING_APPLICATION_ID = "mapping_application_id";
}
......@@ -28,7 +28,6 @@ public class ApplicationNode extends Node {
private Float sla;
private Long callsPerSec;
private Integer responseTimePerSec;
private Long calls;
private Float apdex;
private Boolean isAlarm;
private Integer numOfServer;
......@@ -59,14 +58,6 @@ public class ApplicationNode extends Node {
this.responseTimePerSec = responseTimePerSec;
}
public Long getCalls() {
return calls;
}
public void setCalls(Long calls) {
this.calls = calls;
}
public Float getApdex() {
return apdex;
}
......
......@@ -22,10 +22,94 @@ package org.apache.skywalking.apm.collector.storage.ui.common;
* @author peng-yongsheng
*/
public class Call {
private String source;
private String target;
private Boolean isAlert;
private int source;
private String sourceName;
private int target;
private String targetName;
private boolean isAlert;
private String callType;
private Integer callsPerSec;
private Integer responseTimePerSec;
private int calls;
private int callsPerSec;
private long responseTimes;
private int responseTimePerSec;
public int getSource() {
return source;
}
public void setSource(int source) {
this.source = source;
}
public String getSourceName() {
return sourceName;
}
public void setSourceName(String sourceName) {
this.sourceName = sourceName;
}
public int getTarget() {
return target;
}
public void setTarget(int target) {
this.target = target;
}
public String getTargetName() {
return targetName;
}
public void setTargetName(String targetName) {
this.targetName = targetName;
}
public boolean isAlert() {
return isAlert;
}
public void setAlert(boolean alert) {
isAlert = alert;
}
public String getCallType() {
return callType;
}
public void setCallType(String callType) {
this.callType = callType;
}
public int getCalls() {
return calls;
}
public void setCalls(int calls) {
this.calls = calls;
}
public int getCallsPerSec() {
return callsPerSec;
}
public void setCallsPerSec(int callsPerSec) {
this.callsPerSec = callsPerSec;
}
public long getResponseTimes() {
return responseTimes;
}
public void setResponseTimes(long responseTimes) {
this.responseTimes = responseTimes;
}
public int getResponseTimePerSec() {
return responseTimePerSec;
}
public void setResponseTimePerSec(int responseTimePerSec) {
this.responseTimePerSec = responseTimePerSec;
}
}
......@@ -22,15 +22,15 @@ package org.apache.skywalking.apm.collector.storage.ui.common;
* @author peng-yongsheng
*/
public abstract class Node {
private String id;
private int id;
private String name;
private String type;
public String getId() {
public int getId() {
return id;
}
public void setId(String id) {
public void setId(int id) {
this.id = id;
}
......
......@@ -24,6 +24,23 @@ import java.util.List;
* @author peng-yongsheng
*/
public class Topology {
private List<Node> nodes;
private List<Call> calls;
public List<Node> getNodes() {
return nodes;
}
public void setNodes(List<Node> nodes) {
this.nodes = nodes;
}
public List<Call> getCalls() {
return calls;
}
public void setCalls(List<Call> calls) {
this.calls = calls;
}
}
/*
* 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.storage.utils;
import org.apache.skywalking.apm.collector.core.storage.TimePyramid;
import org.apache.skywalking.apm.collector.core.util.Const;
import org.apache.skywalking.apm.collector.storage.ui.common.Step;
/**
* @author peng-yongsheng
*/
public class TimePyramidTableNameBuilder {
private TimePyramidTableNameBuilder() {
}
public static String build(Step step, String tableName) {
switch (step) {
case MONTH:
tableName = tableName + Const.ID_SPLIT + TimePyramid.Month.getName();
break;
case DAY:
tableName = tableName + Const.ID_SPLIT + TimePyramid.Day.getName();
break;
case HOUR:
tableName = tableName + Const.ID_SPLIT + TimePyramid.Day.getName();
break;
case MINUTE:
tableName = tableName + Const.ID_SPLIT + TimePyramid.Minute.getName();
break;
}
return tableName;
}
}
......@@ -18,13 +18,14 @@
package org.apache.skywalking.apm.collector.storage.es.dao;
import com.google.gson.JsonArray;
import com.google.gson.JsonObject;
import java.util.LinkedList;
import java.util.List;
import org.apache.skywalking.apm.collector.client.elasticsearch.ElasticSearchClient;
import org.apache.skywalking.apm.collector.storage.dao.IApplicationComponentUIDAO;
import org.apache.skywalking.apm.collector.storage.es.base.dao.EsDAO;
import org.apache.skywalking.apm.collector.storage.es.dao.acp.ApplicationComponentMinuteEsPersistenceDAO;
import org.apache.skywalking.apm.collector.storage.table.application.ApplicationComponentTable;
import org.apache.skywalking.apm.collector.storage.ui.common.Step;
import org.apache.skywalking.apm.collector.storage.utils.TimePyramidTableNameBuilder;
import org.elasticsearch.action.search.SearchRequestBuilder;
import org.elasticsearch.action.search.SearchResponse;
import org.elasticsearch.action.search.SearchType;
......@@ -39,51 +40,47 @@ import org.slf4j.LoggerFactory;
*/
public class ApplicationComponentEsUIDAO extends EsDAO implements IApplicationComponentUIDAO {
private final Logger logger = LoggerFactory.getLogger(ApplicationComponentMinuteEsPersistenceDAO.class);
private final Logger logger = LoggerFactory.getLogger(ApplicationComponentEsUIDAO.class);
public ApplicationComponentEsUIDAO(ElasticSearchClient client) {
super(client);
}
@Override public JsonArray load(long startTime, long endTime) {
@Override public List<ApplicationComponent> load(Step step, long startTime, long endTime) {
logger.debug("application component load, start time: {}, end time: {}", startTime, endTime);
JsonArray applicationComponentArray = new JsonArray();
applicationComponentArray.addAll(aggregationByComponentId(startTime, endTime));
return applicationComponentArray;
}
private JsonArray aggregationByComponentId(long startTime, long endTime) {
SearchRequestBuilder searchRequestBuilder = getClient().prepareSearch(ApplicationComponentTable.TABLE);
String tableName = TimePyramidTableNameBuilder.build(step, ApplicationComponentTable.TABLE);
SearchRequestBuilder searchRequestBuilder = getClient().prepareSearch(tableName);
searchRequestBuilder.setTypes(ApplicationComponentTable.TABLE_TYPE);
searchRequestBuilder.setSearchType(SearchType.DFS_QUERY_THEN_FETCH);
searchRequestBuilder.setQuery(QueryBuilders.rangeQuery(ApplicationComponentTable.COLUMN_TIME_BUCKET).gte(startTime).lte(endTime));
searchRequestBuilder.setSize(0);
searchRequestBuilder.addAggregation(AggregationBuilders.terms(ApplicationComponentTable.COLUMN_COMPONENT_ID).field(ApplicationComponentTable.COLUMN_COMPONENT_ID).size(100)
.subAggregation(AggregationBuilders.terms(ApplicationComponentTable.COLUMN_PEER_ID).field(ApplicationComponentTable.COLUMN_PEER_ID).size(100)));
.subAggregation(AggregationBuilders.terms(ApplicationComponentTable.COLUMN_APPLICATION_ID).field(ApplicationComponentTable.COLUMN_APPLICATION_ID).size(100)));
SearchResponse searchResponse = searchRequestBuilder.execute().actionGet();
Terms componentIdTerms = searchResponse.getAggregations().get(ApplicationComponentTable.COLUMN_COMPONENT_ID);
JsonArray applicationComponentArray = new JsonArray();
List<ApplicationComponent> applicationComponents = new LinkedList<>();
for (Terms.Bucket componentIdBucket : componentIdTerms.getBuckets()) {
int componentId = componentIdBucket.getKeyAsNumber().intValue();
buildComponentArray(componentIdBucket, componentId, applicationComponentArray);
buildApplicationComponents(componentIdBucket, componentId, applicationComponents);
}
return applicationComponentArray;
return applicationComponents;
}
private void buildComponentArray(Terms.Bucket componentBucket, int componentId,
JsonArray applicationComponentArray) {
Terms peerIdTerms = componentBucket.getAggregations().get(ApplicationComponentTable.COLUMN_PEER_ID);
private void buildApplicationComponents(Terms.Bucket componentBucket, int componentId,
List<ApplicationComponent> applicationComponents) {
Terms peerIdTerms = componentBucket.getAggregations().get(ApplicationComponentTable.COLUMN_APPLICATION_ID);
for (Terms.Bucket peerIdBucket : peerIdTerms.getBuckets()) {
int peerId = peerIdBucket.getKeyAsNumber().intValue();
int applicationId = peerIdBucket.getKeyAsNumber().intValue();
JsonObject applicationComponentObj = new JsonObject();
applicationComponentObj.addProperty(ApplicationComponentTable.COLUMN_COMPONENT_ID, componentId);
applicationComponentObj.addProperty(ApplicationComponentTable.COLUMN_PEER_ID, peerId);
applicationComponentArray.add(applicationComponentObj);
ApplicationComponent applicationComponent = new ApplicationComponent();
applicationComponent.setComponentId(componentId);
applicationComponent.setApplicationId(applicationId);
applicationComponents.add(applicationComponent);
}
}
}
......@@ -18,12 +18,14 @@
package org.apache.skywalking.apm.collector.storage.es.dao;
import com.google.gson.JsonArray;
import com.google.gson.JsonObject;
import java.util.LinkedList;
import java.util.List;
import org.apache.skywalking.apm.collector.client.elasticsearch.ElasticSearchClient;
import org.apache.skywalking.apm.collector.storage.dao.IApplicationMappingUIDAO;
import org.apache.skywalking.apm.collector.storage.es.base.dao.EsDAO;
import org.apache.skywalking.apm.collector.storage.table.application.ApplicationMappingTable;
import org.apache.skywalking.apm.collector.storage.ui.common.Step;
import org.apache.skywalking.apm.collector.storage.utils.TimePyramidTableNameBuilder;
import org.elasticsearch.action.search.SearchRequestBuilder;
import org.elasticsearch.action.search.SearchResponse;
import org.elasticsearch.action.search.SearchType;
......@@ -44,8 +46,10 @@ public class ApplicationMappingEsUIDAO extends EsDAO implements IApplicationMapp
super(client);
}
@Override public JsonArray load(long startTime, long endTime) {
SearchRequestBuilder searchRequestBuilder = getClient().prepareSearch(ApplicationMappingTable.TABLE);
@Override public List<ApplicationMapping> load(Step step, long startTime, long endTime) {
String tableName = TimePyramidTableNameBuilder.build(step, ApplicationMappingTable.TABLE);
SearchRequestBuilder searchRequestBuilder = getClient().prepareSearch(tableName);
searchRequestBuilder.setTypes(ApplicationMappingTable.TABLE_TYPE);
searchRequestBuilder.setSearchType(SearchType.DFS_QUERY_THEN_FETCH);
searchRequestBuilder.setQuery(QueryBuilders.rangeQuery(ApplicationMappingTable.COLUMN_TIME_BUCKET).gte(startTime).lte(endTime));
......@@ -53,24 +57,25 @@ public class ApplicationMappingEsUIDAO extends EsDAO implements IApplicationMapp
searchRequestBuilder.addAggregation(
AggregationBuilders.terms(ApplicationMappingTable.COLUMN_APPLICATION_ID).field(ApplicationMappingTable.COLUMN_APPLICATION_ID).size(100)
.subAggregation(AggregationBuilders.terms(ApplicationMappingTable.COLUMN_ADDRESS_ID).field(ApplicationMappingTable.COLUMN_ADDRESS_ID).size(100)));
.subAggregation(AggregationBuilders.terms(ApplicationMappingTable.COLUMN_MAPPING_APPLICATION_ID).field(ApplicationMappingTable.COLUMN_MAPPING_APPLICATION_ID).size(100)));
SearchResponse searchResponse = searchRequestBuilder.execute().actionGet();
Terms applicationIdTerms = searchResponse.getAggregations().get(ApplicationMappingTable.COLUMN_APPLICATION_ID);
JsonArray applicationMappingArray = new JsonArray();
List<ApplicationMapping> applicationMappings = new LinkedList<>();
for (Terms.Bucket applicationIdBucket : applicationIdTerms.getBuckets()) {
int applicationId = applicationIdBucket.getKeyAsNumber().intValue();
Terms addressIdTerms = applicationIdBucket.getAggregations().get(ApplicationMappingTable.COLUMN_ADDRESS_ID);
Terms addressIdTerms = applicationIdBucket.getAggregations().get(ApplicationMappingTable.COLUMN_MAPPING_APPLICATION_ID);
for (Terms.Bucket addressIdBucket : addressIdTerms.getBuckets()) {
int addressId = addressIdBucket.getKeyAsNumber().intValue();
JsonObject applicationMappingObj = new JsonObject();
applicationMappingObj.addProperty(ApplicationMappingTable.COLUMN_APPLICATION_ID, applicationId);
applicationMappingObj.addProperty(ApplicationMappingTable.COLUMN_ADDRESS_ID, addressId);
applicationMappingArray.add(applicationMappingObj);
ApplicationMapping applicationMapping = new ApplicationMapping();
applicationMapping.setApplicationId(applicationId);
applicationMapping.setMappingApplicationId(addressId);
applicationMappings.add(applicationMapping);
}
}
logger.debug("application mapping data: {}", applicationMappingArray.toString());
return applicationMappingArray;
logger.debug("application mapping data: {}", applicationMappings.toString());
return applicationMappings;
}
}
......@@ -18,82 +18,114 @@
package org.apache.skywalking.apm.collector.storage.es.dao;
import com.google.gson.JsonArray;
import java.util.LinkedList;
import java.util.List;
import org.apache.skywalking.apm.collector.client.elasticsearch.ElasticSearchClient;
import org.apache.skywalking.apm.collector.storage.dao.IApplicationReferenceMetricUIDAO;
import org.apache.skywalking.apm.collector.storage.es.base.dao.EsDAO;
import org.apache.skywalking.apm.collector.storage.table.MetricSource;
import org.apache.skywalking.apm.collector.storage.table.application.ApplicationReferenceMetricTable;
import org.apache.skywalking.apm.collector.storage.ui.common.Call;
import org.apache.skywalking.apm.collector.storage.ui.common.Step;
import org.apache.skywalking.apm.collector.storage.utils.TimePyramidTableNameBuilder;
import org.elasticsearch.action.search.SearchRequestBuilder;
import org.elasticsearch.action.search.SearchResponse;
import org.elasticsearch.action.search.SearchType;
import org.elasticsearch.index.query.BoolQueryBuilder;
import org.elasticsearch.index.query.QueryBuilders;
import org.elasticsearch.search.aggregations.AggregationBuilders;
import org.elasticsearch.search.aggregations.bucket.terms.Terms;
import org.elasticsearch.search.aggregations.bucket.terms.TermsAggregationBuilder;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.elasticsearch.search.aggregations.metrics.sum.Sum;
/**
* @author peng-yongsheng
*/
public class ApplicationReferenceMetricEsUIDAO extends EsDAO implements IApplicationReferenceMetricUIDAO {
private final Logger logger = LoggerFactory.getLogger(ApplicationReferenceMetricEsUIDAO.class);
public ApplicationReferenceMetricEsUIDAO(ElasticSearchClient client) {
super(client);
}
@Override public JsonArray load(long startTime, long endTime) {
SearchRequestBuilder searchRequestBuilder = getClient().prepareSearch(ApplicationReferenceMetricTable.TABLE);
@Override public List<Call> getFrontApplications(Step step, int applicationId, long startTime, long endTime,
MetricSource metricSource) {
String tableName = TimePyramidTableNameBuilder.build(step, ApplicationReferenceMetricTable.TABLE);
SearchRequestBuilder searchRequestBuilder = getClient().prepareSearch(tableName);
searchRequestBuilder.setTypes(ApplicationReferenceMetricTable.TABLE_TYPE);
searchRequestBuilder.setSearchType(SearchType.DFS_QUERY_THEN_FETCH);
searchRequestBuilder.setQuery(QueryBuilders.rangeQuery(ApplicationReferenceMetricTable.COLUMN_TIME_BUCKET).gte(startTime).lte(endTime));
BoolQueryBuilder boolQuery = QueryBuilders.boolQuery();
boolQuery.must().add(QueryBuilders.rangeQuery(ApplicationReferenceMetricTable.COLUMN_TIME_BUCKET).gte(startTime).lte(endTime));
boolQuery.must().add(QueryBuilders.termQuery(ApplicationReferenceMetricTable.COLUMN_BEHIND_APPLICATION_ID, applicationId));
boolQuery.must().add(QueryBuilders.termQuery(ApplicationReferenceMetricTable.COLUMN_SOURCE_VALUE, metricSource.getValue()));
searchRequestBuilder.setQuery(boolQuery);
searchRequestBuilder.setSize(0);
TermsAggregationBuilder aggregationBuilder = AggregationBuilders.terms(ApplicationReferenceMetricTable.COLUMN_FRONT_APPLICATION_ID).field(ApplicationReferenceMetricTable.COLUMN_FRONT_APPLICATION_ID).size(100);
// aggregationBuilder.subAggregation(AggregationBuilders.terms(ApplicationReferenceMetricTable.COLUMN_BEHIND_APPLICATION_ID).field(ApplicationReferenceMetricTable.COLUMN_BEHIND_APPLICATION_ID).size(100)
// .subAggregation(AggregationBuilders.sum(ApplicationReferenceMetricTable.COLUMN_S1_LTE).field(ApplicationReferenceMetricTable.COLUMN_S1_LTE))
// .subAggregation(AggregationBuilders.sum(ApplicationReferenceMetricTable.COLUMN_S3_LTE).field(ApplicationReferenceMetricTable.COLUMN_S3_LTE))
// .subAggregation(AggregationBuilders.sum(ApplicationReferenceMetricTable.COLUMN_S5_LTE).field(ApplicationReferenceMetricTable.COLUMN_S5_LTE))
// .subAggregation(AggregationBuilders.sum(ApplicationReferenceMetricTable.COLUMN_S5_GT).field(ApplicationReferenceMetricTable.COLUMN_S5_GT))
// .subAggregation(AggregationBuilders.sum(ApplicationReferenceMetricTable.COLUMN_SUMMARY).field(ApplicationReferenceMetricTable.COLUMN_SUMMARY))
// .subAggregation(AggregationBuilders.sum(ApplicationReferenceMetricTable.COLUMN_ERROR).field(ApplicationReferenceMetricTable.COLUMN_ERROR)));
aggregationBuilder.subAggregation(AggregationBuilders.sum(ApplicationReferenceMetricTable.COLUMN_TRANSACTION_CALLS).field(ApplicationReferenceMetricTable.COLUMN_TRANSACTION_CALLS));
aggregationBuilder.subAggregation(AggregationBuilders.sum(ApplicationReferenceMetricTable.COLUMN_TRANSACTION_DURATION_SUM).field(ApplicationReferenceMetricTable.COLUMN_TRANSACTION_DURATION_SUM));
searchRequestBuilder.addAggregation(aggregationBuilder);
SearchResponse searchResponse = searchRequestBuilder.execute().actionGet();
JsonArray applicationReferenceMetricArray = new JsonArray();
// Terms frontApplicationIdTerms = searchResponse.getAggregations().get(ApplicationReferenceMetricTable.COLUMN_FRONT_APPLICATION_ID);
// for (Terms.Bucket frontApplicationIdBucket : frontApplicationIdTerms.getBuckets()) {
// int frontApplicationId = frontApplicationIdBucket.getKeyAsNumber().intValue();
// Terms behindApplicationIdTerms = frontApplicationIdBucket.getAggregations().get(ApplicationReferenceMetricTable.COLUMN_BEHIND_APPLICATION_ID);
// for (Terms.Bucket behindApplicationIdBucket : behindApplicationIdTerms.getBuckets()) {
// int behindApplicationId = behindApplicationIdBucket.getKeyAsNumber().intValue();
//
// if (behindApplicationId != 0) {
// Sum s1LTE = behindApplicationIdBucket.getAggregations().get(ApplicationReferenceMetricTable.COLUMN_S1_LTE);
// Sum s3LTE = behindApplicationIdBucket.getAggregations().get(ApplicationReferenceMetricTable.COLUMN_S3_LTE);
// Sum s5LTE = behindApplicationIdBucket.getAggregations().get(ApplicationReferenceMetricTable.COLUMN_S5_LTE);
// Sum s5GT = behindApplicationIdBucket.getAggregations().get(ApplicationReferenceMetricTable.COLUMN_S5_GT);
// Sum summary = behindApplicationIdBucket.getAggregations().get(ApplicationReferenceMetricTable.COLUMN_SUMMARY);
// Sum error = behindApplicationIdBucket.getAggregations().get(ApplicationReferenceMetricTable.COLUMN_ERROR);
// logger.debug("frontApplicationId: {}, behindApplicationId: {}, s1LTE: {}, s3LTE: {}, s5LTE: {}, s5GT: {}, error: {}, summary: {}", frontApplicationId,
// behindApplicationId, s1LTE.getValue(), s3LTE.getValue(), s5LTE.getValue(), s5GT.getValue(), error.getValue(), summary.getValue());
//
// JsonObject nodeRefResSumObj = new JsonObject();
// nodeRefResSumObj.addProperty(ColumnNameUtils.INSTANCE.rename(ApplicationReferenceMetricTable.COLUMN_FRONT_APPLICATION_ID), frontApplicationId);
// nodeRefResSumObj.addProperty(ColumnNameUtils.INSTANCE.rename(ApplicationReferenceMetricTable.COLUMN_BEHIND_APPLICATION_ID), behindApplicationId);
// nodeRefResSumObj.addProperty(ColumnNameUtils.INSTANCE.rename(ApplicationReferenceMetricTable.COLUMN_S1_LTE), s1LTE.getValue());
// nodeRefResSumObj.addProperty(ColumnNameUtils.INSTANCE.rename(ApplicationReferenceMetricTable.COLUMN_S3_LTE), s3LTE.getValue());
// nodeRefResSumObj.addProperty(ColumnNameUtils.INSTANCE.rename(ApplicationReferenceMetricTable.COLUMN_S5_LTE), s5LTE.getValue());
// nodeRefResSumObj.addProperty(ColumnNameUtils.INSTANCE.rename(ApplicationReferenceMetricTable.COLUMN_S5_GT), s5GT.getValue());
// nodeRefResSumObj.addProperty(ColumnNameUtils.INSTANCE.rename(ApplicationReferenceMetricTable.COLUMN_ERROR), error.getValue());
// nodeRefResSumObj.addProperty(ColumnNameUtils.INSTANCE.rename(ApplicationReferenceMetricTable.COLUMN_SUMMARY), summary.getValue());
// nodeRefResSumArray.add(nodeRefResSumObj);
// }
// }
// }
return applicationReferenceMetricArray;
List<Call> nodes = new LinkedList<>();
Terms frontApplicationIdTerms = searchResponse.getAggregations().get(ApplicationReferenceMetricTable.COLUMN_FRONT_APPLICATION_ID);
for (Terms.Bucket frontApplicationIdBucket : frontApplicationIdTerms.getBuckets()) {
int frontApplicationId = frontApplicationIdBucket.getKeyAsNumber().intValue();
Sum calls = frontApplicationIdBucket.getAggregations().get(ApplicationReferenceMetricTable.COLUMN_TRANSACTION_CALLS);
Sum responseTimes = frontApplicationIdBucket.getAggregations().get(ApplicationReferenceMetricTable.COLUMN_TRANSACTION_DURATION_SUM);
Call call = new Call();
call.setSource(frontApplicationId);
call.setTarget(applicationId);
call.setCalls((int)calls.getValue());
call.setResponseTimes((int)responseTimes.getValue());
nodes.add(call);
}
return nodes;
}
@Override public List<Call> getBehindApplications(Step step, int applicationId, long startTime, long endTime,
MetricSource metricSource) {
String tableName = TimePyramidTableNameBuilder.build(step, ApplicationReferenceMetricTable.TABLE);
SearchRequestBuilder searchRequestBuilder = getClient().prepareSearch(tableName);
searchRequestBuilder.setTypes(ApplicationReferenceMetricTable.TABLE_TYPE);
searchRequestBuilder.setSearchType(SearchType.DFS_QUERY_THEN_FETCH);
BoolQueryBuilder boolQuery = QueryBuilders.boolQuery();
boolQuery.must().add(QueryBuilders.rangeQuery(ApplicationReferenceMetricTable.COLUMN_TIME_BUCKET).gte(startTime).lte(endTime));
boolQuery.must().add(QueryBuilders.termQuery(ApplicationReferenceMetricTable.COLUMN_FRONT_APPLICATION_ID, applicationId));
boolQuery.must().add(QueryBuilders.termQuery(ApplicationReferenceMetricTable.COLUMN_SOURCE_VALUE, metricSource.getValue()));
searchRequestBuilder.setQuery(boolQuery);
searchRequestBuilder.setSize(0);
TermsAggregationBuilder aggregationBuilder = AggregationBuilders.terms(ApplicationReferenceMetricTable.COLUMN_BEHIND_APPLICATION_ID).field(ApplicationReferenceMetricTable.COLUMN_BEHIND_APPLICATION_ID).size(100);
aggregationBuilder.subAggregation(AggregationBuilders.sum(ApplicationReferenceMetricTable.COLUMN_TRANSACTION_CALLS).field(ApplicationReferenceMetricTable.COLUMN_TRANSACTION_CALLS));
aggregationBuilder.subAggregation(AggregationBuilders.sum(ApplicationReferenceMetricTable.COLUMN_TRANSACTION_DURATION_SUM).field(ApplicationReferenceMetricTable.COLUMN_TRANSACTION_DURATION_SUM));
searchRequestBuilder.addAggregation(aggregationBuilder);
SearchResponse searchResponse = searchRequestBuilder.execute().actionGet();
List<Call> nodes = new LinkedList<>();
Terms behindApplicationIdTerms = searchResponse.getAggregations().get(ApplicationReferenceMetricTable.COLUMN_BEHIND_APPLICATION_ID);
for (Terms.Bucket behindApplicationIdBucket : behindApplicationIdTerms.getBuckets()) {
int behindApplicationId = behindApplicationIdBucket.getKeyAsNumber().intValue();
Sum calls = behindApplicationIdBucket.getAggregations().get(ApplicationReferenceMetricTable.COLUMN_TRANSACTION_CALLS);
Sum responseTimes = behindApplicationIdBucket.getAggregations().get(ApplicationReferenceMetricTable.COLUMN_TRANSACTION_DURATION_SUM);
Call call = new Call();
call.setTarget(behindApplicationId);
call.setSource(applicationId);
call.setCalls((int)calls.getValue());
call.setResponseTimes((int)responseTimes.getValue());
nodes.add(call);
}
return nodes;
}
}
......@@ -94,12 +94,19 @@ public class InstanceEsUIDAO extends EsDAO implements IInstanceUIDAO {
return heartBeatTime;
}
@Override public List<Application> getApplications(long startTime, long endTime) {
@Override public List<Application> getApplications(long startTime, long endTime, int... applicationIds) {
logger.debug("application list get, start time: {}, end time: {}", startTime, endTime);
SearchRequestBuilder searchRequestBuilder = getClient().prepareSearch(InstanceTable.TABLE);
searchRequestBuilder.setTypes(InstanceTable.TABLE_TYPE);
searchRequestBuilder.setSearchType(SearchType.DFS_QUERY_THEN_FETCH);
searchRequestBuilder.setQuery(QueryBuilders.rangeQuery(InstanceTable.COLUMN_HEARTBEAT_TIME).gte(startTime));
BoolQueryBuilder boolQueryBuilder = QueryBuilders.boolQuery();
boolQueryBuilder.must().add(QueryBuilders.rangeQuery(InstanceTable.COLUMN_HEARTBEAT_TIME).gte(startTime));
if (applicationIds.length > 0) {
boolQueryBuilder.must().add(QueryBuilders.termsQuery(InstanceTable.COLUMN_APPLICATION_ID, applicationIds));
}
searchRequestBuilder.setQuery(boolQueryBuilder);
searchRequestBuilder.setSize(0);
searchRequestBuilder.addAggregation(AggregationBuilders.terms(InstanceTable.COLUMN_APPLICATION_ID).field(InstanceTable.COLUMN_APPLICATION_ID).size(100)
.subAggregation(AggregationBuilders.count(InstanceTable.COLUMN_INSTANCE_ID).field(InstanceTable.COLUMN_INSTANCE_ID)));
......
......@@ -44,7 +44,7 @@ public abstract class AbstractApplicationComponentEsPersistenceDAO extends Abstr
applicationComponent.setMetricId((String)source.get(ApplicationComponentTable.COLUMN_METRIC_ID));
applicationComponent.setComponentId(((Number)source.get(ApplicationComponentTable.COLUMN_COMPONENT_ID)).intValue());
applicationComponent.setPeerId(((Number)source.get(ApplicationComponentTable.COLUMN_PEER_ID)).intValue());
applicationComponent.setApplicationId(((Number)source.get(ApplicationComponentTable.COLUMN_APPLICATION_ID)).intValue());
applicationComponent.setTimeBucket(((Number)source.get(ApplicationComponentTable.COLUMN_TIME_BUCKET)).longValue());
return applicationComponent;
}
......@@ -55,7 +55,7 @@ public abstract class AbstractApplicationComponentEsPersistenceDAO extends Abstr
source.put(ApplicationComponentTable.COLUMN_METRIC_ID, streamData.getMetricId());
source.put(ApplicationComponentTable.COLUMN_COMPONENT_ID, streamData.getComponentId());
source.put(ApplicationComponentTable.COLUMN_PEER_ID, streamData.getPeerId());
source.put(ApplicationComponentTable.COLUMN_APPLICATION_ID, streamData.getApplicationId());
source.put(ApplicationComponentTable.COLUMN_TIME_BUCKET, streamData.getTimeBucket());
return source;
......
......@@ -44,7 +44,7 @@ public abstract class AbstractApplicationMappingEsPersistenceDAO extends Abstrac
applicationMapping.setMetricId((String)source.get(ApplicationMappingTable.COLUMN_METRIC_ID));
applicationMapping.setApplicationId(((Number)source.get(ApplicationMappingTable.COLUMN_APPLICATION_ID)).intValue());
applicationMapping.setAddressId(((Number)source.get(ApplicationMappingTable.COLUMN_ADDRESS_ID)).intValue());
applicationMapping.setMappingApplicationId(((Number)source.get(ApplicationMappingTable.COLUMN_MAPPING_APPLICATION_ID)).intValue());
applicationMapping.setTimeBucket(((Number)source.get(ApplicationMappingTable.COLUMN_TIME_BUCKET)).longValue());
return applicationMapping;
}
......@@ -55,7 +55,7 @@ public abstract class AbstractApplicationMappingEsPersistenceDAO extends Abstrac
source.put(ApplicationMappingTable.COLUMN_METRIC_ID, streamData.getMetricId());
source.put(ApplicationMappingTable.COLUMN_APPLICATION_ID, streamData.getApplicationId());
source.put(ApplicationMappingTable.COLUMN_ADDRESS_ID, streamData.getAddressId());
source.put(ApplicationMappingTable.COLUMN_MAPPING_APPLICATION_ID, streamData.getMappingApplicationId());
source.put(ApplicationMappingTable.COLUMN_TIME_BUCKET, streamData.getTimeBucket());
return source;
......
......@@ -20,9 +20,9 @@ package org.apache.skywalking.apm.collector.storage.es.dao.cache;
import org.apache.skywalking.apm.collector.client.elasticsearch.ElasticSearchClient;
import org.apache.skywalking.apm.collector.core.util.BooleanUtils;
import org.apache.skywalking.apm.collector.core.util.Const;
import org.apache.skywalking.apm.collector.storage.dao.cache.IApplicationCacheDAO;
import org.apache.skywalking.apm.collector.storage.es.base.dao.EsDAO;
import org.apache.skywalking.apm.collector.storage.table.register.Application;
import org.apache.skywalking.apm.collector.storage.table.register.ApplicationTable;
import org.elasticsearch.action.get.GetRequestBuilder;
import org.elasticsearch.action.get.GetResponse;
......@@ -68,16 +68,20 @@ public class ApplicationEsCacheDAO extends EsDAO implements IApplicationCacheDAO
return 0;
}
@Override public String getApplicationCode(int applicationId) {
@Override public Application getApplication(int applicationId) {
logger.debug("get application code, applicationId: {}", applicationId);
ElasticSearchClient client = getClient();
GetRequestBuilder getRequestBuilder = client.prepareGet(ApplicationTable.TABLE, String.valueOf(applicationId));
GetResponse getResponse = getRequestBuilder.get();
if (getResponse.isExists()) {
return (String)getResponse.getSource().get(ApplicationTable.COLUMN_APPLICATION_CODE);
Application application = new Application();
application.setApplicationId(applicationId);
application.setApplicationCode((String)getResponse.getSource().get(ApplicationTable.COLUMN_APPLICATION_CODE));
application.setIsAddress(((Number)getResponse.getSource().get(ApplicationTable.COLUMN_IS_ADDRESS)).intValue());
return application;
}
return Const.EMPTY_STRING;
return null;
}
@Override public int getApplicationIdByAddressId(int addressId) {
......
......@@ -34,7 +34,7 @@ public abstract class AbstractApplicationComponentEsTableDefine extends ElasticS
@Override public final void initialize() {
addColumn(new ElasticSearchColumnDefine(ApplicationComponentTable.COLUMN_METRIC_ID, ElasticSearchColumnDefine.Type.Keyword.name()));
addColumn(new ElasticSearchColumnDefine(ApplicationComponentTable.COLUMN_COMPONENT_ID, ElasticSearchColumnDefine.Type.Integer.name()));
addColumn(new ElasticSearchColumnDefine(ApplicationComponentTable.COLUMN_PEER_ID, ElasticSearchColumnDefine.Type.Integer.name()));
addColumn(new ElasticSearchColumnDefine(ApplicationComponentTable.COLUMN_APPLICATION_ID, ElasticSearchColumnDefine.Type.Integer.name()));
addColumn(new ElasticSearchColumnDefine(ApplicationComponentTable.COLUMN_TIME_BUCKET, ElasticSearchColumnDefine.Type.Long.name()));
}
}
......@@ -34,7 +34,7 @@ public abstract class AbstractApplicationMappingEsTableDefine extends ElasticSea
@Override public final void initialize() {
addColumn(new ElasticSearchColumnDefine(ApplicationMappingTable.COLUMN_METRIC_ID, ElasticSearchColumnDefine.Type.Keyword.name()));
addColumn(new ElasticSearchColumnDefine(ApplicationMappingTable.COLUMN_APPLICATION_ID, ElasticSearchColumnDefine.Type.Integer.name()));
addColumn(new ElasticSearchColumnDefine(ApplicationMappingTable.COLUMN_ADDRESS_ID, ElasticSearchColumnDefine.Type.Integer.name()));
addColumn(new ElasticSearchColumnDefine(ApplicationMappingTable.COLUMN_MAPPING_APPLICATION_ID, ElasticSearchColumnDefine.Type.Integer.name()));
addColumn(new ElasticSearchColumnDefine(ApplicationMappingTable.COLUMN_TIME_BUCKET, ElasticSearchColumnDefine.Type.Long.name()));
}
}
......@@ -16,19 +16,20 @@
*
*/
package org.apache.skywalking.apm.collector.storage.h2.dao;
import com.google.gson.JsonArray;
import com.google.gson.JsonObject;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.LinkedList;
import java.util.List;
import org.apache.skywalking.apm.collector.client.h2.H2Client;
import org.apache.skywalking.apm.collector.client.h2.H2ClientException;
import org.apache.skywalking.apm.collector.storage.base.sql.SqlBuilder;
import org.apache.skywalking.apm.collector.storage.dao.IApplicationComponentUIDAO;
import org.apache.skywalking.apm.collector.storage.h2.base.dao.H2DAO;
import org.apache.skywalking.apm.collector.storage.table.application.ApplicationComponentTable;
import org.apache.skywalking.apm.collector.client.h2.H2ClientException;
import org.apache.skywalking.apm.collector.storage.dao.IApplicationComponentUIDAO;
import org.apache.skywalking.apm.collector.storage.ui.common.Step;
import org.apache.skywalking.apm.collector.storage.utils.TimePyramidTableNameBuilder;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
......@@ -44,31 +45,29 @@ public class ApplicationComponentH2UIDAO extends H2DAO implements IApplicationCo
super(client);
}
@Override public JsonArray load(long startTime, long endTime) {
JsonArray applicationComponentArray = new JsonArray();
applicationComponentArray.addAll(aggregationComponent(startTime, endTime));
return applicationComponentArray;
}
private JsonArray aggregationComponent(long startTime, long endTime) {
@Override public List<ApplicationComponent> load(Step step, long startTime, long endTime) {
H2Client client = getClient();
JsonArray applicationComponentArray = new JsonArray();
String sql = SqlBuilder.buildSql(AGGREGATE_COMPONENT_SQL, ApplicationComponentTable.COLUMN_COMPONENT_ID, ApplicationComponentTable.COLUMN_PEER_ID,
ApplicationComponentTable.TABLE, ApplicationComponentTable.COLUMN_TIME_BUCKET);
String tableName = TimePyramidTableNameBuilder.build(step, ApplicationComponentTable.TABLE);
List<ApplicationComponent> applicationComponents = new LinkedList<>();
String sql = SqlBuilder.buildSql(AGGREGATE_COMPONENT_SQL, ApplicationComponentTable.COLUMN_COMPONENT_ID, ApplicationComponentTable.COLUMN_APPLICATION_ID,
tableName, ApplicationComponentTable.COLUMN_TIME_BUCKET);
Object[] params = new Object[] {startTime, endTime};
try (ResultSet rs = client.executeQuery(sql, params)) {
while (rs.next()) {
int peerId = rs.getInt(ApplicationComponentTable.COLUMN_PEER_ID);
int applicationId = rs.getInt(ApplicationComponentTable.COLUMN_APPLICATION_ID);
int componentId = rs.getInt(ApplicationComponentTable.COLUMN_COMPONENT_ID);
JsonObject applicationComponentObj = new JsonObject();
applicationComponentObj.addProperty(ApplicationComponentTable.COLUMN_COMPONENT_ID, componentId);
applicationComponentObj.addProperty(ApplicationComponentTable.COLUMN_PEER_ID, peerId);
applicationComponentArray.add(applicationComponentObj);
ApplicationComponent applicationComponent = new ApplicationComponent();
applicationComponent.setComponentId(componentId);
applicationComponent.setApplicationId(applicationId);
applicationComponents.add(applicationComponent);
}
} catch (SQLException | H2ClientException e) {
logger.error(e.getMessage(), e);
}
return applicationComponentArray;
return applicationComponents;
}
}
......@@ -16,19 +16,20 @@
*
*/
package org.apache.skywalking.apm.collector.storage.h2.dao;
import com.google.gson.JsonArray;
import com.google.gson.JsonObject;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.LinkedList;
import java.util.List;
import org.apache.skywalking.apm.collector.client.h2.H2Client;
import org.apache.skywalking.apm.collector.client.h2.H2ClientException;
import org.apache.skywalking.apm.collector.storage.base.sql.SqlBuilder;
import org.apache.skywalking.apm.collector.storage.dao.IApplicationMappingUIDAO;
import org.apache.skywalking.apm.collector.storage.h2.base.dao.H2DAO;
import org.apache.skywalking.apm.collector.storage.table.application.ApplicationMappingTable;
import org.apache.skywalking.apm.collector.client.h2.H2ClientException;
import org.apache.skywalking.apm.collector.storage.dao.IApplicationMappingUIDAO;
import org.apache.skywalking.apm.collector.storage.ui.common.Step;
import org.apache.skywalking.apm.collector.storage.utils.TimePyramidTableNameBuilder;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
......@@ -44,26 +45,29 @@ public class ApplicationMappingH2UIDAO extends H2DAO implements IApplicationMapp
super(client);
}
@Override public JsonArray load(long startTime, long endTime) {
@Override public List<ApplicationMapping> load(Step step, long startTime, long endTime) {
String tableName = TimePyramidTableNameBuilder.build(step, ApplicationMappingTable.TABLE);
H2Client client = getClient();
JsonArray applicationMappingArray = new JsonArray();
String sql = SqlBuilder.buildSql(APPLICATION_MAPPING_SQL, ApplicationMappingTable.COLUMN_APPLICATION_ID,
ApplicationMappingTable.COLUMN_ADDRESS_ID, ApplicationMappingTable.TABLE, ApplicationMappingTable.COLUMN_TIME_BUCKET);
ApplicationMappingTable.COLUMN_MAPPING_APPLICATION_ID, tableName, ApplicationMappingTable.COLUMN_TIME_BUCKET);
List<ApplicationMapping> applicationMappings = new LinkedList<>();
Object[] params = new Object[] {startTime, endTime};
try (ResultSet rs = client.executeQuery(sql, params)) {
while (rs.next()) {
int applicationId = rs.getInt(ApplicationMappingTable.COLUMN_APPLICATION_ID);
int addressId = rs.getInt(ApplicationMappingTable.COLUMN_ADDRESS_ID);
JsonObject applicationMappingObj = new JsonObject();
applicationMappingObj.addProperty(ApplicationMappingTable.COLUMN_APPLICATION_ID, applicationId);
applicationMappingObj.addProperty(ApplicationMappingTable.COLUMN_ADDRESS_ID, addressId);
applicationMappingArray.add(applicationMappingObj);
int addressId = rs.getInt(ApplicationMappingTable.COLUMN_MAPPING_APPLICATION_ID);
ApplicationMapping applicationMapping = new ApplicationMapping();
applicationMapping.setApplicationId(applicationId);
applicationMapping.setMappingApplicationId(addressId);
applicationMappings.add(applicationMapping);
}
} catch (SQLException | H2ClientException e) {
logger.error(e.getMessage(), e);
}
logger.debug("node mapping data: {}", applicationMappingArray.toString());
return applicationMappingArray;
logger.debug("node mapping data: {}", applicationMappings.toString());
return applicationMappings;
}
}
......@@ -16,13 +16,16 @@
*
*/
package org.apache.skywalking.apm.collector.storage.h2.dao;
import com.google.gson.JsonArray;
import java.util.List;
import org.apache.skywalking.apm.collector.client.h2.H2Client;
import org.apache.skywalking.apm.collector.storage.h2.base.dao.H2DAO;
import org.apache.skywalking.apm.collector.storage.dao.IApplicationReferenceMetricUIDAO;
import org.apache.skywalking.apm.collector.storage.h2.base.dao.H2DAO;
import org.apache.skywalking.apm.collector.storage.table.MetricSource;
import org.apache.skywalking.apm.collector.storage.ui.common.Call;
import org.apache.skywalking.apm.collector.storage.ui.common.Step;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
......@@ -39,7 +42,8 @@ public class ApplicationReferenceMetricH2UIDAO extends H2DAO implements IApplica
super(client);
}
@Override public JsonArray load(long startTime, long endTime) {
@Override public List<Call> getFrontApplications(Step step, int applicationId, long startTime, long endTime,
MetricSource metricSource) {
H2Client client = getClient();
JsonArray applicationReferenceMetricArray = new JsonArray();
// String sql = SqlBuilder.buildSql(APPLICATION_REFERENCE_SQL, ApplicationReferenceMetricTable.COLUMN_S1_LTE,
......@@ -67,6 +71,11 @@ public class ApplicationReferenceMetricH2UIDAO extends H2DAO implements IApplica
// } catch (SQLException | H2ClientException e) {
// logger.error(e.getMessage(), e);
// }
return applicationReferenceMetricArray;
return null;
}
@Override public List<Call> getBehindApplications(Step step, int applicationId, long startTime, long endTime,
MetricSource metricSource) {
return null;
}
}
......@@ -87,7 +87,7 @@ public class InstanceH2UIDAO extends H2DAO implements IInstanceUIDAO {
}
@Override
public List<Application> getApplications(long startTime, long endTime) {
public List<Application> getApplications(long startTime, long endTime, int... applicationIds) {
H2Client client = getClient();
List<Application> applications = new LinkedList<>();
String sql = SqlBuilder.buildSql(GET_APPLICATIONS_SQL, InstanceTable.COLUMN_INSTANCE_ID,
......
......@@ -42,7 +42,7 @@ public abstract class AbstractApplicationComponentH2PersistenceDAO extends Abstr
applicationComponent.setMetricId(resultSet.getString(ApplicationComponentTable.COLUMN_METRIC_ID));
applicationComponent.setComponentId(resultSet.getInt(ApplicationComponentTable.COLUMN_COMPONENT_ID));
applicationComponent.setPeerId(resultSet.getInt(ApplicationComponentTable.COLUMN_PEER_ID));
applicationComponent.setApplicationId(resultSet.getInt(ApplicationComponentTable.COLUMN_APPLICATION_ID));
applicationComponent.setTimeBucket(resultSet.getLong(ApplicationComponentTable.COLUMN_TIME_BUCKET));
return applicationComponent;
}
......@@ -52,7 +52,7 @@ public abstract class AbstractApplicationComponentH2PersistenceDAO extends Abstr
source.put(ApplicationComponentTable.COLUMN_METRIC_ID, streamData.getMetricId());
source.put(ApplicationComponentTable.COLUMN_COMPONENT_ID, streamData.getComponentId());
source.put(ApplicationComponentTable.COLUMN_PEER_ID, streamData.getPeerId());
source.put(ApplicationComponentTable.COLUMN_APPLICATION_ID, streamData.getApplicationId());
source.put(ApplicationComponentTable.COLUMN_TIME_BUCKET, streamData.getTimeBucket());
return source;
......
......@@ -42,7 +42,7 @@ public abstract class AbstractApplicationMappingH2PersistenceDAO extends Abstrac
applicationMapping.setMetricId(resultSet.getString(ApplicationMappingTable.COLUMN_METRIC_ID));
applicationMapping.setApplicationId(resultSet.getInt(ApplicationMappingTable.COLUMN_APPLICATION_ID));
applicationMapping.setAddressId(resultSet.getInt(ApplicationMappingTable.COLUMN_ADDRESS_ID));
applicationMapping.setMappingApplicationId(resultSet.getInt(ApplicationMappingTable.COLUMN_MAPPING_APPLICATION_ID));
applicationMapping.setTimeBucket(resultSet.getLong(ApplicationMappingTable.COLUMN_TIME_BUCKET));
return applicationMapping;
}
......@@ -52,7 +52,7 @@ public abstract class AbstractApplicationMappingH2PersistenceDAO extends Abstrac
source.put(ApplicationMappingTable.COLUMN_METRIC_ID, streamData.getMetricId());
source.put(ApplicationMappingTable.COLUMN_APPLICATION_ID, streamData.getApplicationId());
source.put(ApplicationMappingTable.COLUMN_ADDRESS_ID, streamData.getAddressId());
source.put(ApplicationMappingTable.COLUMN_MAPPING_APPLICATION_ID, streamData.getMappingApplicationId());
source.put(ApplicationMappingTable.COLUMN_TIME_BUCKET, streamData.getTimeBucket());
return source;
......
......@@ -22,10 +22,10 @@ import java.sql.ResultSet;
import java.sql.SQLException;
import org.apache.skywalking.apm.collector.client.h2.H2Client;
import org.apache.skywalking.apm.collector.client.h2.H2ClientException;
import org.apache.skywalking.apm.collector.core.util.Const;
import org.apache.skywalking.apm.collector.storage.base.sql.SqlBuilder;
import org.apache.skywalking.apm.collector.storage.dao.cache.IApplicationCacheDAO;
import org.apache.skywalking.apm.collector.storage.h2.base.dao.H2DAO;
import org.apache.skywalking.apm.collector.storage.table.register.Application;
import org.apache.skywalking.apm.collector.storage.table.register.ApplicationTable;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
......@@ -38,7 +38,7 @@ public class ApplicationH2CacheDAO extends H2DAO implements IApplicationCacheDAO
private final Logger logger = LoggerFactory.getLogger(ApplicationH2CacheDAO.class);
private static final String GET_APPLICATION_ID_SQL = "select {0} from {1} where {2} = ? and {3} = ?";
private static final String GET_APPLICATION_CODE_SQL = "select {0} from {1} where {2} = ?";
private static final String GET_APPLICATION_SQL = "select {0},{1} from {2} where {3} = ?";
public ApplicationH2CacheDAO(H2Client client) {
super(client);
......@@ -61,19 +61,23 @@ public class ApplicationH2CacheDAO extends H2DAO implements IApplicationCacheDAO
return 0;
}
@Override public String getApplicationCode(int applicationId) {
@Override public Application getApplication(int applicationId) {
logger.debug("get application code, applicationId: {}", applicationId);
H2Client client = getClient();
String sql = SqlBuilder.buildSql(GET_APPLICATION_CODE_SQL, ApplicationTable.COLUMN_APPLICATION_CODE, ApplicationTable.TABLE, ApplicationTable.COLUMN_APPLICATION_ID);
String sql = SqlBuilder.buildSql(GET_APPLICATION_SQL, ApplicationTable.COLUMN_APPLICATION_CODE, ApplicationTable.COLUMN_IS_ADDRESS, ApplicationTable.TABLE, ApplicationTable.COLUMN_APPLICATION_ID);
Object[] params = new Object[] {applicationId};
try (ResultSet rs = client.executeQuery(sql, params)) {
if (rs.next()) {
return rs.getString(1);
Application application = new Application();
application.setApplicationId(applicationId);
application.setApplicationCode(rs.getString(1));
application.setIsAddress(rs.getInt(2));
return application;
}
} catch (SQLException | H2ClientException e) {
logger.error(e.getMessage(), e);
}
return Const.EMPTY_STRING;
return null;
}
@Override public int getApplicationIdByAddressId(int addressId) {
......
......@@ -35,7 +35,7 @@ public abstract class AbstractApplicationComponentH2TableDefine extends H2TableD
addColumn(new H2ColumnDefine(ApplicationComponentTable.COLUMN_ID, H2ColumnDefine.Type.Varchar.name()));
addColumn(new H2ColumnDefine(ApplicationComponentTable.COLUMN_METRIC_ID, H2ColumnDefine.Type.Varchar.name()));
addColumn(new H2ColumnDefine(ApplicationComponentTable.COLUMN_COMPONENT_ID, H2ColumnDefine.Type.Int.name()));
addColumn(new H2ColumnDefine(ApplicationComponentTable.COLUMN_PEER_ID, H2ColumnDefine.Type.Int.name()));
addColumn(new H2ColumnDefine(ApplicationComponentTable.COLUMN_APPLICATION_ID, H2ColumnDefine.Type.Int.name()));
addColumn(new H2ColumnDefine(ApplicationComponentTable.COLUMN_TIME_BUCKET, H2ColumnDefine.Type.Bigint.name()));
}
}
......@@ -35,7 +35,7 @@ public abstract class AbstractApplicationMappingH2TableDefine extends H2TableDef
addColumn(new H2ColumnDefine(ApplicationMappingTable.COLUMN_ID, H2ColumnDefine.Type.Varchar.name()));
addColumn(new H2ColumnDefine(ApplicationMappingTable.COLUMN_METRIC_ID, H2ColumnDefine.Type.Varchar.name()));
addColumn(new H2ColumnDefine(ApplicationMappingTable.COLUMN_APPLICATION_ID, H2ColumnDefine.Type.Int.name()));
addColumn(new H2ColumnDefine(ApplicationMappingTable.COLUMN_ADDRESS_ID, H2ColumnDefine.Type.Int.name()));
addColumn(new H2ColumnDefine(ApplicationMappingTable.COLUMN_MAPPING_APPLICATION_ID, H2ColumnDefine.Type.Int.name()));
addColumn(new H2ColumnDefine(ApplicationMappingTable.COLUMN_TIME_BUCKET, H2ColumnDefine.Type.Bigint.name()));
}
}
/*
* 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.ui.utils;
import java.text.ParseException;
import org.junit.Test;
/**
* @author peng-yongsheng
*/
public class DurationUtilsTestCase {
@Test
public void test() throws ParseException {
}
}
......@@ -28,8 +28,9 @@ import org.apache.skywalking.apm.collector.storage.ui.common.Topology;
import org.apache.skywalking.apm.collector.storage.ui.server.AppServerInfo;
import org.apache.skywalking.apm.collector.storage.ui.service.ServiceInfo;
import org.apache.skywalking.apm.collector.ui.graphql.Query;
import org.apache.skywalking.apm.collector.ui.graphql.utils.DurationUtils;
import org.apache.skywalking.apm.collector.ui.service.ApplicationService;
import org.apache.skywalking.apm.collector.ui.service.ApplicationTopologyService;
import org.apache.skywalking.apm.collector.ui.utils.DurationUtils;
/**
* @author peng-yongsheng
......@@ -38,6 +39,7 @@ public class ApplicationQuery implements Query {
private final ModuleManager moduleManager;
private ApplicationService applicationService;
private ApplicationTopologyService applicationTopologyService;
public ApplicationQuery(ModuleManager moduleManager) {
this.moduleManager = moduleManager;
......@@ -50,38 +52,25 @@ public class ApplicationQuery implements Query {
return applicationService;
}
public List<Application> getAllApplication(Duration duration) throws ParseException {
long start = 0;
long end = 0;
switch (duration.getStep()) {
case MONTH:
start = DurationUtils.INSTANCE.monthDurationToSecondTimeBucket(duration.getStart());
end = DurationUtils.INSTANCE.monthDurationToSecondTimeBucket(duration.getEnd());
break;
case DAY:
start = DurationUtils.INSTANCE.dayDurationToSecondTimeBucket(duration.getStart());
end = DurationUtils.INSTANCE.dayDurationToSecondTimeBucket(duration.getEnd());
break;
case HOUR:
start = DurationUtils.INSTANCE.hourDurationToSecondTimeBucket(duration.getStart());
end = DurationUtils.INSTANCE.hourDurationToSecondTimeBucket(duration.getEnd());
break;
case MINUTE:
start = DurationUtils.INSTANCE.minuteDurationToSecondTimeBucket(duration.getStart());
end = DurationUtils.INSTANCE.minuteDurationToSecondTimeBucket(duration.getEnd());
break;
case SECOND:
start = DurationUtils.INSTANCE.exchangeToTimeBucket(duration.getStart());
end = DurationUtils.INSTANCE.exchangeToTimeBucket(duration.getEnd());
break;
private ApplicationTopologyService getApplicationTopologyService() {
if (ObjectUtils.isEmpty(applicationTopologyService)) {
this.applicationTopologyService = new ApplicationTopologyService(moduleManager);
}
return applicationTopologyService;
}
public List<Application> getAllApplication(Duration duration) throws ParseException {
long start = DurationUtils.INSTANCE.durationToSecondTimeBucket(duration.getStep(), duration.getStart());
long end = DurationUtils.INSTANCE.durationToSecondTimeBucket(duration.getStep(), duration.getEnd());
return getApplicationService().getApplications(start, end);
}
public Topology getApplicationTopology(int applicationId, Duration duration) {
return null;
public Topology getApplicationTopology(int applicationId, Duration duration) throws ParseException {
long start = DurationUtils.INSTANCE.exchangeToTimeBucket(duration.getStart());
long end = DurationUtils.INSTANCE.exchangeToTimeBucket(duration.getEnd());
return getApplicationTopologyService().getApplicationTopology(duration.getStep(), applicationId, start, end);
}
public List<ServiceInfo> getSlowService(int applicationId, Duration duration, Integer top) {
......
......@@ -39,11 +39,11 @@ public class ApplicationService {
this.applicationCacheService = moduleManager.find(CacheModule.NAME).getService(ApplicationCacheService.class);
}
public List<Application> getApplications(long startTime, long endTime) {
List<Application> applications = instanceDAO.getApplications(startTime, endTime);
public List<Application> getApplications(long startTime, long endTime, int... applicationIds) {
List<Application> applications = instanceDAO.getApplications(startTime, endTime, applicationIds);
applications.forEach(application -> {
String applicationCode = applicationCacheService.getApplicationCodeById(application.getId());
String applicationCode = applicationCacheService.getApplicationById(application.getId()).getApplicationCode();
application.setName(applicationCode);
});
return applications;
......
/*
* 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.ui.service;
import java.text.ParseException;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import org.apache.skywalking.apm.collector.core.module.ModuleManager;
import org.apache.skywalking.apm.collector.storage.StorageModule;
import org.apache.skywalking.apm.collector.storage.dao.IApplicationComponentUIDAO;
import org.apache.skywalking.apm.collector.storage.dao.IApplicationMappingUIDAO;
import org.apache.skywalking.apm.collector.storage.dao.IApplicationReferenceMetricUIDAO;
import org.apache.skywalking.apm.collector.storage.table.MetricSource;
import org.apache.skywalking.apm.collector.storage.ui.common.Call;
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.ui.utils.DurationUtils;
import org.apache.skywalking.apm.network.trace.component.ComponentsDefine;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* @author peng-yongsheng
*/
public class ApplicationTopologyService {
private final Logger logger = LoggerFactory.getLogger(ApplicationTopologyService.class);
private final IApplicationComponentUIDAO applicationComponentUIDAO;
private final IApplicationMappingUIDAO applicationMappingUIDAO;
private final IApplicationReferenceMetricUIDAO applicationReferenceMetricUIDAO;
private final ModuleManager moduleManager;
public ApplicationTopologyService(ModuleManager moduleManager) {
this.moduleManager = moduleManager;
this.applicationComponentUIDAO = moduleManager.find(StorageModule.NAME).getService(IApplicationComponentUIDAO.class);
this.applicationMappingUIDAO = moduleManager.find(StorageModule.NAME).getService(IApplicationMappingUIDAO.class);
this.applicationReferenceMetricUIDAO = moduleManager.find(StorageModule.NAME).getService(IApplicationReferenceMetricUIDAO.class);
}
public Topology getApplicationTopology(Step step, int applicationId, long startTime,
long endTime) throws ParseException {
logger.debug("startTime: {}, endTime: {}", startTime, endTime);
List<IApplicationComponentUIDAO.ApplicationComponent> applicationComponents = applicationComponentUIDAO.load(step, startTime, endTime);
List<IApplicationMappingUIDAO.ApplicationMapping> applicationMappings = applicationMappingUIDAO.load(step, startTime, endTime);
Map<Integer, String> components = new HashMap<>();
applicationComponents.forEach(component -> components.put(component.getApplicationId(), ComponentsDefine.getInstance().getComponentName(component.getComponentId())));
List<Call> callerCalls = applicationReferenceMetricUIDAO.getFrontApplications(step, applicationId, startTime, endTime, MetricSource.Caller);
callerCalls.addAll(applicationReferenceMetricUIDAO.getBehindApplications(step, applicationId, startTime, endTime, MetricSource.Caller));
callerCalls.forEach(callerCall -> callerCall.setCallType(components.get(callerCall.getTarget())));
List<Call> calleeCalls = applicationReferenceMetricUIDAO.getFrontApplications(step, applicationId, startTime, endTime, MetricSource.Callee);
calleeCalls.addAll(applicationReferenceMetricUIDAO.getBehindApplications(step, applicationId, startTime, endTime, MetricSource.Callee));
calleeCalls.forEach(calleeCall -> calleeCall.setCallType(components.get(calleeCall.getTarget())));
Set<Integer> mappings = new HashSet<>();
applicationMappings.forEach(mapping -> {
if (applicationId == mapping.getApplicationId()) {
mappings.add(mapping.getMappingApplicationId());
}
});
mappings.forEach(mappingApplicationId -> {
List<Call> frontCallerApplications = applicationReferenceMetricUIDAO.getFrontApplications(step, mappingApplicationId, startTime, endTime, MetricSource.Caller);
frontCallerApplications.forEach(call -> {
call.setCallType(components.get(call.getTarget()));
call.setTarget(applicationId);
callerCalls.add(call);
});
List<Call> behindCallerApplications = applicationReferenceMetricUIDAO.getBehindApplications(step, mappingApplicationId, startTime, endTime, MetricSource.Caller);
behindCallerApplications.forEach(call -> {
call.setCallType(components.get(call.getTarget()));
call.setSource(applicationId);
callerCalls.add(call);
});
List<Call> frontCalleeApplications = applicationReferenceMetricUIDAO.getFrontApplications(step, mappingApplicationId, startTime, endTime, MetricSource.Callee);
frontCalleeApplications.forEach(call -> {
call.setCallType(components.get(call.getTarget()));
call.setTarget(applicationId);
calleeCalls.add(call);
});
List<Call> behindCalleeApplications = applicationReferenceMetricUIDAO.getBehindApplications(step, mappingApplicationId, startTime, endTime, MetricSource.Callee);
behindCalleeApplications.forEach(call -> {
call.setCallType(components.get(call.getTarget()));
call.setSource(applicationId);
calleeCalls.add(call);
});
});
TopologyBuilder builder = new TopologyBuilder(moduleManager);
long secondsBetween = DurationUtils.INSTANCE.secondsBetween(step, startTime, endTime);
Topology topology = builder.build(applicationComponents, applicationMappings, callerCalls, calleeCalls, secondsBetween);
topology.getCalls().forEach(call -> {
int calls = call.getCalls();
long responseTimes = call.getResponseTimes();
call.setCallsPerSec((int)(calls / secondsBetween));
call.setResponseTimePerSec((int)(responseTimes / secondsBetween));
});
return topology;
}
}
......@@ -60,7 +60,7 @@ public class InstanceHealthService {
response.add("instances", instances);
// instanceList.forEach(instance -> {
// response.addProperty("applicationCode", applicationCacheService.getApplicationCodeById(applicationId));
// response.addProperty("applicationCode", applicationCacheService.getApplicationById(applicationId));
// response.addProperty("applicationId", applicationId);
//
// IInstanceMetricUIDAO.InstanceMetric performance = instanceMetricUIDAO.get(timeBuckets, instance.getInstanceId());
......
......@@ -108,7 +108,7 @@ public class SpanService {
if (spanObject.getPeerId() == 0) {
peerJson.addProperty("value", spanObject.getPeer());
} else {
peerJson.addProperty("value", applicationCacheService.getApplicationCodeById(spanObject.getPeerId()));
peerJson.addProperty("value", applicationCacheService.getApplicationById(spanObject.getPeerId()).getApplicationCode());
}
tagsArray.add(peerJson);
......
/*
* 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.ui.service;
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;
import org.apache.skywalking.apm.collector.core.util.BooleanUtils;
import org.apache.skywalking.apm.collector.core.util.Const;
import org.apache.skywalking.apm.collector.storage.dao.IApplicationComponentUIDAO;
import org.apache.skywalking.apm.collector.storage.dao.IApplicationMappingUIDAO;
import org.apache.skywalking.apm.collector.storage.table.register.Application;
import org.apache.skywalking.apm.collector.storage.ui.application.ApplicationNode;
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.Topology;
import org.apache.skywalking.apm.collector.storage.ui.common.VisualUserNode;
import org.apache.skywalking.apm.network.trace.component.ComponentsDefine;
/**
* @author peng-yongsheng
*/
class TopologyBuilder {
private final ApplicationCacheService applicationCacheService;
TopologyBuilder(ModuleManager moduleManager) {
this.applicationCacheService = moduleManager.find(CacheModule.NAME).getService(ApplicationCacheService.class);
}
Topology build(List<IApplicationComponentUIDAO.ApplicationComponent> applicationComponents,
List<IApplicationMappingUIDAO.ApplicationMapping> applicationMappings, List<Call> callerCalls,
List<Call> calleeCalls, long secondsBetween) {
Map<Integer, String> components = changeNodeComp2Map(applicationComponents);
Map<String, String> mappings = changeMapping2Map(applicationMappings);
List<Call> calls = buildCalls(callerCalls, calleeCalls);
Set<Integer> nodeIds = new HashSet<>();
calls.forEach(call -> {
String sourceName = applicationCacheService.getApplicationById(call.getSource()).getApplicationCode();
String targetName = applicationCacheService.getApplicationById(call.getTarget()).getApplicationCode();
call.setSourceName(sourceName);
call.setTargetName(targetName);
nodeIds.add(call.getSource());
nodeIds.add(call.getTarget());
});
List<Node> nodes = new LinkedList<>();
nodeIds.forEach(nodeId -> {
Application application = applicationCacheService.getApplicationById(nodeId);
if (BooleanUtils.valueToBoolean(application.getAddressId())) {
ConjecturalNode conjecturalNode = new ConjecturalNode();
conjecturalNode.setId(nodeId);
conjecturalNode.setName(application.getApplicationCode());
conjecturalNode.setType(components.getOrDefault(application.getApplicationId(), Const.UNKNOWN));
nodes.add(conjecturalNode);
} else {
if (nodeId == Const.NONE_APPLICATION_ID) {
VisualUserNode node = new VisualUserNode();
node.setId(nodeId);
node.setName(Const.USER_CODE);
node.setType(Const.USER_CODE.toUpperCase());
nodes.add(node);
} else {
ApplicationNode applicationNode = new ApplicationNode();
applicationNode.setId(nodeId);
applicationNode.setName(application.getApplicationCode());
applicationNode.setType(components.getOrDefault(application.getApplicationId(), Const.UNKNOWN));
calleeCalls.forEach(call -> {
if (call.getTarget() == nodeId) {
call.setCallsPerSec((int)(call.getCalls() / secondsBetween));
call.setResponseTimePerSec((int)(call.getResponseTimes() / secondsBetween));
}
});
nodes.add(applicationNode);
}
}
});
Topology topology = new Topology();
topology.setCalls(calls);
topology.setNodes(nodes);
return topology;
}
private Map<String, String> changeMapping2Map(
List<IApplicationMappingUIDAO.ApplicationMapping> applicationMappings) {
Map<String, String> mappings = new HashMap<>();
applicationMappings.forEach(applicationMapping -> {
String applicationCode = applicationCacheService.getApplicationById(applicationMapping.getApplicationId()).getApplicationCode();
String address = applicationCacheService.getApplicationById(applicationMapping.getMappingApplicationId()).getApplicationCode();
mappings.put(address, applicationCode);
});
return mappings;
}
private Map<Integer, String> changeNodeComp2Map(
List<IApplicationComponentUIDAO.ApplicationComponent> applicationComponents) {
Map<Integer, String> components = new HashMap<>();
applicationComponents.forEach(applicationComponent -> {
String componentName = ComponentsDefine.getInstance().getComponentName(applicationComponent.getComponentId());
components.put(applicationComponent.getApplicationId(), componentName);
});
return components;
}
private List<Call> buildCalls(List<Call> callerCalls, List<Call> calleeCalls) {
List<Call> calls = new LinkedList<>();
Set<String> distinctCalls = new HashSet<>();
callerCalls.forEach(callerCall -> {
distinctCalls.add(callerCall.getSource() + Const.ID_SPLIT + callerCall.getTarget());
calls.add(callerCall);
});
calleeCalls.forEach(calleeCall -> {
String call = calleeCall.getSource() + Const.ID_SPLIT + calleeCall.getTarget();
if (!distinctCalls.contains(call)) {
distinctCalls.add(call);
calls.add(calleeCall);
}
});
return calls;
}
}
/*
* 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.ui.service;
import com.google.gson.JsonArray;
import com.google.gson.JsonObject;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.Map;
import org.apache.skywalking.apm.collector.cache.CacheModule;
import org.apache.skywalking.apm.collector.core.util.Const;
import org.apache.skywalking.apm.collector.storage.table.application.ApplicationComponentTable;
import org.apache.skywalking.apm.collector.storage.table.application.ApplicationMappingTable;
import org.apache.skywalking.apm.collector.storage.table.application.ApplicationReferenceMetricTable;
import org.apache.skywalking.apm.collector.cache.service.ApplicationCacheService;
import org.apache.skywalking.apm.collector.core.module.ModuleManager;
import org.apache.skywalking.apm.collector.core.util.ColumnNameUtils;
import org.apache.skywalking.apm.network.trace.component.ComponentsDefine;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* @author peng-yongsheng
*/
public class TraceDagDataBuilder {
private final Logger logger = LoggerFactory.getLogger(TraceDagDataBuilder.class);
private Integer nodeId = -1;
private Map<String, String> mappingMap = new HashMap<>();
private Map<String, String> nodeCompMap = new HashMap<>();
private Map<String, Integer> nodeIdMap = new HashMap<>();
private JsonArray pointArray = new JsonArray();
private JsonArray lineArray = new JsonArray();
private final ApplicationCacheService applicationCacheService;
public TraceDagDataBuilder(ModuleManager moduleManager) {
this.applicationCacheService = moduleManager.find(CacheModule.NAME).getService(ApplicationCacheService.class);
}
public JsonObject build(JsonArray nodeCompArray, JsonArray nodesMappingArray, JsonArray resSumArray) {
changeNodeComp2Map(nodeCompArray);
changeMapping2Map(nodesMappingArray);
Map<String, JsonObject> mergedResSumMap = getApplicationCode(resSumArray);
mergedResSumMap.values().forEach(nodeRefJsonObj -> {
String front = nodeRefJsonObj.get("front").getAsString();
String behind = nodeRefJsonObj.get("behind").getAsString();
if (hasMapping(behind)) {
return;
}
JsonObject lineJsonObj = new JsonObject();
lineJsonObj.addProperty("from", findOrCreateNode(front));
lineJsonObj.addProperty("to", findOrCreateNode(behind));
lineJsonObj.addProperty("resSum", nodeRefJsonObj.get(ApplicationReferenceMetricTable.COLUMN_TRANSACTION_CALLS).getAsInt());
lineArray.add(lineJsonObj);
logger.debug("line: {}", lineJsonObj);
});
JsonObject dagJsonObj = new JsonObject();
dagJsonObj.add("nodes", pointArray);
dagJsonObj.add("nodeRefs", lineArray);
return dagJsonObj;
}
private Integer findOrCreateNode(String peers) {
if (nodeIdMap.containsKey(peers) && !peers.equals(Const.USER_CODE)) {
return nodeIdMap.get(peers);
} else {
nodeId++;
JsonObject nodeJsonObj = new JsonObject();
nodeJsonObj.addProperty("id", nodeId);
nodeJsonObj.addProperty("peer", peers);
if (peers.equals(Const.USER_CODE)) {
nodeJsonObj.addProperty("component", Const.USER_CODE);
} else {
nodeJsonObj.addProperty("component", nodeCompMap.get(peers));
}
pointArray.add(nodeJsonObj);
nodeIdMap.put(peers, nodeId);
logger.debug("node: {}", nodeJsonObj);
}
return nodeId;
}
private void changeMapping2Map(JsonArray nodesMappingArray) {
for (int i = 0; i < nodesMappingArray.size(); i++) {
JsonObject nodesMappingJsonObj = nodesMappingArray.get(i).getAsJsonObject();
int applicationId = nodesMappingJsonObj.get(ApplicationMappingTable.COLUMN_APPLICATION_ID).getAsInt();
String applicationCode = applicationCacheService.getApplicationCodeById(applicationId);
int addressId = nodesMappingJsonObj.get(ApplicationMappingTable.COLUMN_ADDRESS_ID).getAsInt();
String address = applicationCacheService.getApplicationCodeById(addressId);
mappingMap.put(address, applicationCode);
}
}
private void changeNodeComp2Map(JsonArray nodeCompArray) {
for (int i = 0; i < nodeCompArray.size(); i++) {
JsonObject nodesJsonObj = nodeCompArray.get(i).getAsJsonObject();
logger.debug(nodesJsonObj.toString());
int componentId = nodesJsonObj.get(ApplicationComponentTable.COLUMN_COMPONENT_ID).getAsInt();
String componentName = ComponentsDefine.getInstance().getComponentName(componentId);
int peerId = nodesJsonObj.get(ApplicationComponentTable.COLUMN_PEER_ID).getAsInt();
String peer = applicationCacheService.getApplicationCodeById(peerId);
nodeCompMap.put(peer, componentName);
}
}
private boolean hasMapping(String peers) {
return mappingMap.containsKey(peers);
}
private Map<String, JsonObject> getApplicationCode(JsonArray nodeReference) {
Map<String, JsonObject> mergedRef = new LinkedHashMap<>();
for (int i = 0; i < nodeReference.size(); i++) {
JsonObject nodeRefJsonObj = nodeReference.get(i).getAsJsonObject();
int frontApplicationId = nodeRefJsonObj.get(ColumnNameUtils.INSTANCE.rename(ApplicationReferenceMetricTable.COLUMN_FRONT_APPLICATION_ID)).getAsInt();
int behindApplicationId = nodeRefJsonObj.get(ColumnNameUtils.INSTANCE.rename(ApplicationReferenceMetricTable.COLUMN_BEHIND_APPLICATION_ID)).getAsInt();
String front = applicationCacheService.getApplicationCodeById(frontApplicationId);
String behind = applicationCacheService.getApplicationCodeById(behindApplicationId);
String id = front + Const.ID_SPLIT + behind;
nodeRefJsonObj.addProperty("front", front);
nodeRefJsonObj.addProperty("behind", behind);
mergedRef.put(id, nodeRefJsonObj);
}
return mergedRef;
}
}
......@@ -134,7 +134,7 @@ public class TraceStackService {
operationName = Const.EMPTY_STRING;
}
}
String applicationCode = applicationCacheService.getApplicationCodeById(segment.getApplicationId());
String applicationCode = applicationCacheService.getApplicationById(segment.getApplicationId()).getApplicationCode();
long cost = spanObject.getEndTime() - spanObject.getStartTime();
if (cost == 0) {
......
/*
* 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.ui.utils;
import java.text.ParseException;
import java.util.Date;
import org.apache.skywalking.apm.collector.core.util.Const;
import org.apache.skywalking.apm.collector.core.util.TimeBucketUtils;
import org.apache.skywalking.apm.collector.storage.ui.common.Step;
import org.joda.time.DateTime;
import org.joda.time.Seconds;
/**
* @author peng-yongsheng
*/
public enum DurationUtils {
INSTANCE;
public long exchangeToTimeBucket(String dateStr) throws ParseException {
dateStr = dateStr.replaceAll("-", Const.EMPTY_STRING);
dateStr = dateStr.replaceAll(" ", Const.EMPTY_STRING);
return Long.valueOf(dateStr);
}
public long durationToSecondTimeBucket(Step step, String dateStr) throws ParseException {
long secondTimeBucket = 0;
switch (step) {
case MONTH:
secondTimeBucket = exchangeToTimeBucket(dateStr) * 100 * 100 * 100 * 100;
break;
case DAY:
secondTimeBucket = exchangeToTimeBucket(dateStr) * 100 * 100 * 100;
break;
case HOUR:
secondTimeBucket = exchangeToTimeBucket(dateStr) * 100 * 100;
break;
case MINUTE:
secondTimeBucket = exchangeToTimeBucket(dateStr) * 100;
break;
case SECOND:
secondTimeBucket = exchangeToTimeBucket(dateStr);
break;
}
return secondTimeBucket;
}
public long secondsBetween(Step step, long start, long end) throws ParseException {
Date startDate = null;
Date endDate = null;
switch (step) {
case MONTH:
startDate = TimeBucketUtils.MONTH_DATE_FORMAT.parse(String.valueOf(start));
endDate = TimeBucketUtils.MONTH_DATE_FORMAT.parse(String.valueOf(end));
break;
case DAY:
startDate = TimeBucketUtils.DAY_DATE_FORMAT.parse(String.valueOf(start));
endDate = TimeBucketUtils.DAY_DATE_FORMAT.parse(String.valueOf(end));
break;
case HOUR:
startDate = TimeBucketUtils.HOUR_DATE_FORMAT.parse(String.valueOf(start));
endDate = TimeBucketUtils.HOUR_DATE_FORMAT.parse(String.valueOf(end));
break;
case MINUTE:
startDate = TimeBucketUtils.MINUTE_DATE_FORMAT.parse(String.valueOf(start));
endDate = TimeBucketUtils.MINUTE_DATE_FORMAT.parse(String.valueOf(end));
break;
case SECOND:
startDate = TimeBucketUtils.SECOND_DATE_FORMAT.parse(String.valueOf(start));
endDate = TimeBucketUtils.SECOND_DATE_FORMAT.parse(String.valueOf(end));
break;
}
return Seconds.secondsBetween(new DateTime(startDate), new DateTime(endDate)).getSeconds();
}
}
......@@ -40,8 +40,8 @@ public class ApplicationQueryTestCase {
Mockito.when(applicationService.getApplications(Mockito.anyLong(), Mockito.anyLong())).then(invocation -> {
Object[] arguments = invocation.getArguments();
Assert.assertEquals(20170100000000l, arguments[0]);
Assert.assertEquals(20170100000000l, arguments[1]);
Assert.assertEquals(20170100000000L, arguments[0]);
Assert.assertEquals(20170100000000L, arguments[1]);
return null;
});
......@@ -61,8 +61,8 @@ public class ApplicationQueryTestCase {
Mockito.when(applicationService.getApplications(Mockito.anyLong(), Mockito.anyLong())).then(invocation -> {
Object[] arguments = invocation.getArguments();
Assert.assertEquals(20170101000000l, arguments[0]);
Assert.assertEquals(20170101000000l, arguments[1]);
Assert.assertEquals(20170101000000L, arguments[0]);
Assert.assertEquals(20170101000000L, arguments[1]);
return null;
});
......@@ -82,8 +82,8 @@ public class ApplicationQueryTestCase {
Mockito.when(applicationService.getApplications(Mockito.anyLong(), Mockito.anyLong())).then(invocation -> {
Object[] arguments = invocation.getArguments();
Assert.assertEquals(20170101010000l, arguments[0]);
Assert.assertEquals(20170101010000l, arguments[1]);
Assert.assertEquals(20170101010000L, arguments[0]);
Assert.assertEquals(20170101010000L, arguments[1]);
return null;
});
......@@ -103,8 +103,8 @@ public class ApplicationQueryTestCase {
Mockito.when(applicationService.getApplications(Mockito.anyLong(), Mockito.anyLong())).then(invocation -> {
Object[] arguments = invocation.getArguments();
Assert.assertEquals(20170101010100l, arguments[0]);
Assert.assertEquals(20170101010100l, arguments[1]);
Assert.assertEquals(20170101010100L, arguments[0]);
Assert.assertEquals(20170101010100L, arguments[1]);
return null;
});
......@@ -124,8 +124,8 @@ public class ApplicationQueryTestCase {
Mockito.when(applicationService.getApplications(Mockito.anyLong(), Mockito.anyLong())).then(invocation -> {
Object[] arguments = invocation.getArguments();
Assert.assertEquals(20170101010101l, arguments[0]);
Assert.assertEquals(20170101010101l, arguments[1]);
Assert.assertEquals(20170101010101L, arguments[0]);
Assert.assertEquals(20170101010101L, arguments[1]);
return null;
});
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册