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);
}
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;
}
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);
}
}
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);
}
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;
}
Aggregations