Search in sources :

Example 1 with SlowOperSpan

use of com.creditease.uav.invokechain.data.SlowOperSpan in project uavstack by uavorg.

the class SlowOperDataCollectHandler method handle.

@Override
public void handle(CollectDataFrame frame) {
    if (this.log.isDebugEnable()) {
        this.log.debug(this, frame.toJSONString());
    }
    BulkRequestBuilder bulkRequest = client.getClient().prepareBulk();
    String appUUID = frame.getTarget();
    // 从uuid中获取appid
    String appid = appUUID.split("---")[1];
    for (Line line : frame.getLines()) {
        String content = line.getContent();
        try {
            // 提取epinfo
            StringBuilder builder = new StringBuilder();
            int headPoint = 0;
            for (int i = 0; i < content.length(); i++) {
                char item = content.charAt(i);
                if (item == ';') {
                    headPoint++;
                    if (headPoint == 3) {
                        break;
                    }
                } else {
                    if (headPoint > 1) {
                        builder.append(item);
                    }
                }
            }
            String epinfo = builder.toString();
            // 若epinfo为数字则说明为方法级
            if (DataConvertHelper.toInt(epinfo, -1) != -1) {
                epinfo = "method";
            }
            IActionEngine engine = this.getActionEngineMgr().getActionEngine("SlowOperActionEngine");
            ActionContext ac = new ActionContext();
            ac.putParam("content", content);
            ac.putParam("appid", appid);
            engine.execute(epinfo, ac);
            SlowOperSpan span = (SlowOperSpan) ac.getParam("span");
            pushSpanToBulkRequest(appUUID, frame.getAppgroup(), span, bulkRequest, (String) ac.getParam("protocolType"));
        } catch (Exception e) {
            // 防止有不合法的协议报文出现
            this.log.err(this, "unsupported protocol,content is" + frame.toJSONString(), e);
        }
    }
    BulkResponse bulkResponse = bulkRequest.get();
    if (bulkResponse.hasFailures()) {
        log.err(this, "INSERT InvokeChain Data to ES FAIL: " + bulkResponse.buildFailureMessage());
    }
}
Also used : Line(com.creditease.agent.apm.api.CollectDataFrame.Line) SlowOperSpan(com.creditease.uav.invokechain.data.SlowOperSpan) BulkResponse(org.elasticsearch.action.bulk.BulkResponse) BulkRequestBuilder(org.elasticsearch.action.bulk.BulkRequestBuilder) ActionContext(com.creditease.agent.spi.ActionContext) IActionEngine(com.creditease.agent.spi.IActionEngine)

Aggregations

Line (com.creditease.agent.apm.api.CollectDataFrame.Line)1 ActionContext (com.creditease.agent.spi.ActionContext)1 IActionEngine (com.creditease.agent.spi.IActionEngine)1 SlowOperSpan (com.creditease.uav.invokechain.data.SlowOperSpan)1 BulkRequestBuilder (org.elasticsearch.action.bulk.BulkRequestBuilder)1 BulkResponse (org.elasticsearch.action.bulk.BulkResponse)1