Search in sources :

Example 11 with Header

use of com.navercorp.pinpoint.grpc.Header in project pinpoint by naver.

the class AgentHeaderReaderTest method extract.

@Test
public void extract() {
    Metadata metadata = newMetadata();
    Header header = reader.extract(metadata);
    Assert.assertEquals(header.getAgentId(), AGENT_ID);
    Assert.assertEquals(header.getAgentName(), AGENT_NAME);
    Assert.assertEquals(header.getApplicationName(), APPLICATION_NAME);
    Assert.assertEquals(header.getAgentStartTime(), AGENT_START_TIME);
    Assert.assertEquals(header.getSocketId(), SOCKET_ID);
    Assert.assertEquals(header.getServiceType(), SERVICE_TYPE);
}
Also used : Header(com.navercorp.pinpoint.grpc.Header) Metadata(io.grpc.Metadata) Test(org.junit.Test)

Example 12 with Header

use of com.navercorp.pinpoint.grpc.Header in project pinpoint by naver.

the class HeaderPropagationInterceptor method interceptCall.

@Override
public <ReqT, RespT> ServerCall.Listener<ReqT> interceptCall(final ServerCall<ReqT, RespT> call, Metadata headers, ServerCallHandler<ReqT, RespT> next) {
    Header headerObject;
    try {
        headerObject = headerReader.extract(headers);
    } catch (Exception e) {
        if (logger.isInfoEnabled()) {
            logger.info("Header extract fail cause={}, method={} headers={}, attr={}", e.getMessage(), call.getMethodDescriptor().getFullMethodName(), headers, call.getAttributes(), e);
        }
        call.close(Status.INVALID_ARGUMENT.withDescription(e.getMessage()), new Metadata());
        return new ServerCall.Listener<ReqT>() {
        };
    }
    final Context currentContext = Context.current();
    final Context newContext = currentContext.withValue(contextKey, headerObject);
    if (logger.isDebugEnabled()) {
        logger.debug("headerPropagation method={}, headers={}, attr={}", call.getMethodDescriptor().getFullMethodName(), headers, call.getAttributes());
    }
    ServerCall.Listener<ReqT> contextPropagateInterceptor = Contexts.interceptCall(newContext, call, headers, next);
    return contextPropagateInterceptor;
}
Also used : Context(io.grpc.Context) Header(com.navercorp.pinpoint.grpc.Header) ServerCall(io.grpc.ServerCall) Metadata(io.grpc.Metadata)

Example 13 with Header

use of com.navercorp.pinpoint.grpc.Header in project pinpoint by naver.

the class GrpcCommandServiceTest method newVersionHandshakeTest.

@Test
public void newVersionHandshakeTest() throws IOException, PinpointZookeeperException {
    ZookeeperProfilerClusterManager manager = creteMemoryClusterManager();
    ZookeeperClusterService mockClusterService = Mockito.mock(ZookeeperClusterService.class);
    Mockito.when(mockClusterService.getProfilerClusterManager()).thenReturn(manager);
    try (GrpcCommandService commandService = new GrpcCommandService(mockClusterService)) {
        TransportMetadata transportMetaData = createTransportMetaData(new InetSocketAddress("127.0.0.1", 61613), 10);
        attachContext(transportMetaData);
        attachContext(new Header("test", "agentId", null, "applicationName", ServiceType.UNDEFINED.getCode(), System.currentTimeMillis(), Header.SOCKET_ID_NOT_EXIST, getCodeList()));
        StreamObserver<PCmdMessage> handleMessageObserver = commandService.handleCommandV2(new TempServerCallStreamObserver<>());
        awaitility().until(manager::getClusterData, hasSize(1));
        assertHandleMessage(commandService, transportMetaData);
    }
}
Also used : PCmdMessage(com.navercorp.pinpoint.grpc.trace.PCmdMessage) ZookeeperClusterService(com.navercorp.pinpoint.collector.cluster.zookeeper.ZookeeperClusterService) ZookeeperProfilerClusterManager(com.navercorp.pinpoint.collector.cluster.zookeeper.ZookeeperProfilerClusterManager) Header(com.navercorp.pinpoint.grpc.Header) DefaultTransportMetadata(com.navercorp.pinpoint.grpc.server.DefaultTransportMetadata) TransportMetadata(com.navercorp.pinpoint.grpc.server.TransportMetadata) InetSocketAddress(java.net.InetSocketAddress) GrpcCommandService(com.navercorp.pinpoint.collector.receiver.grpc.service.command.GrpcCommandService) Test(org.junit.Test)

