Provide the searchService query.
This commit is contained in:
parent
1d625d2ad5
commit
b513024a85
|
|
@ -18,11 +18,15 @@
|
|||
|
||||
package org.apache.skywalking.apm.collector.storage.dao.ui;
|
||||
|
||||
import java.util.List;
|
||||
import org.apache.skywalking.apm.collector.storage.base.dao.DAO;
|
||||
import org.apache.skywalking.apm.collector.storage.ui.service.ServiceInfo;
|
||||
|
||||
/**
|
||||
* @author peng-yongsheng
|
||||
*/
|
||||
public interface IServiceNameServiceUIDAO extends DAO {
|
||||
int getCount();
|
||||
|
||||
List<ServiceInfo> searchService(String keyword, int topN);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -24,6 +24,20 @@ package org.apache.skywalking.apm.collector.storage.ui.service;
|
|||
public class ServiceInfo {
|
||||
private int id;
|
||||
private String name;
|
||||
private int avgResponseTime;
|
||||
private int tps;
|
||||
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(int id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -24,7 +24,40 @@ import org.apache.skywalking.apm.collector.storage.ui.common.Node;
|
|||
* @author peng-yongsheng
|
||||
*/
|
||||
public class ServiceNode extends Node {
|
||||
private Float sla;
|
||||
private Long calls;
|
||||
private Integer numOfServiceAlarm;
|
||||
private float sla;
|
||||
private long calls;
|
||||
private int numOfServiceAlarm;
|
||||
private int applicationId;
|
||||
|
||||
public float getSla() {
|
||||
return sla;
|
||||
}
|
||||
|
||||
public void setSla(float sla) {
|
||||
this.sla = sla;
|
||||
}
|
||||
|
||||
public long getCalls() {
|
||||
return calls;
|
||||
}
|
||||
|
||||
public void setCalls(long calls) {
|
||||
this.calls = calls;
|
||||
}
|
||||
|
||||
public int getNumOfServiceAlarm() {
|
||||
return numOfServiceAlarm;
|
||||
}
|
||||
|
||||
public void setNumOfServiceAlarm(int numOfServiceAlarm) {
|
||||
this.numOfServiceAlarm = numOfServiceAlarm;
|
||||
}
|
||||
|
||||
public int getApplicationId() {
|
||||
return applicationId;
|
||||
}
|
||||
|
||||
public void setApplicationId(int applicationId) {
|
||||
this.applicationId = applicationId;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -18,13 +18,18 @@
|
|||
|
||||
package org.apache.skywalking.apm.collector.storage.es.dao.ui;
|
||||
|
||||
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.ui.IServiceNameServiceUIDAO;
|
||||
import org.apache.skywalking.apm.collector.storage.es.base.dao.EsDAO;
|
||||
import org.apache.skywalking.apm.collector.storage.table.register.ServiceNameTable;
|
||||
import org.apache.skywalking.apm.collector.storage.ui.service.ServiceInfo;
|
||||
import org.elasticsearch.action.search.SearchRequestBuilder;
|
||||
import org.elasticsearch.action.search.SearchResponse;
|
||||
import org.elasticsearch.action.search.SearchType;
|
||||
import org.elasticsearch.index.query.QueryBuilders;
|
||||
import org.elasticsearch.search.SearchHit;
|
||||
|
||||
/**
|
||||
* @author peng-yongsheng
|
||||
|
|
@ -44,4 +49,25 @@ public class ServiceNameServiceEsUIDAO extends EsDAO implements IServiceNameServ
|
|||
SearchResponse searchResponse = searchRequestBuilder.execute().actionGet();
|
||||
return (int)searchResponse.getHits().getTotalHits();
|
||||
}
|
||||
|
||||
@Override public List<ServiceInfo> searchService(String keyword, int topN) {
|
||||
SearchRequestBuilder searchRequestBuilder = getClient().prepareSearch(ServiceNameTable.TABLE);
|
||||
searchRequestBuilder.setTypes(ServiceNameTable.TABLE_TYPE);
|
||||
searchRequestBuilder.setSearchType(SearchType.DFS_QUERY_THEN_FETCH);
|
||||
searchRequestBuilder.setSize(topN);
|
||||
|
||||
searchRequestBuilder.setQuery(QueryBuilders.matchQuery(ServiceNameTable.COLUMN_SERVICE_NAME, keyword));
|
||||
|
||||
SearchResponse searchResponse = searchRequestBuilder.execute().actionGet();
|
||||
SearchHit[] searchHits = searchResponse.getHits().getHits();
|
||||
|
||||
List<ServiceInfo> serviceInfos = new LinkedList<>();
|
||||
for (SearchHit searchHit : searchHits) {
|
||||
ServiceInfo serviceInfo = new ServiceInfo();
|
||||
serviceInfo.setId(((Number)searchHit.getSource().get(ServiceNameTable.COLUMN_SERVICE_ID)).intValue());
|
||||
serviceInfo.setName((String)searchHit.getSource().get(ServiceNameTable.COLUMN_SERVICE_NAME));
|
||||
serviceInfos.add(serviceInfo);
|
||||
}
|
||||
return serviceInfos;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -37,7 +37,7 @@ public class ServiceNameEsTableDefine extends ElasticSearchTableDefine {
|
|||
|
||||
@Override public void initialize() {
|
||||
addColumn(new ElasticSearchColumnDefine(ServiceNameTable.COLUMN_APPLICATION_ID, ElasticSearchColumnDefine.Type.Integer.name()));
|
||||
addColumn(new ElasticSearchColumnDefine(ServiceNameTable.COLUMN_SERVICE_NAME, ElasticSearchColumnDefine.Type.Keyword.name()));
|
||||
addColumn(new ElasticSearchColumnDefine(ServiceNameTable.COLUMN_SERVICE_NAME, ElasticSearchColumnDefine.Type.Text.name()));
|
||||
addColumn(new ElasticSearchColumnDefine(ServiceNameTable.COLUMN_SERVICE_ID, ElasticSearchColumnDefine.Type.Integer.name()));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -20,12 +20,15 @@ package org.apache.skywalking.apm.collector.storage.h2.dao.ui;
|
|||
|
||||
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.ui.IServiceNameServiceUIDAO;
|
||||
import org.apache.skywalking.apm.collector.storage.h2.base.dao.H2DAO;
|
||||
import org.apache.skywalking.apm.collector.storage.table.register.ServiceNameTable;
|
||||
import org.apache.skywalking.apm.collector.storage.ui.service.ServiceInfo;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
|
|
@ -54,4 +57,23 @@ public class ServiceNameServiceH2UIDAO extends H2DAO implements IServiceNameServ
|
|||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override public List<ServiceInfo> searchService(String keyword, int topN) {
|
||||
String dynamicSql = "select {0},{1} from {2} where {3} like ? limit ?";
|
||||
String sql = SqlBuilder.buildSql(dynamicSql, ServiceNameTable.COLUMN_SERVICE_ID, ServiceNameTable.COLUMN_SERVICE_NAME, ServiceNameTable.TABLE, ServiceNameTable.COLUMN_SERVICE_NAME);
|
||||
Object[] params = new Object[] {keyword, topN};
|
||||
|
||||
List<ServiceInfo> serviceInfos = new LinkedList<>();
|
||||
try (ResultSet rs = getClient().executeQuery(sql, params)) {
|
||||
while (rs.next()) {
|
||||
ServiceInfo serviceInfo = new ServiceInfo();
|
||||
serviceInfo.setId(rs.getInt(ServiceNameTable.COLUMN_SERVICE_ID));
|
||||
serviceInfo.setName(rs.getString(ServiceNameTable.COLUMN_SERVICE_NAME));
|
||||
serviceInfos.add(serviceInfo);
|
||||
}
|
||||
} catch (SQLException | H2ClientException e) {
|
||||
logger.error(e.getMessage(), e);
|
||||
}
|
||||
return serviceInfos;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -43,6 +43,7 @@ import org.apache.skywalking.apm.collector.server.jetty.JettyHandler;
|
|||
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.VisualUserNode;
|
||||
import org.apache.skywalking.apm.collector.storage.ui.service.ServiceNode;
|
||||
import org.apache.skywalking.apm.collector.ui.graphql.VersionMutation;
|
||||
import org.apache.skywalking.apm.collector.ui.graphql.VersionQuery;
|
||||
import org.apache.skywalking.apm.collector.ui.mutation.ConfigMutation;
|
||||
|
|
@ -82,9 +83,9 @@ public class GraphQLHandler extends JettyHandler {
|
|||
.file("ui-graphql/service-layer.graphqls")
|
||||
.file("ui-graphql/trace.graphqls")
|
||||
.resolvers(new VersionQuery(), new VersionMutation(), new AlarmQuery(), new ApplicationQuery(moduleManager))
|
||||
.resolvers(new OverViewLayerQuery(moduleManager), new ServerQuery(moduleManager), new ServiceQuery(), new TraceQuery(moduleManager))
|
||||
.resolvers(new OverViewLayerQuery(moduleManager), new ServerQuery(moduleManager), new ServiceQuery(moduleManager), new TraceQuery(moduleManager))
|
||||
.resolvers(new ConfigQuery(), new ConfigMutation())
|
||||
.dictionary(ConjecturalNode.class, VisualUserNode.class, ApplicationNode.class)
|
||||
.dictionary(ConjecturalNode.class, VisualUserNode.class, ApplicationNode.class, ServiceNode.class)
|
||||
.build()
|
||||
.makeExecutableSchema();
|
||||
|
||||
|
|
|
|||
|
|
@ -18,21 +18,40 @@
|
|||
|
||||
package org.apache.skywalking.apm.collector.ui.query;
|
||||
|
||||
import java.text.ParseException;
|
||||
import java.util.List;
|
||||
import org.apache.skywalking.apm.collector.ui.graphql.Query;
|
||||
import org.apache.skywalking.apm.collector.core.module.ModuleManager;
|
||||
import org.apache.skywalking.apm.collector.core.util.ObjectUtils;
|
||||
import org.apache.skywalking.apm.collector.storage.ui.common.Duration;
|
||||
import org.apache.skywalking.apm.collector.storage.ui.common.ResponseTimeTrend;
|
||||
import org.apache.skywalking.apm.collector.storage.ui.common.SLATrend;
|
||||
import org.apache.skywalking.apm.collector.storage.ui.common.ThroughputTrend;
|
||||
import org.apache.skywalking.apm.collector.storage.ui.common.Topology;
|
||||
import org.apache.skywalking.apm.collector.storage.ui.service.ServiceNode;
|
||||
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.service.ServiceNameService;
|
||||
|
||||
/**
|
||||
* @author peng-yongsheng
|
||||
*/
|
||||
public class ServiceQuery implements Query {
|
||||
public List<ServiceNode> searchService(String keyword, Duration duration, Integer topN) {
|
||||
return null;
|
||||
|
||||
private final ModuleManager moduleManager;
|
||||
private ServiceNameService serviceNameService;
|
||||
|
||||
public ServiceQuery(ModuleManager moduleManager) {
|
||||
this.moduleManager = moduleManager;
|
||||
}
|
||||
|
||||
private ServiceNameService getServiceNameService() {
|
||||
if (ObjectUtils.isEmpty(serviceNameService)) {
|
||||
this.serviceNameService = new ServiceNameService(moduleManager);
|
||||
}
|
||||
return serviceNameService;
|
||||
}
|
||||
|
||||
public List<ServiceInfo> searchService(String keyword, int topN) throws ParseException {
|
||||
return getServiceNameService().searchService(keyword, topN);
|
||||
}
|
||||
|
||||
public ResponseTimeTrend getServiceResponseTimeTrend(int serviceId, Duration duration) {
|
||||
|
|
|
|||
|
|
@ -18,9 +18,11 @@
|
|||
|
||||
package org.apache.skywalking.apm.collector.ui.service;
|
||||
|
||||
import java.util.List;
|
||||
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.ui.IServiceNameServiceUIDAO;
|
||||
import org.apache.skywalking.apm.collector.storage.ui.service.ServiceInfo;
|
||||
|
||||
/**
|
||||
* @author peng-yongsheng
|
||||
|
|
@ -36,4 +38,8 @@ public class ServiceNameService {
|
|||
public int getCount() {
|
||||
return serviceNameServiceUIDAO.getCount();
|
||||
}
|
||||
|
||||
public List<ServiceInfo> searchService(String keyword, int topN) {
|
||||
return serviceNameServiceUIDAO.searchService(keyword, topN);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -15,6 +15,11 @@ type ServiceNode implements Node {
|
|||
type ServiceInfo {
|
||||
id: ID!
|
||||
name: String
|
||||
}
|
||||
|
||||
type ServiceMetric {
|
||||
id: ID!
|
||||
name: String
|
||||
# The unit is millisecond.
|
||||
avgResponseTime: Int!
|
||||
tps: Int!
|
||||
|
|
@ -27,7 +32,7 @@ type TraceItem {
|
|||
}
|
||||
|
||||
extend type Query {
|
||||
searchService(keyword: String!, duration: Duration!, topN: Int!): [ServiceNode!]!
|
||||
searchService(keyword: String!, topN: Int!): [ServiceInfo!]!
|
||||
getServiceResponseTimeTrend(serviceId: ID!, duration: Duration!): ResponseTimeTrend
|
||||
getServiceTPSTrend(serviceId: ID!, duration: Duration!): ThroughputTrend
|
||||
getServiceSLATrend(serviceId: ID!, duration: Duration!): SLATrend
|
||||
|
|
|
|||
Loading…
Reference in New Issue