use of com.navercorp.pinpoint.grpc.trace.PAgentUriStat in project pinpoint by naver.
the class GrpcStatMessageConverter method toMessage.
@Override
public GeneratedMessageV3 toMessage(MetricType message) {
if (message instanceof AgentStatMetricSnapshotBatch) {
final AgentStatMetricSnapshotBatch agentStatMetricSnapshotBatch = (AgentStatMetricSnapshotBatch) message;
final PAgentStatBatch.Builder agentStatBatchBuilder = PAgentStatBatch.newBuilder();
// Skip agentId, startTimestamp
for (AgentStatMetricSnapshot agentStatMetricSnapshot : agentStatMetricSnapshotBatch.getAgentStats()) {
final PAgentStat agentStat = converAgentStat(agentStatMetricSnapshot);
agentStatBatchBuilder.addAgentStat(agentStat);
}
return agentStatBatchBuilder.build();
} else if (message instanceof AgentStatMetricSnapshot) {
final AgentStatMetricSnapshot agentStatMetricSnapshot = (AgentStatMetricSnapshot) message;
final PAgentStat agentStat = converAgentStat(agentStatMetricSnapshot);
return agentStat;
} else if (message instanceof AgentCustomMetricSnapshotBatch) {
final AgentCustomMetricSnapshotBatch agentCustomMetricSnapshotBatch = (AgentCustomMetricSnapshotBatch) message;
final PCustomMetricMessage pCustomMetricMessage = customMetricMessageConverter.toMessage(agentCustomMetricSnapshotBatch);
return pCustomMetricMessage;
} else if (message instanceof AgentUriStatData) {
final AgentUriStatData agentUriStatData = (AgentUriStatData) message;
final PAgentUriStat agentUriStat = uriStatMessageConverter.toMessage(agentUriStatData);
return agentUriStat;
}
return null;
}
use of com.navercorp.pinpoint.grpc.trace.PAgentUriStat in project pinpoint by naver.
the class GrpcUriStatMessageConverterTest method convertTest.
@Test
public void convertTest() {
long currentTimeMillis = System.currentTimeMillis();
AgentUriStatData agentUriStatData = new AgentUriStatData(currentTimeMillis);
List<UriStatInfo> uriStatInfoList = createRandomUriStatInfo(100);
for (UriStatInfo uriStatInfo : uriStatInfoList) {
agentUriStatData.add(uriStatInfo);
}
GrpcUriStatMessageConverter converter = new GrpcUriStatMessageConverter();
PAgentUriStat agentUriStat = converter.toMessage(agentUriStatData);
List<PEachUriStat> eachUriStatList = agentUriStat.getEachUriStatList();
assertData(uriStatInfoList, eachUriStatList);
}
use of com.navercorp.pinpoint.grpc.trace.PAgentUriStat in project pinpoint by naver.
the class StatService method sendAgentStat.
@Override
public StreamObserver<PStatMessage> sendAgentStat(StreamObserver<Empty> responseObserver) {
StreamObserver<PStatMessage> observer = new StreamObserver<PStatMessage>() {
@Override
public void onNext(PStatMessage statMessage) {
if (isDebug) {
logger.debug("Send PAgentStat={}", MessageFormatUtils.debugLog(statMessage));
}
if (statMessage.hasAgentStat()) {
final Message<PAgentStat> message = newMessage(statMessage.getAgentStat(), DefaultTBaseLocator.AGENT_STAT);
send(message, responseObserver);
} else if (statMessage.hasAgentStatBatch()) {
final Message<PAgentStatBatch> message = newMessage(statMessage.getAgentStatBatch(), DefaultTBaseLocator.AGENT_STAT_BATCH);
send(message, responseObserver);
} else if (statMessage.hasAgentUriStat()) {
final Message<PAgentUriStat> message = newMessage(statMessage.getAgentUriStat(), DefaultTBaseLocator.AGENT_URI_STAT);
send(message, responseObserver);
} else {
if (isDebug) {
logger.debug("Found empty stat message {}", MessageFormatUtils.debugLog(statMessage));
}
}
}
@Override
public void onError(Throwable throwable) {
final StatusError statusError = StatusErrors.throwable(throwable);
if (statusError.isSimpleError()) {
logger.info("Failed to stat stream, cause={}", statusError.getMessage());
} else {
logger.warn("Failed to stat stream, cause={}", statusError.getMessage(), statusError.getThrowable());
}
}
@Override
public void onCompleted() {
com.navercorp.pinpoint.grpc.Header header = ServerContext.getAgentInfo();
logger.info("onCompleted {}", header);
responseObserver.onNext(Empty.newBuilder().build());
responseObserver.onCompleted();
}
};
return observer;
}
use of com.navercorp.pinpoint.grpc.trace.PAgentUriStat in project pinpoint by naver.
the class GrpcUriStatMessageConverter method createPAgentUriStat.
private PAgentUriStat createPAgentUriStat(AgentUriStatData agentUriStatData) {
long baseTimestamp = agentUriStatData.getBaseTimestamp();
PAgentUriStat.Builder builder = PAgentUriStat.newBuilder();
builder.setTimestamp(baseTimestamp);
builder.setBucketVersion(UriStatHistogramBucket.getBucketVersion());
Collection<EachUriStatData> allUriStatData = agentUriStatData.getAllUriStatData();
for (EachUriStatData eachUriStatData : allUriStatData) {
PEachUriStat pEachUriStat = createPEachUriStat(eachUriStatData);
builder.addEachUriStat(pEachUriStat);
}
return builder.build();
}
use of com.navercorp.pinpoint.grpc.trace.PAgentUriStat in project pinpoint by naver.
the class GrpcAgentUriStatHandlerV2Test method handleTest.
@Test
public void handleTest() {
AgentUriStatService mockAgentUriStatService = Mockito.mock(AgentUriStatService.class);
attachContext(new Header("name", "agentId", "agentName", "applicationName", ServiceType.UNKNOWN.getCode(), System.currentTimeMillis(), Header.SOCKET_ID_NOT_EXIST, new ArrayList<>()));
PAgentUriStat pAgentUriStat = createPAgentUriStat();
ServerRequest<GeneratedMessageV3> mockServerRequest = Mockito.mock(ServerRequest.class);
Mockito.when(mockServerRequest.getData()).thenReturn(pAgentUriStat);
GrpcAgentStatHandlerV2 handler = createMockHandler(mockAgentUriStatService, true);
handler.handleSimple(mockServerRequest);
Mockito.verify(mockAgentUriStatService, times(1)).save(Mockito.any());
}
Aggregations