Search in sources :

Example 1 with GrpcAgentConnection

use of com.navercorp.pinpoint.collector.cluster.GrpcAgentConnection in project pinpoint by naver.

the class ClusterPointController method checkConnectionStatus.

@GetMapping(value = "/checkConnectionStatus")
public String checkConnectionStatus(@RequestParam("applicationName") String applicationName, @RequestParam("agentId") String agentId, @RequestParam("startTimestamp") long startTimestamp, @RequestParam(value = "checkCount", defaultValue = "3") int checkCount) throws JsonProcessingException {
    Assert.isTrue(checkCount > 0, "checkCount must be ' > 0'");
    List<GrpcAgentConnection> grpcAgentConnectionList = getGrpcAgentConnectionList(applicationName, agentId, startTimestamp);
    List<GrpcAgentConnectionStats> result = new ArrayList<>(grpcAgentConnectionList.size());
    for (GrpcAgentConnection grpcAgentConnection : grpcAgentConnectionList) {
        if (!grpcAgentConnection.isSupportCommand(CONNECTION_CHECK_COMMAND)) {
            result.add(new GrpcAgentConnectionStats(grpcAgentConnection, CheckConnectionStatusResult.STATUS_CHECK_NOT_SUPPORTED));
            continue;
        }
        CheckConnectionStatusResult connectionStatusResult = request(grpcAgentConnection, checkCount);
        result.add(new GrpcAgentConnectionStats(grpcAgentConnection, connectionStatusResult));
    }
    return mapper.writeValueAsString(result);
}
Also used : GrpcAgentConnection(com.navercorp.pinpoint.collector.cluster.GrpcAgentConnection) ArrayList(java.util.ArrayList) GetMapping(org.springframework.web.bind.annotation.GetMapping)

Example 2 with GrpcAgentConnection

use of com.navercorp.pinpoint.collector.cluster.GrpcAgentConnection in project pinpoint by naver.

the class ClusterPointController method getClusterPoint0.

private List<GrpcAgentConnectionStats> getClusterPoint0(final String applicationName, final String agentId, final long startTimestamp) {
    List<GrpcAgentConnection> grpcAgentConnectionList = getGrpcAgentConnectionList(applicationName, agentId, startTimestamp);
    List<GrpcAgentConnectionStats> result = new ArrayList<>(grpcAgentConnectionList.size());
    for (GrpcAgentConnection grpcAgentConnection : grpcAgentConnectionList) {
        result.add(new GrpcAgentConnectionStats(grpcAgentConnection, CheckConnectionStatusResult.NOT_CHECKED));
    }
    return result;
}
Also used : GrpcAgentConnection(com.navercorp.pinpoint.collector.cluster.GrpcAgentConnection) ArrayList(java.util.ArrayList)

Example 3 with GrpcAgentConnection

use of com.navercorp.pinpoint.collector.cluster.GrpcAgentConnection in project pinpoint by naver.

the class ClusterPointController method getGrpcAgentConnectionList.

private List<GrpcAgentConnection> getGrpcAgentConnectionList(final String applicationName, final String agentId, final long startTimestamp) {
    Objects.requireNonNull(applicationName, "applicationName");
    List<GrpcAgentConnection> result = new ArrayList<>();
    List<ClusterPoint<?>> clusterPointList = clusterPointLocator.getClusterPointList();
    for (ClusterPoint<?> clusterPoint : clusterPointList) {
        if (!(clusterPoint instanceof GrpcAgentConnection)) {
            continue;
        }
        AgentInfo destAgentInfo = clusterPoint.getDestAgentInfo();
        if (!destAgentInfo.getApplicationName().equals(applicationName)) {
            continue;
        }
        if (StringUtils.hasText(agentId) && !destAgentInfo.getAgentId().equals(agentId)) {
            continue;
        }
        if (startTimestamp > 0 && destAgentInfo.getStartTimestamp() != startTimestamp) {
            continue;
        }
        result.add((GrpcAgentConnection) clusterPoint);
    }
    return result;
}
Also used : GrpcAgentConnection(com.navercorp.pinpoint.collector.cluster.GrpcAgentConnection) ArrayList(java.util.ArrayList) AgentInfo(com.navercorp.pinpoint.collector.cluster.AgentInfo) ClusterPoint(com.navercorp.pinpoint.collector.cluster.ClusterPoint)

Example 4 with GrpcAgentConnection

use of com.navercorp.pinpoint.collector.cluster.GrpcAgentConnection in project pinpoint by naver.

the class StreamRouteHandler method onRoute0.

