";
@@ -527,7 +536,7 @@ function APMTool(app) {
this.appSelector.init();
this.appInstSelector.init();
- this.callAppProfile();
+ this.callAppProfile(sObj);
}
//mainlist
@@ -536,7 +545,8 @@ function APMTool(app) {
this.mainList.initTable();
this.mainList.cellClickUser = function(id,pNode) {
- app.controller.showWindow({traceid:id},"AppIVCTraceWnd","buildAppIVCTraceWnd","runAppIVCTraceWnd");
+ //comeFrom表示该请求的来源位置,用于后面的返回定位
+ app.controller.showWindow({traceid:id,comeFrom:"IVC"},"AppIVCTraceWnd","buildAppIVCTraceWnd","runAppIVCTraceWnd");
};
//init datetime picker
@@ -579,17 +589,68 @@ function APMTool(app) {
* 调用链Trace窗口UI
*/
this.buildAppIVCTraceWnd=function(sObj) {
- var html="
" +
- "
" +
- "
调用链跟踪"+
- "
"+sObj["traceid"]+"" +
- "
" +
- "
";
- html+="
";
+ if(this.appInfo==undefined){
+ //设置当前应用信息
+ this.appInfo={
+ appuuid:"",
+ appid:"",
+ appurl:"",
+ appname:""
+ };
+ }
+ var html=
+ "
" +
+ "
" +
+ "
调用链跟踪"+
+ "
"+sObj["traceid"]+"";
+ if(sObj!=undefined && "comeFrom" in sObj){
+ this.ivcInfo["comeFrom"] = sObj["comeFrom"];
+ if(sObj["comeFrom"]=="NewLog"){
+ html +=
+ "
" +
+ "
";
+ }else{
+ html +=
+ "
";
+ }
+ }else{
+ html +=
+ "
";
+ }
+ html+=
+ "
"+
+ "
"+
+ "
" +
+ "
";
+
+ var sb=new StringBuffer();
+
+ sb.append('
');
+ sb.append('
');
+ sb.append( '
');
+ sb.append( '');
+ sb.append( '
');
+ sb.append( "');
+
+ sb.append( '
');
+ sb.append( '' + '
' + '
');
+ html += sb.toString();
+
return html;
};
+ this.clearLogSelector=function(){
+ $("#selectLogWin").modal('hide');
+ $("#logSelector").empty();
+ $("#selectLogWinfooter").empty();
+ }
+
/**
* 调用链Trace窗口初始化
*/
@@ -601,6 +662,30 @@ function APMTool(app) {
this.callIVCQuery("trace",sObj);
};
+ /**
+ * 调用链Trace窗退出
+ */
+ this.destroyAppIVCTraceWnd=function(){
+
+ }
+
+ /**
+ * 跳转到日志搜索结果页
+ */
+ this.jumpLogRollWnd = function(param){
+// var pNode = sObj.parentNode.parentNode;
+// var param = StringHelper.str2obj(params);
+// param.ipport = pNode.getElementsByTagName("td")[7].id;;
+// param.appid = pNode.getElementsByTagName("td")[8].id;
+ param.intent="qContent";
+ param.logfile = HtmlHelper.id("logSelector").value;
+ param.logtype = HtmlHelper.id("logSelector").value.replace(".","_") + "_def";
+ $("#selectLogWin").modal('hide');
+ $("#logSelector").empty();
+ $("#selectLogWinfooter").empty();
+
+ app.controller.showWindow(param,"AppNewLogRollWnd","buildAppNewLogRollWnd","runAppNewLogRollWnd");
+ };
/**
* 跳转到重调用链明细页
@@ -787,11 +872,15 @@ function APMTool(app) {
/**
* 加载MAINList的数据,显示该应用的服务调用链数据
*/
- this.loadIVCList = function(list,datas,count,totalCount) {
+ this.loadIVCList = function(list,datas,count,totalCount,params) {
list.clearTable();
-
- list.setCaption("
应用实例:"+this.appInfo["appname"]+"("+this.appInfo["appuuid"].split("/")[2]+"),总数:"+totalCount+"
");
+ if(params!=undefined&&"appname" in params&&"appuuid" in params){
+ _this.appInfo["appid"] = params["appname"];
+ list.setCaption("
应用实例:"+params["appname"]+"("+params["appuuid"].split("/")[2]+"),总数:"+totalCount+"
");
+ }else{
+ list.setCaption("
应用实例:"+this.appInfo["appname"]+"("+this.appInfo["appuuid"].split("/")[2]+"),总数:"+totalCount+"
");
+ }
// 必须先显示分页
list.setTotalRow(count);
@@ -814,9 +903,18 @@ function APMTool(app) {
/**
* 全局视图需要单独取该用户可查看的profile信息
*/
- this.callAppProfile=function() {
+ this.callAppProfile=function(sObj) {
this.profileDAO.callAppProfile(function(jsonData) {
_this.loadAppSelector(jsonData);
+ if(sObj != undefined){
+ if(sObj["appname"]){
+ $("select#AppIVCWnd_AppSelector").val(sObj["appname"]);
+ appAPM.onChangeAppSelector();
+ }
+ if(sObj["appuuid"]){
+ $("select#AppIVCWnd_AppInstSelector").val(sObj["appuuid"]);
+ }
+ }
});
};
@@ -982,8 +1080,10 @@ function APMTool(app) {
var dataList;
var appuuid;
-
- var winmode=this.appInfo["winmode"];
+ var winmode = '';
+ if(this.appInfo!=undefined&&"winmode" in this.appInfo){
+ winmode = this.appInfo["winmode"];
+ }
//全局模式
if ("standalone"==winmode) {
this.appInfo["appid"]=this.appSelector.value();
@@ -1114,7 +1214,7 @@ function APMTool(app) {
apmLoader.show("调用链共"+datas.length+"记录,正生成分析树...",280);
setTimeout(function() {
datas=_this.sortTrace(intent,datas);
- _this.loadIVCList(dataList, datas, datas.length,count);
+ _this.loadIVCList(dataList, datas, datas.length,count,pObj);
},1);
}
else {
@@ -1269,6 +1369,82 @@ function APMTool(app) {
return {stime:startTime,etime:endTime,indexdate:reqDate};
};
+
+ this.buildCtrlObj = function(appuuid){
+ var ctrlObj={
+ nodeURL:"",
+ serverURL:"",
+ file:"",
+ appUUID:"",
+ toolTag:"",
+ mqTopic:"",
+ collectAct:""
+ };
+ ctrlObj["appUUID"]=appuuid;
+ var appInfo=appuuid.split("---");
+ var urlInfo=appuuid.split("/");
+ ctrlObj["serverURL"]=urlInfo[0]+"//"+urlInfo[2];
+ var ipport=urlInfo[2].split(":");
+ ctrlObj["nodeURL"]="http://"+ipport[0]+":10101/node/ctrl";
+ ctrlObj["file"]=appInfo[1]+"_"+ipport[1]+"_";
+ return ctrlObj;
+ }
+
+ this.ivcStart=function(appuuid) {
+ var ctrlObj = this.buildCtrlObj(appuuid);
+ ctrlObj["toolTag"]="ivc";
+ ctrlObj["mqTopic"]="JQ_IVC";
+ ctrlObj["collectAct"]="collectdata.add";
+ ctrlObj["collectRoot"]="com.creditease.uav.invokechain.logroot";
+ _this.callMOFTool("调用链", "start",ctrlObj,"startSupporter","[\"com.creditease.uav.apm.supporters.InvokeChainSupporter\"]");
+ };
+
+ this.ivcStop=function(appuuid) {
+ var ctrlObj = this.buildCtrlObj(appuuid);
+ ctrlObj["toolTag"]="ivc";
+ ctrlObj["mqTopic"]="JQ_IVC";
+ ctrlObj["collectAct"]="collectdata.del";
+ ctrlObj["collectRoot"]="com.creditease.uav.invokechain.logroot";
+ _this.callMOFTool("调用链", "stop",ctrlObj,"stopSupporter","[\"com.creditease.uav.apm.supporters.InvokeChainSupporter\"]");
+ };
+
+ this.ivcCfg=function(appuuid) {
+ var ctrlObj = this.buildCtrlObj(appuuid);
+ $("#MonitorConfigDialog").modal('hide');
+ app.controller.showWindow({winmode:"embed",func:"ivc",appuuid:instID,appurl:appInfo[0],appid:appInfo[1]},"AppAPMCfgWnd","buildAppAPMCfgWnd","runAppAPMCfgWnd");
+ };
+
+ this.ivcDataStart=function(appuuid) {
+ var ctrlObj = this.buildCtrlObj(appuuid);
+ ctrlObj["toolTag"]="ivcdat";
+ ctrlObj["mqTopic"]="JQ_SLW";
+ ctrlObj["collectAct"]="collectdata.add";
+ ctrlObj["collectRoot"]="com.creditease.uav.ivcdat.logroot";
+ _this.callMOFTool("重调用链", "start",ctrlObj,"startSupporter","[\"com.creditease.uav.apm.supporters.SlowOperSupporter\"]");
+ };
+
+ this.ivcDataStop=function(appuuid) {
+ var ctrlObj = this.buildCtrlObj(appuuid);
+ ctrlObj["toolTag"]="ivcdat";
+ ctrlObj["mqTopic"]="JQ_SLW";
+ ctrlObj["collectAct"]="collectdata.del";
+ ctrlObj["collectRoot"]="com.creditease.uav.ivcdat.logroot";
+ _this.callMOFTool("重调用链", "stop",ctrlObj,"stopSupporter","[\"com.creditease.uav.apm.supporters.SlowOperSupporter\"]");
+ };
+
+ this.logTraceStart=function(appuuid) {
+ var ctrlObj = this.buildCtrlObj(appuuid);
+ ctrlObj["toolTag"]="logTrace";
+ _this.callMOFTool("调用链日志追踪", "start",ctrlObj,"startSupporter","[\"com.creditease.uav.apm.supporters.LogTraceSupporter\"]");
+ };
+
+ this.logTraceStop=function(appuuid) {
+ var ctrlObj = this.buildCtrlObj(appuuid);
+ ctrlObj["toolTag"]="logTrace";
+ _this.callMOFTool("调用链日志追踪", "stop",ctrlObj,"stopSupporter","[\"com.creditease.uav.apm.supporters.LogTraceSupporter\"]");
+ };
+
+
}
diff --git a/com.creditease.uav.console/src/main/webapp/uavapp_godeye/appmonitor/js/uav.appmonitor.js b/com.creditease.uav.console/src/main/webapp/uavapp_godeye/appmonitor/js/uav.appmonitor.js
index dba892d9..c171f273 100644
--- a/com.creditease.uav.console/src/main/webapp/uavapp_godeye/appmonitor/js/uav.appmonitor.js
+++ b/com.creditease.uav.console/src/main/webapp/uavapp_godeye/appmonitor/js/uav.appmonitor.js
@@ -1197,6 +1197,14 @@ var mvcObj={
theme:"BGDark",
order:1050
});
+ //build AppIVCCfgWnd
+ window.winmgr.build({
+ id:"AppIVCCfgWnd",
+ height:"auto",
+ "overflow-y":"auto",
+ theme:"BGLight",
+ order:1050
+ });
//build AppAPMCfgWnd
window.winmgr.build({
id:"AppAPMCfgWnd",
@@ -2915,16 +2923,6 @@ var mvcObj={
app.controller.runMonitorChartData(dType);
};
- //监控工具箱只在应用实例级别显示
- if (undefined!=isJse&&isJse==false) {
- appAPM.buildMonitorToolPanel(sObj);
- }
- //清空
- else {
- var toolView=HtmlHelper.id("MonitorConfigDialog_Tool");
- toolView.innerHTML="";
- }
-
$("#MonitorConfigDialog").modal();
},
/**
@@ -5315,6 +5313,27 @@ var mvcObj={
},
destroyAppNewLogRollWnd:function() {
+ },
+ // TODO -------------------------------调用链配置窗口---------------------------------------------------
+ /**
+ * buildAppIVCCfgWnd
+ */
+ buildAppIVCCfgWnd:function(sObj) {
+ return appAPM.buildAppIVCCfgWnd(sObj);
+ },
+
+ /**
+ * runAppIVCCfgWnd
+ */
+ runAppIVCCfgWnd:function(sObj) {
+ appAPM.runAppIVCCfgWnd(sObj);
+ },
+
+ /**
+ * destroyAppIVCCfgWnd
+ */
+ destroyAppIVCCfgWnd:function() {
+
},
// TODO -------------------------------日志配置窗口---------------------------------------------------
/**
diff --git a/com.creditease.uav.console/src/main/webapp/uavapp_godeye/appmonitor/js/uav.log.js b/com.creditease.uav.console/src/main/webapp/uavapp_godeye/appmonitor/js/uav.log.js
index 99fe9c05..40203d09 100644
--- a/com.creditease.uav.console/src/main/webapp/uavapp_godeye/appmonitor/js/uav.log.js
+++ b/com.creditease.uav.console/src/main/webapp/uavapp_godeye/appmonitor/js/uav.log.js
@@ -8,6 +8,10 @@ function NewLogTool(app) {
this.appInfo={};
+ this.LogInfo = {
+ comeFrom : ""
+ };
+
/**
* TODO:日志搜索列表配置
*/
@@ -179,7 +183,7 @@ function NewLogTool(app) {
this.appSelector.init();
this.ipSelector.init();
this.logSelector.init();
- _this.callAppProfile();
+ _this.callAppProfile(sObj);
}
@@ -193,7 +197,7 @@ function NewLogTool(app) {
* 点击打开日志滚动窗口
*/
this.mainList.cellClickUser = function(id,pNode) {
- app.controller.showWindow({l_timestamp:id, node:pNode},"AppNewLogRollWnd","buildAppNewLogRollWnd","runAppNewLogRollWnd");
+ app.controller.showWindow({l_timestamp:id, node:pNode , comeFrom:"NewLog",logfile:appLog.appInfo["logfile"]},"AppNewLogRollWnd","buildAppNewLogRollWnd","runAppNewLogRollWnd");
};
/**
@@ -298,13 +302,16 @@ function NewLogTool(app) {
*/
this.getCurTimeRange=function() {
- var timeRange=HtmlHelper.id("AppNewLogWnd_TimeRange").value;
- var timeUnit=this.timeRangeSelector.value();
+ var timeRange = "";
+ if(HtmlHelper.id("AppNewLogWnd_TimeRange")!=undefined){
+ timeRange=HtmlHelper.id("AppNewLogWnd_TimeRange").value;
+ }
//全部时间
if (timeRange=="") {
return undefined;
}
+ var timeUnit=this.timeRangeSelector.value();
var date;
var plus;
@@ -378,6 +385,11 @@ function NewLogTool(app) {
*/
this.rendLog=function(content,keywords) {
+ //去除调用链的traceId
+ if(content.slice(0,4)=='uav_'){
+ var traceid = content.split(" ")[0].slice(4);
+ content = content.substring(traceid.length+4,content.length);
+ }
if (keywords==undefined||keywords.length==0) {
return content.replace(//g,">");
}
@@ -434,7 +446,7 @@ function NewLogTool(app) {
var keys="";
- if (HtmlHelper.id("AppNewLogWnd_KeyWord").value!="") {
+ if (HtmlHelper.id("AppNewLogWnd_KeyWord")!=undefined&&HtmlHelper.id("AppNewLogWnd_KeyWord").value!="") {
keys=HtmlHelper.id("AppNewLogWnd_KeyWord").value;
}
@@ -611,9 +623,24 @@ function NewLogTool(app) {
/**
* 全局视图需要单独取该用户可查看的profile信息
*/
- this.callAppProfile=function() {
+ this.callAppProfile=function(sObj) {
this.profileDAO.callAppProfile(function(jsonData) {
_this.loadAppSelector(jsonData);
+ if(sObj != undefined){
+ if(sObj["appid"]){
+ $("select#AppNewLogWnd_AppSelector").val(sObj["appid"]);
+ appLog.onChangeAppSelector();
+ }
+ if(sObj["ipport"]){
+ $("select#AppNewLogWnd_IPSelector").val(sObj["ipport"]);
+ }
+ if(sObj["logfile"]){
+ $("select#AppNewLogWnd_LogSelector").val(sObj["logfile"]);
+ }
+ if(sObj["ctn"]){
+ $("#AppNewLogWnd_KeyWord").val("\"" + sObj["ctn"] + "\"");
+ }
+ }
});
};
@@ -784,28 +811,48 @@ function NewLogTool(app) {
curELine:0,
_lock:false
};
- this.logRollInfo["ipport"]=sObj["node"].getElementsByTagName("td")[0].id;
- this.logRollInfo["appid"]=this.appInfo["appid"];
- this.logRollInfo["logtype"]=this.appInfo["logtype"];
+ if(sObj!=undefined&&"ipport" in sObj&&"appid" in sObj&&"logfile" in sObj&&"ctn" in sObj){
+ this.logRollInfo["ipport"]=sObj.ipport;
+ this.logRollInfo["appid"]=sObj.appid;
+ this.logRollInfo["logtype"]=sObj.logfile;
+ this.logRollInfo["ctn"]=sObj.ctn;
+ }else{
+ this.logRollInfo["ipport"]=sObj["node"].getElementsByTagName("td")[0].id;
+ this.logRollInfo["appid"]=this.appInfo["appid"];
+ this.logRollInfo["logtype"]=this.appInfo["logtype"];
+ }
+ console.log(this.logRollInfo);
/**
* 记录从那个时间戳以及哪行进来的
*/
this.logRollInfo["entry"]={
timestamp:sObj["l_timestamp"],
- line:parseInt(sObj["node"].getElementsByTagName("td")[2].id)
+ line:(sObj["node"]!=undefined)?parseInt(sObj["node"].getElementsByTagName("td")[2].id):''
};
var html="
" +
"
" +
"
"+this.logRollInfo["appid"]+"("+this.logRollInfo["ipport"]+")"+
- "
"+this.appInfo["logfile"]+"" +
- "
" +
- "
";
+ "
"+sObj["logfile"]+"";
+ if(sObj!=undefined&&"comeFrom" in sObj){
+ this.LogInfo["comeFrom"] = sObj["comeFrom"];
+ if(sObj["comeFrom"] == "IVC"){
+ html +=
+ "
" +
+ "
";
+ }else{
+ html+=
+ "
";
+ }
+ }else{
+ html+=
+ "
";
+ }
//控制面板
// html+="
";
// html+="
";
//向前滚动
- html+="
";
+ html+="
";
html+="向前滚动日志
";
//日志内容
html+="
";
@@ -865,12 +912,12 @@ function NewLogTool(app) {
/**
* Step 2: 记录这次成功的日志的开始和结束
*/
- if(this.logRollInfo["curSLine"]>=lineRange.sline) {
+ if(lineRange.sline==undefined||this.logRollInfo["curSLine"]>=lineRange.sline) {
this.logRollInfo["curSLine"]=datas[0]["l_num"];
HtmlHelper.id("AppNewLogRollWnd_CurSLine").innerHTML=this.logRollInfo["curSLine"];
}
- if (this.logRollInfo["curELine"]<=lineRange.eline) {
+ if (lineRange.eline==undefined||this.logRollInfo["curELine"]<=lineRange.eline) {
this.logRollInfo["curELine"]=datas[datas.length-1]["l_num"];
HtmlHelper.id("AppNewLogRollWnd_CurELine").innerHTML=this.logRollInfo["curELine"];
}
@@ -898,7 +945,11 @@ function NewLogTool(app) {
var podSLine=this.logRollInfo.pods.get(0);
this.logRollInfo.pods.remove(0);
HtmlHelper.del("NewLogPod_"+podSLine);
- this.logRollInfo["curSLine"]=podSLine+this.logRollInfo["rollsize"]+1;
+ if(this.logRollInfo["fromIVC"] == true){
+ this.logRollInfo["curSLine"] = this.logRollInfo.pods.get(0);
+ }else{
+ this.logRollInfo["curSLine"]=podSLine+this.logRollInfo["rollsize"]+1;
+ }
HtmlHelper.id("AppNewLogRollWnd_CurSLine").innerHTML=this.logRollInfo["curSLine"];
}
else {
@@ -950,8 +1001,27 @@ function NewLogTool(app) {
*/
this.buildLogLine=function(logBuffer,data) {
- var keywords=this.getHighlightKeywords();
- var content=this.rendLog(data["content"], keywords);
+ var content=data["content"];
+ //为拥有traceId的日志添加超链接
+ if(content.slice(0,4)=='uav_'){
+ var traceid = content.split(" ")[0].slice(4);
+ content = content.substring(traceid.length+4,content.length);
+ var params = {};
+ params.traceid = traceid;
+ params.appuuid = "http://"+this.logRollInfo["ipport"]+"/"+this.logRollInfo["appid"]+"---"+this.logRollInfo["appid"];
+ params.comeFrom = this.LogInfo["comeFrom"];
+ params.appname = this.logRollInfo["appid"];
+ params.ipport = this.logRollInfo["ipport"];
+ params.appid = this.logRollInfo["appid"];
+ params = JSON.stringify(params);
+ var keywords=this.getHighlightKeywords();
+ content=this.rendLog(content, keywords);
+ content = "
"+content+"";
+ }else{
+ var keywords=this.getHighlightKeywords();
+ content=this.rendLog(content, keywords);
+ }
+
var lnum=data["l_num"];
var highlight="";
@@ -1014,11 +1084,19 @@ function NewLogTool(app) {
if (action=="up") {
eline=this.logRollInfo["curSLine"];
- sline=eline-rollsize-1;
+ sline=eline-rollsize-1;
+ //如果从调用链界面进来,则向上翻页的时候不用sline
+ if(this.logRollInfo["fromIVC"] == true){
+ sline = NaN;
+ }
}
else if (action=="down") {
sline=this.logRollInfo["curELine"]+1;
eline=sline+rollsize+1;
+ //如果从调用链界面进来,则向下翻页的时候不用eline
+ if(this.logRollInfo["fromIVC"] == true){
+ eline = NaN;
+ }
}
return {sline:sline,eline:eline};
@@ -1037,7 +1115,6 @@ function NewLogTool(app) {
this.logRollInfo["_lock"]=true;
var data={intent:"qContent",request:{}};
-
/**
* Step 1: 默认使用_def, 但是稍后可以允许用户自己选自己的Rule
*/
@@ -1045,9 +1122,15 @@ function NewLogTool(app) {
//取appid和logtype,ipport
data["request"]["appid"]=this.logRollInfo["appid"];
- data["request"]["logtype"]=this.logRollInfo["logtype"]+currentLogRuleName;
+ data["request"]["logtype"]=this.logRollInfo["logtype"]+currentLogRuleName;
data["request"]["ipport"]=this.logRollInfo["ipport"];
-
+ if(this.logRollInfo["ctn"] != undefined && this.logRollInfo["ctn"] != "");{
+ data["request"]["ctn"]=this.logRollInfo["ctn"];
+ }
+ //第一次进入页面的line为“ ”说明是从IVC界面进来的
+ if(this.logRollInfo["entry"]["line"] == ""){
+ this.logRollInfo["fromIVC"] = true;
+ }
/**
* Step 2: 定位拉去的行范围,按行号
*/
@@ -1059,8 +1142,12 @@ function NewLogTool(app) {
lineRange=this.getNextRollRange(undefined,pObj["action"]);
}
- data["request"]["sline"]=lineRange["sline"]+"";
- data["request"]["eline"]=lineRange["eline"]+"";
+ if(!isNaN(lineRange["sline"])){
+ data["request"]["sline"]=lineRange["sline"]+"";
+ }
+ if(!isNaN(lineRange["eline"])){
+ data["request"]["eline"]=lineRange["eline"]+"";
+ }
/**
* Step 3: 时间区段
@@ -1073,10 +1160,24 @@ function NewLogTool(app) {
data["request"]["indexdate"]=timeRange["indexdate"]+"";
data["request"]["stime"]=timeRange["stime"]+"";
data["request"]["etime"]=timeRange["etime"]+"";
+ }else{
+ //如果在日志搜索时没有选择时间区间,则在newLogRoll窗口中将仅通过sline和eline限定,此时会将符合行号范围的历史数据全部加载出来,
+ //为了避免此种情况这里设定一个时间区间,将日志范围限制到当日0点到现在区间,这里仅是一个workaround
+ if(this.logRollInfo["fromIVC"] != true){
+ data["request"]["stime"]=new Date().setHours(0,0,0,0)+"";
+ data["request"]["etime"]=new Date().getTime()+"";
+ }
}
data["request"]["sort"]="l_timestamp=ASC,l_num=ASC";
data["request"]["from"]=0+"";
data["request"]["size"]=1000+"";
+ //如果当前页面来源于IVC那么通过pagesize控制拉去日志的数量
+ if(this.logRollInfo["fromIVC"] == true){
+ var traceid = data["request"]["ctn"];
+ var indexdate = TimeHelper.getTime(Number(traceid.split('_')[3]),"FD");
+ data["request"]["indexdate"] = indexdate;
+ data["request"]["size"]=100+"";
+ }
break;
}
@@ -1110,6 +1211,17 @@ function NewLogTool(app) {
var datas=eval(res);
try {
+ if (datas.length > 0) {
+ if(isNaN(lineRange.sline)){
+ lineRange.sline = datas[0].l_num;
+ }
+ if(isNaN(lineRange.eline)){
+ lineRange.eline = datas[datas.length - 1].l_num;
+ }
+ if(_this.logRollInfo["entry"]["line"] == ""){
+ _this.logRollInfo["entry"]["line"] = datas[0].l_num;
+ }
+ }
_this.loadRollLog(datas,lineRange,pObj["action"]);
}catch(e) {
diff --git a/com.creditease.uav.healthmanager/src/main/java/com/creditease/uav/feature/healthmanager/http/handlers/HMCacheQueryHandler.java b/com.creditease.uav.healthmanager/src/main/java/com/creditease/uav/feature/healthmanager/http/handlers/HMCacheQueryHandler.java
index 161c7942..38aad07e 100644
--- a/com.creditease.uav.healthmanager/src/main/java/com/creditease/uav/feature/healthmanager/http/handlers/HMCacheQueryHandler.java
+++ b/com.creditease.uav.healthmanager/src/main/java/com/creditease/uav/feature/healthmanager/http/handlers/HMCacheQueryHandler.java
@@ -358,7 +358,7 @@ private void queryCache(UAVHttpMessage data, String cacheKey) {
else if ("appurl".equals(filterKey)) {
for (String key : keys) {
- String keyCheck = key.substring(0, key.indexOf("@"));
+ String keyCheck = key.substring(key.indexOf("@") + 1);
for (String vString : fValues) {
if (vString.equals(keyCheck)) {
targets.add(key);
diff --git a/com.creditease.uav.invokechain/src/main/java/com/creditease/uav/healthmanager/newlog/handlers/NewLogDataMessageHandler.java b/com.creditease.uav.invokechain/src/main/java/com/creditease/uav/healthmanager/newlog/handlers/NewLogDataMessageHandler.java
index 1f92514d..3a620b0f 100644
--- a/com.creditease.uav.invokechain/src/main/java/com/creditease/uav/healthmanager/newlog/handlers/NewLogDataMessageHandler.java
+++ b/com.creditease.uav.invokechain/src/main/java/com/creditease/uav/healthmanager/newlog/handlers/NewLogDataMessageHandler.java
@@ -201,8 +201,11 @@ private void pushLogLineToBulkRequest(MonitorDataFrame mdf, String appid, String
* 如果没有规则设置,使用了全行抓取,则索引Type=日志文件名+"_def"
*/
String logFileType = logFileName;
+ StringBuilder uuidStr = new StringBuilder();
+ uuidStr.append(ipport).append(mdf.getServerId()).append("-").append(appid).append("-").append(logid);
if (line.containsKey("content")) {
logFileType += "_def";
+ uuidStr.append("-").append(line.get("content"));
}
/**
* 如果设置了规则,则应该使用索引Type=日志文件名+"_"+<规则名>
@@ -212,10 +215,9 @@ private void pushLogLineToBulkRequest(MonitorDataFrame mdf, String appid, String
}
/**
- * 保证不重复:IP+SvrID+AppID+LogFileName+LogLineNum
+ * 保证不重复:IP+SvrID+AppID+LogFileName+日志内容(def下为content)
*/
- String uuid = EncodeHelper.encodeMD5(new StringBuilder().append(ipport).append(mdf.getServerId())
- .append("-").append(appid).append("-").append(logid).append("-").append(lnum).toString());
+ String uuid = EncodeHelper.encodeMD5(uuidStr.toString());
// 准备index,如果不存在,就创建
String currentIndex = indexMgr.prepareIndex(appid);
diff --git a/com.creditease.uav.invokechain/src/main/java/com/creditease/uav/healthmanager/newlog/http/NewLogQueryHandler.java b/com.creditease.uav.invokechain/src/main/java/com/creditease/uav/healthmanager/newlog/http/NewLogQueryHandler.java
index 65ab6690..4056f089 100644
--- a/com.creditease.uav.invokechain/src/main/java/com/creditease/uav/healthmanager/newlog/http/NewLogQueryHandler.java
+++ b/com.creditease.uav.invokechain/src/main/java/com/creditease/uav/healthmanager/newlog/http/NewLogQueryHandler.java
@@ -21,6 +21,7 @@
package com.creditease.uav.healthmanager.newlog.http;
import java.util.ArrayList;
+import java.util.Collections;
import java.util.List;
import java.util.Map;
@@ -40,6 +41,7 @@
import com.creditease.agent.ConfigurationManager;
import com.creditease.agent.helpers.DataConvertHelper;
import com.creditease.agent.helpers.JSONHelper;
+import com.creditease.agent.helpers.StringHelper;
import com.creditease.agent.http.api.UAVHttpMessage;
import com.creditease.agent.spi.AbstractHttpHandler;
import com.creditease.uav.elasticsearch.client.ESClient;
@@ -104,7 +106,7 @@ private void queryByLogContent(UAVHttpMessage data) {
}
/**
- * 如果有日志行号
+ * 如果有日志行号 有可能只有sline或eline也有可能都有
*/
long startLine = DataConvertHelper.toLong(data.getRequest("sline"), -1);
long endLine = DataConvertHelper.toLong(data.getRequest("eline"), -1);
@@ -112,6 +114,12 @@ private void queryByLogContent(UAVHttpMessage data) {
if (startLine > -1 && endLine > -1 && endLine > startLine) {
queryBuilder.must(QueryBuilders.rangeQuery("l_num").gte(startLine).lt(endLine));
}
+ else if (startLine > -1) {
+ queryBuilder.must(QueryBuilders.rangeQuery("l_num").gte(startLine));
+ }
+ else if (endLine > -1) {
+ queryBuilder.must(QueryBuilders.rangeQuery("l_num").lt(endLine));
+ }
/**
* 关键字ipport
@@ -170,6 +178,13 @@ private void parseSearchCondition(BoolQueryBuilder queryBuilder, UAVHttpMessage
if (content == null) {
return;
}
+ // 如果查询内容使用""包裹,则使用matchphrase
+ if (content.startsWith("\"") && content.endsWith("\"")) {
+ // 去除两端的""
+ content = content.substring(1, content.length() - 1);
+ queryBuilder.must(QueryBuilders.matchPhraseQuery("content", content));
+ return;
+ }
boolean hasCompandSearch = (content.indexOf("+") > -1) ? true : false;
@@ -275,6 +290,13 @@ private void queryToList(UAVHttpMessage data, QueryBuilder queryBuilder, QueryBu
records.add(record);
}
+ // 如果只存在eline则需要把结果逆序,保证其原始顺序
+ long startLine = DataConvertHelper.toLong(data.getRequest("sline"), -1);
+ long endLine = DataConvertHelper.toLong(data.getRequest("eline"), -1);
+ if (startLine == -1 && endLine > -1) {
+ Collections.reverse(records);
+ }
+
data.putResponse("rs", JSONHelper.toString(records));
// 返回总条数
data.putResponse("count", shits.getTotalHits() + "");
@@ -298,16 +320,32 @@ private SearchResponse query(UAVHttpMessage data, QueryBuilder queryBuilder, Que
}
// get logtype for search
- String logType = data.getRequest("logtype").replace('.', '_');
+ SearchRequestBuilder srb = null;
+ if (StringHelper.isEmpty(data.getRequest("logtype"))) {
- SearchRequestBuilder srb = client.getClient().prepareSearch(currentIndex).setTypes(logType)
- .setSearchType(SearchType.DFS_QUERY_THEN_FETCH);
+ srb = client.getClient().prepareSearch(currentIndex).setSearchType(SearchType.DFS_QUERY_THEN_FETCH);
+ }
+ else {
+ String logType = data.getRequest("logtype").replace('.', '_');
+
+ srb = client.getClient().prepareSearch(currentIndex).setTypes(logType)
+ .setSearchType(SearchType.DFS_QUERY_THEN_FETCH);
+ }
int from = DataConvertHelper.toInt(data.getRequest("from"), -1);
int size = DataConvertHelper.toInt(data.getRequest("size"), -1);
if (from != -1 && size != -1) {
- srb = srb.setFrom(from).setSize(size);
+ long startLine = DataConvertHelper.toLong(data.getRequest("sline"), -1);
+ long endLine = DataConvertHelper.toLong(data.getRequest("eline"), -1);
+ // 判断如果只有endline则需要将结果倒序,取其前100行,然后在返回响应时再逆序回来,从而取到endline前的100行
+ if (startLine == -1 && endLine > -1) {
+ srb = srb.addSort("l_timestamp", SortOrder.DESC).addSort("l_num", SortOrder.DESC).setFrom(from)
+ .setSize(size);
+ }
+ else {
+ srb = srb.setFrom(from).setSize(size);
+ }
}
srb.setQuery(queryBuilder);
diff --git a/com.creditease.uav.invokechain/src/main/java/com/creditease/uav/invokechain/http/InvokeChainQueryHandler.java b/com.creditease.uav.invokechain/src/main/java/com/creditease/uav/invokechain/http/InvokeChainQueryHandler.java
index 6f23c782..f9c1c536 100644
--- a/com.creditease.uav.invokechain/src/main/java/com/creditease/uav/invokechain/http/InvokeChainQueryHandler.java
+++ b/com.creditease.uav.invokechain/src/main/java/com/creditease/uav/invokechain/http/InvokeChainQueryHandler.java
@@ -20,6 +20,8 @@
package com.creditease.uav.invokechain.http;
+import java.text.DateFormat;
+import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
@@ -110,9 +112,41 @@ private void queryByTrace(UAVHttpMessage data) {
SortBuilder[] sorts = buildSort(data);
+ String indexDate = getIndexDateFromTraceId(traceid);
+
+ data.putRequest("indexdate", indexDate);
+
queryToList(data, qb, null, sorts);
}
+ /**
+ * \ 根据traceid获取时间,确定ES的索引
+ *
+ * @param traceid
+ * @return indexData
+ */
+ private static String getIndexDateFromTraceId(String traceid) {
+
+ int count = 0;
+ StringBuilder sb = new StringBuilder();
+ // 从traceid中获取时间戳,取第二个'_'和第三个'_'之间的字符
+ for (int i = 0; i < traceid.length(); i++) {
+ if (count == 2 && traceid.charAt(i) != '_') {
+ sb.append(traceid.charAt(i));
+ }
+ else if (count == 2) {
+ break;
+ }
+ if (traceid.charAt(i) == '_') {
+ count++;
+ }
+ }
+ DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
+ Long timeStamp = DataConvertHelper.toLong(sb.toString(), System.currentTimeMillis());
+ String indexdate = dateFormat.format(timeStamp);
+ return indexdate;
+ }
+
/**
* 从应用维度对调用链进行查询
*
diff --git a/com.creditease.uav.loghook/pom.xml b/com.creditease.uav.loghook/pom.xml
index e1a9b7d7..bcc45722 100644
--- a/com.creditease.uav.loghook/pom.xml
+++ b/com.creditease.uav.loghook/pom.xml
@@ -1,6 +1,6 @@
- 4.0.0
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ 4.0.0
ce-datamonitorsystem
@@ -8,53 +8,63 @@
1.0
../com.creditease.uav.superpom
-
- com.creditease.uav.loghook
-
-
-
- junit
- junit
- 3.8.1
- test
-
-
-
- log4j
- log4j
- 1.2.17
- system
- ${basedir}/lib/log4j-1.2.17.jar
-
-
-
- org.slf4j
- slf4j-api
- 1.7.21
- system
- ${basedir}/lib/slf4j-api-1.7.21.jar
-
-
-
- ch.qos.logback
- logback-core
- 1.1.7
- system
- ${basedir}/lib/logback-core-1.1.7.jar
-
-
-
- ch.qos.logback
- logback-classic
- 1.1.7
- system
- ${basedir}/lib/logback-classic-1.1.7.jar
-
-
-
- com.creditease.moniter
- com.creditease.uav.monitorframework
-
-
-
+
+ com.creditease.uav.loghook
+
+
+
+ junit
+ junit
+ 3.8.1
+ test
+
+
+
+ com.creditease.moniter
+ com.creditease.uav.monitorframework.apm
+
+
+
+ com.creditease.moniter
+ com.creditease.uav.monitorframework.dproxy
+
+
+
+ log4j
+ log4j
+ 1.2.17
+ system
+ ${basedir}/lib/log4j-1.2.17.jar
+
+
+
+ org.slf4j
+ slf4j-api
+ 1.7.21
+ system
+ ${basedir}/lib/slf4j-api-1.7.21.jar
+
+
+
+ ch.qos.logback
+ logback-core
+ 1.1.7
+ system
+ ${basedir}/lib/logback-core-1.1.7.jar
+
+
+
+ ch.qos.logback
+ logback-classic
+ 1.1.7
+ system
+ ${basedir}/lib/logback-classic-1.1.7.jar
+
+
+
+ com.creditease.moniter
+ com.creditease.uav.monitorframework
+
+
+
diff --git a/com.creditease.uav.loghook/src/main/java/com/creditease/uav/log/hook/Log4jHookProxy.java b/com.creditease.uav.loghook/src/main/java/com/creditease/uav/log/hook/Log4jHookProxy.java
index e8c172ce..29d223aa 100644
--- a/com.creditease.uav.loghook/src/main/java/com/creditease/uav/log/hook/Log4jHookProxy.java
+++ b/com.creditease.uav.loghook/src/main/java/com/creditease/uav/log/hook/Log4jHookProxy.java
@@ -41,13 +41,21 @@
import com.creditease.monitor.interceptframework.spi.InterceptConstants;
import com.creditease.monitor.interceptframework.spi.InterceptContext;
import com.creditease.monitor.interceptframework.spi.InterceptContext.Event;
+import com.creditease.uav.log.hook.interceptors.LogIT;
+import com.creditease.uav.monitorframework.dproxy.DynamicProxyInstaller;
+import com.creditease.uav.monitorframework.dproxy.DynamicProxyProcessor;
import com.creditease.uav.profiling.handlers.log.LogProfileInfo;
+import javassist.CtMethod;
+
public class Log4jHookProxy extends HookProxy {
+ private final DynamicProxyInstaller dpInstall;
+
@SuppressWarnings("rawtypes")
public Log4jHookProxy(String id, Map config) {
super(id, config);
+ dpInstall = new DynamicProxyInstaller();
}
@Override
@@ -58,7 +66,7 @@ public void start(HookContext context, ClassLoader webapploader) {
switch (evt) {
case WEBCONTAINER_RESOURCE_INIT:
case WEBCONTAINER_INIT:
-
+ InsertIntercept(context, webapploader);
break;
// when servlet init
case AFTER_SERVET_INIT:
@@ -194,4 +202,34 @@ else if (layout instanceof TTCCLayout) {
}
}
+
+ private void InsertIntercept(HookContext context, ClassLoader webapploader) {
+
+ /**
+ * set the webapploader is the target classloader
+ */
+ dpInstall.setTargetClassLoader(webapploader);
+
+ // 定义一个类里面的hook变量并初始化,防止每次拦截write时都初始化对象
+ dpInstall.defineField("uavLogHook", LogIT.class, "org.apache.log4j.helpers.QuietWriter", "new LogIT()");
+ // 定义换行符变量(与log4j中保持一致)
+ dpInstall.defineField("uavLogHookLineSep", String.class, "org.apache.log4j.helpers.QuietWriter",
+ "System.getProperty(\"line.separator\")");
+
+ dpInstall.installProxy("org.apache.log4j.helpers.QuietWriter",
+ new String[] { "com.creditease.uav.log.hook.interceptors" }, new DynamicProxyProcessor() {
+
+ @Override
+ public void process(CtMethod m) throws Exception {
+
+ if ("write".equals(m.getName())) {
+ m.insertBefore("{if(!$1.equals(uavLogHookLineSep)){$1=uavLogHook.formatLog($1);}}");
+
+ }
+ }
+ }, false);
+
+ // release loader
+ dpInstall.releaseTargetClassLoader();
+ }
}
diff --git a/com.creditease.uav.loghook/src/main/java/com/creditease/uav/log/hook/LogBackHookProxy.java b/com.creditease.uav.loghook/src/main/java/com/creditease/uav/log/hook/LogBackHookProxy.java
index 53305688..7ae67d1b 100644
--- a/com.creditease.uav.loghook/src/main/java/com/creditease/uav/log/hook/LogBackHookProxy.java
+++ b/com.creditease.uav.loghook/src/main/java/com/creditease/uav/log/hook/LogBackHookProxy.java
@@ -34,6 +34,9 @@
import com.creditease.monitor.interceptframework.spi.InterceptConstants;
import com.creditease.monitor.interceptframework.spi.InterceptContext;
import com.creditease.monitor.interceptframework.spi.InterceptContext.Event;
+import com.creditease.uav.log.hook.interceptors.LogIT;
+import com.creditease.uav.monitorframework.dproxy.DynamicProxyInstaller;
+import com.creditease.uav.monitorframework.dproxy.DynamicProxyProcessor;
import com.creditease.uav.profiling.handlers.log.LogProfileInfo;
import ch.qos.logback.classic.Logger;
@@ -47,12 +50,16 @@
import ch.qos.logback.core.FileAppender;
import ch.qos.logback.core.Layout;
import ch.qos.logback.core.encoder.LayoutWrappingEncoder;
+import javassist.CtMethod;
public class LogBackHookProxy extends HookProxy {
+ private final DynamicProxyInstaller dpInstall;
+
@SuppressWarnings("rawtypes")
public LogBackHookProxy(String id, Map config) {
super(id, config);
+ dpInstall = new DynamicProxyInstaller();
}
@Override
@@ -61,6 +68,9 @@ public void start(HookContext context, ClassLoader webapploader) {
Event evt = context.get(Event.class);
switch (evt) {
+ case WEBCONTAINER_INIT:
+ InsertIntercept(context, webapploader);
+ break;
// when servlet init
case AFTER_SERVET_INIT:
break;
@@ -174,4 +184,32 @@ else if (layout instanceof TTLLLayout) {
}
}
+
+ private void InsertIntercept(HookContext context, ClassLoader webapploader) {
+
+ /**
+ * set the webapploader is the target classloader
+ */
+ dpInstall.setTargetClassLoader(webapploader);
+
+ // 定义一个类里面的hook变量并初始化,防止每次拦截write时都初始化对象
+ dpInstall.defineField("uavLogHook", LogIT.class, "ch.qos.logback.core.encoder.LayoutWrappingEncoder",
+ "new LogIT()");
+
+ dpInstall.installProxy("ch.qos.logback.core.encoder.LayoutWrappingEncoder",
+ new String[] { "com.creditease.uav.log.hook.interceptors" }, new DynamicProxyProcessor() {
+
+ @Override
+ public void process(CtMethod m) throws Exception {
+
+ if ("convertToBytes".equals(m.getName())) {
+ m.insertBefore("{$1=uavLogHook.formatLog($1);}");
+
+ }
+ }
+ }, false);
+
+ // release loader
+ dpInstall.releaseTargetClassLoader();
+ }
}
diff --git a/com.creditease.uav.loghook/src/main/java/com/creditease/uav/log/hook/interceptors/LogIT.java b/com.creditease.uav.loghook/src/main/java/com/creditease/uav/log/hook/interceptors/LogIT.java
new file mode 100644
index 00000000..f1c59619
--- /dev/null
+++ b/com.creditease.uav.loghook/src/main/java/com/creditease/uav/log/hook/interceptors/LogIT.java
@@ -0,0 +1,44 @@
+/*-
+ * <<
+ * UAVStack
+ * ==
+ * Copyright (C) 2016 - 2017 UAVStack
+ * ==
+ * Licensed 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 com.creditease.uav.log.hook.interceptors;
+
+import com.creditease.monitor.UAVServer;
+import com.creditease.uav.apm.invokechain.spi.InvokeChainSpanContext;
+import com.creditease.uav.common.BaseComponent;
+
+public class LogIT extends BaseComponent {
+
+ public String formatLog(String str) {
+
+ if (UAVServer.instance().isExistSupportor("com.creditease.uav.apm.supporters.InvokeChainSupporter")) {
+ if (UAVServer.instance().isExistSupportor("com.creditease.uav.apm.supporters.LogTraceSupporter")) {
+ InvokeChainSpanContext context = (InvokeChainSpanContext) UAVServer.instance()
+ .runSupporter("com.creditease.uav.apm.supporters.InvokeChainSupporter", "getSpanContext");
+ if (context != null) {
+ String traceId = context.getMainSpan().getTraceId();
+ return new StringBuilder().append("uav_").append(traceId).append(" ").append(str).toString();
+ }
+ }
+ }
+ return str;
+ }
+
+}
diff --git a/com.creditease.uav.monitorframework.apm/src/main/java/com/creditease/uav/apm/invokechain/handlers/ClientSpanInvokeChainHandler.java b/com.creditease.uav.monitorframework.apm/src/main/java/com/creditease/uav/apm/invokechain/handlers/ClientSpanInvokeChainHandler.java
index 14aef00a..a97f524c 100644
--- a/com.creditease.uav.monitorframework.apm/src/main/java/com/creditease/uav/apm/invokechain/handlers/ClientSpanInvokeChainHandler.java
+++ b/com.creditease.uav.monitorframework.apm/src/main/java/com/creditease/uav/apm/invokechain/handlers/ClientSpanInvokeChainHandler.java
@@ -57,10 +57,15 @@ public void preCap(InvokeChainContext context) {
/**
* Step 3: get client invoke context info: such as Class, Method, URL
*/
- int level = Integer.parseInt(String.valueOf(context.get(InvokeChainConstants.CLIENT_IT_KEY)));
- String clazz = String.valueOf(context.get(InvokeChainConstants.CLIENT_IT_CLASS));
+ try {
+ int level = Integer.parseInt(String.valueOf(context.get(InvokeChainConstants.CLIENT_IT_KEY)));
+ String clazz = String.valueOf(context.get(InvokeChainConstants.CLIENT_IT_CLASS));
- setCallerThreadInfo(span, level, clazz);
+ setCallerThreadInfo(span, level, clazz);
+ }
+ catch (Exception e) {
+ // ignore
+ }
String url = (String) context.get(CaptureConstants.INFO_CLIENT_REQUEST_URL);
span.setUrl(url);
diff --git a/com.creditease.uav.monitorframework.apm/src/main/java/com/creditease/uav/apm/invokechain/handlers/MethodSpanInvokeChainHandler.java b/com.creditease.uav.monitorframework.apm/src/main/java/com/creditease/uav/apm/invokechain/handlers/MethodSpanInvokeChainHandler.java
index 819219ba..ac73c759 100644
--- a/com.creditease.uav.monitorframework.apm/src/main/java/com/creditease/uav/apm/invokechain/handlers/MethodSpanInvokeChainHandler.java
+++ b/com.creditease.uav.monitorframework.apm/src/main/java/com/creditease/uav/apm/invokechain/handlers/MethodSpanInvokeChainHandler.java
@@ -52,7 +52,7 @@ public void preCap(InvokeChainContext context) {
String sign = (String) context.get(InvokeChainConstants.METHOD_SPAN_MTDSIGN);
span.setClassName(cls);
span.setMethodName(method + ((StringHelper.isEmpty(sign)) ? "" : "(" + sign + ")"));
- span.setEndpointInfo(mSeqCountFormat.format(parentSpan.getSpanMethodSeqCounter()));
+ span.setEndpointInfo(mSeqCountFormat.format(parentSpan.incrementAndGetSpanMethodSeqCounter()));
span.setUrl("");
String storekey = new StringBuilder().append(cls).append(".").append(method).append(".").append(sign)
diff --git a/com.creditease.uav.monitorframework.apm/src/main/java/com/creditease/uav/apm/invokechain/handlers/SpanContextHandler.java b/com.creditease.uav.monitorframework.apm/src/main/java/com/creditease/uav/apm/invokechain/handlers/SpanContextHandler.java
new file mode 100644
index 00000000..1918f15c
--- /dev/null
+++ b/com.creditease.uav.monitorframework.apm/src/main/java/com/creditease/uav/apm/invokechain/handlers/SpanContextHandler.java
@@ -0,0 +1,69 @@
+/*-
+ * <<
+ * UAVStack
+ * ==
+ * Copyright (C) 2016 - 2017 UAVStack
+ * ==
+ * Licensed 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 com.creditease.uav.apm.invokechain.handlers;
+
+import java.util.Map;
+
+import com.creditease.uav.apm.invokechain.span.Span;
+import com.creditease.uav.apm.invokechain.spi.InvokeChainCapHandler;
+import com.creditease.uav.apm.invokechain.spi.InvokeChainContext;
+import com.creditease.uav.apm.invokechain.spi.InvokeChainSpanContext;
+
+/**
+ *
+ * ClientEnd Point InvokeChainHandler usage of client request/response Handler
+ *
+ *
+ */
+
+public class SpanContextHandler extends InvokeChainCapHandler {
+
+ @Override
+ public void preCap(InvokeChainContext context) {
+
+ // do nothing
+ }
+
+ /**
+ * Finish Span and Logger the Span Metrics
+ */
+ @Override
+ public void doCap(InvokeChainContext context) {
+
+ // do nothing
+ }
+
+ public class SpanContext implements InvokeChainSpanContext {
+
+ @Override
+ public Map
getSpansFromContext() {
+
+ return spanFactory.getSpansFromContext();
+ }
+
+ @Override
+ public Span getMainSpan() {
+
+ return spanFactory.getSpanFromContext("main");
+ }
+ }
+
+}
diff --git a/com.creditease.uav.monitorframework.apm/src/main/java/com/creditease/uav/apm/invokechain/span/Span.java b/com.creditease.uav.monitorframework.apm/src/main/java/com/creditease/uav/apm/invokechain/span/Span.java
index 261819d8..1e0a6528 100644
--- a/com.creditease.uav.monitorframework.apm/src/main/java/com/creditease/uav/apm/invokechain/span/Span.java
+++ b/com.creditease.uav.monitorframework.apm/src/main/java/com/creditease/uav/apm/invokechain/span/Span.java
@@ -107,6 +107,11 @@ public AtomicInteger getSubSpanSeqCounter() {
public int getSpanMethodSeqCounter() {
+ return this.spanMethodSeqCounter.get();
+ }
+
+ public int incrementAndGetSpanMethodSeqCounter() {
+
return this.spanMethodSeqCounter.incrementAndGet();
}
diff --git a/com.creditease.uav.monitorframework.apm/src/main/java/com/creditease/uav/apm/invokechain/span/SpanFactory.java b/com.creditease.uav.monitorframework.apm/src/main/java/com/creditease/uav/apm/invokechain/span/SpanFactory.java
index 59a13f46..1552a347 100644
--- a/com.creditease.uav.monitorframework.apm/src/main/java/com/creditease/uav/apm/invokechain/span/SpanFactory.java
+++ b/com.creditease.uav.monitorframework.apm/src/main/java/com/creditease/uav/apm/invokechain/span/SpanFactory.java
@@ -198,6 +198,16 @@ public String getSpanMeta(Span span) {
return b.toString();
}
+ /**
+ * 从ThreadLocal中获取spanMap
+ *
+ * @return
+ */
+ public Map getSpansFromContext() {
+
+ return threadLocalTracker.get();
+ }
+
/**
* 从ThreadLocal中获取span
*
diff --git a/com.creditease.uav.monitorframework.apm/src/main/java/com/creditease/uav/apm/invokechain/spi/InvokeChainSpanContext.java b/com.creditease.uav.monitorframework.apm/src/main/java/com/creditease/uav/apm/invokechain/spi/InvokeChainSpanContext.java
new file mode 100644
index 00000000..9f9c95ab
--- /dev/null
+++ b/com.creditease.uav.monitorframework.apm/src/main/java/com/creditease/uav/apm/invokechain/spi/InvokeChainSpanContext.java
@@ -0,0 +1,49 @@
+/*-
+ * <<
+ * UAVStack
+ * ==
+ * Copyright (C) 2016 - 2017 UAVStack
+ * ==
+ * Licensed 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 com.creditease.uav.apm.invokechain.spi;
+
+import java.util.Map;
+
+import com.creditease.uav.apm.invokechain.span.Span;
+
+/**
+ *
+ * SpanContext description: 调用链span上下文
+ *
+ * 此类提供当前调用链的上下信息
+ *
+ */
+public interface InvokeChainSpanContext {
+
+ /**
+ * 获取当前调用所有所有span
+ *
+ * @return
+ */
+ public Map getSpansFromContext();
+
+ /**
+ * 获取当前服务内调用链的根节点
+ *
+ * @return
+ */
+ public Span getMainSpan();
+}
diff --git a/com.creditease.uav.monitorframework.apm/src/main/java/com/creditease/uav/apm/supporters/InvokeChainSupporter.java b/com.creditease.uav.monitorframework.apm/src/main/java/com/creditease/uav/apm/supporters/InvokeChainSupporter.java
index 27fa9e81..35f18d93 100644
--- a/com.creditease.uav.monitorframework.apm/src/main/java/com/creditease/uav/apm/supporters/InvokeChainSupporter.java
+++ b/com.creditease.uav.monitorframework.apm/src/main/java/com/creditease/uav/apm/supporters/InvokeChainSupporter.java
@@ -33,12 +33,13 @@
import com.creditease.uav.apm.invokechain.handlers.ClientSpanInvokeChainHandler;
import com.creditease.uav.apm.invokechain.handlers.MethodSpanInvokeChainHandler;
import com.creditease.uav.apm.invokechain.handlers.ServiceSpanInvokeChainHandler;
+import com.creditease.uav.apm.invokechain.handlers.SpanContextHandler;
import com.creditease.uav.apm.invokechain.jee.JEEServiceRunGlobalFilterHandler;
import com.creditease.uav.apm.invokechain.spi.InvokeChainAdapter;
import com.creditease.uav.apm.invokechain.spi.InvokeChainCapHandler;
import com.creditease.uav.apm.invokechain.spi.InvokeChainConstants;
-import com.creditease.uav.apm.invokechain.spi.InvokeChainContext;
import com.creditease.uav.apm.invokechain.spi.InvokeChainConstants.CapturePhase;
+import com.creditease.uav.apm.invokechain.spi.InvokeChainContext;
import com.creditease.uav.appserver.listeners.GlobalFilterDispatchListener;
import com.creditease.uav.common.Supporter;
@@ -96,6 +97,7 @@ public void start() {
// register MethodSpanInvokeChainHandler
handlerMap.put(InvokeChainConstants.CHAIN_APP_METHOD, new MethodSpanInvokeChainHandler());
+
}
@Override
@@ -265,6 +267,15 @@ else if (methodName.equals("registerAdapter")) {
return false;
}
}
+ else if (methodName.equals("getSpanContext")) {
+ try {
+ return new SpanContextHandler().new SpanContext();
+ }
+ catch (Exception e) {
+ this.logger.error("getSpanContext FAIL. ", e);
+ return null;
+ }
+ }
return null;
}
diff --git a/com.creditease.uav.monitorframework.apm/src/main/java/com/creditease/uav/apm/supporters/LogTraceSupporter.java b/com.creditease.uav.monitorframework.apm/src/main/java/com/creditease/uav/apm/supporters/LogTraceSupporter.java
new file mode 100644
index 00000000..0a7be8fb
--- /dev/null
+++ b/com.creditease.uav.monitorframework.apm/src/main/java/com/creditease/uav/apm/supporters/LogTraceSupporter.java
@@ -0,0 +1,46 @@
+/*-
+ * <<
+ * UAVStack
+ * ==
+ * Copyright (C) 2016 - 2017 UAVStack
+ * ==
+ * Licensed 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 com.creditease.uav.apm.supporters;
+
+import com.creditease.uav.common.Supporter;
+
+/**
+ *
+ * LogTraceSupporter description: 日志追踪supporter
+ *
+ * 当前supporter作为一个开关,具体实现依附于调用链,并由调用链提供数据支持
+ *
+ */
+public class LogTraceSupporter extends Supporter {
+
+ @Override
+ public void start() {
+
+ // do nothing
+ }
+
+ @Override
+ public void stop() {
+
+ super.stop();
+ }
+
+}