Example 14 with Header

use of com.navercorp.pinpoint.grpc.Header in project pinpoint by naver.

the class DefaultPingEventHandler method connect.

@Override
public void connect() {
    final TransportMetadata transportMetadata = ServerContext.getTransportMetadata();
    if (transportMetadata == null) {
        logger.info("Skip connect event handle of ping, not found TransportMetadata. header={}", ServerContext.getAgentInfo());
        return;
    }
    final Long transportId = transportMetadata.getTransportId();
    final Header header = ServerContext.getAgentInfo();
    final PingSession pingSession = new PingSession(transportId, header);
    pingSession.setLastPingTimeMillis(System.currentTimeMillis());
    final PingSession oldSession = pingSessionRegistry.add(pingSession.getId(), pingSession);
    if (oldSession != null) {
        logger.warn("Duplicated ping session old={}, new={}", oldSession, pingSession);
    }
    lifecycleListener.connect(pingSession);
}
Also used : Header(com.navercorp.pinpoint.grpc.Header) TransportMetadata(com.navercorp.pinpoint.grpc.server.TransportMetadata)

Example 15 with Header

use of com.navercorp.pinpoint.grpc.Header in project pinpoint by naver.

the class GrpcAgentUriStatMapper method map.

public AgentUriStatBo map(final PAgentUriStat agentUriStat) {
    final Header agentInfo = ServerContext.getAgentInfo();
    final String agentId = agentInfo.getAgentId();
    final long startTimestamp = agentInfo.getAgentStartTime();
    long timestamp = agentUriStat.getTimestamp();
    int bucketVersion = agentUriStat.getBucketVersion();
    AgentUriStatBo agentUriStatBo = new AgentUriStatBo();
    agentUriStatBo.setAgentId(agentId);
    agentUriStatBo.setStartTimestamp(startTimestamp);
    agentUriStatBo.setTimestamp(timestamp);
    agentUriStatBo.setBucketVersion((byte) bucketVersion);
    List<PEachUriStat> eachUriStatList = agentUriStat.getEachUriStatList();
    for (PEachUriStat pEachUriStat : eachUriStatList) {
        EachUriStatBo eachUriStatBo = createEachUriStatBo(pEachUriStat);
        agentUriStatBo.addEachUriStatBo(eachUriStatBo);
    }
    return agentUriStatBo;
}
Also used : AgentUriStatBo(com.navercorp.pinpoint.common.server.bo.stat.AgentUriStatBo) Header(com.navercorp.pinpoint.grpc.Header) PEachUriStat(com.navercorp.pinpoint.grpc.trace.PEachUriStat) EachUriStatBo(com.navercorp.pinpoint.common.server.bo.stat.EachUriStatBo)

Aggregations

Header (com.navercorp.pinpoint.grpc.Header)28 Test (org.junit.Test)10 SpanChunkBo (com.navercorp.pinpoint.common.server.bo.SpanChunkBo)5 TransportMetadata (com.navercorp.pinpoint.grpc.server.TransportMetadata)5 SpanEventBo (com.navercorp.pinpoint.common.server.bo.SpanEventBo)4 PSpanChunk (com.navercorp.pinpoint.grpc.trace.PSpanChunk)4 InetSocketAddress (java.net.InetSocketAddress)4 ZookeeperClusterService (com.navercorp.pinpoint.collector.cluster.zookeeper.ZookeeperClusterService)3 ZookeeperProfilerClusterManager (com.navercorp.pinpoint.collector.cluster.zookeeper.ZookeeperProfilerClusterManager)3 GrpcCommandService (com.navercorp.pinpoint.collector.receiver.grpc.service.command.GrpcCommandService)3 DefaultTransportMetadata (com.navercorp.pinpoint.grpc.server.DefaultTransportMetadata)3 PCmdMessage (com.navercorp.pinpoint.grpc.trace.PCmdMessage)3 Metadata (io.grpc.Metadata)3 AgentProperty (com.navercorp.pinpoint.collector.service.async.AgentProperty)2 DefaultAgentProperty (com.navercorp.pinpoint.collector.service.async.DefaultAgentProperty)2 AgentInfoBo (com.navercorp.pinpoint.common.server.bo.AgentInfoBo)2 AgentEventBo (com.navercorp.pinpoint.common.server.bo.event.AgentEventBo)2 AgentStatBo (com.navercorp.pinpoint.common.server.bo.stat.AgentStatBo)2 Context (io.grpc.Context)2 GeneratedMessageV3 (com.google.protobuf.GeneratedMessageV3)1