private TCommandTransferResponse onRoute0(StreamEvent event) {
    TBase<?, ?> requestObject = event.getRequestObject();
    if (requestObject == null) {
        return createResponse(TRouteResult.EMPTY_REQUEST);
    }
    ClusterPoint<?> clusterPoint = findClusterPoint(event.getDeliveryCommand());
    if (clusterPoint == null) {
        return createResponse(TRouteResult.NOT_FOUND);
    }
    if (!clusterPoint.isSupportCommand(requestObject)) {
        logger.warn("Create StreamChannel failed. target:{}, message:{} is not supported command", clusterPoint, requestObject.getClass().getName());
        return createResponse(TRouteResult.NOT_SUPPORTED_REQUEST);
    }
    try {
        if (clusterPoint instanceof ThriftAgentConnection) {
            StreamRouteManager routeManager = new StreamRouteManager(event);
            ServerStreamChannel consumerStreamChannel = event.getStreamChannel();
            consumerStreamChannel.setAttributeIfAbsent(ATTACHMENT_KEY, routeManager);
            ClientStreamChannel producerStreamChannel = createStreamChannel((ThriftAgentConnection) clusterPoint, event.getDeliveryCommand().getPayload(), routeManager);
            routeManager.setProducer(producerStreamChannel);
            return createResponse(TRouteResult.OK);
        } else if (clusterPoint instanceof GrpcAgentConnection) {
            StreamRouteManager routeManager = new StreamRouteManager(event);
            ServerStreamChannel consumerStreamChannel = event.getStreamChannel();
            consumerStreamChannel.setAttributeIfAbsent(ATTACHMENT_KEY, routeManager);
            ClientStreamChannel producerStreamChannel = ((GrpcAgentConnection) clusterPoint).openStream(event.getRequestObject(), routeManager);
            routeManager.setProducer(producerStreamChannel);
            return createResponse(TRouteResult.OK);
        } else {
            return createResponse(TRouteResult.NOT_SUPPORTED_SERVICE);
        }
    } catch (StreamException e) {
        StreamCode streamCode = e.getStreamCode();
        return createResponse(TRouteResult.STREAM_CREATE_ERROR, streamCode.name());
    } catch (Exception e) {
        if (logger.isWarnEnabled()) {
            logger.warn("Create StreamChannel failed. target:{}, message:{}", clusterPoint, e.getMessage(), e);
        }
    }
    return createResponse(TRouteResult.UNKNOWN);
}
Also used : ThriftAgentConnection(com.navercorp.pinpoint.collector.cluster.ThriftAgentConnection) GrpcAgentConnection(com.navercorp.pinpoint.collector.cluster.GrpcAgentConnection) ClientStreamChannel(com.navercorp.pinpoint.rpc.stream.ClientStreamChannel) StreamCode(com.navercorp.pinpoint.rpc.packet.stream.StreamCode) StreamException(com.navercorp.pinpoint.rpc.stream.StreamException) ServerStreamChannel(com.navercorp.pinpoint.rpc.stream.ServerStreamChannel) StreamException(com.navercorp.pinpoint.rpc.stream.StreamException)

Example 5 with GrpcAgentConnection

use of com.navercorp.pinpoint.collector.cluster.GrpcAgentConnection in project pinpoint by naver.

the class DefaultRouteHandler method onRoute0.

private TCommandTransferResponse onRoute0(RequestEvent event) {
    TBase<?, ?> requestObject = event.getRequestObject();
    if (requestObject == null) {
        return createResponse(TRouteResult.EMPTY_REQUEST);
    }
    ClusterPoint<?> clusterPoint = findClusterPoint(event.getDeliveryCommand());
    if (clusterPoint == null) {
        return createResponse(TRouteResult.NOT_FOUND);
    }
    if (!clusterPoint.isSupportCommand(requestObject)) {
        return createResponse(TRouteResult.NOT_SUPPORTED_REQUEST);
    }
    Future<ResponseMessage> future;
    if (clusterPoint instanceof ThriftAgentConnection) {
        ThriftAgentConnection thriftAgentConnection = (ThriftAgentConnection) clusterPoint;
        future = thriftAgentConnection.request(event.getDeliveryCommand().getPayload());
    } else if (clusterPoint instanceof GrpcAgentConnection) {
        GrpcAgentConnection grpcAgentConnection = (GrpcAgentConnection) clusterPoint;
        future = grpcAgentConnection.request(event.getRequestObject());
    } else {
        return createResponse(TRouteResult.NOT_ACCEPTABLE);
    }
    boolean isCompleted = future.await();
    if (!isCompleted) {
        return createResponse(TRouteResult.TIMEOUT);
    }
    if (future.getCause() != null) {
        return createResponse(TRouteResult.UNKNOWN, future.getCause().getMessage());
    }
    ResponseMessage responseMessage = future.getResult();
    if (responseMessage == null) {
        return createResponse(TRouteResult.EMPTY_RESPONSE);
    }
    final byte[] responsePayload = responseMessage.getMessage();
    if (ArrayUtils.isEmpty(responsePayload)) {
        return createResponse(TRouteResult.EMPTY_RESPONSE, new byte[0]);
    }
    return createResponse(TRouteResult.OK, responsePayload);
}
Also used : ThriftAgentConnection(com.navercorp.pinpoint.collector.cluster.ThriftAgentConnection) GrpcAgentConnection(com.navercorp.pinpoint.collector.cluster.GrpcAgentConnection) ResponseMessage(com.navercorp.pinpoint.rpc.ResponseMessage)

Aggregations

GrpcAgentConnection (com.navercorp.pinpoint.collector.cluster.GrpcAgentConnection)8 ArrayList (java.util.ArrayList)3 ThriftAgentConnection (com.navercorp.pinpoint.collector.cluster.ThriftAgentConnection)2 PinpointGrpcServer (com.navercorp.pinpoint.collector.receiver.grpc.PinpointGrpcServer)2 ResponseMessage (com.navercorp.pinpoint.rpc.ResponseMessage)2 Test (org.junit.Test)2 AgentInfo (com.navercorp.pinpoint.collector.cluster.AgentInfo)1 ClusterPoint (com.navercorp.pinpoint.collector.cluster.ClusterPoint)1 SocketStateChangeResult (com.navercorp.pinpoint.rpc.common.SocketStateChangeResult)1 StreamCode (com.navercorp.pinpoint.rpc.packet.stream.StreamCode)1 ClientStreamChannel (com.navercorp.pinpoint.rpc.stream.ClientStreamChannel)1 ServerStreamChannel (com.navercorp.pinpoint.rpc.stream.ServerStreamChannel)1 StreamException (com.navercorp.pinpoint.rpc.stream.StreamException)1 TResult (com.navercorp.pinpoint.thrift.dto.TResult)1 TCommandEcho (com.navercorp.pinpoint.thrift.dto.command.TCommandEcho)1 GetMapping (org.springframework.web.bind.annotation.GetMapping)1