提交 4582e9d9 编写于 作者: P pengys5

Support entry service id or entry service name argument to query service tree.

上级 8abad65f
...@@ -58,11 +58,7 @@ public class ServiceEntrySpanListener implements RefsListener, FirstSpanListener ...@@ -58,11 +58,7 @@ public class ServiceEntrySpanListener implements RefsListener, FirstSpanListener
StreamModuleContext context = (StreamModuleContext)CollectorContextHelper.INSTANCE.getContext(StreamModuleGroupDefine.GROUP_NAME); StreamModuleContext context = (StreamModuleContext)CollectorContextHelper.INSTANCE.getContext(StreamModuleGroupDefine.GROUP_NAME);
if (!hasReference && hasEntry) { if (!hasReference && hasEntry) {
ServiceEntryDataDefine.ServiceEntry serviceEntry = new ServiceEntryDataDefine.ServiceEntry(); ServiceEntryDataDefine.ServiceEntry serviceEntry = new ServiceEntryDataDefine.ServiceEntry();
if (entryServiceId == 0) { serviceEntry.setId(applicationId + Const.ID_SPLIT + entryServiceName);
serviceEntry.setId(applicationId + Const.ID_SPLIT + entryServiceName);
} else {
serviceEntry.setId(applicationId + Const.ID_SPLIT + entryServiceId);
}
serviceEntry.setApplicationId(applicationId); serviceEntry.setApplicationId(applicationId);
serviceEntry.setEntryServiceId(entryServiceId); serviceEntry.setEntryServiceId(entryServiceId);
serviceEntry.setEntryServiceName(entryServiceName); serviceEntry.setEntryServiceName(entryServiceName);
......
...@@ -21,7 +21,7 @@ public class ServiceEntryDataDefine extends DataDefine { ...@@ -21,7 +21,7 @@ public class ServiceEntryDataDefine extends DataDefine {
@Override protected void attributeDefine() { @Override protected void attributeDefine() {
addAttribute(0, new Attribute(ServiceEntryTable.COLUMN_ID, AttributeType.STRING, new NonOperation())); addAttribute(0, new Attribute(ServiceEntryTable.COLUMN_ID, AttributeType.STRING, new NonOperation()));
addAttribute(1, new Attribute(ServiceEntryTable.COLUMN_APPLICATION_ID, AttributeType.INTEGER, new NonOperation())); addAttribute(1, new Attribute(ServiceEntryTable.COLUMN_APPLICATION_ID, AttributeType.INTEGER, new NonOperation()));
addAttribute(2, new Attribute(ServiceEntryTable.COLUMN_ENTRY_SERVICE_ID, AttributeType.INTEGER, new NonOperation())); addAttribute(2, new Attribute(ServiceEntryTable.COLUMN_ENTRY_SERVICE_ID, AttributeType.INTEGER, new CoverOperation()));
addAttribute(3, new Attribute(ServiceEntryTable.COLUMN_ENTRY_SERVICE_NAME, AttributeType.STRING, new NonOperation())); addAttribute(3, new Attribute(ServiceEntryTable.COLUMN_ENTRY_SERVICE_NAME, AttributeType.STRING, new NonOperation()));
addAttribute(4, new Attribute(ServiceEntryTable.COLUMN_REGISTER_TIME, AttributeType.LONG, new NonOperation())); addAttribute(4, new Attribute(ServiceEntryTable.COLUMN_REGISTER_TIME, AttributeType.LONG, new NonOperation()));
addAttribute(5, new Attribute(ServiceEntryTable.COLUMN_NEWEST_TIME, AttributeType.LONG, new CoverOperation())); addAttribute(5, new Attribute(ServiceEntryTable.COLUMN_NEWEST_TIME, AttributeType.LONG, new CoverOperation()));
......
...@@ -12,7 +12,7 @@ import org.skywalking.apm.collector.ui.dao.IServiceNameDAO; ...@@ -12,7 +12,7 @@ import org.skywalking.apm.collector.ui.dao.IServiceNameDAO;
public class ServiceNameCache { public class ServiceNameCache {
//TODO size configuration //TODO size configuration
private static Cache<Integer, String> CACHE = CacheBuilder.newBuilder().maximumSize(1000).build(); private static Cache<Integer, String> CACHE = CacheBuilder.newBuilder().maximumSize(10000).build();
public static String get(int serviceId) { public static String get(int serviceId) {
try { try {
......
...@@ -7,4 +7,6 @@ import com.google.gson.JsonArray; ...@@ -7,4 +7,6 @@ import com.google.gson.JsonArray;
*/ */
public interface IServiceReferenceDAO { public interface IServiceReferenceDAO {
JsonArray load(int entryServiceId, long startTime, long endTime); JsonArray load(int entryServiceId, long startTime, long endTime);
JsonArray load(String entryServiceName, int entryApplicationId, long startTime, long endTime);
} }
...@@ -22,7 +22,9 @@ public class ServiceNameEsDAO extends EsDAO implements IServiceNameDAO { ...@@ -22,7 +22,9 @@ public class ServiceNameEsDAO extends EsDAO implements IServiceNameDAO {
GetResponse getResponse = getRequestBuilder.get(); GetResponse getResponse = getRequestBuilder.get();
if (getResponse.isExists()) { if (getResponse.isExists()) {
return (String)getResponse.getSource().get(ServiceNameTable.COLUMN_SERVICE_NAME); String serviceName = (String)getResponse.getSource().get(ServiceNameTable.COLUMN_SERVICE_NAME);
int applicationId = ((Number)getResponse.getSource().get(ServiceNameTable.COLUMN_APPLICATION_ID)).intValue();
return applicationId + Const.ID_SPLIT + serviceName;
} }
return Const.UNKNOWN; return Const.UNKNOWN;
} }
......
...@@ -27,18 +27,51 @@ public class ServiceReferenceEsDAO extends EsDAO implements IServiceReferenceDAO ...@@ -27,18 +27,51 @@ public class ServiceReferenceEsDAO extends EsDAO implements IServiceReferenceDAO
private final Logger logger = LoggerFactory.getLogger(ServiceReferenceEsDAO.class); private final Logger logger = LoggerFactory.getLogger(ServiceReferenceEsDAO.class);
@Override public JsonArray load(String entryServiceName, int entryApplicationId, long startTime, long endTime) {
SearchRequestBuilder searchRequestBuilder = getClient().prepareSearch(ServiceReferenceTable.TABLE);
searchRequestBuilder.setTypes(ServiceReferenceTable.TABLE_TYPE);
searchRequestBuilder.setSearchType(SearchType.DFS_QUERY_THEN_FETCH);
BoolQueryBuilder boolQuery = QueryBuilders.boolQuery();
boolQuery.must().add(QueryBuilders.rangeQuery(ServiceReferenceTable.COLUMN_TIME_BUCKET).gte(startTime).lte(endTime));
boolQuery.must().add(QueryBuilders.rangeQuery(ServiceReferenceTable.COLUMN_TIME_BUCKET).gte(startTime).lte(endTime));
int entryServiceId = ServiceIdCache.get(entryApplicationId, entryServiceName);
BoolQueryBuilder entryBoolQuery = QueryBuilders.boolQuery();
if (entryServiceId != 0) {
entryBoolQuery.should().add(QueryBuilders.matchQuery(ServiceReferenceTable.COLUMN_ENTRY_SERVICE_ID, entryServiceId));
}
entryBoolQuery.should().add(QueryBuilders.matchQuery(ServiceReferenceTable.COLUMN_ENTRY_SERVICE_NAME, entryApplicationId + Const.ID_SPLIT + entryServiceName));
boolQuery.must(entryBoolQuery);
searchRequestBuilder.setQuery(boolQuery);
searchRequestBuilder.setSize(0);
return load(searchRequestBuilder);
}
@Override public JsonArray load(int entryServiceId, long startTime, long endTime) { @Override public JsonArray load(int entryServiceId, long startTime, long endTime) {
SearchRequestBuilder searchRequestBuilder = getClient().prepareSearch(ServiceReferenceTable.TABLE); SearchRequestBuilder searchRequestBuilder = getClient().prepareSearch(ServiceReferenceTable.TABLE);
searchRequestBuilder.setTypes(ServiceReferenceTable.TABLE_TYPE); searchRequestBuilder.setTypes(ServiceReferenceTable.TABLE_TYPE);
searchRequestBuilder.setSearchType(SearchType.DFS_QUERY_THEN_FETCH); searchRequestBuilder.setSearchType(SearchType.DFS_QUERY_THEN_FETCH);
BoolQueryBuilder boolQuery = QueryBuilders.boolQuery(); BoolQueryBuilder boolQuery = QueryBuilders.boolQuery();
boolQuery.should().add(QueryBuilders.matchQuery(ServiceReferenceTable.COLUMN_ENTRY_SERVICE_ID, entryServiceId));
boolQuery.should().add(QueryBuilders.matchQuery(ServiceReferenceTable.COLUMN_ENTRY_SERVICE_NAME, ServiceNameCache.getForUI(entryServiceId)));
boolQuery.must().add(QueryBuilders.rangeQuery(ServiceReferenceTable.COLUMN_TIME_BUCKET).gte(startTime).lte(endTime)); boolQuery.must().add(QueryBuilders.rangeQuery(ServiceReferenceTable.COLUMN_TIME_BUCKET).gte(startTime).lte(endTime));
boolQuery.must().add(QueryBuilders.rangeQuery(ServiceReferenceTable.COLUMN_TIME_BUCKET).gte(startTime).lte(endTime));
String entryServiceName = ServiceNameCache.get(entryServiceId);
BoolQueryBuilder entryBoolQuery = QueryBuilders.boolQuery();
entryBoolQuery.should().add(QueryBuilders.matchQuery(ServiceReferenceTable.COLUMN_ENTRY_SERVICE_ID, entryServiceId));
entryBoolQuery.should().add(QueryBuilders.matchQuery(ServiceReferenceTable.COLUMN_ENTRY_SERVICE_NAME, entryServiceName));
boolQuery.must(entryBoolQuery);
searchRequestBuilder.setQuery(boolQuery); searchRequestBuilder.setQuery(boolQuery);
searchRequestBuilder.setSize(0); searchRequestBuilder.setSize(0);
return load(searchRequestBuilder);
}
private JsonArray load(SearchRequestBuilder searchRequestBuilder) {
searchRequestBuilder.addAggregation(AggregationBuilders.terms(ServiceReferenceTable.COLUMN_FRONT_SERVICE_ID).field(ServiceReferenceTable.COLUMN_FRONT_SERVICE_ID).size(100) searchRequestBuilder.addAggregation(AggregationBuilders.terms(ServiceReferenceTable.COLUMN_FRONT_SERVICE_ID).field(ServiceReferenceTable.COLUMN_FRONT_SERVICE_ID).size(100)
.subAggregation(AggregationBuilders.terms(ServiceReferenceTable.COLUMN_BEHIND_SERVICE_ID).field(ServiceReferenceTable.COLUMN_BEHIND_SERVICE_ID).size(100) .subAggregation(AggregationBuilders.terms(ServiceReferenceTable.COLUMN_BEHIND_SERVICE_ID).field(ServiceReferenceTable.COLUMN_BEHIND_SERVICE_ID).size(100)
.subAggregation(AggregationBuilders.sum(ServiceReferenceTable.COLUMN_S1_LTE).field(ServiceReferenceTable.COLUMN_S1_LTE)) .subAggregation(AggregationBuilders.sum(ServiceReferenceTable.COLUMN_S1_LTE).field(ServiceReferenceTable.COLUMN_S1_LTE))
...@@ -112,7 +145,13 @@ public class ServiceReferenceEsDAO extends EsDAO implements IServiceReferenceDAO ...@@ -112,7 +145,13 @@ public class ServiceReferenceEsDAO extends EsDAO implements IServiceReferenceDAO
Sum costSum = behindServiceIdBucket.getAggregations().get(ServiceReferenceTable.COLUMN_COST_SUMMARY); Sum costSum = behindServiceIdBucket.getAggregations().get(ServiceReferenceTable.COLUMN_COST_SUMMARY);
String frontServiceName = ServiceNameCache.getForUI(frontServiceId); String frontServiceName = ServiceNameCache.getForUI(frontServiceId);
if (StringUtils.isNotEmpty(frontServiceName)) {
frontServiceName = frontServiceName.split(Const.ID_SPLIT)[1];
}
String behindServiceName = ServiceNameCache.getForUI(behindServiceId); String behindServiceName = ServiceNameCache.getForUI(behindServiceId);
if (StringUtils.isNotEmpty(frontServiceName)) {
behindServiceName = behindServiceName.split(Const.ID_SPLIT)[1];
}
JsonObject serviceReference = new JsonObject(); JsonObject serviceReference = new JsonObject();
serviceReference.addProperty(ColumnNameUtils.INSTANCE.rename(ServiceReferenceTable.COLUMN_FRONT_SERVICE_ID), frontServiceId); serviceReference.addProperty(ColumnNameUtils.INSTANCE.rename(ServiceReferenceTable.COLUMN_FRONT_SERVICE_ID), frontServiceId);
......
...@@ -11,4 +11,8 @@ public class ServiceReferenceH2DAO extends H2DAO implements IServiceReferenceDAO ...@@ -11,4 +11,8 @@ public class ServiceReferenceH2DAO extends H2DAO implements IServiceReferenceDAO
@Override public JsonArray load(int entryServiceId, long startTime, long endTime) { @Override public JsonArray load(int entryServiceId, long startTime, long endTime) {
return null; return null;
} }
@Override public JsonArray load(String entryServiceName, int entryApplicationId, long startTime, long endTime) {
return null;
}
} }
...@@ -21,7 +21,8 @@ import org.skywalking.apm.collector.ui.jetty.handler.instancemetric.InstanceMetr ...@@ -21,7 +21,8 @@ import org.skywalking.apm.collector.ui.jetty.handler.instancemetric.InstanceMetr
import org.skywalking.apm.collector.ui.jetty.handler.instancemetric.InstanceMetricGetRangeTimeBucketHandler; import org.skywalking.apm.collector.ui.jetty.handler.instancemetric.InstanceMetricGetRangeTimeBucketHandler;
import org.skywalking.apm.collector.ui.jetty.handler.instancemetric.InstanceOsInfoGetHandler; import org.skywalking.apm.collector.ui.jetty.handler.instancemetric.InstanceOsInfoGetHandler;
import org.skywalking.apm.collector.ui.jetty.handler.servicetree.EntryServiceGetHandler; import org.skywalking.apm.collector.ui.jetty.handler.servicetree.EntryServiceGetHandler;
import org.skywalking.apm.collector.ui.jetty.handler.servicetree.ServiceTreeGetHandler; import org.skywalking.apm.collector.ui.jetty.handler.servicetree.ServiceTreeGetByIdHandler;
import org.skywalking.apm.collector.ui.jetty.handler.servicetree.ServiceTreeGetByNameHandler;
import org.skywalking.apm.collector.ui.jetty.handler.time.AllInstanceLastTimeGetHandler; import org.skywalking.apm.collector.ui.jetty.handler.time.AllInstanceLastTimeGetHandler;
import org.skywalking.apm.collector.ui.jetty.handler.time.OneInstanceLastTimeGetHandler; import org.skywalking.apm.collector.ui.jetty.handler.time.OneInstanceLastTimeGetHandler;
...@@ -71,7 +72,8 @@ public class UIJettyModuleDefine extends UIModuleDefine { ...@@ -71,7 +72,8 @@ public class UIJettyModuleDefine extends UIModuleDefine {
handlers.add(new InstanceMetricGetOneTimeBucketHandler()); handlers.add(new InstanceMetricGetOneTimeBucketHandler());
handlers.add(new InstanceMetricGetRangeTimeBucketHandler()); handlers.add(new InstanceMetricGetRangeTimeBucketHandler());
handlers.add(new EntryServiceGetHandler()); handlers.add(new EntryServiceGetHandler());
handlers.add(new ServiceTreeGetHandler()); handlers.add(new ServiceTreeGetByIdHandler());
handlers.add(new ServiceTreeGetByNameHandler());
return handlers; return handlers;
} }
} }
...@@ -11,12 +11,12 @@ import org.slf4j.LoggerFactory; ...@@ -11,12 +11,12 @@ import org.slf4j.LoggerFactory;
/** /**
* @author pengys5 * @author pengys5
*/ */
public class ServiceTreeGetHandler extends JettyHandler { public class ServiceTreeGetByIdHandler extends JettyHandler {
private final Logger logger = LoggerFactory.getLogger(ServiceTreeGetHandler.class); private final Logger logger = LoggerFactory.getLogger(ServiceTreeGetByIdHandler.class);
@Override public String pathSpec() { @Override public String pathSpec() {
return "/service/tree"; return "/service/tree/entryServiceId";
} }
private ServiceTreeService service = new ServiceTreeService(); private ServiceTreeService service = new ServiceTreeService();
......
package org.skywalking.apm.collector.ui.jetty.handler.servicetree;
import com.google.gson.JsonElement;
import javax.servlet.http.HttpServletRequest;
import org.skywalking.apm.collector.server.jetty.ArgumentsParseException;
import org.skywalking.apm.collector.server.jetty.JettyHandler;
import org.skywalking.apm.collector.ui.service.ServiceTreeService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* @author pengys5
*/
public class ServiceTreeGetByNameHandler extends JettyHandler {
private final Logger logger = LoggerFactory.getLogger(ServiceTreeGetByNameHandler.class);
@Override public String pathSpec() {
return "/service/tree/entryServiceName";
}
private ServiceTreeService service = new ServiceTreeService();
@Override protected JsonElement doGet(HttpServletRequest req) throws ArgumentsParseException {
if (!req.getParameterMap().containsKey("entryServiceName") || !req.getParameterMap().containsKey("entryApplicationId") || !req.getParameterMap().containsKey("startTime") || !req.getParameterMap().containsKey("endTime")) {
throw new ArgumentsParseException("must contains parameters: entryServiceName, entryApplicationId, startTime, endTime");
}
String entryServiceName = req.getParameter("entryServiceName");
String entryApplicationIdStr = req.getParameter("entryApplicationId");
String startTimeStr = req.getParameter("startTime");
String endTimeStr = req.getParameter("endTime");
logger.debug("service entry get entryServiceName: {}, startTime: {}, endTime: {}", entryServiceName, startTimeStr, endTimeStr);
int entryApplicationId;
try {
entryApplicationId = Integer.parseInt(entryApplicationIdStr);
} catch (NumberFormatException e) {
throw new ArgumentsParseException("entry application id must be integer");
}
long startTime;
try {
startTime = Long.parseLong(startTimeStr);
} catch (NumberFormatException e) {
throw new ArgumentsParseException("start time must be long");
}
long endTime;
try {
endTime = Long.parseLong(endTimeStr);
} catch (NumberFormatException e) {
throw new ArgumentsParseException("end time must be long");
}
return service.loadServiceTree(entryServiceName, entryApplicationId, startTime, endTime);
}
@Override protected JsonElement doPost(HttpServletRequest req) throws ArgumentsParseException {
throw new UnsupportedOperationException();
}
}
...@@ -21,4 +21,9 @@ public class ServiceTreeService { ...@@ -21,4 +21,9 @@ public class ServiceTreeService {
IServiceReferenceDAO serviceReferenceDAO = (IServiceReferenceDAO)DAOContainer.INSTANCE.get(IServiceReferenceDAO.class.getName()); IServiceReferenceDAO serviceReferenceDAO = (IServiceReferenceDAO)DAOContainer.INSTANCE.get(IServiceReferenceDAO.class.getName());
return serviceReferenceDAO.load(entryServiceId, startTime, endTime); return serviceReferenceDAO.load(entryServiceId, startTime, endTime);
} }
public JsonArray loadServiceTree(String entryServiceName, int entryApplicationId, long startTime, long endTime) {
IServiceReferenceDAO serviceReferenceDAO = (IServiceReferenceDAO)DAOContainer.INSTANCE.get(IServiceReferenceDAO.class.getName());
return serviceReferenceDAO.load(entryServiceName, entryApplicationId, startTime, endTime);
}
} }
\ No newline at end of file
...@@ -3,6 +3,8 @@ package org.skywalking.apm.collector.ui.service; ...@@ -3,6 +3,8 @@ package org.skywalking.apm.collector.ui.service;
import com.google.gson.JsonArray; import com.google.gson.JsonArray;
import com.google.gson.JsonObject; import com.google.gson.JsonObject;
import java.util.List; import java.util.List;
import org.skywalking.apm.collector.core.util.Const;
import org.skywalking.apm.collector.core.util.StringUtils;
import org.skywalking.apm.collector.storage.dao.DAOContainer; import org.skywalking.apm.collector.storage.dao.DAOContainer;
import org.skywalking.apm.collector.ui.cache.ServiceNameCache; import org.skywalking.apm.collector.ui.cache.ServiceNameCache;
import org.skywalking.apm.collector.ui.dao.ISegmentDAO; import org.skywalking.apm.collector.ui.dao.ISegmentDAO;
...@@ -26,7 +28,12 @@ public class SpanService { ...@@ -26,7 +28,12 @@ public class SpanService {
if (spanId == spanObject.getSpanId()) { if (spanId == spanObject.getSpanId()) {
String operationName = spanObject.getOperationName(); String operationName = spanObject.getOperationName();
if (spanObject.getOperationNameId() != 0) { if (spanObject.getOperationNameId() != 0) {
operationName = ServiceNameCache.get(spanObject.getOperationNameId()); String serviceName = ServiceNameCache.get(spanObject.getOperationNameId());
if (StringUtils.isNotEmpty(serviceName)) {
operationName = serviceName.split(Const.ID_SPLIT)[1];
} else {
operationName = Const.EMPTY_STRING;
}
} }
spanJson.addProperty("operationName", operationName); spanJson.addProperty("operationName", operationName);
spanJson.addProperty("startTime", spanObject.getStartTime()); spanJson.addProperty("startTime", spanObject.getStartTime());
......
...@@ -7,6 +7,7 @@ import java.util.List; ...@@ -7,6 +7,7 @@ import java.util.List;
import org.skywalking.apm.collector.core.util.CollectionUtils; import org.skywalking.apm.collector.core.util.CollectionUtils;
import org.skywalking.apm.collector.core.util.Const; import org.skywalking.apm.collector.core.util.Const;
import org.skywalking.apm.collector.core.util.ObjectUtils; import org.skywalking.apm.collector.core.util.ObjectUtils;
import org.skywalking.apm.collector.core.util.StringUtils;
import org.skywalking.apm.collector.storage.dao.DAOContainer; import org.skywalking.apm.collector.storage.dao.DAOContainer;
import org.skywalking.apm.collector.ui.cache.ApplicationCache; import org.skywalking.apm.collector.ui.cache.ApplicationCache;
import org.skywalking.apm.collector.ui.cache.ServiceNameCache; import org.skywalking.apm.collector.ui.cache.ServiceNameCache;
...@@ -98,7 +99,12 @@ public class TraceStackService { ...@@ -98,7 +99,12 @@ public class TraceStackService {
String operationName = spanObject.getOperationName(); String operationName = spanObject.getOperationName();
if (spanObject.getOperationNameId() != 0) { if (spanObject.getOperationNameId() != 0) {
operationName = ServiceNameCache.get(spanObject.getOperationNameId()); String serviceName = ServiceNameCache.get(spanObject.getOperationNameId());
if (StringUtils.isNotEmpty(serviceName)) {
operationName = serviceName.split(Const.ID_SPLIT)[1];
} else {
operationName = Const.EMPTY_STRING;
}
} }
String applicationCode = ApplicationCache.get(segment.getApplicationId()); String applicationCode = ApplicationCache.get(segment.getApplicationId());
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册