use of com.creditease.uav.profiling.spi.ProfileServiceMapMgr in project uavstack by uavorg.
the class ServiceSpanInvokeChainHandler method doCap.
/**
* Finish Span and Logger the Span metrics
*/
@Override
public void doCap(InvokeChainContext context) {
/**
* Step 1: try to get service span,
*/
// 移除main,防止uav没有劫持到的请求发生调用链连接现象
this.spanFactory.getRemoveSpanFromContext("main");
String url = (String) context.get(CaptureConstants.INFO_APPSERVER_CONNECTOR_REQUEST_URL);
Span span;
if (UAVServer.instance().isExistSupportor("com.creditease.uav.apm.supporters.SlowOperSupporter")) {
span = this.spanFactory.getSpanFromContext(url);
} else {
span = this.spanFactory.getRemoveSpanFromContext(url);
}
if (span == null) {
return;
}
String appid = null;
if (context.get(CaptureConstants.INFO_CLIENT_APPID) != null && !StringHelper.isEmpty(context.get(CaptureConstants.INFO_CLIENT_APPID).toString())) {
appid = (String) context.get(CaptureConstants.INFO_CLIENT_APPID);
span.setClassName(context.get(InvokeChainConstants.CLIENT_IT_CLASS).toString());
span.setMethodName(context.get(InvokeChainConstants.CLIENT_IT_METHOD).toString());
String responseState = (String) context.get(CaptureConstants.INFO_CLIENT_RESPONSESTATE);
span.setState(context.get(CaptureConstants.INFO_CLIENT_RESPONSECODE).toString(), responseState);
} else if (context.get(CaptureConstants.INFO_APPSERVER_APPID) != null && !StringHelper.isEmpty(context.get(CaptureConstants.INFO_APPSERVER_APPID).toString())) {
appid = (String) context.get(CaptureConstants.INFO_APPSERVER_APPID);
span.setClassName(context.get(InvokeChainConstants.CLIENT_IT_CLASS).toString());
span.setMethodName(context.get(InvokeChainConstants.CLIENT_IT_METHOD).toString());
String responseState = (String) context.get(CaptureConstants.INFO_CLIENT_RESPONSESTATE);
span.setState(context.get(CaptureConstants.INFO_APPSERVER_CONNECTOR_RESPONSECODE).toString(), responseState);
} else {
String appContext = (String) context.get(CaptureConstants.INFO_APPSERVER_CONNECTOR_CONTEXT);
String realpath = (String) context.get(CaptureConstants.INFO_APPSERVER_CONNECTOR_CONTEXT_REALPATH);
if (null == appContext && null == realpath) {
return;
}
appid = MonitorServerUtil.getApplicationId(appContext, realpath);
if (appid == null) {
return;
}
/**
* match service class & method
*/
ProfileServiceMapMgr smgr = (ProfileServiceMapMgr) UAVServer.instance().getServerInfo("profile.servicemapmgr");
ServiceMapBinding smb = smgr.searchServiceMapBinding(appid, url);
if (smb != null) {
span.setClassName(smb.getClazz());
if (StringHelper.isEmpty(span.getMethodName())) {
span.setMethodName(smb.getMethod());
}
}
span.setState(context.get(CaptureConstants.INFO_APPSERVER_CONNECTOR_RESPONSECODE).toString(), null);
}
context.put(CaptureConstants.INFO_APPSERVER_APPID, appid);
/**
* Step 2: end span
*/
span.end();
/**
* Step 3: set service span info
*/
span.setAppid(appid);
span.setUrl(url);
String spanLog = span.toString();
if (logger.isDebugable()) {
logger.debug("doCap:span=" + spanLog, null);
}
/**
* Step 3: get the related invokechain logger of this application to record span
*/
DataLogger invokeChainLogger = this.getAppInvokeChainLogger(appid);
if (invokeChainLogger == null) {
return;
}
invokeChainLogger.logData(spanLog);
}
use of com.creditease.uav.profiling.spi.ProfileServiceMapMgr in project uavstack by uavorg.
the class doTestProfileServiceMapMgr method main.
public static void main(String[] args) {
// prepare
ProfileServiceMapMgr psmm = new ProfileServiceMapMgr();
String[] servlet_1_urls = new String[] { "/test" };
psmm.addServiceMapBinding("test", "servlet_1", "service", Arrays.asList(servlet_1_urls), 2);
String[] filter_1_urls = new String[] { "/test" };
psmm.addServiceMapBinding("test", "filter_1", "doFilter", Arrays.asList(filter_1_urls), 1);
String[] jaxrs_1_urls = new String[] { "/app1/m1" };
psmm.addServiceMapBinding("test", "jaxrs_1", "m1", Arrays.asList(jaxrs_1_urls), 0);
String[] jaxrs_2_urls = new String[] { "/app1/m2/{id}/{age}" };
psmm.addServiceMapBinding("test", "jaxrs_1", "m2", Arrays.asList(jaxrs_2_urls), 0);
String[] jaxrs_3_urls = new String[] { "/app1/{id}" };
psmm.addServiceMapBinding("test", "jaxrs_1", "m3", Arrays.asList(jaxrs_3_urls), 0);
// 精确匹配filter
test(psmm, "http://localhost:8080/myapp/test");
// 模糊匹配filter
test(psmm, "http://localhost:8080/myapp/test/1");
// 精确匹配jaxrs
test(psmm, "http://localhost:8080/myapp/test/app1/m1");
// 精确匹配jaxrs, 但无法匹配,会匹配到filter
test(psmm, "http://localhost:8080/myapp/test/app1/m1/1");
// 精确匹配jaxrs带pathParam
test(psmm, "http://localhost:8080/myapp/test/app1/m2/1/2");
// 精确匹配jaxrs带pathParam
test(psmm, "http://localhost:8080/myapp/test/app1/1");
double tcost = 0;
int count = 10000;
for (int i = 0; i < count; i++) {
tcost += test(psmm, "http://localhost:8080/myapp/test/app1/m2/1/2");
}
System.out.println(tcost / count);
}
use of com.creditease.uav.profiling.spi.ProfileServiceMapMgr in project uavstack by uavorg.
the class ComponentProfileHandler method collectProfileServiceMap.
/**
* NOTE: 收集所有应用的服务代码与url模式的匹配关系
*
* @param componentClassName
* @param inst
*/
@SuppressWarnings("unchecked")
private void collectProfileServiceMap(String componentClassName, ProfileElementInstance inst) {
if (componentClassName.equalsIgnoreCase("javax.servlet.annotation.WebListener")) {
return;
}
ProfileServiceMapMgr smgr = (ProfileServiceMapMgr) UAVServer.instance().getServerInfo("profile.servicemapmgr");
String appid = inst.getProfileElement().getRepository().getProfile().getId();
for (String className : inst.getValues().keySet()) {
Map<String, Object> classInfo = (Map<String, Object>) inst.getValues().get(className);
// Servlet
if (componentClassName.equalsIgnoreCase("javax.servlet.annotation.WebServlet")) {
Collection<String> urls = getServletFilterUrlPatterns(classInfo);
smgr.addServiceMapBinding(appid, className, "service", urls, 2);
} else // Filter
if (componentClassName.equalsIgnoreCase("javax.servlet.annotation.WebFilter")) {
Collection<String> urls = getServletFilterUrlPatterns(classInfo);
smgr.addServiceMapBinding(appid, className, "doFilter", urls, 1);
} else // JAXWS
if (componentClassName.equalsIgnoreCase("javax.jws.WebService")) {
addAppFrkServiceMapBinding(smgr, appid, className, classInfo, "javax.jws.WebService", "serviceName", null, true);
} else // JAXWS
if (componentClassName.equalsIgnoreCase("javax.xml.ws.WebServiceProvider")) {
// TODO
} else // JAXRS
if (componentClassName.equalsIgnoreCase("javax.ws.rs.Path")) {
addAppFrkServiceMapBinding(smgr, appid, className, classInfo, "javax.ws.rs.Path", "value", "javax.ws.rs.Path", false);
} else // Spring
if (componentClassName.equalsIgnoreCase("org.springframework.stereotype.Controller") || componentClassName.equalsIgnoreCase("org.springframework.web.bind.annotation.RestController")) {
addAppFrkServiceMapBinding(smgr, appid, className, classInfo, "org.springframework.web.bind.annotation.RequestMapping", "value", "org.springframework.web.bind.annotation.RequestMapping", false);
} else // Struts2
if (componentClassName.equalsIgnoreCase("com.opensymphony.xwork2.Action")) {
addStruts2URLMapBinding(smgr, inst, appid, className, classInfo);
}
}
}
use of com.creditease.uav.profiling.spi.ProfileServiceMapMgr in project uavstack by uavorg.
the class ComponentProfileHandler method collectProfileServiceMap.
/**
* NOTE: 收集所有应用的服务代码与url模式的匹配关系
*
* @param componentClassName
* @param inst
*/
@SuppressWarnings("unchecked")
private void collectProfileServiceMap(String componentClassName, ProfileElementInstance inst, ClassLoader webappclsLoader) {
if (componentClassName.equalsIgnoreCase("javax.servlet.annotation.WebListener")) {
return;
}
ProfileServiceMapMgr smgr = (ProfileServiceMapMgr) UAVServer.instance().getServerInfo("profile.servicemapmgr");
String appid = inst.getProfileElement().getRepository().getProfile().getId();
for (String className : inst.getValues().keySet()) {
Map<String, Object> classInfo = (Map<String, Object>) inst.getValues().get(className);
// Servlet
if (componentClassName.equalsIgnoreCase("javax.servlet.annotation.WebServlet")) {
Collection<String> urls = getServletFilterUrlPatterns(classInfo);
smgr.addServiceMapBinding(appid, className, "service", urls, 2);
} else // Filter
if (componentClassName.equalsIgnoreCase("javax.servlet.annotation.WebFilter")) {
Collection<String> urls = getServletFilterUrlPatterns(classInfo);
smgr.addServiceMapBinding(appid, className, "doFilter", urls, 1);
} else // JAXWS
if (componentClassName.equalsIgnoreCase("javax.jws.WebService")) {
addAppFrkServiceMapBinding(smgr, appid, className, classInfo, "javax.jws.WebService", "serviceName", null, true);
} else // JAXWS
if (componentClassName.equalsIgnoreCase("javax.xml.ws.WebServiceProvider")) {
// TODO
} else // JAXRS
if (componentClassName.equalsIgnoreCase("javax.ws.rs.Path")) {
addAppFrkServiceMapBinding(smgr, appid, className, classInfo, "javax.ws.rs.Path", "value", "javax.ws.rs.Path", false);
} else // Spring
if (componentClassName.equalsIgnoreCase("org.springframework.stereotype.Controller") || componentClassName.equalsIgnoreCase("org.springframework.web.bind.annotation.RestController")) {
addSpringMVCServiceMapBinding(smgr, inst, appid, className, classInfo, webappclsLoader);
} else // Struts2
if (componentClassName.equalsIgnoreCase("com.opensymphony.xwork2.Action")) {
addStruts2URLMapBinding(smgr, inst, appid, className, classInfo);
}
}
}
use of com.creditease.uav.profiling.spi.ProfileServiceMapMgr in project uavstack by uavorg.
the class MonitorUrlFilterMgr method serviceValidate.
public boolean serviceValidate(String appId, String reUrl, String[] urlInfos) {
if (profileValidate) {
/**
* NOTE: if not in profile services, do not collect;
*/
ProfileServiceMapMgr smgr = (ProfileServiceMapMgr) UAVServer.instance().getServerInfo("profile.servicemapmgr");
ServiceURLBinding sub = smgr.searchServiceURLBinding(appId, reUrl);
if (sub == null) {
return false;
}
String urlId = urlInfos[2];
// rewrite pathparam url
urlId = urlId.substring(0, urlId.indexOf(sub.getPathPattern())) + sub.getPath();
urlInfos[2] = urlId;
}
return true;
}
Aggregations