Search in sources :

Example 1 with DoorPlank

use of com.pamirs.pradar.pressurement.agent.shared.domain.DoorPlank in project LinkAgent by shulieTech.

the class ArbiterEntrance method shallWePassHttp.

/**
 * 判断压测数据是否能通过这道门
 * @return
 */
public static DoorPlank shallWePassHttp() {
    DoorPlank doorPlank = new DoorPlank();
    if (!PradarSwitcher.isClusterTestReady()) {
        doorPlank.setCloseReason(CLOSE_REASON);
        doorPlank.setStatus(Pradar.DOOR_CLOSED);
    } else {
        if (contextPath != null) {
            Set<String> set = GlobalConfig.getInstance().getContextPathBlockList();
            for (String blockWar : set) {
                if (blockWar.equals(contextPath)) {
                    doorPlank.setCloseReason(DoorConstants.ARBITER_DOOR_BLOCK);
                    doorPlank.setStatus(Pradar.DOOR_CLOSED);
                    return doorPlank;
                }
            }
        }
        doorPlank.setCloseReason("");
        doorPlank.setStatus(Pradar.DOOR_OPENED);
    }
    return doorPlank;
}
Also used : DoorPlank(com.pamirs.pradar.pressurement.agent.shared.domain.DoorPlank)

Example 2 with DoorPlank

use of com.pamirs.pradar.pressurement.agent.shared.domain.DoorPlank in project LinkAgent by shulieTech.

the class RequestTracer method startTrace.

/**
 * 开始调用链,注意,开始之后,不管后续处理是否正常,都需要调用。
 */
public final boolean startTrace(REQ request, RESP response, String pluginName) {
    String url = getRequestURI(request);
    if (isNeedFilter(url, request)) {
        return false;
    }
    String ip = null;
    if (!PradarSwitcher.USE_LOCAL_IP) {
        ip = getRemoteAddress(request);
    }
    String traceId = getTraceId(request);
    boolean isClusterTestRequest = isClusterTestRequest(request);
    boolean isDebug = isDebugRequest(request);
    ClusterTestUtils.validateClusterTest(isClusterTestRequest);
    boolean isTraceIdBlank = false;
    if (StringUtils.isBlank(traceId)) {
        traceId = TraceIdGenerator.generate(ip, isClusterTestRequest);
        isTraceIdBlank = true;
    }
    if (isDebug && isTraceIdBlank) {
        setResponseHeader(response, "traceId", traceId);
    }
    if (isClusterTestRequest) {
        final DoorPlank arbiterDp = ArbiterEntrance.shallWePassHttp();
        if (Pradar.DOOR_CLOSED.equals(arbiterDp.getStatus())) {
            ErrorReporter.buildError().setErrorType(ErrorTypeEnum.AgentError).setErrorCode("agent-0008").setMessage("压测开关关闭").setDetail("data receiver filter is close!").report();
            throw new PressureMeasureError("data receiver filter is close! " + arbiterDp, isClusterTestRequest);
        }
    }
    if (!isTraceIdBlank) {
        Map<String, String> context = getContext(request);
        if (context != null) {
            context.put(PradarService.PRADAR_TRACE_ID_KEY, traceId);
            context.put(PradarService.PRADAR_CLUSTER_TEST_KEY, String.valueOf(isClusterTestRequest));
        }
        if (LOGGER.isDebugEnabled()) {
            LOGGER.debug("accept web server rpcServerRecv context:{}, currentContext:{} currentMiddleware:{}", context, Pradar.getInvokeContextMap(), Pradar.getMiddlewareName());
        }
        Pradar.startServerInvoke(url, StringUtils.upperCase(getMethod(request)), context);
        setAttribute(request, "isTrace", false);
    } else {
        Pradar.clearInvokeContext();
        Pradar.startTrace(traceId, url, StringUtils.upperCase(getMethod(request)));
        setAttribute(request, "isTrace", true);
    }
    InvokeContext invokeContext = Pradar.getInvokeContext();
    invokeContext.setClusterTest(isClusterTestRequest);
    invokeContext.setDebug(isDebug);
    final long contentLength = getContentLength(request);
    invokeContext.setRequestSize(contentLength < 0 ? 0 : contentLength);
    String remoteIp = invokeContext.getRemoteIp();
    if (StringUtils.isBlank(remoteIp) || "127.0.0.1".equals(remoteIp)) {
        remoteIp = getRemoteAddress(request);
    }
    if (StringUtils.isNotBlank(remoteIp)) {
        invokeContext.setRemoteIp(remoteIp);
    }
    String port = getRemotePort(request);
    if (port != null) {
        invokeContext.setPort(port);
    }
    invokeContext.setMiddlewareName(pluginName);
    return true;
}
Also used : DoorPlank(com.pamirs.pradar.pressurement.agent.shared.domain.DoorPlank) PressureMeasureError(com.pamirs.pradar.exception.PressureMeasureError)

Aggregations

DoorPlank (com.pamirs.pradar.pressurement.agent.shared.domain.DoorPlank)2 PressureMeasureError (com.pamirs.pradar.exception.PressureMeasureError)1