From 678ecbed85f688ef0d5f2060e6345537fa73c909 Mon Sep 17 00:00:00 2001 From: Kim YoungJin Date: Mon, 18 Mar 2024 21:29:49 +0900 Subject: [PATCH] [#10741] Added service id --- .../bootstrap/context/TraceContext.java | 3 +- .../pinpoint/bootstrap/context/TraceId.java | 4 +- .../pinpoint/bootstrap/AgentIdResolver.java | 62 +++---- .../bootstrap/AgentIdResolverBuilder.java | 12 +- .../pinpoint/bootstrap/AgentIds.java | 16 +- .../pinpoint/bootstrap/AgentOption.java | 5 +- .../pinpoint/bootstrap/AgentProperties.java | 40 ++--- .../bootstrap/DefaultAgentOption.java | 35 ++-- .../pinpoint/bootstrap/IdValidator.java | 5 + .../pinpoint/bootstrap/PinpointStarter.java | 33 ++-- .../bootstrap/AgentBootLoaderTest.java | 3 +- .../bootstrap/AgentIdResolverTest.java | 52 +++--- .../jboss/InvokeMethodInterceptorTest.java | 3 +- .../test/MockApplicationContextFactory.java | 9 +- .../profiler/test/TestAgentInformation.java | 6 +- .../MockApplicationContextModuleTest.java | 9 +- .../test/OrderedSpanRecorderTest.java | 3 +- .../test/monitor/AgentStatMonitorTest.java | 3 +- .../pinpoint/profiler/AgentInformation.java | 5 +- .../profiler/DefaultAgentInformation.java | 42 +++-- .../profiler/context/DefaultTraceContext.java | 3 +- .../grpc/GrpcSpanMessageConverter.java | 11 +- .../GrpcSpanMessageConverterProvider.java | 11 +- .../grpc/mapper/TraceIdMapStructUtils.java | 3 +- .../profiler/context/id/DefaultTraceId.java | 34 ++-- .../context/id/DefaultTraceIdFactory.java | 7 +- .../context/id/DefaultTraceRootFactory.java | 7 +- .../context/id/LocalTraceRootImpl.java | 8 +- .../context/id/RemoteTraceRootImpl.java | 3 +- .../profiler/context/id/TraceRoot.java | 5 +- .../context/module/AgentIdHolder.java | 34 ++++ .../module/{AgentId.java => ServiceName.java} | 2 +- .../context/module/config/ConfigModule.java | 18 +- .../provider/AgentInformationProvider.java | 26 ++- .../grpc/AgentHeaderFactoryProvider.java | 9 +- .../pinpoint/profiler/monitor/CollectJob.java | 11 +- .../monitor/DefaultAgentStatMonitor.java | 11 +- .../monitor/collector/AgentStatCollector.java | 39 ++-- .../context/DefaultTraceContextTest.java | 5 +- .../MockApplicationContextFactory.java | 6 +- .../context/TestAgentInformation.java | 6 +- .../pinpoint/profiler/context/TraceTest.java | 3 +- .../active/ActiveTraceRepositoryTest.java | 3 +- .../compress/GrpcSpanProcessorV2Test.java | 14 +- .../context/graph/DependencyGraph.java | 3 +- .../GrpcExceptionMetaDataConverterTest.java | 3 +- .../grpc/GrpcSpanMessageConverterTest.java | 3 +- .../context/id/LocalTraceRootTest.java | 14 +- .../module/DefaultApplicationContextTest.java | 3 +- .../context/storage/BufferedStorageTest.java | 3 +- .../profiler/monitor/CollectJobTest.java | 3 +- .../grpc/AgentGrpcDataSenderTestMain.java | 8 +- .../vo/sender/payload/WebhookPayload.java | 2 +- .../pinpoint/batch/alarm/AlarmProcessor.java | 7 +- .../pinot/DataSourceDataCollector.java | 10 +- .../batch/job/AgentCountProcessor.java | 10 +- .../pinpoint/batch/job/AgentCountReader.java | 10 +- .../pinpoint/batch/job/AgentRemover.java | 4 +- .../job/ApplicationCleaningProcessor.java | 19 +- .../pinpoint/batch/job/ApplicationReader.java | 10 +- .../batch/job/ApplicationRemover.java | 3 +- .../job/CleanupInactiveAgentsTasklet.java | 23 +-- .../batch/service/BatchAgentService.java | 9 +- .../batch/service/BatchAgentServiceImpl.java | 14 +- .../service/BatchApplicationService.java | 9 +- .../service/BatchApplicationServiceImpl.java | 10 +- .../pinpoint/batch/alarm/AlarmReaderTest.java | 9 +- .../alarm/checker/GcCountCheckerTest.java | 4 +- .../pinpoint/collector/dao/AgentInfoDao.java | 3 +- .../collector/dao/ApplicationInfoDao.java | 15 +- .../collector/dao/ServiceInfoDao.java | 34 ++++ .../dao/hbase/HbaseAgentInfoDao.java | 12 +- .../dao/hbase/HbaseApplicationIndexDao.java | 5 +- .../dao/hbase/HbaseApplicationInfoDao.java | 131 ++++++++------ .../hbase/HbaseApplicationTraceIndexDao.java | 2 +- .../hbase/HbaseMapStatisticsCalleeDao.java | 4 +- .../hbase/HbaseMapStatisticsCallerDao.java | 4 +- .../dao/hbase/HbaseServiceInfoDao.java | 169 ++++++++++++++++++ .../ApplicationIndexRowKeyEncoderV2.java | 8 +- .../dao/hbase/statistics/CallRowKey.java | 17 +- .../hbase/statistics/CalleeColumnName.java | 22 +-- .../handler/grpc/GrpcApiMetaDataHandler.java | 5 +- .../grpc/GrpcExceptionMetaDataHandler.java | 11 +- .../handler/grpc/GrpcSpanChunkHandler.java | 10 +- .../handler/grpc/GrpcSpanHandler.java | 10 +- .../handler/grpc/GrpcSqlMetaDataHandler.java | 17 +- .../grpc/GrpcSqlUidMetaDataHandler.java | 5 +- .../grpc/GrpcStringMetaDataHandler.java | 6 +- .../mapper/grpc/GrpcAgentInfoBoMapper.java | 19 +- .../grpc/event/GrpcAgentEventBatchMapper.java | 5 +- .../grpc/event/GrpcAgentEventMapper.java | 5 +- .../grpc/stat/GrpcAgentStatBatchMapper.java | 5 +- .../mapper/grpc/stat/GrpcAgentStatMapper.java | 7 +- .../grpc/stat/GrpcAgentUriStatMapper.java | 6 +- .../grpc/service/KeepAliveService.java | 6 +- .../collector/service/AgentInfoService.java | 14 +- .../service/ApplicationInfoService.java | 20 ++- .../service/ChainServiceInfoService.java | 68 +++++++ .../collector/service/HbaseTraceService.java | 15 +- .../collector/service/ServiceInfoService.java | 33 ++++ .../service/ServiceInfoServiceImpl.java | 62 +++++++ .../service/StaticServiceInfoService.java | 58 ++++++ .../async/AgentEventAsyncTaskService.java | 7 +- .../async/AgentLifeCycleAsyncTaskService.java | 11 +- .../service/async/AgentProperty.java | 4 +- .../async/AgentPropertyChannelAdaptor.java | 11 +- .../service/async/DefaultAgentProperty.java | 22 +-- .../collector/util/CollectorUtils.java | 5 + .../ApplicationIndexRowKeyEncoderV2Test.java | 4 +- .../grpc/GrpcAgentUriMetricHandlerV2Test.java | 4 +- .../grpc/GrpcApiMetaDataHandlerTest.java | 3 +- .../receiver/grpc/AgentClientMock.java | 3 +- .../receiver/grpc/MetadataClientMock.java | 18 +- .../receiver/grpc/MetadataClientTestMain.java | 2 +- .../receiver/grpc/SpanClientMock.java | 7 +- .../receiver/grpc/StatClientMock.java | 5 +- .../sampler/SimpleSpanFactoryTest.java | 5 +- .../common/hbase/HbaseColumnFamily.java | 8 + .../pinpoint/common/hbase/HbaseTable.java | 1 + .../pinpoint/common/hbase/util/CellUtils.java | 9 + .../common/profiler/util/TransactionId.java | 13 +- .../profiler/util/TransactionIdUtils.java | 26 ++- .../util/TransactionIdComparatorTest.java | 23 +-- .../profiler/util/TransactionIdUtilsTest.java | 15 +- .../common/server/bo/AgentInfoBo.java | 52 ++++-- .../common/server/bo/ApplicationInfo.java | 38 ++++ .../common/server/bo/ApplicationSelector.java | 64 +++++++ .../pinpoint/common/server/bo/BasicSpan.java | 5 +- .../common/server/bo/ServiceInfo.java | 35 ++++ .../pinpoint/common/server/bo/SpanBo.java | 11 +- .../common/server/bo/SpanChunkBo.java | 7 +- .../common/server/bo/grpc/BindAttribute.java | 7 +- .../common/server/bo/grpc/GrpcSpanBinder.java | 3 +- .../bo/serializer/trace/v2/SpanDecoderV0.java | 3 +- .../bo/serializer/trace/v2/SpanEncoderV0.java | 2 +- .../trace/v2/TraceRowKeyDecoderV2.java | 3 +- .../trace/v2/TraceRowKeyEncoderV2.java | 2 +- .../common/server/bo/thrift/SpanFactory.java | 7 +- .../common/server/cluster/ClusterKey.java | 5 + .../CommonCacheManagerConfiguration.java | 8 +- .../config/CustomCacheRegistration.java | 29 +++ .../DefaultCustomCacheRegistration.java | 35 ++++ .../dao/hbase/mapper/AgentInfoBoMapper.java | 6 +- .../mapper/ApplicationIdForwardMapper.java | 26 ++- .../mapper/ApplicationIdInverseMapper.java | 15 +- .../hbase/mapper/ServiceIdForwardMapper.java | 27 ++- .../hbase/mapper/ServiceIdInverseMapper.java | 49 +++++ .../common/server/util/SpanUtils.java | 5 +- .../server/bo/ApplicationSelectorTest.java | 42 +++++ .../common/server/bo/RandomTSpan.java | 5 +- .../common/server/bo/SpanFactoryAssert.java | 4 +- .../bo/grpc/CollectorGrpcSpanFactoryTest.java | 3 +- .../server/bo/thrift/SpanFactoryTest.java | 8 +- .../pinpoint/common/PinpointConstants.java | 2 + .../navercorp/pinpoint/common/id/AgentId.java | 23 ++- .../pinpoint/common/id/ApplicationId.java | 6 +- .../pinpoint/common/id/ServiceId.java | 43 +++++ .../common/id/StringPinpointIdentifier.java | 7 +- .../common/id/UUIDPinpointIdentifier.java | 7 +- .../pinpoint/common/util/IdValidateUtils.java | 5 + .../pinpoint/grpc/AgentHeaderFactory.java | 11 +- .../com/navercorp/pinpoint/grpc/Header.java | 22 ++- .../grpc/server/AgentHeaderReader.java | 13 +- .../pinpoint/grpc/ChannelFactoryTest.java | 11 +- .../grpc/server/AgentHeaderReaderTest.java | 2 +- hbase/scripts/hbase-create.hbase | 2 + hbase/scripts/hbase-drop.hbase | 13 ++ .../receiver/grpc/GrpcCommandServiceTest.java | 4 +- .../StatisticsServerGroupListFactory.java | 3 +- .../AgentInfoServerGroupListDataSource.java | 2 +- .../map/FilteredMapBuilder.java | 4 +- .../applicationmap/nodes/ServerInstance.java | 2 +- .../controller/AdminController.java | 46 ++++- .../web/cache/CacheConfiguration.java | 23 +++ .../span/MetaSpanCallTreeFactory.java | 15 +- .../pinpoint/web/calltree/span/SpanAlign.java | 5 +- .../web/calltree/span/SpanEventAlign.java | 2 +- .../web/component/ApplicationFactory.java | 5 +- .../component/DefaultApplicationFactory.java | 4 +- .../web/controller/ApplicationController.java | 28 ++- .../pinpoint/web/dao/AgentLifeCycleDao.java | 3 +- .../pinpoint/web/dao/ApplicationIndexDao.java | 8 +- .../web/dao/ApplicationIndexDaoV2.java | 12 +- .../pinpoint/web/dao/ApplicationInfoDao.java | 13 +- .../web/dao/ApplicationTraceIndexDaoV2.java | 14 +- .../pinpoint/web/dao/ServiceInfoDao.java | 34 ++++ .../web/dao/hbase/HbaseAgentLifeCycleDao.java | 7 +- .../dao/hbase/HbaseApplicationIndexDao.java | 4 +- .../dao/hbase/HbaseApplicationIndexDaoV2.java | 27 ++- .../dao/hbase/HbaseApplicationInfoDao.java | 142 ++++++++++++--- .../HbaseApplicationTraceIndexDaoV2.java | 29 +-- .../dao/hbase/HbaseHostApplicationMapDao.java | 6 +- .../web/dao/hbase/HbaseServiceInfoDao.java | 120 +++++++++++++ .../web/filter/transaction/SpanContext.java | 3 +- .../web/mapper/ApplicationNameMapperV2.java | 4 +- .../pinpoint/web/mapper/SpanMapperV2.java | 4 +- .../pinpoint/web/service/AdminService.java | 9 +- .../web/service/AdminServiceImpl.java | 43 ++--- .../web/service/AgentIdStartTimeKey.java | 5 + .../web/service/AgentInfoService.java | 3 +- .../web/service/AgentInfoServiceImpl.java | 30 ++-- .../web/service/AgentServiceImpl.java | 4 +- .../web/service/ApplicationInfoService.java | 25 ++- .../web/service/ApplicationService.java | 15 +- .../web/service/ApplicationServiceImpl.java | 75 +++++--- .../ApplicationTraceIndexServiceImpl.java | 20 ++- .../pinpoint/web/service/CommonService.java | 4 +- .../web/service/CommonServiceImpl.java | 3 +- .../pinpoint/web/service/DotExtractor.java | 5 +- .../web/service/ScatterChartServiceImpl.java | 4 +- .../web/service/ServiceInfoService.java | 35 ++++ .../web/service/ServiceInfoServiceImpl.java | 65 +++++++ .../web/view/ApplicationSerializer.java | 4 +- .../TransactionMetaDataViewModel.java | 2 +- .../pinpoint/web/vo/Application.java | 6 +- .../pinpoint/web/vo/ResponseHistograms.java | 2 +- .../pinpoint/web/vo/agent/AgentInfo.java | 7 +- .../pinpoint/web/vo/agent/AgentStatus.java | 21 ++- .../web/vo/agent/AgentStatusQuery.java | 2 +- .../pinpoint/web/vo/scatter/DotAgentInfo.java | 2 +- .../web/vo/tree/ApplicationAgentHostList.java | 15 +- .../pinpoint/web/TestTraceUtils.java | 7 +- .../ApplicationMapBuilderTest.java | 2 +- .../ApplicationMapBuilderTestHelper.java | 3 +- .../applicationmap/ServerGroupListTest.java | 3 +- .../web/calltree/span/SpanCallTreeTest.java | 11 +- .../web/calltree/span/SpanFiltersTest.java | 5 +- .../dao/hbase/HbaseAgentLifeCycleDaoTest.java | 7 +- .../web/dao/hbase/SpanQueryBuilderTest.java | 5 +- .../pinpoint/web/filter/LinkFilterTest.java | 13 +- .../web/service/AdminServiceImplTest.java | 18 +- .../web/vo/AgentsMapByApplicationTest.java | 3 +- .../pinpoint/web/vo/AgentsMapByHostTest.java | 3 +- .../web/vo/callstacks/RecordFactoryTest.java | 3 +- 234 files changed, 2606 insertions(+), 970 deletions(-) create mode 100644 agent-module/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/module/AgentIdHolder.java rename agent-module/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/module/{AgentId.java => ServiceName.java} (96%) create mode 100644 collector/src/main/java/com/navercorp/pinpoint/collector/dao/ServiceInfoDao.java create mode 100644 collector/src/main/java/com/navercorp/pinpoint/collector/dao/hbase/HbaseServiceInfoDao.java create mode 100644 collector/src/main/java/com/navercorp/pinpoint/collector/service/ChainServiceInfoService.java create mode 100644 collector/src/main/java/com/navercorp/pinpoint/collector/service/ServiceInfoService.java create mode 100644 collector/src/main/java/com/navercorp/pinpoint/collector/service/ServiceInfoServiceImpl.java create mode 100644 collector/src/main/java/com/navercorp/pinpoint/collector/service/StaticServiceInfoService.java create mode 100644 commons-server/src/main/java/com/navercorp/pinpoint/common/server/bo/ApplicationInfo.java create mode 100644 commons-server/src/main/java/com/navercorp/pinpoint/common/server/bo/ApplicationSelector.java create mode 100644 commons-server/src/main/java/com/navercorp/pinpoint/common/server/bo/ServiceInfo.java create mode 100644 commons-server/src/main/java/com/navercorp/pinpoint/common/server/config/CustomCacheRegistration.java create mode 100644 commons-server/src/main/java/com/navercorp/pinpoint/common/server/config/DefaultCustomCacheRegistration.java rename web/src/main/java/com/navercorp/pinpoint/web/dao/hbase/mapper/ApplicationForwardMapper.java => commons-server/src/main/java/com/navercorp/pinpoint/common/server/dao/hbase/mapper/ServiceIdForwardMapper.java (64%) create mode 100644 commons-server/src/main/java/com/navercorp/pinpoint/common/server/dao/hbase/mapper/ServiceIdInverseMapper.java create mode 100644 commons-server/src/test/java/com/navercorp/pinpoint/common/server/bo/ApplicationSelectorTest.java create mode 100644 commons/src/main/java/com/navercorp/pinpoint/common/id/ServiceId.java create mode 100644 web/src/main/java/com/navercorp/pinpoint/web/dao/ServiceInfoDao.java create mode 100644 web/src/main/java/com/navercorp/pinpoint/web/dao/hbase/HbaseServiceInfoDao.java create mode 100644 web/src/main/java/com/navercorp/pinpoint/web/service/ServiceInfoService.java create mode 100644 web/src/main/java/com/navercorp/pinpoint/web/service/ServiceInfoServiceImpl.java diff --git a/agent-module/bootstraps/bootstrap-core/src/main/java/com/navercorp/pinpoint/bootstrap/context/TraceContext.java b/agent-module/bootstraps/bootstrap-core/src/main/java/com/navercorp/pinpoint/bootstrap/context/TraceContext.java index a87161b7fda6..19bbd74a66a0 100644 --- a/agent-module/bootstraps/bootstrap-core/src/main/java/com/navercorp/pinpoint/bootstrap/context/TraceContext.java +++ b/agent-module/bootstraps/bootstrap-core/src/main/java/com/navercorp/pinpoint/bootstrap/context/TraceContext.java @@ -20,6 +20,7 @@ import com.navercorp.pinpoint.bootstrap.plugin.jdbc.JdbcContext; import com.navercorp.pinpoint.common.annotations.InterfaceAudience; import com.navercorp.pinpoint.common.annotations.InterfaceStability; +import com.navercorp.pinpoint.common.id.AgentId; /** * @author emeroad @@ -73,7 +74,7 @@ public interface TraceContext { // ActiveThreadCounter getActiveThreadCounter(); - String getAgentId(); + AgentId getAgentId(); String getApplicationName(); diff --git a/agent-module/bootstraps/bootstrap-core/src/main/java/com/navercorp/pinpoint/bootstrap/context/TraceId.java b/agent-module/bootstraps/bootstrap-core/src/main/java/com/navercorp/pinpoint/bootstrap/context/TraceId.java index 18eb7b143c12..3fbcfa5566e9 100644 --- a/agent-module/bootstraps/bootstrap-core/src/main/java/com/navercorp/pinpoint/bootstrap/context/TraceId.java +++ b/agent-module/bootstraps/bootstrap-core/src/main/java/com/navercorp/pinpoint/bootstrap/context/TraceId.java @@ -16,6 +16,8 @@ package com.navercorp.pinpoint.bootstrap.context; +import com.navercorp.pinpoint.common.id.AgentId; + /** * @author emeroad */ @@ -27,7 +29,7 @@ public interface TraceId { String getTransactionId(); - String getAgentId(); + AgentId getAgentId(); long getAgentStartTime(); diff --git a/agent-module/bootstraps/bootstrap/src/main/java/com/navercorp/pinpoint/bootstrap/AgentIdResolver.java b/agent-module/bootstraps/bootstrap/src/main/java/com/navercorp/pinpoint/bootstrap/AgentIdResolver.java index c3f70c37a581..1dc4fe682bb3 100644 --- a/agent-module/bootstraps/bootstrap/src/main/java/com/navercorp/pinpoint/bootstrap/AgentIdResolver.java +++ b/agent-module/bootstraps/bootstrap/src/main/java/com/navercorp/pinpoint/bootstrap/AgentIdResolver.java @@ -17,30 +17,28 @@ package com.navercorp.pinpoint.bootstrap; import com.navercorp.pinpoint.common.PinpointConstants; -import com.navercorp.pinpoint.common.util.AgentUuidUtils; +import com.navercorp.pinpoint.common.id.ServiceId; import com.navercorp.pinpoint.common.util.StringUtils; -import com.navercorp.pinpoint.common.util.UuidUtils; import java.util.List; import java.util.Objects; -import java.util.UUID; /** * @author Woonduk Kang(emeroad) */ public class AgentIdResolver { public static final String APPLICATION_NAME = "applicationName"; - public static final String AGENT_ID = "agentId"; + public static final String SERVICE_NAME = "serviceName"; public static final String AGENT_NAME = "agentName"; public static final String SYSTEM_PROPERTY_PREFIX = "pinpoint."; public static final String APPLICATION_NAME_SYSTEM_PROPERTY = SYSTEM_PROPERTY_PREFIX + "applicationName"; - public static final String AGENT_ID_SYSTEM_PROPERTY = SYSTEM_PROPERTY_PREFIX + "agentId"; + public static final String SERVICE_NAME_SYSTEM_PROPERTY = SYSTEM_PROPERTY_PREFIX + "serviceName"; public static final String AGENT_NAME_SYSTEM_PROPERTY = SYSTEM_PROPERTY_PREFIX + "agentName"; public static final String ENV_PROPERTY_PREFIX = "PINPOINT_"; public static final String APPLICATION_NAME_ENV_PROPERTY = ENV_PROPERTY_PREFIX + "APPLICATION_NAME"; - public static final String AGENT_ID_ENV_PROPERTY = ENV_PROPERTY_PREFIX + "AGENT_ID"; + public static final String SERVICE_NAME_ENV_PROPERTY = ENV_PROPERTY_PREFIX + "SERVICE_NAME"; public static final String AGENT_NAME_ENV_PROPERTY = ENV_PROPERTY_PREFIX + "AGENT_NAME"; private final BootLogger logger = BootLogger.getLogger(this.getClass()); @@ -49,51 +47,32 @@ public class AgentIdResolver { private final IdValidator idValidator = new IdValidator(); private final IdValidator applicationNameValidator = new IdValidator(PinpointConstants.APPLICATION_NAME_MAX_LEN); + private final IdValidator serviceNameValidator = new IdValidator(PinpointConstants.SERVICE_NAME_MAX_LEN); public AgentIdResolver(List agentPropertyList) { this.agentPropertyList = Objects.requireNonNull(agentPropertyList, "agentPropertyList"); } public AgentIds resolve() { - String agentId = getAgentId(); - if (StringUtils.isEmpty(agentId)) { - logger.info("Failed to resolve AgentId(-Dpinpoint.agentId)"); - agentId = newRandomAgentId(); - logger.info("Auto generate AgentId='" + agentId + "'"); - } - final String applicationName = getApplicationName(); if (StringUtils.isEmpty(applicationName)) { logger.warn("Failed to resolve ApplicationName(-Dpinpoint.applicationName)"); return null; } + String serviceName = getServiceName(); + if (StringUtils.isEmpty(serviceName)) { + logger.info("Failed to resolve ServiceName(-Dpinpoint.serviceName)"); + serviceName = ServiceId.DEFAULT_SERVICE_NAME; + logger.info("Using default serviceName='" + serviceName + "'"); + } + final String agentName = getAgentName(); if (StringUtils.isEmpty(agentName)) { logger.info("No AgentName(-Dpinpoint.agentName) provided, it's optional!"); } - return new AgentIds(agentId, agentName, applicationName); - } - - private String newRandomAgentId() { - UUID agentUUID = UuidUtils.createV4(); - return AgentUuidUtils.encode(agentUUID); - } - - private String getAgentId() { - String source = null; - for (AgentProperties agentProperty : agentPropertyList) { - final String agentId = agentProperty.getAgentId(); - if (StringUtils.isEmpty(agentId)) { - continue; - } - if (idValidator.validateAgentId(agentProperty.getType(), agentId)) { - logger.info(agentProperty.getType() + " " + agentProperty.getAgentIdKey() + "=" + agentId); - source = agentId; - } - } - return source; + return new AgentIds(agentName, applicationName, serviceName); } private String getAgentName() { @@ -123,4 +102,19 @@ private String getApplicationName() { return source; } + private String getServiceName() { + String source = null; + for (AgentProperties agentProperty : agentPropertyList) { + final String serviceName = agentProperty.getServiceName(); + if (StringUtils.isEmpty(serviceName)) { + continue; + } + if (serviceNameValidator.validateServiceName(agentProperty.getType(), serviceName)) { + logger.info(agentProperty.getType() + " " + agentProperty.getServiceNameKey() + "=" + serviceName); + source = serviceName; + } + } + return source; + } + } diff --git a/agent-module/bootstraps/bootstrap/src/main/java/com/navercorp/pinpoint/bootstrap/AgentIdResolverBuilder.java b/agent-module/bootstraps/bootstrap/src/main/java/com/navercorp/pinpoint/bootstrap/AgentIdResolverBuilder.java index 7e0cc6c09aab..f09e1a43cccc 100644 --- a/agent-module/bootstraps/bootstrap/src/main/java/com/navercorp/pinpoint/bootstrap/AgentIdResolverBuilder.java +++ b/agent-module/bootstraps/bootstrap/src/main/java/com/navercorp/pinpoint/bootstrap/AgentIdResolverBuilder.java @@ -32,9 +32,9 @@ public void addSystemProperties(Properties system) { Objects.requireNonNull(system, "system"); AgentProperties systemProperties = new AgentProperties(AgentIdSourceType.SYSTEM, system, - AgentIdResolver.AGENT_ID_SYSTEM_PROPERTY, AgentIdResolver.AGENT_NAME_SYSTEM_PROPERTY, - AgentIdResolver.APPLICATION_NAME_SYSTEM_PROPERTY); + AgentIdResolver.APPLICATION_NAME_SYSTEM_PROPERTY, + AgentIdResolver.SERVICE_NAME_SYSTEM_PROPERTY); this.agentProperties.add(systemProperties); } @@ -42,9 +42,9 @@ public void addEnvProperties(Map env) { Objects.requireNonNull(env, "env"); AgentProperties envProperties = new AgentProperties(AgentIdSourceType.SYSTEM_ENV, env, - AgentIdResolver.AGENT_ID_ENV_PROPERTY, AgentIdResolver.AGENT_NAME_ENV_PROPERTY, - AgentIdResolver.APPLICATION_NAME_ENV_PROPERTY); + AgentIdResolver.APPLICATION_NAME_ENV_PROPERTY, + AgentIdResolver.SERVICE_NAME_ENV_PROPERTY); this.agentProperties.add(envProperties); } @@ -52,9 +52,9 @@ public void addAgentArgument(Map agentArguments) { Objects.requireNonNull(agentArguments, "agentArguments"); AgentProperties agentArgument = new AgentProperties(AgentIdSourceType.AGENT_ARGUMENT, agentArguments, - AgentIdResolver.AGENT_ID, AgentIdResolver.AGENT_NAME, - AgentIdResolver.APPLICATION_NAME); + AgentIdResolver.APPLICATION_NAME, + AgentIdResolver.SERVICE_NAME); this.agentProperties.add(agentArgument); } diff --git a/agent-module/bootstraps/bootstrap/src/main/java/com/navercorp/pinpoint/bootstrap/AgentIds.java b/agent-module/bootstraps/bootstrap/src/main/java/com/navercorp/pinpoint/bootstrap/AgentIds.java index 032dbe46302f..8c860e6d03f4 100644 --- a/agent-module/bootstraps/bootstrap/src/main/java/com/navercorp/pinpoint/bootstrap/AgentIds.java +++ b/agent-module/bootstraps/bootstrap/src/main/java/com/navercorp/pinpoint/bootstrap/AgentIds.java @@ -22,19 +22,14 @@ * @author Woonduk Kang(emeroad) */ public class AgentIds { - private final String agentId; private final String agentName; private final String applicationName; + private final String serviceName; - public AgentIds(String agentId, String agentName, String applicationName) { - this.agentId = Objects.requireNonNull(agentId, "agentId"); + public AgentIds(String agentName, String applicationName, String serviceName) { this.agentName = agentName; this.applicationName = Objects.requireNonNull(applicationName, "applicationName"); - } - - - public String getAgentId() { - return agentId; + this.serviceName = Objects.requireNonNull(serviceName, "serviceName"); } public String getAgentName() { @@ -44,4 +39,9 @@ public String getAgentName() { public String getApplicationName() { return applicationName; } + + public String getServiceName() { + return serviceName; + } + } diff --git a/agent-module/bootstraps/bootstrap/src/main/java/com/navercorp/pinpoint/bootstrap/AgentOption.java b/agent-module/bootstraps/bootstrap/src/main/java/com/navercorp/pinpoint/bootstrap/AgentOption.java index ed78c955c538..a70280da1903 100644 --- a/agent-module/bootstraps/bootstrap/src/main/java/com/navercorp/pinpoint/bootstrap/AgentOption.java +++ b/agent-module/bootstraps/bootstrap/src/main/java/com/navercorp/pinpoint/bootstrap/AgentOption.java @@ -17,6 +17,7 @@ package com.navercorp.pinpoint.bootstrap; import com.navercorp.pinpoint.bootstrap.config.ProfilerConfig; +import com.navercorp.pinpoint.common.id.AgentId; import java.lang.instrument.Instrumentation; import java.util.List; @@ -28,12 +29,14 @@ public interface AgentOption { Instrumentation getInstrumentation(); - String getAgentId(); + AgentId getAgentId(); String getAgentName(); String getApplicationName(); + String getServiceName(); + boolean isContainer(); ProfilerConfig getProfilerConfig(); diff --git a/agent-module/bootstraps/bootstrap/src/main/java/com/navercorp/pinpoint/bootstrap/AgentProperties.java b/agent-module/bootstraps/bootstrap/src/main/java/com/navercorp/pinpoint/bootstrap/AgentProperties.java index 5ea2fa8ea2d2..51ab1dd33145 100644 --- a/agent-module/bootstraps/bootstrap/src/main/java/com/navercorp/pinpoint/bootstrap/AgentProperties.java +++ b/agent-module/bootstraps/bootstrap/src/main/java/com/navercorp/pinpoint/bootstrap/AgentProperties.java @@ -26,20 +26,20 @@ public class AgentProperties { private final AgentIdSourceType type; private final Properties properties; - private final String agentIdKey; private final String agentNameKey; private final String applicationNameKey; + private final String serviceNameKey; - public AgentProperties(AgentIdSourceType type, Properties properties, String agentIdKey, String agentNameKey, String applicationNameKey) { + public AgentProperties(AgentIdSourceType type, Properties properties, String agentNameKey, String applicationNameKey, String serviceNameKey) { this.type = Objects.requireNonNull(type, "type"); this.properties = Objects.requireNonNull(properties, "properties"); - this.agentIdKey = Objects.requireNonNull(agentIdKey, "agentIdKey"); this.agentNameKey = Objects.requireNonNull(agentNameKey, "agentNameKey"); this.applicationNameKey = Objects.requireNonNull(applicationNameKey, "applicationNameKey"); + this.serviceNameKey = Objects.requireNonNull(serviceNameKey, "serviceNameKey"); } - public AgentProperties(AgentIdSourceType type, Map properties, String agentIdKey, String agentNameKey, String applicationNameKey) { - this(type, toProperties(properties), agentIdKey, agentNameKey, applicationNameKey); + public AgentProperties(AgentIdSourceType type, Map properties, String agentNameKey, String applicationNameKey, String serviceNameKey) { + this(type, toProperties(properties), agentNameKey, applicationNameKey, serviceNameKey); } private static Properties toProperties(Map properties) { @@ -54,18 +54,10 @@ public AgentIdSourceType getType() { return type; } - public String getAgentId() { - return trim(this.properties.getProperty(agentIdKey)); - } - public String getAgentName() { return trim(this.properties.getProperty(agentNameKey)); } - public String getAgentIdKey() { - return agentIdKey; - } - public String getAgentNameKey() { return agentNameKey; } @@ -78,6 +70,14 @@ public String getApplicationNameKey() { return applicationNameKey; } + public String getServiceName() { + return trim(this.properties.getProperty(serviceNameKey)); + } + + public String getServiceNameKey() { + return serviceNameKey; + } + private String trim(String string) { if (string == null) { return null; @@ -87,13 +87,11 @@ private String trim(String string) { @Override public String toString() { - final StringBuilder sb = new StringBuilder("AgentProperties{"); - sb.append("type=").append(type); - sb.append(", properties=").append(properties); - sb.append(", agentIdKey='").append(agentIdKey).append('\''); - sb.append(", agentNameKey='").append(agentNameKey).append('\''); - sb.append(", applicationNameKey='").append(applicationNameKey).append('\''); - sb.append('}'); - return sb.toString(); + return "AgentProperties{" + "type=" + type + + ", properties=" + properties + + ", agentNameKey='" + agentNameKey + '\'' + + ", applicationNameKey='" + applicationNameKey + '\'' + + ", serviceNameKey='" + serviceNameKey + '\'' + + '}'; } } diff --git a/agent-module/bootstraps/bootstrap/src/main/java/com/navercorp/pinpoint/bootstrap/DefaultAgentOption.java b/agent-module/bootstraps/bootstrap/src/main/java/com/navercorp/pinpoint/bootstrap/DefaultAgentOption.java index 033cf698adb7..ad63aa26716c 100644 --- a/agent-module/bootstraps/bootstrap/src/main/java/com/navercorp/pinpoint/bootstrap/DefaultAgentOption.java +++ b/agent-module/bootstraps/bootstrap/src/main/java/com/navercorp/pinpoint/bootstrap/DefaultAgentOption.java @@ -17,6 +17,7 @@ package com.navercorp.pinpoint.bootstrap; import com.navercorp.pinpoint.bootstrap.config.ProfilerConfig; +import com.navercorp.pinpoint.common.id.AgentId; import java.lang.instrument.Instrumentation; import java.util.List; @@ -29,9 +30,10 @@ public class DefaultAgentOption implements AgentOption { private final Instrumentation instrumentation; - private final String agentId; + private final AgentId agentId; private final String agentName; private final String applicationName; + private final String serviceName; private final boolean isContainer; private final ProfilerConfig profilerConfig; @@ -39,12 +41,13 @@ public class DefaultAgentOption implements AgentOption { private final List bootstrapJarPaths; public DefaultAgentOption(final Instrumentation instrumentation, - String agentId, String agentName, String applicationName, final boolean isContainer, + AgentId agentId, String agentName, String applicationName, String serviceName, final boolean isContainer, final ProfilerConfig profilerConfig, final List pluginJars, final List bootstrapJarPaths) { this.instrumentation = Objects.requireNonNull(instrumentation, "instrumentation"); this.agentId = Objects.requireNonNull(agentId, "agentId"); this.agentName = Objects.requireNonNull(agentName, "agentName"); this.applicationName = Objects.requireNonNull(applicationName, "applicationName"); + this.serviceName = Objects.requireNonNull(serviceName, "serviceName"); this.isContainer = isContainer; this.profilerConfig = Objects.requireNonNull(profilerConfig, "profilerConfig"); this.pluginJars = Objects.requireNonNull(pluginJars, "pluginJars"); @@ -57,7 +60,7 @@ public Instrumentation getInstrumentation() { } @Override - public String getAgentId() { + public AgentId getAgentId() { return agentId; } @@ -71,6 +74,11 @@ public String getApplicationName() { return applicationName; } + @Override + public String getServiceName() { + return serviceName; + } + @Override public boolean isContainer() { return isContainer; @@ -93,16 +101,15 @@ public ProfilerConfig getProfilerConfig() { @Override public String toString() { - final StringBuilder sb = new StringBuilder("DefaultAgentOption{"); - sb.append("instrumentation=").append(instrumentation); - sb.append(", agentId='").append(agentId).append('\''); - sb.append(", agentName='").append(agentName).append('\''); - sb.append(", applicationName='").append(applicationName).append('\''); - sb.append(", isContainer=").append(isContainer); - sb.append(", profilerConfig=").append(profilerConfig); - sb.append(", pluginJars=").append(pluginJars); - sb.append(", bootstrapJarPaths=").append(bootstrapJarPaths); - sb.append('}'); - return sb.toString(); + return "DefaultAgentOption{" + "instrumentation=" + instrumentation + + ", agentId='" + agentId + '\'' + + ", agentName='" + agentName + '\'' + + ", applicationName='" + applicationName + '\'' + + ", serviceName='" + serviceName + '\'' + + ", isContainer=" + isContainer + + ", profilerConfig=" + profilerConfig + + ", pluginJars=" + pluginJars + + ", bootstrapJarPaths=" + bootstrapJarPaths + + '}'; } } diff --git a/agent-module/bootstraps/bootstrap/src/main/java/com/navercorp/pinpoint/bootstrap/IdValidator.java b/agent-module/bootstraps/bootstrap/src/main/java/com/navercorp/pinpoint/bootstrap/IdValidator.java index db50a2202508..b694d4265aa6 100644 --- a/agent-module/bootstraps/bootstrap/src/main/java/com/navercorp/pinpoint/bootstrap/IdValidator.java +++ b/agent-module/bootstraps/bootstrap/src/main/java/com/navercorp/pinpoint/bootstrap/IdValidator.java @@ -55,6 +55,11 @@ public boolean validateApplicationName(AgentIdSourceType type, String applicatio return validate0(type + " applicationName", applicationName); } + public boolean validateServiceName(AgentIdSourceType type, String serviceName) { + Objects.requireNonNull(serviceName, "serviceName"); + return validate0(type + " serviceName", serviceName); + } + public boolean validateAgentName(AgentIdSourceType type, String agentName) { if (StringUtils.isEmpty(agentName)) { return false; diff --git a/agent-module/bootstraps/bootstrap/src/main/java/com/navercorp/pinpoint/bootstrap/PinpointStarter.java b/agent-module/bootstraps/bootstrap/src/main/java/com/navercorp/pinpoint/bootstrap/PinpointStarter.java index a35a7072ffa4..c6c4bd2668dc 100644 --- a/agent-module/bootstraps/bootstrap/src/main/java/com/navercorp/pinpoint/bootstrap/PinpointStarter.java +++ b/agent-module/bootstraps/bootstrap/src/main/java/com/navercorp/pinpoint/bootstrap/PinpointStarter.java @@ -27,6 +27,7 @@ import com.navercorp.pinpoint.bootstrap.config.PropertyLoaderFactory; import com.navercorp.pinpoint.common.Version; import com.navercorp.pinpoint.common.banner.PinpointBanner; +import com.navercorp.pinpoint.common.id.AgentId; import com.navercorp.pinpoint.common.util.OsEnvSimpleProperty; import com.navercorp.pinpoint.common.util.PropertySnapshot; import com.navercorp.pinpoint.common.util.SimpleProperty; @@ -61,7 +62,7 @@ class PinpointStarter { public static final String PLUGIN_TEST_AGENT = "PLUGIN_TEST"; public static final String PLUGIN_TEST_BOOT_CLASS = "com.navercorp.pinpoint.profiler.test.PluginTestAgent"; - private SimpleProperty systemProperty = SystemProperty.INSTANCE; + private final SimpleProperty systemProperty = SystemProperty.INSTANCE; private final Map agentArgs; private final AgentType agentType; @@ -99,16 +100,18 @@ boolean start() { return false; } - final String agentId = agentIds.getAgentId(); - if (agentId == null) { - logger.warn("agentId is null"); - return false; - } + final AgentId agentId = AgentId.random(); + final String applicationName = agentIds.getApplicationName(); if (applicationName == null) { logger.warn("applicationName is null"); return false; } + final String serviceName = agentIds.getServiceName(); + if (serviceName == null) { + logger.warn("serviceName is null"); + return false; + } final ContainerResolver containerResolver = new ContainerResolver(); final boolean isContainer = containerResolver.isContainer(); @@ -123,7 +126,6 @@ boolean start() { } // set the path of log file as a system property - saveAgentIdForLog(agentIds); saveLogFilePath(agentDirectory.getAgentLogFilePath()); savePinpointVersion(); @@ -144,7 +146,7 @@ boolean start() { final List pluginJars = agentDirectory.getPlugins(); final String agentName = agentIds.getAgentName(); - AgentOption option = createAgentOption(agentId, agentName, applicationName, isContainer, + AgentOption option = createAgentOption(agentId, agentName, applicationName, serviceName, isContainer, profilerConfig, instrumentation, pluginJars, @@ -258,14 +260,16 @@ private String getAgentType() { } - private AgentOption createAgentOption(String agentId, String agentName, String applicationName, boolean isContainer, + private AgentOption createAgentOption(AgentId agentId, String agentName, String applicationName, String serviceName, + boolean isContainer, ProfilerConfig profilerConfig, Instrumentation instrumentation, List pluginJars, List bootstrapJarPaths) { List pluginJarStrPath = toPathList(pluginJars); List bootstrapJarPathStrPath = toPathList(bootstrapJarPaths); - return new DefaultAgentOption(instrumentation, agentId, agentName, applicationName, isContainer, profilerConfig, pluginJarStrPath, bootstrapJarPathStrPath); + return new DefaultAgentOption(instrumentation, agentId, agentName, applicationName, serviceName, + isContainer, profilerConfig, pluginJarStrPath, bootstrapJarPathStrPath); } private List toPathList(List paths) { @@ -276,15 +280,6 @@ private List toPathList(List paths) { return list; } - // for test - void setSystemProperty(SimpleProperty systemProperty) { - this.systemProperty = systemProperty; - } - - private void saveAgentIdForLog(AgentIds agentIds) { - systemProperty.setProperty(AgentIdResolver.AGENT_ID_SYSTEM_PROPERTY, agentIds.getAgentId()); - } - private void saveLogFilePath(Path agentLogFilePath) { logger.info("logPath:" + agentLogFilePath); systemProperty.setProperty(ProductInfo.NAME + ".log", agentLogFilePath.toString()); diff --git a/agent-module/bootstraps/bootstrap/src/test/java/com/navercorp/pinpoint/bootstrap/AgentBootLoaderTest.java b/agent-module/bootstraps/bootstrap/src/test/java/com/navercorp/pinpoint/bootstrap/AgentBootLoaderTest.java index 33256aac0f86..b2dcb84d02fe 100644 --- a/agent-module/bootstraps/bootstrap/src/test/java/com/navercorp/pinpoint/bootstrap/AgentBootLoaderTest.java +++ b/agent-module/bootstraps/bootstrap/src/test/java/com/navercorp/pinpoint/bootstrap/AgentBootLoaderTest.java @@ -18,6 +18,7 @@ import com.navercorp.pinpoint.bootstrap.config.DefaultProfilerConfig; +import com.navercorp.pinpoint.common.id.AgentId; import com.navercorp.pinpoint.common.util.CodeSourceUtils; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; @@ -50,7 +51,7 @@ private void boot(String agentName) { ClassLoader classLoader = AgentBootLoaderTest.class.getClassLoader(); AgentBootLoader agentBootLoader = new AgentBootLoader("com.navercorp.pinpoint.bootstrap.DummyAgent", classLoader); Instrumentation instrumentation = mock(Instrumentation.class); - AgentOption option = new DefaultAgentOption(instrumentation, "testCaseAgent", agentName, "testCaseAppName", false, + AgentOption option = new DefaultAgentOption(instrumentation, AgentId.of("testCaseAgent"), agentName, "testCaseAppName", "testCaseServiceName", false, new DefaultProfilerConfig(), Collections.emptyList(), Collections.emptyList()); Agent boot = agentBootLoader.boot(option); boot.start(); diff --git a/agent-module/bootstraps/bootstrap/src/test/java/com/navercorp/pinpoint/bootstrap/AgentIdResolverTest.java b/agent-module/bootstraps/bootstrap/src/test/java/com/navercorp/pinpoint/bootstrap/AgentIdResolverTest.java index 5b35d2d2c9db..693bb37b73e7 100644 --- a/agent-module/bootstraps/bootstrap/src/test/java/com/navercorp/pinpoint/bootstrap/AgentIdResolverTest.java +++ b/agent-module/bootstraps/bootstrap/src/test/java/com/navercorp/pinpoint/bootstrap/AgentIdResolverTest.java @@ -1,95 +1,87 @@ package com.navercorp.pinpoint.bootstrap; -import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; import java.util.Arrays; +import java.util.Collections; import java.util.Properties; +import static org.assertj.core.api.Assertions.assertThat; + public class AgentIdResolverTest { @Test public void resolve() { Properties properties = new Properties(); - properties.setProperty(AgentIdResolver.AGENT_ID, "agentId"); properties.setProperty(AgentIdResolver.AGENT_NAME, "agentName"); properties.setProperty(AgentIdResolver.APPLICATION_NAME, "appName"); - AgentProperties ap = new AgentProperties(AgentIdSourceType.AGENT_ARGUMENT, properties, AgentIdResolver.AGENT_ID, AgentIdResolver.AGENT_NAME, AgentIdResolver.APPLICATION_NAME); + AgentProperties ap = new AgentProperties(AgentIdSourceType.AGENT_ARGUMENT, properties, AgentIdResolver.AGENT_NAME, AgentIdResolver.APPLICATION_NAME, AgentIdResolver.SERVICE_NAME); - AgentIdResolver resolver = new AgentIdResolver(Arrays.asList(ap)); + AgentIdResolver resolver = new AgentIdResolver(Collections.singletonList(ap)); AgentIds resolve = resolver.resolve(); - Assertions.assertEquals("agentId", resolve.getAgentId()); - Assertions.assertEquals("agentName", resolve.getAgentName()); - Assertions.assertEquals("appName", resolve.getApplicationName()); + assertThat(resolve.getAgentName()).isEqualTo("agentName"); + assertThat(resolve.getApplicationName()).isEqualTo("appName"); } @Test public void resolve_optional_agent_name() { Properties properties = new Properties(); - properties.setProperty(AgentIdResolver.AGENT_ID, "agentId"); properties.setProperty(AgentIdResolver.APPLICATION_NAME, "appName"); - AgentProperties ap = new AgentProperties(AgentIdSourceType.AGENT_ARGUMENT, properties, AgentIdResolver.AGENT_ID, AgentIdResolver.AGENT_NAME, AgentIdResolver.APPLICATION_NAME); + AgentProperties ap = new AgentProperties(AgentIdSourceType.AGENT_ARGUMENT, properties, AgentIdResolver.AGENT_NAME, AgentIdResolver.APPLICATION_NAME, AgentIdResolver.SERVICE_NAME); - AgentIdResolver resolver = new AgentIdResolver(Arrays.asList(ap)); + AgentIdResolver resolver = new AgentIdResolver(Collections.singletonList(ap)); AgentIds resolve = resolver.resolve(); - Assertions.assertEquals("agentId", resolve.getAgentId()); - Assertions.assertEquals("appName", resolve.getApplicationName()); - Assertions.assertEquals("", resolve.getAgentName()); + assertThat(resolve.getApplicationName()).isEqualTo("appName"); + assertThat(resolve.getAgentName()).isEmpty(); } @Test public void resolve_fail() { Properties properties = new Properties(); - properties.setProperty(AgentIdResolver.AGENT_ID, "agentId"); - AgentProperties ap = new AgentProperties(AgentIdSourceType.AGENT_ARGUMENT, properties, AgentIdResolver.AGENT_ID, AgentIdResolver.AGENT_NAME, AgentIdResolver.APPLICATION_NAME); + AgentProperties ap = new AgentProperties(AgentIdSourceType.AGENT_ARGUMENT, properties, AgentIdResolver.AGENT_NAME, AgentIdResolver.APPLICATION_NAME, AgentIdResolver.SERVICE_NAME); - AgentIdResolver resolver = new AgentIdResolver(Arrays.asList(ap)); + AgentIdResolver resolver = new AgentIdResolver(Collections.singletonList(ap)); AgentIds resolve = resolver.resolve(); - Assertions.assertNull(resolve); + assertThat(resolve).isNull(); } @Test public void resolve_multi_source() { Properties properties1 = new Properties(); - properties1.setProperty(AgentIdResolver.AGENT_ID, "agentId1"); properties1.setProperty(AgentIdResolver.AGENT_NAME, "agentName1"); - AgentProperties ap = new AgentProperties(AgentIdSourceType.AGENT_ARGUMENT, properties1, AgentIdResolver.AGENT_ID, AgentIdResolver.AGENT_NAME, AgentIdResolver.APPLICATION_NAME); + AgentProperties ap = new AgentProperties(AgentIdSourceType.AGENT_ARGUMENT, properties1, AgentIdResolver.AGENT_NAME, AgentIdResolver.APPLICATION_NAME, AgentIdResolver.SERVICE_NAME); Properties properties2 = new Properties(); properties2.setProperty(AgentIdResolver.APPLICATION_NAME, "appName2"); - AgentProperties ap2 = new AgentProperties(AgentIdSourceType.SYSTEM, properties2, AgentIdResolver.AGENT_ID, AgentIdResolver.AGENT_NAME, AgentIdResolver.APPLICATION_NAME); + AgentProperties ap2 = new AgentProperties(AgentIdSourceType.SYSTEM, properties2, AgentIdResolver.AGENT_NAME, AgentIdResolver.APPLICATION_NAME, AgentIdResolver.SERVICE_NAME); AgentIdResolver resolver = new AgentIdResolver(Arrays.asList(ap, ap2)); AgentIds resolve = resolver.resolve(); - Assertions.assertEquals("agentId1", resolve.getAgentId()); - Assertions.assertEquals("appName2", resolve.getApplicationName()); - Assertions.assertEquals("agentName1", resolve.getAgentName()); + assertThat(resolve.getApplicationName()).isEqualTo("appName2"); + assertThat(resolve.getAgentName()).isEqualTo("agentName1"); } @Test public void resolve_multi_source_2() { Properties properties1 = new Properties(); - properties1.setProperty(AgentIdResolver.AGENT_ID, "agentId1"); properties1.setProperty(AgentIdResolver.AGENT_NAME, "agentName1"); - AgentProperties ap = new AgentProperties(AgentIdSourceType.AGENT_ARGUMENT, properties1, AgentIdResolver.AGENT_ID, AgentIdResolver.AGENT_NAME, AgentIdResolver.APPLICATION_NAME); + AgentProperties ap = new AgentProperties(AgentIdSourceType.AGENT_ARGUMENT, properties1, AgentIdResolver.AGENT_NAME, AgentIdResolver.APPLICATION_NAME, AgentIdResolver.SERVICE_NAME); Properties properties2 = new Properties(); - properties2.setProperty(AgentIdResolver.AGENT_ID, "agentId2"); properties2.setProperty(AgentIdResolver.AGENT_NAME, "agentName2"); properties2.setProperty(AgentIdResolver.APPLICATION_NAME, "appName2"); - AgentProperties ap2 = new AgentProperties(AgentIdSourceType.SYSTEM, properties2, AgentIdResolver.AGENT_ID, AgentIdResolver.AGENT_NAME, AgentIdResolver.APPLICATION_NAME); + AgentProperties ap2 = new AgentProperties(AgentIdSourceType.SYSTEM, properties2, AgentIdResolver.AGENT_NAME, AgentIdResolver.APPLICATION_NAME, AgentIdResolver.SERVICE_NAME); AgentIdResolver resolver = new AgentIdResolver(Arrays.asList(ap, ap2)); AgentIds resolve = resolver.resolve(); - Assertions.assertEquals("agentId2", resolve.getAgentId()); - Assertions.assertEquals("appName2", resolve.getApplicationName()); - Assertions.assertEquals("agentName2", resolve.getAgentName()); + assertThat(resolve.getApplicationName()).isEqualTo("appName2"); + assertThat(resolve.getAgentName()).isEqualTo("agentName2"); } } \ No newline at end of file diff --git a/agent-module/plugins/jboss/src/test/java/com/navercorp/pinpoint/plugin/jboss/InvokeMethodInterceptorTest.java b/agent-module/plugins/jboss/src/test/java/com/navercorp/pinpoint/plugin/jboss/InvokeMethodInterceptorTest.java index 2277daa12102..af08249ead67 100644 --- a/agent-module/plugins/jboss/src/test/java/com/navercorp/pinpoint/plugin/jboss/InvokeMethodInterceptorTest.java +++ b/agent-module/plugins/jboss/src/test/java/com/navercorp/pinpoint/plugin/jboss/InvokeMethodInterceptorTest.java @@ -25,6 +25,7 @@ import com.navercorp.pinpoint.bootstrap.plugin.RequestRecorderFactory; import com.navercorp.pinpoint.bootstrap.plugin.proxy.DisableRequestRecorder; import com.navercorp.pinpoint.bootstrap.plugin.request.RequestAdaptor; +import com.navercorp.pinpoint.common.id.AgentId; import com.navercorp.pinpoint.plugin.jboss.interceptor.StandardHostValveInvokeInterceptor; import com.navercorp.pinpoint.profiler.context.DefaultMethodDescriptor; import com.navercorp.pinpoint.profiler.context.id.DefaultTraceId; @@ -200,7 +201,7 @@ public void testValidHeaderExists() { when(request.getRequestURI()).thenReturn("/hellotest.nhn"); when(request.getRemoteAddr()).thenReturn("10.0.0.1"); - TraceId traceId = new DefaultTraceId("agentTest", System.currentTimeMillis(), 1); + TraceId traceId = new DefaultTraceId(AgentId.of("agentTest"), System.currentTimeMillis(), 1); when(request.getHeader(Header.HTTP_TRACE_ID.toString())).thenReturn(traceId.getTransactionId()); when(request.getHeader(Header.HTTP_PARENT_SPAN_ID.toString())).thenReturn("PARENTSPANID"); when(request.getHeader(Header.HTTP_SPAN_ID.toString())).thenReturn("SPANID"); diff --git a/agent-module/profiler-test/src/main/java/com/navercorp/pinpoint/profiler/test/MockApplicationContextFactory.java b/agent-module/profiler-test/src/main/java/com/navercorp/pinpoint/profiler/test/MockApplicationContextFactory.java index 25f835fd00a4..fa0c226a7e25 100644 --- a/agent-module/profiler-test/src/main/java/com/navercorp/pinpoint/profiler/test/MockApplicationContextFactory.java +++ b/agent-module/profiler-test/src/main/java/com/navercorp/pinpoint/profiler/test/MockApplicationContextFactory.java @@ -21,6 +21,7 @@ import com.navercorp.pinpoint.bootstrap.DefaultAgentOption; import com.navercorp.pinpoint.bootstrap.config.ProfilerConfig; import com.navercorp.pinpoint.bootstrap.config.ProfilerConfigLoader; +import com.navercorp.pinpoint.common.id.AgentId; import com.navercorp.pinpoint.profiler.context.module.DefaultApplicationContext; import com.navercorp.pinpoint.profiler.context.module.ModuleFactory; import com.navercorp.pinpoint.profiler.interceptor.registry.InterceptorRegistryBinder; @@ -64,11 +65,12 @@ public DefaultApplicationContext build(ProfilerConfig config) { public DefaultApplicationContext build(ProfilerConfig config, ModuleFactory moduleFactory) { Instrumentation instrumentation = new DummyInstrumentation(); - String mockAgentId = "mockAgentId"; + AgentId mockAgentId = AgentId.of("mockAgentId"); String mockAgentName = "mockAgentName"; String mockApplicationName = "mockApplicationName"; + String mockServiceName = "mockServiceName"; - AgentOption agentOption = new DefaultAgentOption(instrumentation, mockAgentId, mockAgentName, mockApplicationName, false, + AgentOption agentOption = new DefaultAgentOption(instrumentation, mockAgentId, mockAgentName, mockApplicationName, mockServiceName, false, config, Collections.emptyList(), Collections.emptyList()); return new DefaultApplicationContext(agentOption, moduleFactory); } @@ -79,8 +81,7 @@ private ModuleFactory newModuleFactory() { InterceptorRegistryBinder binder = new TestInterceptorRegistryBinder(); Module interceptorRegistryModule = InterceptorRegistryModule.wrap(binder); - ModuleFactory moduleFactory = new OverrideModuleFactory(pluginModule, interceptorRegistryModule); - return moduleFactory; + return new OverrideModuleFactory(pluginModule, interceptorRegistryModule); } } diff --git a/agent-module/profiler-test/src/main/java/com/navercorp/pinpoint/profiler/test/TestAgentInformation.java b/agent-module/profiler-test/src/main/java/com/navercorp/pinpoint/profiler/test/TestAgentInformation.java index 978b503c45b4..2cbe4a9fd835 100644 --- a/agent-module/profiler-test/src/main/java/com/navercorp/pinpoint/profiler/test/TestAgentInformation.java +++ b/agent-module/profiler-test/src/main/java/com/navercorp/pinpoint/profiler/test/TestAgentInformation.java @@ -17,6 +17,7 @@ package com.navercorp.pinpoint.profiler.test; import com.navercorp.pinpoint.common.Version; +import com.navercorp.pinpoint.common.id.AgentId; import com.navercorp.pinpoint.common.trace.ServiceType; import com.navercorp.pinpoint.common.util.JvmUtils; import com.navercorp.pinpoint.common.util.SystemPropertyKey; @@ -27,9 +28,10 @@ */ public class TestAgentInformation extends DefaultAgentInformation { - private static final String AGENT_ID = "test-agent"; + private static final AgentId AGENT_ID = AgentId.of("test-agent"); private static final String AGENT_NAME = "test-agent-name"; private static final String APPLICATION_NAME = "TEST_APPLICATION"; + private static final String SERVICE_NAME = "TEST_SERVICE"; private static final boolean IS_CONTAINER = false; private static final int PID = 10; private static final String MACHINE_NAME = "test-machine"; @@ -39,6 +41,6 @@ public class TestAgentInformation extends DefaultAgentInformation { private static final String AGENT_VERSION = Version.VERSION; public TestAgentInformation() { - super(AGENT_ID, AGENT_NAME, APPLICATION_NAME, IS_CONTAINER, System.currentTimeMillis(), PID, MACHINE_NAME, HOST_IP, SERVICE_TYPE, JVM_VERSION, AGENT_VERSION); + super(AGENT_ID, AGENT_NAME, APPLICATION_NAME, SERVICE_NAME, IS_CONTAINER, System.currentTimeMillis(), PID, MACHINE_NAME, HOST_IP, SERVICE_TYPE, JVM_VERSION, AGENT_VERSION); } } diff --git a/agent-module/profiler-test/src/test/java/com/navercorp/pinpoint/profiler/test/MockApplicationContextModuleTest.java b/agent-module/profiler-test/src/test/java/com/navercorp/pinpoint/profiler/test/MockApplicationContextModuleTest.java index e394847a3bb0..1c8cfe560c2e 100644 --- a/agent-module/profiler-test/src/test/java/com/navercorp/pinpoint/profiler/test/MockApplicationContextModuleTest.java +++ b/agent-module/profiler-test/src/test/java/com/navercorp/pinpoint/profiler/test/MockApplicationContextModuleTest.java @@ -23,6 +23,7 @@ import com.navercorp.pinpoint.bootstrap.config.DefaultProfilerConfig; import com.navercorp.pinpoint.bootstrap.config.ProfilerConfig; import com.navercorp.pinpoint.bootstrap.config.Profiles; +import com.navercorp.pinpoint.common.id.AgentId; import com.navercorp.pinpoint.profiler.AgentInfoSender; import com.navercorp.pinpoint.profiler.context.module.DefaultApplicationContext; import com.navercorp.pinpoint.profiler.context.module.ModuleFactory; @@ -36,6 +37,7 @@ import java.net.URL; import java.util.Collections; +import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.Mockito.spy; import static org.mockito.Mockito.when; @@ -49,11 +51,12 @@ public void test() { ProfilerConfig profilerConfig = spy(new DefaultProfilerConfig()); when(profilerConfig.getStaticResourceCleanup()).thenReturn(true); URL resource = getClass().getResource("/"); + assertThat(resource).isNotNull(); when(profilerConfig.readString(Profiles.LOG_CONFIG_LOCATION_KEY, null)).thenReturn(resource.getPath()); Instrumentation instrumentation = Mockito.mock(Instrumentation.class); AgentOption agentOption = new DefaultAgentOption(instrumentation, - "mockAgentId", "mockAgentName", "mockApplicationName", false, + AgentId.of("mockAgentId"), "mockAgentName", "mockApplicationName", "mockServiceName", false, profilerConfig, Collections.emptyList(), Collections.emptyList()); PluginTestAgent pluginTestAgent = new PluginTestAgent(agentOption); @@ -71,7 +74,7 @@ public void testMockApplicationContext() { Instrumentation instrumentation = Mockito.mock(Instrumentation.class); AgentOption agentOption = new DefaultAgentOption(instrumentation, - "mockAgentId", "mockAgentName", "mockApplicationName", false, + AgentId.of("mockAgentId"), "mockAgentName", "mockApplicationName", "mockServiceName", false, profilerConfig, Collections.emptyList(), Collections.emptyList()); Module pluginModule = new PluginApplicationContextModule(); @@ -87,7 +90,7 @@ public void testMockApplicationContext() { AgentInfoSender instance2 = injector.getInstance(AgentInfoSender.class); Assertions.assertSame(instance1, instance2); - ClassFileTransformer instance4 = injector.getInstance(ClassFileTransformer.class); + injector.getInstance(ClassFileTransformer.class); applicationContext.close(); } diff --git a/agent-module/profiler-test/src/test/java/com/navercorp/pinpoint/profiler/test/OrderedSpanRecorderTest.java b/agent-module/profiler-test/src/test/java/com/navercorp/pinpoint/profiler/test/OrderedSpanRecorderTest.java index dcf820b6c9fb..3b5ac9218a2f 100644 --- a/agent-module/profiler-test/src/test/java/com/navercorp/pinpoint/profiler/test/OrderedSpanRecorderTest.java +++ b/agent-module/profiler-test/src/test/java/com/navercorp/pinpoint/profiler/test/OrderedSpanRecorderTest.java @@ -17,6 +17,7 @@ package com.navercorp.pinpoint.profiler.test; import com.navercorp.pinpoint.bootstrap.context.TraceId; +import com.navercorp.pinpoint.common.id.AgentId; import com.navercorp.pinpoint.profiler.context.DefaultAsyncSpanChunk; import com.navercorp.pinpoint.profiler.context.DefaultLocalAsyncId; import com.navercorp.pinpoint.profiler.context.DefaultSpanChunk; @@ -54,7 +55,7 @@ public class OrderedSpanRecorderTest { private final OrderedSpanRecorder recorder = new OrderedSpanRecorder(); - private final String agentId = "agentId"; + private final AgentId agentId = AgentId.of("agentId"); @AfterEach public void tearDown() { diff --git a/agent-module/profiler-test/src/test/java/com/navercorp/pinpoint/profiler/test/monitor/AgentStatMonitorTest.java b/agent-module/profiler-test/src/test/java/com/navercorp/pinpoint/profiler/test/monitor/AgentStatMonitorTest.java index 4eb3914dadc3..49551e4e1c55 100644 --- a/agent-module/profiler-test/src/test/java/com/navercorp/pinpoint/profiler/test/monitor/AgentStatMonitorTest.java +++ b/agent-module/profiler-test/src/test/java/com/navercorp/pinpoint/profiler/test/monitor/AgentStatMonitorTest.java @@ -17,6 +17,7 @@ package com.navercorp.pinpoint.profiler.test.monitor; +import com.navercorp.pinpoint.common.id.AgentId; import com.navercorp.pinpoint.common.profiler.message.DataSender; import com.navercorp.pinpoint.profiler.context.monitor.config.MonitorConfig; import com.navercorp.pinpoint.profiler.monitor.AgentStatMonitor; @@ -82,7 +83,7 @@ public void testAgentStatMonitor() throws InterruptedException { Mockito.when(mockProfilerConfig.getProfileJvmStatBatchSendCount()).thenReturn(numCollectionsPerBatch); // When - AgentStatMonitor monitor = new DefaultAgentStatMonitor(this.dataSender, "agentId", System.currentTimeMillis(), + AgentStatMonitor monitor = new DefaultAgentStatMonitor(this.dataSender, AgentId.of("agentId"), System.currentTimeMillis(), agentStatCollector, null, null, mockProfilerConfig); monitor.start(); Thread.sleep(totalTestDurationMs); diff --git a/agent-module/profiler/src/main/java/com/navercorp/pinpoint/profiler/AgentInformation.java b/agent-module/profiler/src/main/java/com/navercorp/pinpoint/profiler/AgentInformation.java index e5bf26a75703..5eac22377406 100644 --- a/agent-module/profiler/src/main/java/com/navercorp/pinpoint/profiler/AgentInformation.java +++ b/agent-module/profiler/src/main/java/com/navercorp/pinpoint/profiler/AgentInformation.java @@ -16,6 +16,7 @@ package com.navercorp.pinpoint.profiler; +import com.navercorp.pinpoint.common.id.AgentId; import com.navercorp.pinpoint.common.trace.ServiceType; /** @@ -23,12 +24,14 @@ */ public interface AgentInformation { - String getAgentId(); + AgentId getAgentId(); String getAgentName(); String getApplicationName(); + String getServiceName(); + boolean isContainer(); long getStartTime(); diff --git a/agent-module/profiler/src/main/java/com/navercorp/pinpoint/profiler/DefaultAgentInformation.java b/agent-module/profiler/src/main/java/com/navercorp/pinpoint/profiler/DefaultAgentInformation.java index 83ee586bb9b0..ae07b806f1fd 100644 --- a/agent-module/profiler/src/main/java/com/navercorp/pinpoint/profiler/DefaultAgentInformation.java +++ b/agent-module/profiler/src/main/java/com/navercorp/pinpoint/profiler/DefaultAgentInformation.java @@ -16,6 +16,7 @@ package com.navercorp.pinpoint.profiler; +import com.navercorp.pinpoint.common.id.AgentId; import com.navercorp.pinpoint.common.trace.ServiceType; import java.util.Objects; @@ -26,9 +27,10 @@ * @author hyungil.jeong */ public class DefaultAgentInformation implements AgentInformation { - private final String agentId; + private final AgentId agentId; private final String agentName; private final String applicationName; + private final String serviceName; private final boolean isContainer; private final long startTime; private final int pid; @@ -39,9 +41,10 @@ public class DefaultAgentInformation implements AgentInformation { private final String agentVersion; public DefaultAgentInformation( - String agentId, + AgentId agentId, String agentName, String applicationName, + String serviceName, boolean isContainer, long startTime, int pid, @@ -53,6 +56,7 @@ public DefaultAgentInformation( this.agentId = Objects.requireNonNull(agentId, "agentId"); this.agentName = Objects.requireNonNull(agentName, "agentName"); this.applicationName = Objects.requireNonNull(applicationName, "applicationName"); + this.serviceName = Objects.requireNonNull(serviceName, "serviceName"); this.isContainer = isContainer; this.startTime = startTime; this.pid = pid; @@ -64,7 +68,7 @@ public DefaultAgentInformation( } @Override - public String getAgentId() { + public AgentId getAgentId() { return agentId; } @@ -78,6 +82,11 @@ public String getApplicationName() { return applicationName; } + @Override + public String getServiceName() { + return serviceName; + } + @Override public boolean isContainer() { return isContainer; @@ -120,19 +129,18 @@ public String getAgentVersion() { @Override public String toString() { - final StringBuilder sb = new StringBuilder("{"); - sb.append("agentId='").append(agentId).append('\''); - sb.append(", agentName='").append(agentName).append('\''); - sb.append(", applicationName='").append(applicationName).append('\''); - sb.append(", isContainer=").append(isContainer); - sb.append(", startTime=").append(startTime); - sb.append(", pid=").append(pid); - sb.append(", machineName='").append(machineName).append('\''); - sb.append(", hostIp='").append(hostIp).append('\''); - sb.append(", serverType=").append(serverType); - sb.append(", jvmVersion='").append(jvmVersion).append('\''); - sb.append(", agentVersion='").append(agentVersion).append('\''); - sb.append('}'); - return sb.toString(); + return "{" + "agentId='" + agentId + '\'' + + ", agentName='" + agentName + '\'' + + ", applicationName='" + applicationName + '\'' + + ", serviceName='" + serviceName + '\'' + + ", isContainer=" + isContainer + + ", startTime=" + startTime + + ", pid=" + pid + + ", machineName='" + machineName + '\'' + + ", hostIp='" + hostIp + '\'' + + ", serverType=" + serverType + + ", jvmVersion='" + jvmVersion + '\'' + + ", agentVersion='" + agentVersion + '\'' + + '}'; } } diff --git a/agent-module/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/DefaultTraceContext.java b/agent-module/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/DefaultTraceContext.java index 5aebc48168e4..9b1aa48681fb 100644 --- a/agent-module/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/DefaultTraceContext.java +++ b/agent-module/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/DefaultTraceContext.java @@ -25,6 +25,7 @@ import com.navercorp.pinpoint.bootstrap.context.TraceId; import com.navercorp.pinpoint.bootstrap.plugin.jdbc.JdbcContext; import com.navercorp.pinpoint.common.annotations.InterfaceAudience; +import com.navercorp.pinpoint.common.id.AgentId; import com.navercorp.pinpoint.profiler.AgentInformation; import com.navercorp.pinpoint.profiler.context.id.TraceIdFactory; import com.navercorp.pinpoint.profiler.metadata.ApiMetaDataService; @@ -188,7 +189,7 @@ private Trace closeUnsampledTrace(Trace trace) { } @Override - public String getAgentId() { + public AgentId getAgentId() { return this.agentInformation.getAgentId(); } diff --git a/agent-module/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/grpc/GrpcSpanMessageConverter.java b/agent-module/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/grpc/GrpcSpanMessageConverter.java index c5cb490fbd53..a29248d05e24 100644 --- a/agent-module/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/grpc/GrpcSpanMessageConverter.java +++ b/agent-module/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/grpc/GrpcSpanMessageConverter.java @@ -18,7 +18,7 @@ import com.google.protobuf.GeneratedMessageV3; import com.navercorp.pinpoint.common.annotations.VisibleForTesting; -import com.navercorp.pinpoint.common.profiler.logging.ThrottledLogger; +import com.navercorp.pinpoint.common.id.AgentId; import com.navercorp.pinpoint.common.profiler.message.MessageConverter; import com.navercorp.pinpoint.grpc.trace.PSpan; import com.navercorp.pinpoint.grpc.trace.PSpanChunk; @@ -27,8 +27,6 @@ import com.navercorp.pinpoint.profiler.context.SpanType; import com.navercorp.pinpoint.profiler.context.compress.SpanProcessor; import com.navercorp.pinpoint.profiler.context.grpc.mapper.SpanMessageMapper; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; import java.util.Objects; @@ -39,10 +37,7 @@ */ public class GrpcSpanMessageConverter implements MessageConverter { - private final Logger logger = LogManager.getLogger(this.getClass()); - private final ThrottledLogger throttledLogger = ThrottledLogger.getLogger(this.logger, 100); - - private final String agentId; + private final AgentId agentId; private final short applicationServiceType; private final SpanProcessor spanProcessor; @@ -51,7 +46,7 @@ public class GrpcSpanMessageConverter implements MessageConverter spanProcessor, SpanMessageMapper spanMessageMapper) { this.agentId = Objects.requireNonNull(agentId, "agentId"); diff --git a/agent-module/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/grpc/GrpcSpanMessageConverterProvider.java b/agent-module/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/grpc/GrpcSpanMessageConverterProvider.java index d05aad2c16e7..87bf0805ec0a 100644 --- a/agent-module/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/grpc/GrpcSpanMessageConverterProvider.java +++ b/agent-module/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/grpc/GrpcSpanMessageConverterProvider.java @@ -19,15 +19,15 @@ import com.google.inject.Inject; import com.google.inject.Provider; import com.google.protobuf.GeneratedMessageV3; +import com.navercorp.pinpoint.common.id.AgentId; import com.navercorp.pinpoint.common.profiler.message.MessageConverter; import com.navercorp.pinpoint.common.trace.ServiceType; import com.navercorp.pinpoint.grpc.trace.PSpan; import com.navercorp.pinpoint.grpc.trace.PSpanChunk; import com.navercorp.pinpoint.profiler.context.SpanType; import com.navercorp.pinpoint.profiler.context.compress.SpanProcessor; -import com.navercorp.pinpoint.profiler.context.grpc.config.SpanUriGetter; import com.navercorp.pinpoint.profiler.context.grpc.mapper.SpanMessageMapper; -import com.navercorp.pinpoint.profiler.context.module.AgentId; +import com.navercorp.pinpoint.profiler.context.module.AgentIdHolder; import com.navercorp.pinpoint.profiler.context.module.ApplicationServerType; import java.util.Objects; @@ -37,21 +37,18 @@ */ public class GrpcSpanMessageConverterProvider implements Provider> { - private final String agentId; + private final AgentId agentId; private final short applicationServiceTypeCode; private final SpanProcessor spanPostProcessor; - private final SpanUriGetter spanUriGetter; private final SpanMessageMapper mapper; @Inject - public GrpcSpanMessageConverterProvider(@AgentId String agentId, @ApplicationServerType ServiceType applicationServiceType, + public GrpcSpanMessageConverterProvider(@AgentIdHolder AgentId agentId, @ApplicationServerType ServiceType applicationServiceType, SpanProcessor spanPostProcessor, - SpanUriGetter spanUriGetter, SpanMessageMapper spanMessageMapper) { this.agentId = Objects.requireNonNull(agentId, "agentId"); this.applicationServiceTypeCode = applicationServiceType.getCode(); this.spanPostProcessor = Objects.requireNonNull(spanPostProcessor, "spanPostProcessor"); - this.spanUriGetter = Objects.requireNonNull(spanUriGetter, "spanUriGetter"); this.mapper = Objects.requireNonNull(spanMessageMapper, "spanMessageMapper"); } diff --git a/agent-module/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/grpc/mapper/TraceIdMapStructUtils.java b/agent-module/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/grpc/mapper/TraceIdMapStructUtils.java index 52b80b0bd2e6..b8043d9fd11c 100644 --- a/agent-module/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/grpc/mapper/TraceIdMapStructUtils.java +++ b/agent-module/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/grpc/mapper/TraceIdMapStructUtils.java @@ -16,6 +16,7 @@ package com.navercorp.pinpoint.profiler.context.grpc.mapper; import com.navercorp.pinpoint.bootstrap.context.TraceId; +import com.navercorp.pinpoint.common.id.AgentId; import com.navercorp.pinpoint.grpc.trace.PTransactionId; import org.mapstruct.Qualifier; @@ -37,7 +38,7 @@ public class TraceIdMapStructUtils { @ToTransactionId public static PTransactionId newTransactionId(TraceId traceId) { final PTransactionId.Builder builder = PTransactionId.newBuilder(); - builder.setAgentId(traceId.getAgentId()); + builder.setAgentId(AgentId.unwrap(traceId.getAgentId())); builder.setAgentStartTime(traceId.getAgentStartTime()); builder.setSequence(traceId.getTransactionSequence()); return builder.build(); diff --git a/agent-module/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/id/DefaultTraceId.java b/agent-module/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/id/DefaultTraceId.java index 2f26f00ddcaa..120b3497105e 100644 --- a/agent-module/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/id/DefaultTraceId.java +++ b/agent-module/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/id/DefaultTraceId.java @@ -18,6 +18,7 @@ import com.navercorp.pinpoint.bootstrap.context.SpanId; import com.navercorp.pinpoint.bootstrap.context.TraceId; +import com.navercorp.pinpoint.common.id.AgentId; import com.navercorp.pinpoint.common.profiler.util.TransactionIdUtils; import java.util.Objects; @@ -27,7 +28,7 @@ */ public class DefaultTraceId implements TraceId { - private final String agentId; + private final AgentId agentId; private final long agentStartTime; private final long transactionSequence; @@ -35,15 +36,16 @@ public class DefaultTraceId implements TraceId { private final long spanId; private final short flags; - public DefaultTraceId(String agentId, long agentStartTime, long transactionId) { + public DefaultTraceId(AgentId agentId, long agentStartTime, long transactionId) { this(agentId, agentStartTime, transactionId, SpanId.NULL, SpanId.newSpanId(), (short) 0); } + @Override public TraceId getNextTraceId() { return new DefaultTraceId(this.agentId, this.agentStartTime, transactionSequence, spanId, SpanId.nextSpanID(spanId, parentSpanId), flags); } - public DefaultTraceId(String agentId, long agentStartTime, long transactionId, long parentSpanId, long spanId, short flags) { + public DefaultTraceId(AgentId agentId, long agentStartTime, long transactionId, long parentSpanId, long spanId, short flags) { this.agentId = Objects.requireNonNull(agentId, "agentId"); this.agentStartTime = agentStartTime; this.transactionSequence = transactionId; @@ -53,51 +55,57 @@ public DefaultTraceId(String agentId, long agentStartTime, long transactionId, l this.flags = flags; } + @Override public String getTransactionId() { return TransactionIdUtils.formatString(agentId, agentStartTime, transactionSequence); } - public String getAgentId() { + @Override + public AgentId getAgentId() { return agentId; } + @Override public long getAgentStartTime() { return agentStartTime; } + @Override public long getTransactionSequence() { return transactionSequence; } + @Override public long getParentSpanId() { return parentSpanId; } + @Override public long getSpanId() { return spanId; } + @Override public short getFlags() { return flags; } + @Override public boolean isRoot() { return this.parentSpanId == SpanId.NULL; } @Override public String toString() { - final StringBuilder sb = new StringBuilder("DefaultTraceId{"); - sb.append("agentId='").append(agentId).append('\''); - sb.append(", agentStartTime=").append(agentStartTime); - sb.append(", transactionSequence=").append(transactionSequence); - sb.append(", parentSpanId=").append(parentSpanId); - sb.append(", spanId=").append(spanId); - sb.append(", flags=").append(flags); - sb.append('}'); - return sb.toString(); + return "DefaultTraceId{" + "agentId='" + agentId + '\'' + + ", agentStartTime=" + agentStartTime + + ", transactionSequence=" + transactionSequence + + ", parentSpanId=" + parentSpanId + + ", spanId=" + spanId + + ", flags=" + flags + + '}'; } } diff --git a/agent-module/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/id/DefaultTraceIdFactory.java b/agent-module/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/id/DefaultTraceIdFactory.java index 0e2f6c32c489..ad4396c8e0e8 100644 --- a/agent-module/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/id/DefaultTraceIdFactory.java +++ b/agent-module/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/id/DefaultTraceIdFactory.java @@ -18,9 +18,10 @@ import com.google.inject.Inject; import com.navercorp.pinpoint.bootstrap.context.TraceId; +import com.navercorp.pinpoint.common.id.AgentId; import com.navercorp.pinpoint.common.profiler.util.TransactionId; import com.navercorp.pinpoint.common.profiler.util.TransactionIdUtils; -import com.navercorp.pinpoint.profiler.context.module.AgentId; +import com.navercorp.pinpoint.profiler.context.module.AgentIdHolder; import com.navercorp.pinpoint.profiler.context.module.AgentStartTime; import java.util.Objects; @@ -30,11 +31,11 @@ */ public class DefaultTraceIdFactory implements TraceIdFactory { - private final String agentId; + private final AgentId agentId; private final long agentStartTime; @Inject - public DefaultTraceIdFactory(@AgentId String agentId, @AgentStartTime long agentStartTime) { + public DefaultTraceIdFactory(@AgentIdHolder AgentId agentId, @AgentStartTime long agentStartTime) { this.agentId = Objects.requireNonNull(agentId, "agentId"); this.agentStartTime = agentStartTime; diff --git a/agent-module/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/id/DefaultTraceRootFactory.java b/agent-module/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/id/DefaultTraceRootFactory.java index b55875f4cddf..063d4db904a1 100644 --- a/agent-module/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/id/DefaultTraceRootFactory.java +++ b/agent-module/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/id/DefaultTraceRootFactory.java @@ -18,7 +18,8 @@ import com.google.inject.Inject; import com.navercorp.pinpoint.bootstrap.context.TraceId; -import com.navercorp.pinpoint.profiler.context.module.AgentId; +import com.navercorp.pinpoint.common.id.AgentId; +import com.navercorp.pinpoint.profiler.context.module.AgentIdHolder; import java.util.Objects; @@ -27,11 +28,11 @@ */ public class DefaultTraceRootFactory implements TraceRootFactory { - private final String agentId; + private final AgentId agentId; private final TraceIdFactory traceIdFactory; @Inject - public DefaultTraceRootFactory(@AgentId String agentId, TraceIdFactory traceIdFactory) { + public DefaultTraceRootFactory(@AgentIdHolder AgentId agentId, TraceIdFactory traceIdFactory) { this.agentId = Objects.requireNonNull(agentId, "agentId"); this.traceIdFactory = Objects.requireNonNull(traceIdFactory, "traceIdFactory"); } diff --git a/agent-module/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/id/LocalTraceRootImpl.java b/agent-module/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/id/LocalTraceRootImpl.java index 322fa560db6b..1fa7782fd032 100644 --- a/agent-module/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/id/LocalTraceRootImpl.java +++ b/agent-module/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/id/LocalTraceRootImpl.java @@ -1,5 +1,7 @@ package com.navercorp.pinpoint.profiler.context.id; +import com.navercorp.pinpoint.common.id.AgentId; + import java.util.Objects; /** @@ -7,7 +9,7 @@ */ public class LocalTraceRootImpl implements LocalTraceRoot { - protected final String agentId; + protected final AgentId agentId; protected final long localTransactionId; protected final long traceStartTime; @@ -15,13 +17,13 @@ public class LocalTraceRootImpl implements LocalTraceRoot { protected final Shared shared = new DefaultShared(); - LocalTraceRootImpl(String agentId, long traceStartTime, long localTransactionId) { + LocalTraceRootImpl(AgentId agentId, long traceStartTime, long localTransactionId) { this.agentId = Objects.requireNonNull(agentId, "agentId"); this.traceStartTime = traceStartTime; this.localTransactionId = localTransactionId; } - public String getAgentId() { + public AgentId getAgentId() { return agentId; } diff --git a/agent-module/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/id/RemoteTraceRootImpl.java b/agent-module/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/id/RemoteTraceRootImpl.java index aac3050cf35d..8eb94f7e40d5 100644 --- a/agent-module/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/id/RemoteTraceRootImpl.java +++ b/agent-module/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/id/RemoteTraceRootImpl.java @@ -17,6 +17,7 @@ package com.navercorp.pinpoint.profiler.context.id; import com.navercorp.pinpoint.bootstrap.context.TraceId; +import com.navercorp.pinpoint.common.id.AgentId; import java.util.Objects; @@ -27,7 +28,7 @@ public class RemoteTraceRootImpl extends LocalTraceRootImpl implements TraceRoot private final TraceId traceId; - RemoteTraceRootImpl(TraceId traceId, String agentId, long traceStartTime, long localTransactionId) { + RemoteTraceRootImpl(TraceId traceId, AgentId agentId, long traceStartTime, long localTransactionId) { super(agentId, traceStartTime, localTransactionId); this.traceId = Objects.requireNonNull(traceId, "traceId"); } diff --git a/agent-module/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/id/TraceRoot.java b/agent-module/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/id/TraceRoot.java index 0e39754f0164..38a8e35e24c4 100644 --- a/agent-module/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/id/TraceRoot.java +++ b/agent-module/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/id/TraceRoot.java @@ -17,6 +17,7 @@ package com.navercorp.pinpoint.profiler.context.id; import com.navercorp.pinpoint.bootstrap.context.TraceId; +import com.navercorp.pinpoint.common.id.AgentId; import java.util.Objects; @@ -36,11 +37,11 @@ public interface TraceRoot extends LocalTraceRoot { @Override Shared getShared(); - static TraceRoot remote(TraceId traceId, String agentId, long traceStartTime, long localTransactionId) { + static TraceRoot remote(TraceId traceId, AgentId agentId, long traceStartTime, long localTransactionId) { return new RemoteTraceRootImpl(traceId, agentId, traceStartTime, localTransactionId); } - static LocalTraceRoot local(String agentId, long traceStartTime, long localTransactionId) { + static LocalTraceRoot local(AgentId agentId, long traceStartTime, long localTransactionId) { Objects.requireNonNull(agentId, "agentId"); return new LocalTraceRootImpl(agentId, traceStartTime, localTransactionId); } diff --git a/agent-module/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/module/AgentIdHolder.java b/agent-module/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/module/AgentIdHolder.java new file mode 100644 index 000000000000..6dfdc46e8933 --- /dev/null +++ b/agent-module/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/module/AgentIdHolder.java @@ -0,0 +1,34 @@ +/* + * Copyright 2017 NAVER Corp. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.navercorp.pinpoint.profiler.context.module; + +import com.google.inject.BindingAnnotation; + +import java.lang.annotation.Retention; +import java.lang.annotation.Target; + +import static java.lang.annotation.ElementType.PARAMETER; +import static java.lang.annotation.RetentionPolicy.RUNTIME; + +/** + * @author Woonduk Kang(emeroad) + */ +@BindingAnnotation +@Target(PARAMETER) +@Retention(RUNTIME) +public @interface AgentIdHolder { +} diff --git a/agent-module/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/module/AgentId.java b/agent-module/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/module/ServiceName.java similarity index 96% rename from agent-module/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/module/AgentId.java rename to agent-module/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/module/ServiceName.java index e8fdc396ab7c..9b0c8257a070 100644 --- a/agent-module/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/module/AgentId.java +++ b/agent-module/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/module/ServiceName.java @@ -30,5 +30,5 @@ @BindingAnnotation @Target(PARAMETER) @Retention(RUNTIME) -public @interface AgentId { +public @interface ServiceName { } diff --git a/agent-module/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/module/config/ConfigModule.java b/agent-module/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/module/config/ConfigModule.java index 7a26c275cc84..1aa46593a012 100644 --- a/agent-module/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/module/config/ConfigModule.java +++ b/agent-module/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/module/config/ConfigModule.java @@ -22,11 +22,12 @@ import com.navercorp.pinpoint.bootstrap.AgentOption; import com.navercorp.pinpoint.bootstrap.config.ProfilerConfig; import com.navercorp.pinpoint.bootstrap.config.TransportModule; +import com.navercorp.pinpoint.common.id.AgentId; import com.navercorp.pinpoint.common.trace.ServiceType; import com.navercorp.pinpoint.profiler.context.TraceDataFormatVersion; import com.navercorp.pinpoint.profiler.context.config.ContextConfig; import com.navercorp.pinpoint.profiler.context.config.DefaultContextConfig; -import com.navercorp.pinpoint.profiler.context.module.AgentId; +import com.navercorp.pinpoint.profiler.context.module.AgentIdHolder; import com.navercorp.pinpoint.profiler.context.module.AgentName; import com.navercorp.pinpoint.profiler.context.module.AgentStartTime; import com.navercorp.pinpoint.profiler.context.module.ApplicationName; @@ -35,6 +36,7 @@ import com.navercorp.pinpoint.profiler.context.module.Container; import com.navercorp.pinpoint.profiler.context.module.PluginJarPaths; import com.navercorp.pinpoint.profiler.context.module.PluginJars; +import com.navercorp.pinpoint.profiler.context.module.ServiceName; import com.navercorp.pinpoint.profiler.context.monitor.config.DefaultMonitorConfig; import com.navercorp.pinpoint.profiler.context.monitor.config.MonitorConfig; import com.navercorp.pinpoint.profiler.context.provider.AgentStartTimeProvider; @@ -130,7 +132,13 @@ protected void configure() { bindBootstrapCoreInformation(); - bindAgentInformation(agentOption.getAgentId(), agentOption.getAgentName(), agentOption.getApplicationName(), agentOption.isContainer()); + bindAgentInformation( + agentOption.getAgentId(), + agentOption.getAgentName(), + agentOption.getApplicationName(), + agentOption.getServiceName(), + agentOption.isContainer() + ); bindShutdownHook(contextConfig); } @@ -154,11 +162,11 @@ private void bindConstants(ContextConfig contextConfig) { bindConstant().annotatedWith(DeadlockMonitorInterval.class).to(contextConfig.getDeadlockMonitorInterval()); } - private void bindAgentInformation(String agentId, String agentName, String applicationName, boolean isContainer) { - - bind(String.class).annotatedWith(AgentId.class).toInstance(agentId); + private void bindAgentInformation(AgentId agentId, String agentName, String applicationName, String serviceName, boolean isContainer) { + bind(AgentId.class).annotatedWith(AgentIdHolder.class).toInstance(agentId); bind(String.class).annotatedWith(AgentName.class).toInstance(agentName); bind(String.class).annotatedWith(ApplicationName.class).toInstance(applicationName); + bind(String.class).annotatedWith(ServiceName.class).toInstance(serviceName); bind(Boolean.class).annotatedWith(Container.class).toInstance(isContainer); bind(Long.class).annotatedWith(AgentStartTime.class).toProvider(AgentStartTimeProvider.class).in(Scopes.SINGLETON); bind(ServiceType.class).annotatedWith(ConfiguredApplicationType.class).toProvider(ConfiguredApplicationTypeProvider.class).in(Scopes.SINGLETON); diff --git a/agent-module/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/provider/AgentInformationProvider.java b/agent-module/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/provider/AgentInformationProvider.java index f551384b9451..6e13868c8ac2 100644 --- a/agent-module/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/provider/AgentInformationProvider.java +++ b/agent-module/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/provider/AgentInformationProvider.java @@ -21,18 +21,20 @@ import com.navercorp.pinpoint.bootstrap.util.NetworkUtils; import com.navercorp.pinpoint.common.PinpointConstants; import com.navercorp.pinpoint.common.Version; +import com.navercorp.pinpoint.common.id.AgentId; import com.navercorp.pinpoint.common.trace.ServiceType; import com.navercorp.pinpoint.common.util.IdValidateUtils; import com.navercorp.pinpoint.common.util.JvmUtils; import com.navercorp.pinpoint.common.util.SystemPropertyKey; import com.navercorp.pinpoint.profiler.AgentInformation; import com.navercorp.pinpoint.profiler.DefaultAgentInformation; -import com.navercorp.pinpoint.profiler.context.module.AgentId; +import com.navercorp.pinpoint.profiler.context.module.AgentIdHolder; import com.navercorp.pinpoint.profiler.context.module.AgentName; import com.navercorp.pinpoint.profiler.context.module.AgentStartTime; import com.navercorp.pinpoint.profiler.context.module.ApplicationName; import com.navercorp.pinpoint.profiler.context.module.ApplicationServerType; import com.navercorp.pinpoint.profiler.context.module.Container; +import com.navercorp.pinpoint.profiler.context.module.ServiceName; import com.navercorp.pinpoint.profiler.util.RuntimeMXBeanUtils; import java.util.Objects; @@ -42,21 +44,30 @@ */ public class AgentInformationProvider implements Provider { - private final String agentId; + private final AgentId agentId; private final String agentName; private final String applicationName; + private final String serviceName; private final boolean isContainer; private final long agentStartTime; private final ServiceType serverType; @Inject - public AgentInformationProvider(@AgentId String agentId, @AgentName String agentName, @ApplicationName String applicationName, - @Container boolean isContainer, @AgentStartTime long agentStartTime, @ApplicationServerType ServiceType serverType) { + public AgentInformationProvider( + @AgentIdHolder AgentId agentId, + @AgentName String agentName, + @ApplicationName String applicationName, + @ServiceName String serviceName, + @Container boolean isContainer, + @AgentStartTime long agentStartTime, + @ApplicationServerType ServiceType serverType + ) { Objects.requireNonNull(agentId, "agentId"); Objects.requireNonNull(applicationName, "applicationName"); this.agentId = checkId("agentId", agentId, PinpointConstants.AGENT_ID_MAX_LEN); this.applicationName = checkId("applicationName", applicationName, PinpointConstants.APPLICATION_NAME_MAX_LEN); + this.serviceName = checkId("serviceName", serviceName, PinpointConstants.SERVICE_NAME_MAX_LEN); this.agentName = agentName; this.isContainer = isContainer; this.agentStartTime = agentStartTime; @@ -74,7 +85,8 @@ public AgentInformation createAgentInformation() { final int pid = RuntimeMXBeanUtils.getPid(); final String jvmVersion = JvmUtils.getSystemProperty(SystemPropertyKey.JAVA_VERSION); - return new DefaultAgentInformation(agentId, agentName, applicationName, isContainer, agentStartTime, pid, machineName, hostIp, serverType, jvmVersion, Version.VERSION); + return new DefaultAgentInformation(agentId, agentName, applicationName, serviceName, + isContainer, agentStartTime, pid, machineName, hostIp, serverType, jvmVersion, Version.VERSION); } private String checkId(String keyName, String id, int maxLen) { @@ -84,4 +96,8 @@ private String checkId(String keyName, String id, int maxLen) { return id; } + private AgentId checkId(String keyName, AgentId id, int maxLen) { + return AgentId.of(checkId(keyName, AgentId.unwrap(id), maxLen)); + } + } diff --git a/agent-module/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/provider/grpc/AgentHeaderFactoryProvider.java b/agent-module/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/provider/grpc/AgentHeaderFactoryProvider.java index da5ae6c104df..752a7825de15 100644 --- a/agent-module/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/provider/grpc/AgentHeaderFactoryProvider.java +++ b/agent-module/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/provider/grpc/AgentHeaderFactoryProvider.java @@ -37,6 +37,13 @@ public AgentHeaderFactoryProvider(AgentInformation agentInformation) { @Override public HeaderFactory get() { - return new AgentHeaderFactory(agentInformation.getAgentId(), agentInformation.getAgentName(), agentInformation.getApplicationName(), agentInformation.getServerType().getCode(), agentInformation.getStartTime()); + return new AgentHeaderFactory( + agentInformation.getAgentId(), + agentInformation.getAgentName(), + agentInformation.getApplicationName(), + agentInformation.getServiceName(), + agentInformation.getServerType().getCode(), + agentInformation.getStartTime() + ); } } diff --git a/agent-module/profiler/src/main/java/com/navercorp/pinpoint/profiler/monitor/CollectJob.java b/agent-module/profiler/src/main/java/com/navercorp/pinpoint/profiler/monitor/CollectJob.java index 489dd46412f3..67817b635996 100644 --- a/agent-module/profiler/src/main/java/com/navercorp/pinpoint/profiler/monitor/CollectJob.java +++ b/agent-module/profiler/src/main/java/com/navercorp/pinpoint/profiler/monitor/CollectJob.java @@ -16,6 +16,7 @@ package com.navercorp.pinpoint.profiler.monitor; +import com.navercorp.pinpoint.common.id.AgentId; import com.navercorp.pinpoint.common.profiler.message.DataSender; import com.navercorp.pinpoint.profiler.monitor.collector.AgentStatMetricCollector; import com.navercorp.pinpoint.profiler.monitor.metric.AgentStatMetricSnapshot; @@ -36,7 +37,7 @@ public class CollectJob implements Runnable { private final Logger logger = LogManager.getLogger(this.getClass()); private final DataSender dataSender; - private final String agentId; + private final AgentId agentId; private final long agentStartTimestamp; private final AgentStatMetricCollector agentStatCollector; private final int numCollectionsPerBatch; @@ -47,9 +48,9 @@ public class CollectJob implements Runnable { private List agentStats; public CollectJob(DataSender dataSender, - String agentId, long agentStartTimestamp, - AgentStatMetricCollector agentStatCollector, - int numCollectionsPerBatch) { + AgentId agentId, long agentStartTimestamp, + AgentStatMetricCollector agentStatCollector, + int numCollectionsPerBatch) { this.dataSender = Objects.requireNonNull(dataSender, "dataSender"); this.agentId = agentId; this.agentStartTimestamp = agentStartTimestamp; @@ -83,7 +84,7 @@ private void sendAgentStats() { // TODO multi thread issue. // If we reuse TAgentStat, there could be concurrency issue because data sender runs in a different thread. final AgentStatMetricSnapshotBatch agentStatBatch = new AgentStatMetricSnapshotBatch(); - agentStatBatch.setAgentId(agentId); + agentStatBatch.setAgentId(agentId.value()); agentStatBatch.setStartTimestamp(agentStartTimestamp); agentStatBatch.setAgentStats(this.agentStats); // If we reuse agentStats list, there could be concurrency issue because data sender runs in a different diff --git a/agent-module/profiler/src/main/java/com/navercorp/pinpoint/profiler/monitor/DefaultAgentStatMonitor.java b/agent-module/profiler/src/main/java/com/navercorp/pinpoint/profiler/monitor/DefaultAgentStatMonitor.java index 3bfc93451d48..33aaf3ef5fce 100644 --- a/agent-module/profiler/src/main/java/com/navercorp/pinpoint/profiler/monitor/DefaultAgentStatMonitor.java +++ b/agent-module/profiler/src/main/java/com/navercorp/pinpoint/profiler/monitor/DefaultAgentStatMonitor.java @@ -18,10 +18,11 @@ import com.google.inject.Inject; import com.google.inject.name.Named; +import com.navercorp.pinpoint.common.id.AgentId; import com.navercorp.pinpoint.common.profiler.concurrent.PinpointThreadFactory; import com.navercorp.pinpoint.common.profiler.message.DataSender; import com.navercorp.pinpoint.common.profiler.message.EmptyDataSender; -import com.navercorp.pinpoint.profiler.context.module.AgentId; +import com.navercorp.pinpoint.profiler.context.module.AgentIdHolder; import com.navercorp.pinpoint.profiler.context.module.AgentStartTime; import com.navercorp.pinpoint.profiler.context.module.StatDataSender; import com.navercorp.pinpoint.profiler.context.monitor.config.DefaultMonitorConfig; @@ -64,7 +65,7 @@ public class DefaultAgentStatMonitor implements AgentStatMonitor { @Inject public DefaultAgentStatMonitor(@StatDataSender DataSender dataSender, - @AgentId String agentId, + @AgentIdHolder AgentId agentId, @AgentStartTime long agentStartTimestamp, @Named("AgentStatCollector") AgentStatMetricCollector agentStatCollector, CustomMetricRegistryService customMetricRegistryService, @@ -114,7 +115,7 @@ public DefaultAgentStatMonitor(@StatDataSender DataSender dataSender // prevent deadlock for JDK6 // Single thread execution is more safe than multi thread execution. // eg) executor.scheduleAtFixedRate(collectJob, 0(initialDelay is zero), this.collectionIntervalMs, TimeUnit.MILLISECONDS); - private void preLoadClass(String agentId, long agentStartTimestamp, AgentStatMetricCollector agentStatCollector) { + private void preLoadClass(AgentId agentId, long agentStartTimestamp, AgentStatMetricCollector agentStatCollector) { logger.debug("pre-load class start"); CollectJob collectJob = new CollectJob(EmptyDataSender.instance(), agentId, agentStartTimestamp, agentStatCollector, 1); @@ -137,7 +138,9 @@ public void stop() { executor.shutdown(); try { - executor.awaitTermination(3000, TimeUnit.MILLISECONDS); + if (!executor.awaitTermination(3000, TimeUnit.MILLISECONDS)) { + logger.warn("AgentStat monitor shutdown forcefully"); + } } catch (InterruptedException e) { Thread.currentThread().interrupt(); } diff --git a/agent-module/profiler/src/main/java/com/navercorp/pinpoint/profiler/monitor/collector/AgentStatCollector.java b/agent-module/profiler/src/main/java/com/navercorp/pinpoint/profiler/monitor/collector/AgentStatCollector.java index a668f365bd2a..5aa12a896811 100644 --- a/agent-module/profiler/src/main/java/com/navercorp/pinpoint/profiler/monitor/collector/AgentStatCollector.java +++ b/agent-module/profiler/src/main/java/com/navercorp/pinpoint/profiler/monitor/collector/AgentStatCollector.java @@ -17,8 +17,9 @@ package com.navercorp.pinpoint.profiler.monitor.collector; import com.google.inject.Inject; +import com.navercorp.pinpoint.common.id.AgentId; import com.navercorp.pinpoint.profiler.context.active.ActiveTraceHistogram; -import com.navercorp.pinpoint.profiler.context.module.AgentId; +import com.navercorp.pinpoint.profiler.context.module.AgentIdHolder; import com.navercorp.pinpoint.profiler.context.module.AgentStartTime; import com.navercorp.pinpoint.profiler.monitor.metric.AgentStatMetricSnapshot; import com.navercorp.pinpoint.profiler.monitor.metric.JvmGcMetricSnapshot; @@ -39,7 +40,7 @@ */ public class AgentStatCollector implements AgentStatMetricCollector { - private final String agentId; + private final AgentId agentId; private final long agentStartTimestamp; private final AgentStatMetricCollector jvmGcMetricCollector; private final AgentStatMetricCollector cpuLoadMetricCollector; @@ -55,7 +56,7 @@ public class AgentStatCollector implements AgentStatMetricCollector jvmGcMetricCollector, AgentStatMetricCollector cpuLoadMetricCollector, @@ -86,7 +87,7 @@ public AgentStatCollector( @Override public AgentStatMetricSnapshot collect() { AgentStatMetricSnapshot agentStat = new AgentStatMetricSnapshot(); - agentStat.setAgentId(agentId); + agentStat.setAgentId(agentId.value()); agentStat.setStartTimestamp(agentStartTimestamp); agentStat.setGc(jvmGcMetricCollector.collect()); agentStat.setCpuLoad(cpuLoadMetricCollector.collect()); @@ -105,21 +106,19 @@ public AgentStatMetricSnapshot collect() { @Override public String toString() { - final StringBuilder sb = new StringBuilder("AgentStatCollector{"); - sb.append("agentId='").append(agentId).append('\''); - sb.append(", agentStartTimestamp=").append(agentStartTimestamp); - sb.append(", jvmGcMetricCollector=").append(jvmGcMetricCollector); - sb.append(", cpuLoadMetricCollector=").append(cpuLoadMetricCollector); - sb.append(", transactionMetricCollector=").append(transactionMetricCollector); - sb.append(", activeTraceMetricCollector=").append(activeTraceMetricCollector); - sb.append(", dataSourceMetricCollector=").append(dataSourceMetricCollector); - sb.append(", responseTimeMetricCollector=").append(responseTimeMetricCollector); - sb.append(", deadlockMetricCollector=").append(deadlockMetricCollector); - sb.append(", fileDescriptorMetricCollector=").append(fileDescriptorMetricCollector); - sb.append(", bufferMetricCollector=").append(bufferMetricCollector); - sb.append(", totalThreadMetricCollector=").append(totalThreadMetricCollector); - sb.append(", loadedClassMetricCollector=").append(loadedClassMetricCollector); - sb.append('}'); - return sb.toString(); + return "AgentStatCollector{" + "agentId='" + agentId + '\'' + + ", agentStartTimestamp=" + agentStartTimestamp + + ", jvmGcMetricCollector=" + jvmGcMetricCollector + + ", cpuLoadMetricCollector=" + cpuLoadMetricCollector + + ", transactionMetricCollector=" + transactionMetricCollector + + ", activeTraceMetricCollector=" + activeTraceMetricCollector + + ", dataSourceMetricCollector=" + dataSourceMetricCollector + + ", responseTimeMetricCollector=" + responseTimeMetricCollector + + ", deadlockMetricCollector=" + deadlockMetricCollector + + ", fileDescriptorMetricCollector=" + fileDescriptorMetricCollector + + ", bufferMetricCollector=" + bufferMetricCollector + + ", totalThreadMetricCollector=" + totalThreadMetricCollector + + ", loadedClassMetricCollector=" + loadedClassMetricCollector + + '}'; } } \ No newline at end of file diff --git a/agent-module/profiler/src/test/java/com/navercorp/pinpoint/profiler/context/DefaultTraceContextTest.java b/agent-module/profiler/src/test/java/com/navercorp/pinpoint/profiler/context/DefaultTraceContextTest.java index 0af10b51c80a..103300483748 100644 --- a/agent-module/profiler/src/test/java/com/navercorp/pinpoint/profiler/context/DefaultTraceContextTest.java +++ b/agent-module/profiler/src/test/java/com/navercorp/pinpoint/profiler/context/DefaultTraceContextTest.java @@ -21,6 +21,7 @@ import com.navercorp.pinpoint.bootstrap.context.Trace; import com.navercorp.pinpoint.bootstrap.context.TraceContext; import com.navercorp.pinpoint.bootstrap.context.TraceId; +import com.navercorp.pinpoint.common.id.AgentId; import com.navercorp.pinpoint.common.profiler.util.TransactionId; import com.navercorp.pinpoint.common.profiler.util.TransactionIdUtils; import com.navercorp.pinpoint.profiler.context.id.DefaultTraceId; @@ -66,7 +67,7 @@ public void tearDown() throws Exception { @Test public void parseTest() { - String agent = "test"; + AgentId agent = AgentId.of("test"); long agentStartTime = System.currentTimeMillis(); long agentTransactionCount = 10; TraceId traceId = new DefaultTraceId(agent, agentStartTime, agentTransactionCount); @@ -141,7 +142,7 @@ public void transactionCountTest() { final long expectedSampledContinuationCount = 5L; for (int i = 0; i < expectedSampledContinuationCount; i++) { - traceContext.continueTraceObject(new DefaultTraceId("agentId", 0L, i)); + traceContext.continueTraceObject(new DefaultTraceId(AgentId.of("agentId"), 0L, i)); traceContext.removeTraceObject(); } diff --git a/agent-module/profiler/src/test/java/com/navercorp/pinpoint/profiler/context/MockApplicationContextFactory.java b/agent-module/profiler/src/test/java/com/navercorp/pinpoint/profiler/context/MockApplicationContextFactory.java index 21d9802375cd..5323c2fe901f 100644 --- a/agent-module/profiler/src/test/java/com/navercorp/pinpoint/profiler/context/MockApplicationContextFactory.java +++ b/agent-module/profiler/src/test/java/com/navercorp/pinpoint/profiler/context/MockApplicationContextFactory.java @@ -19,6 +19,7 @@ import com.navercorp.pinpoint.bootstrap.AgentOption; import com.navercorp.pinpoint.bootstrap.DefaultAgentOption; import com.navercorp.pinpoint.bootstrap.config.ProfilerConfig; +import com.navercorp.pinpoint.common.id.AgentId; import com.navercorp.pinpoint.profiler.context.module.DefaultApplicationContext; import com.navercorp.pinpoint.profiler.context.module.ModuleFactory; import org.mockito.Mockito; @@ -37,10 +38,11 @@ public MockApplicationContextFactory() { public DefaultApplicationContext build(ProfilerConfig config, ModuleFactory moduleFactory) { Instrumentation instrumentation = Mockito.mock(Instrumentation.class); - String mockAgentId = "mockAgentId"; + AgentId mockAgentId = AgentId.of("mockAgentId"); String mockAgentName = "mockAgentName"; String mockApplicationName = "mockApplicationName"; - AgentOption agentOption = new DefaultAgentOption(instrumentation, mockAgentId, mockAgentName, mockApplicationName, false, + String mockServiceName = "mockServiceName"; + AgentOption agentOption = new DefaultAgentOption(instrumentation, mockAgentId, mockAgentName, mockApplicationName, mockServiceName, false, config, Collections.emptyList(), Collections.emptyList()); return new DefaultApplicationContext(agentOption, moduleFactory); } diff --git a/agent-module/profiler/src/test/java/com/navercorp/pinpoint/profiler/context/TestAgentInformation.java b/agent-module/profiler/src/test/java/com/navercorp/pinpoint/profiler/context/TestAgentInformation.java index 672ce9ab59b0..c57e861d6ddf 100644 --- a/agent-module/profiler/src/test/java/com/navercorp/pinpoint/profiler/context/TestAgentInformation.java +++ b/agent-module/profiler/src/test/java/com/navercorp/pinpoint/profiler/context/TestAgentInformation.java @@ -18,6 +18,7 @@ package com.navercorp.pinpoint.profiler.context; import com.navercorp.pinpoint.common.Version; +import com.navercorp.pinpoint.common.id.AgentId; import com.navercorp.pinpoint.common.trace.ServiceType; import com.navercorp.pinpoint.common.util.JvmUtils; import com.navercorp.pinpoint.common.util.SystemPropertyKey; @@ -29,9 +30,10 @@ */ public class TestAgentInformation extends DefaultAgentInformation { - private static final String AGENT_ID = "test-agent"; + private static final AgentId AGENT_ID = AgentId.of("test-agent"); private static final String AGENT_NAME = "test-agent-name"; private static final String APPLICATION_NAME = "TEST_APPLICATION"; + private static final String SERVICE_NAME = "TEST_SERVICE"; private static final boolean IS_CONTAINER = false; private static final int PID = 10; private static final String MACHINE_NAME = "test-machine"; @@ -41,6 +43,6 @@ public class TestAgentInformation extends DefaultAgentInformation { private static final String AGENT_VERSION = Version.VERSION; public TestAgentInformation() { - super(AGENT_ID, AGENT_NAME, APPLICATION_NAME, IS_CONTAINER, System.currentTimeMillis(), PID, MACHINE_NAME, HOST_IP, SERVICE_TYPE, JVM_VERSION, AGENT_VERSION); + super(AGENT_ID, AGENT_NAME, APPLICATION_NAME, SERVICE_NAME, IS_CONTAINER, System.currentTimeMillis(), PID, MACHINE_NAME, HOST_IP, SERVICE_TYPE, JVM_VERSION, AGENT_VERSION); } } diff --git a/agent-module/profiler/src/test/java/com/navercorp/pinpoint/profiler/context/TraceTest.java b/agent-module/profiler/src/test/java/com/navercorp/pinpoint/profiler/context/TraceTest.java index 58de56d8105b..47c83fd2e22c 100644 --- a/agent-module/profiler/src/test/java/com/navercorp/pinpoint/profiler/context/TraceTest.java +++ b/agent-module/profiler/src/test/java/com/navercorp/pinpoint/profiler/context/TraceTest.java @@ -19,6 +19,7 @@ import com.navercorp.pinpoint.bootstrap.context.SpanRecorder; import com.navercorp.pinpoint.bootstrap.context.Trace; import com.navercorp.pinpoint.bootstrap.context.TraceId; +import com.navercorp.pinpoint.common.id.AgentId; import com.navercorp.pinpoint.profiler.context.errorhandler.BypassErrorHandler; import com.navercorp.pinpoint.profiler.context.errorhandler.IgnoreErrorHandler; import com.navercorp.pinpoint.profiler.context.exception.ExceptionRecorder; @@ -51,7 +52,7 @@ public class TraceTest { private final Logger logger = LogManager.getLogger(this.getClass()); - private final String agentId = "agent"; + private final AgentId agentId = AgentId.of("agent"); private final long agentStartTime = System.currentTimeMillis(); private final long traceStartTime = agentStartTime + 100; diff --git a/agent-module/profiler/src/test/java/com/navercorp/pinpoint/profiler/context/active/ActiveTraceRepositoryTest.java b/agent-module/profiler/src/test/java/com/navercorp/pinpoint/profiler/context/active/ActiveTraceRepositoryTest.java index 4b180b5edab6..5701a6011181 100644 --- a/agent-module/profiler/src/test/java/com/navercorp/pinpoint/profiler/context/active/ActiveTraceRepositoryTest.java +++ b/agent-module/profiler/src/test/java/com/navercorp/pinpoint/profiler/context/active/ActiveTraceRepositoryTest.java @@ -25,6 +25,7 @@ import com.navercorp.pinpoint.bootstrap.context.Trace; import com.navercorp.pinpoint.bootstrap.context.TraceContext; import com.navercorp.pinpoint.bootstrap.context.TraceId; +import com.navercorp.pinpoint.common.id.AgentId; import com.navercorp.pinpoint.profiler.context.MockTraceContextFactory; import com.navercorp.pinpoint.profiler.context.id.DefaultTraceId; import com.navercorp.pinpoint.profiler.context.id.DefaultTransactionCounter; @@ -175,7 +176,7 @@ private ListenableFuture executeSampledContinuedTrace(Listenin @Override public TraceThreadTuple call() throws Exception { try { - TraceId agentId1 = new DefaultTraceId("agentId", 0L, id); + TraceId agentId1 = new DefaultTraceId(AgentId.of("agentId"), 0L, id); Trace agentId = traceContext.continueTraceObject(agentId1); return new TraceThreadTuple(agentId, Thread.currentThread().getId()); } finally { diff --git a/agent-module/profiler/src/test/java/com/navercorp/pinpoint/profiler/context/compress/GrpcSpanProcessorV2Test.java b/agent-module/profiler/src/test/java/com/navercorp/pinpoint/profiler/context/compress/GrpcSpanProcessorV2Test.java index 329c0badf59b..57a9e9b6440a 100644 --- a/agent-module/profiler/src/test/java/com/navercorp/pinpoint/profiler/context/compress/GrpcSpanProcessorV2Test.java +++ b/agent-module/profiler/src/test/java/com/navercorp/pinpoint/profiler/context/compress/GrpcSpanProcessorV2Test.java @@ -17,12 +17,12 @@ package com.navercorp.pinpoint.profiler.context.compress; import com.navercorp.pinpoint.bootstrap.context.TraceId; +import com.navercorp.pinpoint.common.id.AgentId; import com.navercorp.pinpoint.grpc.trace.PSpan; import com.navercorp.pinpoint.grpc.trace.PSpanChunk; import com.navercorp.pinpoint.grpc.trace.PSpanEvent; import com.navercorp.pinpoint.profiler.context.Span; import com.navercorp.pinpoint.profiler.context.SpanEvent; -import com.navercorp.pinpoint.profiler.context.grpc.GrpcSpanMessageConverter; import com.navercorp.pinpoint.profiler.context.grpc.config.SpanAutoUriGetter; import com.navercorp.pinpoint.profiler.context.grpc.mapper.AnnotationValueMapper; import com.navercorp.pinpoint.profiler.context.grpc.mapper.AnnotationValueMapperImpl; @@ -40,11 +40,9 @@ */ public class GrpcSpanProcessorV2Test { - private SpanProcessor spanProcessorProtoV2 = new GrpcSpanProcessorV2(); - - private AnnotationValueMapper annotationValueMapper = new AnnotationValueMapperImpl(); - private SpanMessageMapper mapper = new SpanMessageMapperImpl(annotationValueMapper, new SpanAutoUriGetter()); - private GrpcSpanMessageConverter converter = new GrpcSpanMessageConverter("agentId", (short) 1, spanProcessorProtoV2, mapper); + private final SpanProcessor spanProcessorProtoV2 = new GrpcSpanProcessorV2(); + private final AnnotationValueMapper annotationValueMapper = new AnnotationValueMapperImpl(); + private final SpanMessageMapper mapper = new SpanMessageMapperImpl(annotationValueMapper, new SpanAutoUriGetter()); @Test public void preProcess() { @@ -66,8 +64,8 @@ public void preProcess() { } private Span newSpan() { - TraceId traceId = new DefaultTraceId("agent", 1, 0); - TraceRoot traceRoot = TraceRoot.remote(traceId, "agent", 0, 3); + TraceId traceId = new DefaultTraceId(AgentId.of("agent"), 1, 0); + TraceRoot traceRoot = TraceRoot.remote(traceId, AgentId.of("agent"), 0, 3); return new Span(traceRoot); } diff --git a/agent-module/profiler/src/test/java/com/navercorp/pinpoint/profiler/context/graph/DependencyGraph.java b/agent-module/profiler/src/test/java/com/navercorp/pinpoint/profiler/context/graph/DependencyGraph.java index c68e5f03b1ab..b058f843478c 100644 --- a/agent-module/profiler/src/test/java/com/navercorp/pinpoint/profiler/context/graph/DependencyGraph.java +++ b/agent-module/profiler/src/test/java/com/navercorp/pinpoint/profiler/context/graph/DependencyGraph.java @@ -25,6 +25,7 @@ import com.navercorp.pinpoint.bootstrap.DefaultAgentOption; import com.navercorp.pinpoint.bootstrap.config.DefaultProfilerConfig; import com.navercorp.pinpoint.bootstrap.config.ProfilerConfig; +import com.navercorp.pinpoint.common.id.AgentId; import com.navercorp.pinpoint.common.util.CodeSourceUtils; import com.navercorp.pinpoint.profiler.context.module.DefaultApplicationContext; import com.navercorp.pinpoint.profiler.context.module.InterceptorRegistryModule; @@ -83,7 +84,7 @@ private DefaultApplicationContext newApplicationContext() { Instrumentation instrumentation = mock(Instrumentation.class); AgentOption agentOption = new DefaultAgentOption(instrumentation, - "mockAgentId", "mockAgentName", "mockApplicationName", false, + AgentId.of("mockAgentId"), "mockAgentName", "mockApplicationName", "mockServiceName", false, profilerConfig, Collections.emptyList(), Collections.emptyList()); InterceptorRegistryBinder interceptorRegistryBinder = new TestInterceptorRegistryBinder(); diff --git a/agent-module/profiler/src/test/java/com/navercorp/pinpoint/profiler/context/grpc/GrpcExceptionMetaDataConverterTest.java b/agent-module/profiler/src/test/java/com/navercorp/pinpoint/profiler/context/grpc/GrpcExceptionMetaDataConverterTest.java index 3db6bc515499..fe3529d4287e 100644 --- a/agent-module/profiler/src/test/java/com/navercorp/pinpoint/profiler/context/grpc/GrpcExceptionMetaDataConverterTest.java +++ b/agent-module/profiler/src/test/java/com/navercorp/pinpoint/profiler/context/grpc/GrpcExceptionMetaDataConverterTest.java @@ -1,5 +1,6 @@ package com.navercorp.pinpoint.profiler.context.grpc; +import com.navercorp.pinpoint.common.id.AgentId; import com.navercorp.pinpoint.grpc.trace.PException; import com.navercorp.pinpoint.grpc.trace.PExceptionMetaData; import com.navercorp.pinpoint.grpc.trace.PStackTraceElement; @@ -36,7 +37,7 @@ class GrpcExceptionMetaDataConverterTest { private static TraceRoot newTraceRoot() { TraceRoot traceRoot = mock(TraceRoot.class); - final String agentId = "agent"; + final AgentId agentId = AgentId.of("agent"); final long agentStartTime = System.currentTimeMillis(); when(traceRoot.getTraceId()).thenReturn(new DefaultTraceId(agentId, agentStartTime, 0)); when(traceRoot.getTraceStartTime()).thenReturn(agentStartTime + 100); diff --git a/agent-module/profiler/src/test/java/com/navercorp/pinpoint/profiler/context/grpc/GrpcSpanMessageConverterTest.java b/agent-module/profiler/src/test/java/com/navercorp/pinpoint/profiler/context/grpc/GrpcSpanMessageConverterTest.java index fecd43b4468d..c2cf56feec08 100644 --- a/agent-module/profiler/src/test/java/com/navercorp/pinpoint/profiler/context/grpc/GrpcSpanMessageConverterTest.java +++ b/agent-module/profiler/src/test/java/com/navercorp/pinpoint/profiler/context/grpc/GrpcSpanMessageConverterTest.java @@ -1,5 +1,6 @@ package com.navercorp.pinpoint.profiler.context.grpc; +import com.navercorp.pinpoint.common.id.AgentId; import com.navercorp.pinpoint.common.util.IntStringValue; import com.navercorp.pinpoint.grpc.trace.PSpan; import com.navercorp.pinpoint.grpc.trace.PSpanChunk; @@ -42,7 +43,7 @@ class GrpcSpanMessageConverterTest { private static final Random random = new Random(); - private static final String agentId = "agent"; + private static final AgentId agentId = AgentId.of("agent"); private static final String parentAgentId = "agent-parent"; private static final short applicationServiceType = 0; private final SpanProcessor spanProcessorProtoV2 = new GrpcSpanProcessorV2(); diff --git a/agent-module/profiler/src/test/java/com/navercorp/pinpoint/profiler/context/id/LocalTraceRootTest.java b/agent-module/profiler/src/test/java/com/navercorp/pinpoint/profiler/context/id/LocalTraceRootTest.java index bdb1d085682a..03e05ddff1c8 100644 --- a/agent-module/profiler/src/test/java/com/navercorp/pinpoint/profiler/context/id/LocalTraceRootTest.java +++ b/agent-module/profiler/src/test/java/com/navercorp/pinpoint/profiler/context/id/LocalTraceRootTest.java @@ -3,6 +3,7 @@ import com.navercorp.pinpoint.bootstrap.context.SpanEventRecorder; import com.navercorp.pinpoint.bootstrap.context.SpanRecorder; import com.navercorp.pinpoint.bootstrap.context.Trace; +import com.navercorp.pinpoint.common.id.AgentId; import com.navercorp.pinpoint.profiler.context.CloseListener; import com.navercorp.pinpoint.profiler.context.DisableChildTrace; import com.navercorp.pinpoint.profiler.context.DisableTrace; @@ -12,9 +13,12 @@ import static org.mockito.Mockito.mock; public class LocalTraceRootTest { + + private static final AgentId AGENT_ID = AgentId.of("testAgent"); + @Test public void testGetScope() { - LocalTraceRoot traceRoot = TraceRoot.local("testAgent", 2, 1); + LocalTraceRoot traceRoot = TraceRoot.local(AGENT_ID, 2, 1); Trace trace = newTrace(traceRoot); Trace childTrace = newChildTrace(traceRoot); Assertions.assertNull(trace.addScope("empty")); @@ -23,7 +27,7 @@ public void testGetScope() { @Test public void testAddScope() { - LocalTraceRoot traceRoot = TraceRoot.local("testAgent", 2, 1); + LocalTraceRoot traceRoot = TraceRoot.local(AGENT_ID, 2, 1); Trace trace = newTrace(traceRoot); Trace childTrace = newChildTrace(traceRoot); @@ -35,7 +39,7 @@ public void testAddScope() { @Test public void testSampled() { - LocalTraceRoot traceRoot = TraceRoot.local("testAgent", 2, 1); + LocalTraceRoot traceRoot = TraceRoot.local(AGENT_ID, 2, 1); Trace trace = newTrace(traceRoot); Trace childTrace = newChildTrace(traceRoot); @@ -45,7 +49,7 @@ public void testSampled() { @Test public void testSpanRecorder() { - LocalTraceRoot traceRoot = TraceRoot.local("testAgent", 2, 1); + LocalTraceRoot traceRoot = TraceRoot.local(AGENT_ID, 2, 1); Trace trace = newTrace(traceRoot); Trace childTrace = newChildTrace(traceRoot); SpanRecorder spanRecorder = trace.getSpanRecorder(); @@ -57,7 +61,7 @@ public void testSpanRecorder() { @Test public void testCurrentSpanEventRecorder() { - LocalTraceRoot traceRoot = TraceRoot.local("testAgent", 2, 1); + LocalTraceRoot traceRoot = TraceRoot.local(AGENT_ID, 2, 1); Trace trace = newTrace(traceRoot); Trace childTrace = newChildTrace(traceRoot); SpanEventRecorder spanEventRecorder = trace.currentSpanEventRecorder(); diff --git a/agent-module/profiler/src/test/java/com/navercorp/pinpoint/profiler/context/module/DefaultApplicationContextTest.java b/agent-module/profiler/src/test/java/com/navercorp/pinpoint/profiler/context/module/DefaultApplicationContextTest.java index bf0ab6d93dea..bb756fb9f8be 100644 --- a/agent-module/profiler/src/test/java/com/navercorp/pinpoint/profiler/context/module/DefaultApplicationContextTest.java +++ b/agent-module/profiler/src/test/java/com/navercorp/pinpoint/profiler/context/module/DefaultApplicationContextTest.java @@ -26,6 +26,7 @@ import com.navercorp.pinpoint.bootstrap.DefaultAgentOption; import com.navercorp.pinpoint.bootstrap.config.DefaultProfilerConfig; import com.navercorp.pinpoint.bootstrap.config.ProfilerConfig; +import com.navercorp.pinpoint.common.id.AgentId; import com.navercorp.pinpoint.profiler.AgentInfoSender; import com.navercorp.pinpoint.profiler.interceptor.registry.InterceptorRegistryBinder; import com.navercorp.pinpoint.profiler.util.TestInterceptorRegistryBinder; @@ -89,7 +90,7 @@ private DefaultApplicationContext newApplicationContext() { // when(profilerConfig.getTransportModule()).thenReturn("GRPC"); Instrumentation instrumentation = mock(Instrumentation.class); - AgentOption agentOption = new DefaultAgentOption(instrumentation, "mockAgentId", "mockAgentName", "mockApplicationName", false, + AgentOption agentOption = new DefaultAgentOption(instrumentation, AgentId.of("mockAgentId"), "mockAgentName", "mockApplicationName", "mockServiceName", false, profilerConfig, Collections.emptyList(), Collections.emptyList()); InterceptorRegistryBinder interceptorRegistryBinder = new TestInterceptorRegistryBinder(); diff --git a/agent-module/profiler/src/test/java/com/navercorp/pinpoint/profiler/context/storage/BufferedStorageTest.java b/agent-module/profiler/src/test/java/com/navercorp/pinpoint/profiler/context/storage/BufferedStorageTest.java index e5b6704dded6..ef8087d0a2ea 100644 --- a/agent-module/profiler/src/test/java/com/navercorp/pinpoint/profiler/context/storage/BufferedStorageTest.java +++ b/agent-module/profiler/src/test/java/com/navercorp/pinpoint/profiler/context/storage/BufferedStorageTest.java @@ -17,6 +17,7 @@ package com.navercorp.pinpoint.profiler.context.storage; import com.navercorp.pinpoint.bootstrap.context.TraceId; +import com.navercorp.pinpoint.common.id.AgentId; import com.navercorp.pinpoint.profiler.context.DefaultSpanChunkFactory; import com.navercorp.pinpoint.profiler.context.Span; import com.navercorp.pinpoint.profiler.context.SpanChunkFactory; @@ -30,7 +31,7 @@ public class BufferedStorageTest { - private final String agentId = "agentId"; + private final AgentId agentId = AgentId.of("agentId"); private final long agentStartTime = System.currentTimeMillis(); private final CountingDataSender countingDataSender = new CountingDataSender(); diff --git a/agent-module/profiler/src/test/java/com/navercorp/pinpoint/profiler/monitor/CollectJobTest.java b/agent-module/profiler/src/test/java/com/navercorp/pinpoint/profiler/monitor/CollectJobTest.java index 5d559a6a9ad1..3a697a5494f1 100644 --- a/agent-module/profiler/src/test/java/com/navercorp/pinpoint/profiler/monitor/CollectJobTest.java +++ b/agent-module/profiler/src/test/java/com/navercorp/pinpoint/profiler/monitor/CollectJobTest.java @@ -16,6 +16,7 @@ package com.navercorp.pinpoint.profiler.monitor; +import com.navercorp.pinpoint.common.id.AgentId; import com.navercorp.pinpoint.common.profiler.message.DataSender; import com.navercorp.pinpoint.profiler.monitor.collector.AgentStatMetricCollector; import com.navercorp.pinpoint.profiler.monitor.metric.AgentStatMetricSnapshot; @@ -39,7 +40,7 @@ public void run() throws Exception { DataSender dataSender = mock(DataSender.class); - CollectJob job = new CollectJob(dataSender, "agent", 0, agentStatMetricCollector, 1); + CollectJob job = new CollectJob(dataSender, AgentId.of("agent"), 0, agentStatMetricCollector, 1); job.run(); Mockito.verify(dataSender).send(any(AgentStatMetricSnapshotBatch.class)); diff --git a/agent-module/profiler/src/test/java/com/navercorp/pinpoint/profiler/sender/grpc/AgentGrpcDataSenderTestMain.java b/agent-module/profiler/src/test/java/com/navercorp/pinpoint/profiler/sender/grpc/AgentGrpcDataSenderTestMain.java index 7d37c71b2532..840dbc0be752 100644 --- a/agent-module/profiler/src/test/java/com/navercorp/pinpoint/profiler/sender/grpc/AgentGrpcDataSenderTestMain.java +++ b/agent-module/profiler/src/test/java/com/navercorp/pinpoint/profiler/sender/grpc/AgentGrpcDataSenderTestMain.java @@ -18,6 +18,7 @@ import com.google.protobuf.GeneratedMessageV3; import com.navercorp.pinpoint.bootstrap.context.ServerMetaData; +import com.navercorp.pinpoint.common.id.AgentId; import com.navercorp.pinpoint.common.profiler.message.MessageConverter; import com.navercorp.pinpoint.common.trace.ServiceType; import com.navercorp.pinpoint.grpc.AgentHeaderFactory; @@ -46,9 +47,10 @@ import java.util.concurrent.TimeUnit; public class AgentGrpcDataSenderTestMain { - private static final String AGENT_ID = "mockAgentId"; + private static final AgentId AGENT_ID = AgentId.of("mockAgentId"); private static final String AGENT_NAME = "mockAgentName"; private static final String APPLICATION_NAME = "mockApplicationName"; + private static final String SERVICE_NAME = "mockServiceName"; private static final long START_TIME = System.currentTimeMillis(); private static final int SERVICE_TYPE = ServiceType.UNDEFINED.getCode(); private final ScheduledExecutorService scheduledExecutorService = Executors.newSingleThreadScheduledExecutor(); @@ -58,7 +60,7 @@ public class AgentGrpcDataSenderTestMain { public void request() throws Exception { MetaDataMapper mapper = new MetaDataMapperImpl(); MessageConverter messageConverter = new GrpcMetadataMessageConverter(mapper); - HeaderFactory headerFactory = new AgentHeaderFactory(AGENT_ID, AGENT_NAME, APPLICATION_NAME, SERVICE_TYPE, START_TIME); + HeaderFactory headerFactory = new AgentHeaderFactory(AGENT_ID, AGENT_NAME, APPLICATION_NAME, SERVICE_NAME, SERVICE_TYPE, START_TIME); DnsExecutorServiceProvider dnsExecutorServiceProvider = new DnsExecutorServiceProvider(); GrpcNameResolverProvider grpcNameResolverProvider = new GrpcNameResolverProvider(dnsExecutorServiceProvider); @@ -82,7 +84,7 @@ public void request() throws Exception { } private AgentInfo newAgentInfo() { - AgentInformation agentInformation = new DefaultAgentInformation(AGENT_ID, AGENT_NAME, APPLICATION_NAME, true, START_TIME, 99, "", "", ServiceType.TEST_STAND_ALONE, "1.0", "1.0"); + AgentInformation agentInformation = new DefaultAgentInformation(AGENT_ID, AGENT_NAME, APPLICATION_NAME, SERVICE_NAME, true, START_TIME, 99, "", "", ServiceType.TEST_STAND_ALONE, "1.0", "1.0"); JvmInformation jvmInformation = new JvmInformation("1.0", JvmGcType.G1); ServerMetaData serverInfo = new DefaultServerMetaData("serverInfo", Collections.emptyList(), Collections.emptyMap(), Collections.emptyList()); return new AgentInfo(agentInformation, serverInfo, jvmInformation); diff --git a/batch-alarmsender/src/main/java/com/navercorp/pinpoint/batch/alarm/vo/sender/payload/WebhookPayload.java b/batch-alarmsender/src/main/java/com/navercorp/pinpoint/batch/alarm/vo/sender/payload/WebhookPayload.java index f2998012b84b..664884a0b573 100644 --- a/batch-alarmsender/src/main/java/com/navercorp/pinpoint/batch/alarm/vo/sender/payload/WebhookPayload.java +++ b/batch-alarmsender/src/main/java/com/navercorp/pinpoint/batch/alarm/vo/sender/payload/WebhookPayload.java @@ -107,7 +107,7 @@ public String toString() { return "WebhookPayload{" + "pinpointUrl='" + pinpointUrl + '\'' + ", batchEnv='" + batchEnv + '\'' + - ", applicationId='" + applicationName + '\'' + + ", applicationName='" + applicationName + '\'' + ", serviceType='" + serviceType + '\'' + ", checkerName='" + checkerName + '\'' + ", checkerType='" + checkerType + '\'' + diff --git a/batch/src/main/java/com/navercorp/pinpoint/batch/alarm/AlarmProcessor.java b/batch/src/main/java/com/navercorp/pinpoint/batch/alarm/AlarmProcessor.java index 004f8d68c87b..12608fcbfeb7 100644 --- a/batch/src/main/java/com/navercorp/pinpoint/batch/alarm/AlarmProcessor.java +++ b/batch/src/main/java/com/navercorp/pinpoint/batch/alarm/AlarmProcessor.java @@ -20,6 +20,8 @@ import com.navercorp.pinpoint.batch.alarm.checker.AlarmChecker; import com.navercorp.pinpoint.batch.alarm.collector.DataCollector; import com.navercorp.pinpoint.batch.alarm.vo.AppAlarmChecker; +import com.navercorp.pinpoint.common.id.AgentId; +import com.navercorp.pinpoint.common.id.ApplicationId; import com.navercorp.pinpoint.common.server.util.time.Range; import com.navercorp.pinpoint.common.util.CollectionUtils; import com.navercorp.pinpoint.web.alarm.CheckerCategory; @@ -37,7 +39,6 @@ import java.util.List; import java.util.Map; import java.util.Objects; -import java.util.UUID; import java.util.concurrent.TimeUnit; import java.util.function.Supplier; @@ -106,10 +107,10 @@ private Supplier> getAgentIdsSupplier(Application application, long return Suppliers.memoize(() -> fetchActiveAgents(application.id(), range)); } - private List fetchActiveAgents(UUID applicationId, Range activeRange) { + private List fetchActiveAgents(ApplicationId applicationId, Range activeRange) { return this.applicationService.getAgents(applicationId) .stream() - .filter(id -> agentInfoService.isActiveAgent(id, activeRange)) + .filter(id -> agentInfoService.isActiveAgent(AgentId.of(id), activeRange)) .toList(); } diff --git a/batch/src/main/java/com/navercorp/pinpoint/batch/alarm/collector/pinot/DataSourceDataCollector.java b/batch/src/main/java/com/navercorp/pinpoint/batch/alarm/collector/pinot/DataSourceDataCollector.java index 2dce91608153..4f75775669f2 100644 --- a/batch/src/main/java/com/navercorp/pinpoint/batch/alarm/collector/pinot/DataSourceDataCollector.java +++ b/batch/src/main/java/com/navercorp/pinpoint/batch/alarm/collector/pinot/DataSourceDataCollector.java @@ -123,11 +123,11 @@ public void collect() { agentDataSourceConnectionUsageRateMap.add(tagInformation.agentId(), dataSourceAlarmVO); } } catch (RuntimeException e) { - logger.error("Fail to get agent datasource data. applicationName : {}", application.getName(), e); + logger.error("Fail to get agent datasource data. applicationName : {}", application.name(), e); } catch (ExecutionException e) { - logger.error("Fail to get agent datasource data with ExecutionException. applicationName : {}", application.getName(), e); + logger.error("Fail to get agent datasource data with ExecutionException. applicationName : {}", application.name(), e); } catch (InterruptedException e) { - logger.error("Fail to get agent datasource data with InterruptedException. applicationName : {}", application.getName(), e); + logger.error("Fail to get agent datasource data with InterruptedException. applicationName : {}", application.name(), e); } } @@ -163,7 +163,7 @@ private Map> getAgentTagInformation(Range range) th errorCount++; if (errorCount > 2) { - logger.error("Fail to get agent tag information. applicationName : {}, agentId : {}", application.getName(), agentId, e); + logger.error("Fail to get agent tag information. applicationName : {}, agentId : {}", application.name(), agentId, e); throw e; } } @@ -201,7 +201,7 @@ private Map> distinctJdbUrlForAgent(Range range) throws Execut } catch (Exception e) { errorCount++; if (errorCount > 2) { - logger.error("Fail to get agent jdbcUrl. applicationName : {}, agentId : {}", application.getName(), agentId, e); + logger.error("Fail to get agent jdbcUrl. applicationName : {}, agentId : {}", application.name(), agentId, e); throw e; } } diff --git a/batch/src/main/java/com/navercorp/pinpoint/batch/job/AgentCountProcessor.java b/batch/src/main/java/com/navercorp/pinpoint/batch/job/AgentCountProcessor.java index c5f0e534592b..390d6c63d778 100644 --- a/batch/src/main/java/com/navercorp/pinpoint/batch/job/AgentCountProcessor.java +++ b/batch/src/main/java/com/navercorp/pinpoint/batch/job/AgentCountProcessor.java @@ -16,6 +16,8 @@ package com.navercorp.pinpoint.batch.job; import com.navercorp.pinpoint.batch.common.BatchProperties; +import com.navercorp.pinpoint.common.id.AgentId; +import com.navercorp.pinpoint.common.id.ApplicationId; import com.navercorp.pinpoint.common.server.util.time.Range; import com.navercorp.pinpoint.web.service.AgentInfoService; import com.navercorp.pinpoint.web.service.ApplicationService; @@ -25,13 +27,12 @@ import org.springframework.batch.item.ItemProcessor; import java.util.Objects; -import java.util.UUID; import java.util.concurrent.TimeUnit; /** * @author youngjin.kim2 */ -public class AgentCountProcessor implements ItemProcessor { +public class AgentCountProcessor implements ItemProcessor { private final Logger logger = LogManager.getLogger(this.getClass()); @@ -52,16 +53,17 @@ public AgentCountProcessor( } @Override - public Integer process(@Nonnull UUID applicationId) { + public Integer process(@Nonnull ApplicationId applicationId) { long localCount = applicationService.getAgents(applicationId) .stream() + .map(AgentId::of) .filter(this::isActive) .count(); logger.info("Application {} has {} agents", applicationId, localCount); return Math.toIntExact(localCount); } - private boolean isActive(String agentId) { + private boolean isActive(AgentId agentId) { long now = System.currentTimeMillis(); Range range = Range.between(now - duration, now); return agentInfoService.isActiveAgent(agentId, range); diff --git a/batch/src/main/java/com/navercorp/pinpoint/batch/job/AgentCountReader.java b/batch/src/main/java/com/navercorp/pinpoint/batch/job/AgentCountReader.java index 44a63ac13c72..a9c8caf21ce3 100644 --- a/batch/src/main/java/com/navercorp/pinpoint/batch/job/AgentCountReader.java +++ b/batch/src/main/java/com/navercorp/pinpoint/batch/job/AgentCountReader.java @@ -16,6 +16,7 @@ package com.navercorp.pinpoint.batch.job; +import com.navercorp.pinpoint.common.id.ApplicationId; import com.navercorp.pinpoint.web.service.ApplicationService; import com.navercorp.pinpoint.web.vo.Application; import jakarta.annotation.Nonnull; @@ -27,17 +28,16 @@ import java.util.List; import java.util.Objects; import java.util.Queue; -import java.util.UUID; import java.util.concurrent.ConcurrentLinkedQueue; /** * @author youngjin.kim2 */ -public class AgentCountReader implements ItemReader, StepExecutionListener { +public class AgentCountReader implements ItemReader, StepExecutionListener { private final ApplicationService applicationService; - private Queue applicationNameQueue; + private Queue applicationNameQueue; public AgentCountReader(ApplicationService applicationService) { this.applicationService = Objects.requireNonNull(applicationService, "applicationService"); @@ -45,7 +45,7 @@ public AgentCountReader(ApplicationService applicationService) { @Override public void beforeStep(@Nonnull StepExecution stepExecution) { - List applicationNames = applicationService.getApplications() + List applicationNames = applicationService.getApplications() .stream() .map(Application::id) .toList(); @@ -58,7 +58,7 @@ public ExitStatus afterStep(@Nonnull StepExecution stepExecution) { } @Override - public UUID read() { + public ApplicationId read() { return applicationNameQueue.poll(); } diff --git a/batch/src/main/java/com/navercorp/pinpoint/batch/job/AgentRemover.java b/batch/src/main/java/com/navercorp/pinpoint/batch/job/AgentRemover.java index bd9aaa9fcde2..2bf960c1f149 100644 --- a/batch/src/main/java/com/navercorp/pinpoint/batch/job/AgentRemover.java +++ b/batch/src/main/java/com/navercorp/pinpoint/batch/job/AgentRemover.java @@ -17,6 +17,7 @@ package com.navercorp.pinpoint.batch.job; import com.navercorp.pinpoint.batch.service.BatchAgentService; +import com.navercorp.pinpoint.common.id.ApplicationId; import com.navercorp.pinpoint.common.server.cluster.ClusterKey; import jakarta.annotation.Nonnull; import org.apache.logging.log4j.LogManager; @@ -45,7 +46,8 @@ public void write(@Nonnull List serAgentKeys) throws Exception for (String serKey: serAgentKeys) { logger.info("Removing agent: {}", serKey); ClusterKey key = ClusterKey.parse(serKey); - this.agentService.remove(UUID.fromString(key.getApplicationName()), key.getAgentId()); + UUID applicationIdValue = UUID.fromString(key.getApplicationName()); + this.agentService.remove(ApplicationId.of(applicationIdValue), key.getAgentId()); } } } diff --git a/batch/src/main/java/com/navercorp/pinpoint/batch/job/ApplicationCleaningProcessor.java b/batch/src/main/java/com/navercorp/pinpoint/batch/job/ApplicationCleaningProcessor.java index 27d027916fc8..7f31fb233387 100644 --- a/batch/src/main/java/com/navercorp/pinpoint/batch/job/ApplicationCleaningProcessor.java +++ b/batch/src/main/java/com/navercorp/pinpoint/batch/job/ApplicationCleaningProcessor.java @@ -19,6 +19,8 @@ import com.navercorp.pinpoint.batch.service.BatchAgentService; import com.navercorp.pinpoint.batch.service.BatchApplicationService; import com.navercorp.pinpoint.batch.vo.CleanTarget; +import com.navercorp.pinpoint.common.id.AgentId; +import com.navercorp.pinpoint.common.id.ApplicationId; import com.navercorp.pinpoint.common.server.cluster.ClusterKey; import com.navercorp.pinpoint.common.server.util.time.Range; import jakarta.annotation.Nonnull; @@ -30,12 +32,11 @@ import java.util.ArrayList; import java.util.List; import java.util.Objects; -import java.util.UUID; /** * @author youngjin.kim2 */ -public class ApplicationCleaningProcessor implements ItemProcessor> { +public class ApplicationCleaningProcessor implements ItemProcessor> { private static final Logger logger = LogManager.getLogger(ApplicationCleaningProcessor.class); @@ -54,16 +55,16 @@ public ApplicationCleaningProcessor( } @Override - public List process(@Nonnull UUID applicationId) throws Exception { + public List process(@Nonnull ApplicationId applicationId) throws Exception { logger.info("Processing application: {}", applicationId); Range range = getRange(); - List agentIds = getAgents(applicationId); + List agentIds = getAgents(applicationId); List targets = new ArrayList<>(agentIds.size() + 1); - for (String agentId: agentIds) { + for (AgentId agentId: agentIds) { if (isAgentTarget(agentId, range)) { - String agentKey = ClusterKey.compose(applicationId.toString(), agentId, -1); + String agentKey = ClusterKey.compose(applicationId.toString(), agentId.value(), -1); targets.add(new CleanTarget(CleanTarget.TYPE_AGENT, agentKey)); } } @@ -80,15 +81,15 @@ public List process(@Nonnull UUID applicationId) throws Exception { return targets; } - private boolean isApplicationTarget(UUID applicationId) { + private boolean isApplicationTarget(ApplicationId applicationId) { return !this.batchApplicationService.isActive(applicationId, this.emptyDurationThreshold); } - private boolean isAgentTarget(String agentId, Range range) { + private boolean isAgentTarget(AgentId agentId, Range range) { return !this.agentService.isActive(agentId, range); } - private List getAgents(UUID applicationId) { + private List getAgents(ApplicationId applicationId) { return this.agentService.getIds(applicationId); } diff --git a/batch/src/main/java/com/navercorp/pinpoint/batch/job/ApplicationReader.java b/batch/src/main/java/com/navercorp/pinpoint/batch/job/ApplicationReader.java index ed5f70396525..3c7f1a46bb44 100644 --- a/batch/src/main/java/com/navercorp/pinpoint/batch/job/ApplicationReader.java +++ b/batch/src/main/java/com/navercorp/pinpoint/batch/job/ApplicationReader.java @@ -17,6 +17,7 @@ package com.navercorp.pinpoint.batch.job; import com.navercorp.pinpoint.batch.service.BatchApplicationService; +import com.navercorp.pinpoint.common.id.ApplicationId; import jakarta.annotation.Nonnull; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; @@ -26,20 +27,19 @@ import java.util.List; import java.util.Objects; -import java.util.UUID; import java.util.concurrent.atomic.AtomicInteger; /** * @author youngjin.kim2 */ -public class ApplicationReader implements ItemStreamReader { +public class ApplicationReader implements ItemStreamReader { private static final Logger logger = LogManager.getLogger(ApplicationReader.class); private static final String CURRENT_INDEX = "current.index"; private final BatchApplicationService applicationService; - private List applicationIds; + private List applicationIds; private final AtomicInteger currentIndexAtom = new AtomicInteger(0); @@ -48,7 +48,7 @@ public ApplicationReader(BatchApplicationService applicationService) { } @Override - public UUID read() { + public ApplicationId read() { int currentIndex = currentIndexAtom.getAndIncrement(); if (currentIndex < applicationIds.size()) { logger.info("Reading application: {} / {}", currentIndex, applicationIds.size()); @@ -83,7 +83,7 @@ public void close() throws ItemStreamException { logger.info("Closing application reader"); } - private List getAllApplications() { + private List getAllApplications() { return this.applicationService.getAll() .stream() .sorted() diff --git a/batch/src/main/java/com/navercorp/pinpoint/batch/job/ApplicationRemover.java b/batch/src/main/java/com/navercorp/pinpoint/batch/job/ApplicationRemover.java index 4126e4fa7585..04fae9a44361 100644 --- a/batch/src/main/java/com/navercorp/pinpoint/batch/job/ApplicationRemover.java +++ b/batch/src/main/java/com/navercorp/pinpoint/batch/job/ApplicationRemover.java @@ -17,6 +17,7 @@ package com.navercorp.pinpoint.batch.job; import com.navercorp.pinpoint.batch.service.BatchApplicationService; +import com.navercorp.pinpoint.common.id.ApplicationId; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import org.springframework.batch.item.ItemWriter; @@ -41,7 +42,7 @@ public ApplicationRemover(BatchApplicationService applicationService) { @Override public void write(List applicationIds) throws Exception { for (String applicationIdStr : applicationIds) { - UUID applicationId = UUID.fromString(applicationIdStr); + ApplicationId applicationId = ApplicationId.of(UUID.fromString(applicationIdStr)); logger.info("Removing application: {}", applicationId); this.applicationService.remove(applicationId); logger.info("Removed application: {}", applicationId); diff --git a/batch/src/main/java/com/navercorp/pinpoint/batch/job/CleanupInactiveAgentsTasklet.java b/batch/src/main/java/com/navercorp/pinpoint/batch/job/CleanupInactiveAgentsTasklet.java index 27a1b49b9770..d7005b894b64 100644 --- a/batch/src/main/java/com/navercorp/pinpoint/batch/job/CleanupInactiveAgentsTasklet.java +++ b/batch/src/main/java/com/navercorp/pinpoint/batch/job/CleanupInactiveAgentsTasklet.java @@ -17,6 +17,7 @@ package com.navercorp.pinpoint.batch.job; import com.navercorp.pinpoint.batch.common.BatchProperties; +import com.navercorp.pinpoint.common.id.ApplicationId; import com.navercorp.pinpoint.web.service.AdminService; import com.navercorp.pinpoint.web.service.ApplicationService; import com.navercorp.pinpoint.web.vo.Application; @@ -52,7 +53,7 @@ public class CleanupInactiveAgentsTasklet implements Tasklet, StepExecutionListe private final ApplicationService applicationService; - private Queue applicationNameQueue; + private Queue applicationIdsQueue; private int progress; private int total; private int inactiveCount; @@ -70,16 +71,16 @@ public CleanupInactiveAgentsTasklet( @Override public void beforeStep(@Nonnull StepExecution stepExecution) { - List applicationNames = this.applicationService.getApplications() + List applicationIds = this.applicationService.getApplications() .stream() - .map(Application::name) + .map(Application::id) .distinct() .collect(Collectors.toList()); - Collections.shuffle(applicationNames); + Collections.shuffle(applicationIds); - this.applicationNameQueue = new ArrayDeque<>(applicationNames); + this.applicationIdsQueue = new ArrayDeque<>(applicationIds); this.progress = 0; - this.total = applicationNames.size(); + this.total = applicationIds.size(); this.inactiveCount = 0; } @@ -94,16 +95,16 @@ public RepeatStatus execute( @Nonnull StepContribution contribution, @Nonnull ChunkContext chunkContext ) throws Exception { - String applicationName = this.applicationNameQueue.poll(); - if (applicationName == null) { + ApplicationId applicationId = this.applicationIdsQueue.poll(); + if (applicationId == null) { return RepeatStatus.FINISHED; } try { - logger.info("Cleaning application {} ({}/{})", applicationName, ++progress, total); - inactiveCount += adminService.removeInactiveAgentInApplication(applicationName, durationDays); + logger.info("Cleaning application {} ({}/{})", applicationId, ++progress, total); + inactiveCount += adminService.removeInactiveAgentInApplication(applicationId, durationDays); } catch (Exception e) { - logger.warn("Failed to clean application {}. message: {}", applicationName, e.getMessage(), e); + logger.warn("Failed to clean application {}. message: {}", applicationId, e.getMessage(), e); } return RepeatStatus.CONTINUABLE; diff --git a/batch/src/main/java/com/navercorp/pinpoint/batch/service/BatchAgentService.java b/batch/src/main/java/com/navercorp/pinpoint/batch/service/BatchAgentService.java index 3e42d1dd1b02..cbcf21377a90 100644 --- a/batch/src/main/java/com/navercorp/pinpoint/batch/service/BatchAgentService.java +++ b/batch/src/main/java/com/navercorp/pinpoint/batch/service/BatchAgentService.java @@ -16,20 +16,21 @@ package com.navercorp.pinpoint.batch.service; +import com.navercorp.pinpoint.common.id.AgentId; +import com.navercorp.pinpoint.common.id.ApplicationId; import com.navercorp.pinpoint.common.server.util.time.Range; import java.util.List; -import java.util.UUID; /** * @author youngjin.kim2 */ public interface BatchAgentService { - List getIds(UUID applicationId); + List getIds(ApplicationId applicationId); - boolean isActive(String agentId, Range range); + boolean isActive(AgentId agentId, Range range); - void remove(UUID applicationId, String agentId); + void remove(ApplicationId applicationId, String agentId); } diff --git a/batch/src/main/java/com/navercorp/pinpoint/batch/service/BatchAgentServiceImpl.java b/batch/src/main/java/com/navercorp/pinpoint/batch/service/BatchAgentServiceImpl.java index f4ad2b41610a..956ca42a1586 100644 --- a/batch/src/main/java/com/navercorp/pinpoint/batch/service/BatchAgentServiceImpl.java +++ b/batch/src/main/java/com/navercorp/pinpoint/batch/service/BatchAgentServiceImpl.java @@ -16,13 +16,14 @@ package com.navercorp.pinpoint.batch.service; +import com.navercorp.pinpoint.common.id.AgentId; +import com.navercorp.pinpoint.common.id.ApplicationId; import com.navercorp.pinpoint.common.server.util.time.Range; import com.navercorp.pinpoint.web.service.AgentInfoService; import com.navercorp.pinpoint.web.service.ApplicationService; import java.util.List; import java.util.Objects; -import java.util.UUID; /** * @author youngjin.kim2 @@ -41,17 +42,20 @@ public BatchAgentServiceImpl( } @Override - public List getIds(UUID applicationId) { - return this.applicationService.getAgents(applicationId); + public List getIds(ApplicationId applicationId) { + return this.applicationService.getAgents(applicationId) + .stream() + .map(AgentId::of) + .toList(); } @Override - public boolean isActive(String agentId, Range range) { + public boolean isActive(AgentId agentId, Range range) { return this.agentInfoService.isActiveAgent(agentId, range); } @Override - public void remove(UUID applicationId, String agentId) { + public void remove(ApplicationId applicationId, String agentId) { this.applicationService.deleteAgent(applicationId, agentId); } } diff --git a/batch/src/main/java/com/navercorp/pinpoint/batch/service/BatchApplicationService.java b/batch/src/main/java/com/navercorp/pinpoint/batch/service/BatchApplicationService.java index d477a09a5e1b..43fa97f81932 100644 --- a/batch/src/main/java/com/navercorp/pinpoint/batch/service/BatchApplicationService.java +++ b/batch/src/main/java/com/navercorp/pinpoint/batch/service/BatchApplicationService.java @@ -16,19 +16,20 @@ package com.navercorp.pinpoint.batch.service; +import com.navercorp.pinpoint.common.id.ApplicationId; + import java.time.Duration; import java.util.List; -import java.util.UUID; /** * @author youngjin.kim2 */ public interface BatchApplicationService { - List getAll(); + List getAll(); - boolean isActive(UUID applicationId, Duration duration); + boolean isActive(ApplicationId applicationId, Duration duration); - void remove(UUID applicationId); + void remove(ApplicationId applicationId); } diff --git a/batch/src/main/java/com/navercorp/pinpoint/batch/service/BatchApplicationServiceImpl.java b/batch/src/main/java/com/navercorp/pinpoint/batch/service/BatchApplicationServiceImpl.java index c7ec6339ce35..b0b8e566994b 100644 --- a/batch/src/main/java/com/navercorp/pinpoint/batch/service/BatchApplicationServiceImpl.java +++ b/batch/src/main/java/com/navercorp/pinpoint/batch/service/BatchApplicationServiceImpl.java @@ -16,6 +16,7 @@ package com.navercorp.pinpoint.batch.service; +import com.navercorp.pinpoint.common.id.ApplicationId; import com.navercorp.pinpoint.common.server.util.time.Range; import com.navercorp.pinpoint.web.dao.ApplicationTraceIndexDaoV2; import com.navercorp.pinpoint.web.service.ApplicationService; @@ -25,7 +26,6 @@ import java.time.Duration; import java.util.List; import java.util.Objects; -import java.util.UUID; /** * @author youngjin.kim2 @@ -45,7 +45,7 @@ public BatchApplicationServiceImpl( } @Override - public List getAll() { + public List getAll() { return this.applicationService.getApplications() .stream() .map(Application::id) @@ -53,18 +53,18 @@ public List getAll() { } @Override - public boolean isActive(UUID applicationId, Duration duration) { + public boolean isActive(ApplicationId applicationId, Duration duration) { long now = System.currentTimeMillis(); Range range = Range.between(now - duration.toMillis(), now); return hasTrace(applicationId, range); } - private boolean hasTrace(UUID applicationId, Range range) { + private boolean hasTrace(ApplicationId applicationId, Range range) { return this.applicationTraceIndexDao.hasTraceIndex(applicationId, range,false); } @Override - public void remove(UUID applicationId) { + public void remove(ApplicationId applicationId) { this.applicationService.deleteApplication(applicationId); } diff --git a/batch/src/test/java/com/navercorp/pinpoint/batch/alarm/AlarmReaderTest.java b/batch/src/test/java/com/navercorp/pinpoint/batch/alarm/AlarmReaderTest.java index f86daef7c3c0..f03caa12b3a4 100644 --- a/batch/src/test/java/com/navercorp/pinpoint/batch/alarm/AlarmReaderTest.java +++ b/batch/src/test/java/com/navercorp/pinpoint/batch/alarm/AlarmReaderTest.java @@ -16,6 +16,7 @@ package com.navercorp.pinpoint.batch.alarm; +import com.navercorp.pinpoint.common.id.ApplicationId; import com.navercorp.pinpoint.common.trace.ServiceType; import com.navercorp.pinpoint.web.service.AlarmService; import com.navercorp.pinpoint.web.service.ApplicationService; @@ -46,10 +47,10 @@ public class AlarmReaderTest { private StepExecution stepExecution; private static final List mockApplications = List.of( - new Application(UUID.randomUUID(), "testApplication0", ServiceType.TEST), - new Application(UUID.randomUUID(), "testApplication1", ServiceType.TEST), - new Application(UUID.randomUUID(), "testApplication2", ServiceType.TEST), - new Application(UUID.randomUUID(), "testApplication3", ServiceType.TEST) + new Application(ApplicationId.of(UUID.randomUUID()), "testApplication0", ServiceType.TEST), + new Application(ApplicationId.of(UUID.randomUUID()), "testApplication1", ServiceType.TEST), + new Application(ApplicationId.of(UUID.randomUUID()), "testApplication2", ServiceType.TEST), + new Application(ApplicationId.of(UUID.randomUUID()), "testApplication3", ServiceType.TEST) ); private static final List applicationIds = mockApplications.stream() diff --git a/batch/src/test/java/com/navercorp/pinpoint/batch/alarm/checker/GcCountCheckerTest.java b/batch/src/test/java/com/navercorp/pinpoint/batch/alarm/checker/GcCountCheckerTest.java index 7fabbf226bc0..cce4bdcdb0d7 100644 --- a/batch/src/test/java/com/navercorp/pinpoint/batch/alarm/checker/GcCountCheckerTest.java +++ b/batch/src/test/java/com/navercorp/pinpoint/batch/alarm/checker/GcCountCheckerTest.java @@ -91,12 +91,12 @@ public boolean agentStatExists(String agentId, Range range) { applicationIndexDao = new ApplicationIndexDao() { @Override - public List selectAllApplicationNames() { + public List selectAllApplications() { throw new UnsupportedOperationException(); } @Override - public List selectApplicationName(String applicationName) { + public List selectApplicationByName(String applicationName) { throw new UnsupportedOperationException(); } diff --git a/collector/src/main/java/com/navercorp/pinpoint/collector/dao/AgentInfoDao.java b/collector/src/main/java/com/navercorp/pinpoint/collector/dao/AgentInfoDao.java index 76fd0415ba66..23f5ee7d5b6e 100644 --- a/collector/src/main/java/com/navercorp/pinpoint/collector/dao/AgentInfoDao.java +++ b/collector/src/main/java/com/navercorp/pinpoint/collector/dao/AgentInfoDao.java @@ -16,6 +16,7 @@ package com.navercorp.pinpoint.collector.dao; +import com.navercorp.pinpoint.common.id.AgentId; import com.navercorp.pinpoint.common.server.bo.AgentInfoBo; /** @@ -25,5 +26,5 @@ public interface AgentInfoDao { void insert(AgentInfoBo agentInfo); - AgentInfoBo getAgentInfo(String agentId, long timestamp); + AgentInfoBo getAgentInfo(AgentId agentId, long timestamp); } diff --git a/collector/src/main/java/com/navercorp/pinpoint/collector/dao/ApplicationInfoDao.java b/collector/src/main/java/com/navercorp/pinpoint/collector/dao/ApplicationInfoDao.java index 3d9f02dbf5e8..df6c76f0d602 100644 --- a/collector/src/main/java/com/navercorp/pinpoint/collector/dao/ApplicationInfoDao.java +++ b/collector/src/main/java/com/navercorp/pinpoint/collector/dao/ApplicationInfoDao.java @@ -17,18 +17,25 @@ package com.navercorp.pinpoint.collector.dao; import com.navercorp.pinpoint.common.id.ApplicationId; +import com.navercorp.pinpoint.common.id.ServiceId; +import com.navercorp.pinpoint.common.server.bo.ApplicationInfo; +import com.navercorp.pinpoint.common.server.bo.ApplicationSelector; + +import java.util.List; /** * @author youngjin.kim2 */ public interface ApplicationInfoDao { - ApplicationId getApplicationId(String applicationName); + ApplicationId getApplicationId(ApplicationSelector application); + + ApplicationInfo getApplication(ApplicationId applicationId); - String getApplicationName(ApplicationId applicationId); + ApplicationId putApplicationIdIfAbsent(ApplicationInfo application); - ApplicationId putApplicationIdIfAbsent(String applicationName, ApplicationId applicationId); + void ensureInverse(ApplicationInfo application); - void ensureInverse(String applicationName, ApplicationId applicationId); + List getApplications(ServiceId serviceId); } diff --git a/collector/src/main/java/com/navercorp/pinpoint/collector/dao/ServiceInfoDao.java b/collector/src/main/java/com/navercorp/pinpoint/collector/dao/ServiceInfoDao.java new file mode 100644 index 000000000000..af9680a8760e --- /dev/null +++ b/collector/src/main/java/com/navercorp/pinpoint/collector/dao/ServiceInfoDao.java @@ -0,0 +1,34 @@ +/* + * Copyright 2024 NAVER Corp. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.navercorp.pinpoint.collector.dao; + +import com.navercorp.pinpoint.common.id.ServiceId; +import com.navercorp.pinpoint.common.server.bo.ServiceInfo; + +/** + * @author youngjin.kim2 + */ +public interface ServiceInfoDao { + + ServiceId getServiceId(String serviceName); + + ServiceInfo getServiceInfo(ServiceId serviceId); + + ServiceId putServiceIdIfAbsent(String serviceName, ServiceId serviceId); + + void ensurePut(String serviceName, ServiceId serviceId); + +} diff --git a/collector/src/main/java/com/navercorp/pinpoint/collector/dao/hbase/HbaseAgentInfoDao.java b/collector/src/main/java/com/navercorp/pinpoint/collector/dao/hbase/HbaseAgentInfoDao.java index 8f55c3cefc0b..e05e58bf7761 100644 --- a/collector/src/main/java/com/navercorp/pinpoint/collector/dao/hbase/HbaseAgentInfoDao.java +++ b/collector/src/main/java/com/navercorp/pinpoint/collector/dao/hbase/HbaseAgentInfoDao.java @@ -22,6 +22,7 @@ import com.navercorp.pinpoint.common.hbase.HbaseOperations; import com.navercorp.pinpoint.common.hbase.ResultsExtractor; import com.navercorp.pinpoint.common.hbase.TableNameProvider; +import com.navercorp.pinpoint.common.id.AgentId; import com.navercorp.pinpoint.common.server.bo.AgentInfoBo; import com.navercorp.pinpoint.common.server.bo.serializer.agent.AgentIdRowKeyEncoder; import com.navercorp.pinpoint.common.server.util.RowKeyUtils; @@ -73,7 +74,7 @@ public void insert(AgentInfoBo agentInfo) { //check agentName if set CollectorUtils.checkAgentName(agentInfo.getAgentName()); - final byte[] rowKey = rowKeyEncoder.encodeRowKey(agentInfo.getAgentId(), agentInfo.getStartTime()); + final byte[] rowKey = rowKeyEncoder.encodeRowKey(AgentId.unwrap(agentInfo.getAgentId()), agentInfo.getStartTime()); final Put put = new Put(rowKey); // should add additional agent information. for now added only start-time for sqlMetaData @@ -94,7 +95,8 @@ public void insert(AgentInfoBo agentInfo) { hbaseTemplate.put(agentInfoTableName, put); } - public AgentInfoBo getAgentInfo(final String agentId, final long timestamp) { + @Override + public AgentInfoBo getAgentInfo(final AgentId agentId, final long timestamp) { Objects.requireNonNull(agentId, "agentId"); final Scan scan = createScan(agentId, timestamp); @@ -102,11 +104,11 @@ public AgentInfoBo getAgentInfo(final String agentId, final long timestamp) { return this.hbaseTemplate.find(agentInfoTableName, scan, agentInfoResultsExtractor); } - private Scan createScan(String agentId, long currentTime) { + private Scan createScan(AgentId agentId, long currentTime) { final Scan scan = new Scan(); - final byte[] startKeyBytes = rowKeyEncoder.encodeRowKey(agentId, currentTime); - final byte[] endKeyBytes = RowKeyUtils.agentIdAndTimestamp(agentId, Long.MAX_VALUE); + final byte[] startKeyBytes = rowKeyEncoder.encodeRowKey(agentId.value(), currentTime); + final byte[] endKeyBytes = RowKeyUtils.agentIdAndTimestamp(agentId.value(), Long.MAX_VALUE); scan.withStartRow(startKeyBytes); scan.withStopRow(endKeyBytes); diff --git a/collector/src/main/java/com/navercorp/pinpoint/collector/dao/hbase/HbaseApplicationIndexDao.java b/collector/src/main/java/com/navercorp/pinpoint/collector/dao/hbase/HbaseApplicationIndexDao.java index 02939149ba80..0a7db21906df 100644 --- a/collector/src/main/java/com/navercorp/pinpoint/collector/dao/hbase/HbaseApplicationIndexDao.java +++ b/collector/src/main/java/com/navercorp/pinpoint/collector/dao/hbase/HbaseApplicationIndexDao.java @@ -23,7 +23,6 @@ import com.navercorp.pinpoint.common.hbase.TableNameProvider; import com.navercorp.pinpoint.common.hbase.ValueMapper; import com.navercorp.pinpoint.common.server.bo.AgentInfoBo; -import com.navercorp.pinpoint.common.util.UuidUtils; import org.apache.hadoop.hbase.TableName; import org.apache.hadoop.hbase.client.Put; import org.apache.hadoop.hbase.util.Bytes; @@ -70,8 +69,8 @@ public void insert(final AgentInfoBo agentInfo) { // Assert applicationName CollectorUtils.checkApplicationName(agentInfo.getApplicationName()); - final Put put = new Put(UuidUtils.toBytes(agentInfo.getApplicationId().value())); - final byte[] qualifier = Bytes.toBytes(agentInfo.getAgentId()); + final Put put = new Put(agentInfo.getApplicationId().toBytes()); + final byte[] qualifier = Bytes.toBytes(agentInfo.getAgentId().value()); final byte[] value = this.valueMapper.mapValue(agentInfo); put.addColumn(DESCRIPTOR.getName(), qualifier, value); diff --git a/collector/src/main/java/com/navercorp/pinpoint/collector/dao/hbase/HbaseApplicationInfoDao.java b/collector/src/main/java/com/navercorp/pinpoint/collector/dao/hbase/HbaseApplicationInfoDao.java index d55bb2f807da..732cf941a5d1 100644 --- a/collector/src/main/java/com/navercorp/pinpoint/collector/dao/hbase/HbaseApplicationInfoDao.java +++ b/collector/src/main/java/com/navercorp/pinpoint/collector/dao/hbase/HbaseApplicationInfoDao.java @@ -22,22 +22,22 @@ import com.navercorp.pinpoint.common.hbase.RowMapper; import com.navercorp.pinpoint.common.hbase.TableNameProvider; import com.navercorp.pinpoint.common.id.ApplicationId; -import com.navercorp.pinpoint.common.server.util.HashUtils; -import com.navercorp.pinpoint.common.util.BytesUtils; -import com.navercorp.pinpoint.common.util.UuidUtils; -import org.apache.hadoop.hbase.Cell; +import com.navercorp.pinpoint.common.id.ServiceId; +import com.navercorp.pinpoint.common.server.bo.ApplicationInfo; +import com.navercorp.pinpoint.common.server.bo.ApplicationSelector; import org.apache.hadoop.hbase.TableName; import org.apache.hadoop.hbase.client.CheckAndMutate; import org.apache.hadoop.hbase.client.CheckAndMutateResult; import org.apache.hadoop.hbase.client.Get; import org.apache.hadoop.hbase.client.Put; +import org.apache.hadoop.hbase.client.Scan; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.stereotype.Repository; +import java.util.List; import java.util.Objects; -import java.util.UUID; /** * @author youngjin.kim2 @@ -51,14 +51,14 @@ public class HbaseApplicationInfoDao implements ApplicationInfoDao { private final HbaseOperations hbaseTemplate; private final TableNameProvider tableNameProvider; - private final RowMapper forwardRowMapper; - private final RowMapper inverseRowMapper; + private final RowMapper forwardRowMapper; + private final RowMapper inverseRowMapper; public HbaseApplicationInfoDao( HbaseOperations hbaseTemplate, TableNameProvider tableNameProvider, - @Qualifier("applicationIdForwardMapper") RowMapper forwardRowMapper, - @Qualifier("applicationIdInverseMapper") RowMapper inverseRowMapper) { + @Qualifier("applicationIdForwardMapper") RowMapper forwardRowMapper, + @Qualifier("applicationIdInverseMapper") RowMapper inverseRowMapper) { this.hbaseTemplate = Objects.requireNonNull(hbaseTemplate, "hbaseTemplate"); this.tableNameProvider = Objects.requireNonNull(tableNameProvider, "tableNameProvider"); this.forwardRowMapper = Objects.requireNonNull(forwardRowMapper, "forwardRowMapper"); @@ -66,83 +66,101 @@ public HbaseApplicationInfoDao( } @Override - public ApplicationId getApplicationId(String applicationName) { - Objects.requireNonNull(applicationName, "applicationName"); + public ApplicationId getApplicationId(ApplicationSelector application) { + Objects.requireNonNull(application, "application"); if (logger.isDebugEnabled()) { - logger.debug("getApplicationId() applicationName:{}", applicationName); + logger.debug("getApplicationId() applicationName:{}", application.name()); } - TableName tableName = this.tableNameProvider.getTableName(DESCRIPTOR_FORWARD.getTable()); - byte[] rowKey = encodeStringAsRowKey(applicationName); - byte[] family = DESCRIPTOR_FORWARD.getName(); - byte[] qualifier = DESCRIPTOR_FORWARD.getName(); + TableName tableName = this.tableNameProvider.getTableName(DESCRIPTOR_INVERSE.getTable()); + byte[] rowKey = application.toBytes(); + byte[] family = DESCRIPTOR_INVERSE.getName(); + byte[] qualifier = DESCRIPTOR_INVERSE.getName(); Get get = new Get(rowKey); get.addColumn(family, qualifier); - return ApplicationId.of(hbaseTemplate.get(tableName, get, this.forwardRowMapper)); + return hbaseTemplate.get(tableName, get, this.inverseRowMapper); } @Override - public String getApplicationName(ApplicationId applicationId) { + public ApplicationInfo getApplication(ApplicationId applicationId) { Objects.requireNonNull(applicationId, "applicationId"); if (logger.isDebugEnabled()) { - logger.debug("getApplicationName() applicationId:{}", applicationId); + logger.debug("getApplication() applicationId:{}", applicationId); } - TableName tableName = this.tableNameProvider.getTableName(DESCRIPTOR_INVERSE.getTable()); - byte[] rowKey = encodeUuidAsRowKey(applicationId.value()); - byte[] family = DESCRIPTOR_INVERSE.getName(); - byte[] qualifier = DESCRIPTOR_INVERSE.getName(); + TableName tableName = this.tableNameProvider.getTableName(DESCRIPTOR_FORWARD.getTable()); + byte[] rowKey = applicationId.toBytes(); + byte[] family = DESCRIPTOR_FORWARD.getName(); + byte[] qualifier = DESCRIPTOR_FORWARD.getName(); Get get = new Get(rowKey); get.addColumn(family, qualifier); - return hbaseTemplate.get(tableName, get, this.inverseRowMapper); + return hbaseTemplate.get(tableName, get, this.forwardRowMapper); } @Override - public ApplicationId putApplicationIdIfAbsent(String applicationName, ApplicationId applicationId) { - Objects.requireNonNull(applicationName, "applicationName"); - Objects.requireNonNull(applicationId, "applicationId"); + public ApplicationId putApplicationIdIfAbsent(ApplicationInfo application) { + Objects.requireNonNull(application, "application"); if (logger.isDebugEnabled()) { - logger.debug("putApplicationIdIfAbsent() applicationName:{}, applicationId:{}", applicationName, applicationId); + logger.debug("putApplicationIdIfAbsent() serviceId: {}, applicationName:{}, applicationId:{}", + application.serviceId(), application.name(), application.id()); } - byte[] family = DESCRIPTOR_FORWARD.getName(); - byte[] qualifier = DESCRIPTOR_FORWARD.getName(); + CheckAndMutateResult camResult = putInverse(application); + if (camResult.isSuccess()) { + putForward(application); + } - CheckAndMutateResult camResult = putForward(applicationName, applicationId); + ApplicationId applicationId = getApplicationId(new ApplicationSelector(application.serviceId(), application.name())); + if (applicationId == null) { + throw new IllegalStateException("Failed to put applicationId: " + application); + } - if (camResult.isSuccess()) { - putInverse(applicationId, applicationName); + return applicationId; + } + + @Override + public void ensureInverse(ApplicationInfo application) { + Objects.requireNonNull(application, "application"); + + if (logger.isDebugEnabled()) { + logger.debug("ensurePut() serviceId: {}, applicationName:{}, applicationId:{}", + application.serviceId(), application.name(), application.id()); } - Cell cell = camResult.getResult().getColumnLatestCell(family, qualifier); - return ApplicationId.of(UuidUtils.fromBytes(cell.getValueArray())); + putInverse(application); } @Override - public void ensureInverse(String applicationName, ApplicationId applicationId) { - Objects.requireNonNull(applicationName, "applicationName"); - Objects.requireNonNull(applicationId, "applicationId"); + public List getApplications(ServiceId serviceId) { + Objects.requireNonNull(serviceId, "serviceId"); if (logger.isDebugEnabled()) { - logger.debug("ensureInverse() applicationName:{}, applicationId:{}", applicationName, applicationId); + logger.debug("getApplications() serviceId:{}", serviceId); } - putInverse(applicationId, applicationName); + TableName tableName = this.tableNameProvider.getTableName(DESCRIPTOR_INVERSE.getTable()); + + Scan scan = new Scan(); + scan.setStartStopRowForPrefixScan(serviceId.toBytes()); + + return hbaseTemplate.find(tableName, scan, this.inverseRowMapper); } - private CheckAndMutateResult putForward(String applicationName, ApplicationId applicationId) { - TableName tableName = this.tableNameProvider.getTableName(DESCRIPTOR_FORWARD.getTable()); - byte[] rowKey = encodeStringAsRowKey(applicationName); - byte[] family = DESCRIPTOR_FORWARD.getName(); - byte[] qualifier = DESCRIPTOR_FORWARD.getName(); - byte[] value = UuidUtils.toBytes(applicationId.value()); + private CheckAndMutateResult putInverse(ApplicationInfo application) { + ApplicationSelector selector = new ApplicationSelector(application.serviceId(), application.name()); + + TableName tableName = this.tableNameProvider.getTableName(DESCRIPTOR_INVERSE.getTable()); + byte[] rowKey = selector.toBytes(); + byte[] family = DESCRIPTOR_INVERSE.getName(); + byte[] qualifier = DESCRIPTOR_INVERSE.getName(); + byte[] value = application.id().toBytes(); Put put = new Put(rowKey); put.addColumn(family, qualifier, value); @@ -154,12 +172,14 @@ private CheckAndMutateResult putForward(String applicationName, ApplicationId ap return hbaseTemplate.checkAndMutate(tableName, checkAndMutate); } - private void putInverse(ApplicationId applicationId, String applicationName) { - TableName tableName = this.tableNameProvider.getTableName(DESCRIPTOR_INVERSE.getTable()); - byte[] rowKey = encodeUuidAsRowKey(applicationId.value()); - byte[] family = DESCRIPTOR_INVERSE.getName(); - byte[] qualifier = DESCRIPTOR_INVERSE.getName(); - byte[] value = BytesUtils.toBytes(applicationName); + private void putForward(ApplicationInfo application) { + ApplicationSelector selector = new ApplicationSelector(application.serviceId(), application.name()); + + TableName tableName = this.tableNameProvider.getTableName(DESCRIPTOR_FORWARD.getTable()); + byte[] rowKey = application.id().toBytes(); + byte[] family = DESCRIPTOR_FORWARD.getName(); + byte[] qualifier = DESCRIPTOR_FORWARD.getName(); + byte[] value = selector.toBytes(); Put put = new Put(rowKey); put.addColumn(family, qualifier, value); @@ -167,11 +187,4 @@ private void putInverse(ApplicationId applicationId, String applicationName) { hbaseTemplate.put(tableName, put); } - private static byte[] encodeStringAsRowKey(String str) { - return HashUtils.hashBytes(BytesUtils.toBytes(str)).asBytes(); - } - - private static byte[] encodeUuidAsRowKey(UUID uuid) { - return UuidUtils.toBytes(uuid); - } } diff --git a/collector/src/main/java/com/navercorp/pinpoint/collector/dao/hbase/HbaseApplicationTraceIndexDao.java b/collector/src/main/java/com/navercorp/pinpoint/collector/dao/hbase/HbaseApplicationTraceIndexDao.java index 5280b0023546..1474e3ebc0b7 100644 --- a/collector/src/main/java/com/navercorp/pinpoint/collector/dao/hbase/HbaseApplicationTraceIndexDao.java +++ b/collector/src/main/java/com/navercorp/pinpoint/collector/dao/hbase/HbaseApplicationTraceIndexDao.java @@ -98,7 +98,7 @@ private byte[] buildIndexValue(SpanBo span) { final Buffer buffer = new AutomaticBuffer(10 + HbaseTableConstants.AGENT_ID_MAX_LEN); buffer.putVInt(span.getElapsed()); buffer.putSVInt(span.getErrCode()); - buffer.putPrefixedString(span.getAgentId()); + buffer.putPrefixedString(span.getAgentId().value()); return buffer.getBuffer(); } diff --git a/collector/src/main/java/com/navercorp/pinpoint/collector/dao/hbase/HbaseMapStatisticsCalleeDao.java b/collector/src/main/java/com/navercorp/pinpoint/collector/dao/hbase/HbaseMapStatisticsCalleeDao.java index 2a1478c81710..f0b5bedac3ab 100644 --- a/collector/src/main/java/com/navercorp/pinpoint/collector/dao/hbase/HbaseMapStatisticsCalleeDao.java +++ b/collector/src/main/java/com/navercorp/pinpoint/collector/dao/hbase/HbaseMapStatisticsCalleeDao.java @@ -82,14 +82,14 @@ public void update(String calleeApplicationName, ServiceType calleeServiceType, // there may be no endpoint in case of httpclient callerHost = StringUtils.defaultString(callerHost); - // TODO callee, caller parameter normalization + // TODO: callee, caller parameter normalization if (ignoreStatFilter.filter(calleeServiceType, callerHost)) { logger.debug("[Ignore-Callee] {} ({}) <- {} ({})[{}]", calleeApplicationName, calleeServiceType, callerApplicationName, callerServiceType, callerHost); return; } - // make row key. rowkey is me + // make row key. row key is me final long acceptedTime = acceptedTimeService.getAcceptedTime(); final long rowTimeSlot = timeSlot.getTimeSlot(acceptedTime); final RowKey calleeRowKey = new CallRowKey(calleeApplicationName, calleeServiceType.getCode(), rowTimeSlot); diff --git a/collector/src/main/java/com/navercorp/pinpoint/collector/dao/hbase/HbaseMapStatisticsCallerDao.java b/collector/src/main/java/com/navercorp/pinpoint/collector/dao/hbase/HbaseMapStatisticsCallerDao.java index 2edf93f85fe5..9884cfa9200a 100644 --- a/collector/src/main/java/com/navercorp/pinpoint/collector/dao/hbase/HbaseMapStatisticsCallerDao.java +++ b/collector/src/main/java/com/navercorp/pinpoint/collector/dao/hbase/HbaseMapStatisticsCallerDao.java @@ -62,7 +62,7 @@ public HbaseMapStatisticsCallerDao(MapLinkConfiguration mapLinkConfiguration, this.acceptedTimeService = Objects.requireNonNull(acceptedTimeService, "acceptedTimeService"); this.timeSlot = Objects.requireNonNull(timeSlot, "timeSlot"); - this.bulkWriter = Objects.requireNonNull(bulkWriter, "bulkWrtier"); + this.bulkWriter = Objects.requireNonNull(bulkWriter, "bulkWriter"); } @@ -80,7 +80,7 @@ public void update(String callerApplicationName, ServiceType callerServiceType, // there may be no endpoint in case of httpclient calleeHost = StringUtils.defaultString(calleeHost); - // make row key. rowkey is me + // make row key. row key is me final long acceptedTime = acceptedTimeService.getAcceptedTime(); final long rowTimeSlot = timeSlot.getTimeSlot(acceptedTime); final RowKey callerRowKey = new CallRowKey(callerApplicationName, callerServiceType.getCode(), rowTimeSlot); diff --git a/collector/src/main/java/com/navercorp/pinpoint/collector/dao/hbase/HbaseServiceInfoDao.java b/collector/src/main/java/com/navercorp/pinpoint/collector/dao/hbase/HbaseServiceInfoDao.java new file mode 100644 index 000000000000..82fcf25fb4c4 --- /dev/null +++ b/collector/src/main/java/com/navercorp/pinpoint/collector/dao/hbase/HbaseServiceInfoDao.java @@ -0,0 +1,169 @@ +/* + * Copyright 2024 NAVER Corp. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.navercorp.pinpoint.collector.dao.hbase; + +import com.navercorp.pinpoint.collector.dao.ServiceInfoDao; +import com.navercorp.pinpoint.common.hbase.HbaseColumnFamily; +import com.navercorp.pinpoint.common.hbase.HbaseOperations; +import com.navercorp.pinpoint.common.hbase.RowMapper; +import com.navercorp.pinpoint.common.hbase.TableNameProvider; +import com.navercorp.pinpoint.common.id.ServiceId; +import com.navercorp.pinpoint.common.server.bo.ServiceInfo; +import com.navercorp.pinpoint.common.util.BytesUtils; +import org.apache.hadoop.hbase.TableName; +import org.apache.hadoop.hbase.client.CheckAndMutate; +import org.apache.hadoop.hbase.client.CheckAndMutateResult; +import org.apache.hadoop.hbase.client.Get; +import org.apache.hadoop.hbase.client.Put; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; +import org.springframework.beans.factory.annotation.Qualifier; +import org.springframework.stereotype.Repository; + +import java.util.Objects; + +/** + * @author youngjin.kim2 + */ +@Repository +public class HbaseServiceInfoDao implements ServiceInfoDao { + + private final Logger logger = LogManager.getLogger(this.getClass()); + + private static final HbaseColumnFamily.ServiceId DESCRIPTOR_FORWARD = HbaseColumnFamily.SERVICE_ID_FORWARD; + private static final HbaseColumnFamily.ServiceId DESCRIPTOR_INVERSE = HbaseColumnFamily.SERVICE_ID_INVERSE; + + private final HbaseOperations hbaseTemplate; + private final TableNameProvider tableNameProvider; + private final RowMapper forwardRowMapper; + private final RowMapper inverseRowMapper; + + public HbaseServiceInfoDao( + HbaseOperations hbaseTemplate, + TableNameProvider tableNameProvider, + @Qualifier("serviceIdForwardMapper") RowMapper forwardRowMapper, + @Qualifier("serviceIdInverseMapper") RowMapper inverseRowMapper) { + this.hbaseTemplate = Objects.requireNonNull(hbaseTemplate, "hbaseTemplate"); + this.tableNameProvider = Objects.requireNonNull(tableNameProvider, "tableNameProvider"); + this.forwardRowMapper = Objects.requireNonNull(forwardRowMapper, "forwardRowMapper"); + this.inverseRowMapper = Objects.requireNonNull(inverseRowMapper, "inverseRowMapper"); + } + + @Override + public ServiceId getServiceId(String serviceName) { + Objects.requireNonNull(serviceName, "serviceName"); + + if (logger.isDebugEnabled()) { + logger.debug("getServiceId() serviceName:{}", serviceName); + } + + TableName tableName = this.tableNameProvider.getTableName(DESCRIPTOR_INVERSE.getTable()); + byte[] rowKey = encodeStringAsRowKey(serviceName); + byte[] family = DESCRIPTOR_INVERSE.getName(); + byte[] qualifier = DESCRIPTOR_INVERSE.getName(); + + Get get = new Get(rowKey); + get.addColumn(family, qualifier); + + return hbaseTemplate.get(tableName, get, this.inverseRowMapper); + } + + @Override + public ServiceInfo getServiceInfo(ServiceId serviceId) { + Objects.requireNonNull(serviceId, "serviceId"); + + if (logger.isDebugEnabled()) { + logger.debug("getServiceInfo() serviceId:{}", serviceId); + } + + TableName tableName = this.tableNameProvider.getTableName(DESCRIPTOR_FORWARD.getTable()); + byte[] rowKey = serviceId.toBytes(); + byte[] family = DESCRIPTOR_FORWARD.getName(); + byte[] qualifier = DESCRIPTOR_FORWARD.getName(); + + Get get = new Get(rowKey); + get.addColumn(family, qualifier); + + return hbaseTemplate.get(tableName, get, this.forwardRowMapper); + } + + @Override + public ServiceId putServiceIdIfAbsent(String serviceName, ServiceId serviceId) { + Objects.requireNonNull(serviceName, "serviceName"); + Objects.requireNonNull(serviceId, "serviceId"); + + if (logger.isDebugEnabled()) { + logger.debug("putServiceIdIfAbsent() serviceName:{}, serviceId:{}", serviceName, serviceId); + } + + ServiceInfo service = new ServiceInfo(serviceId, serviceName); + CheckAndMutateResult camResult = this.putInverse(service); + + if (camResult.isSuccess()) { + putForward(service); + } + + return getServiceId(serviceName); + } + + @Override + public void ensurePut(String serviceName, ServiceId serviceId) { + Objects.requireNonNull(serviceName, "serviceName"); + Objects.requireNonNull(serviceId, "serviceId"); + + if (logger.isDebugEnabled()) { + logger.debug("ensurePut() serviceName:{}, serviceId:{}", serviceName, serviceId); + } + + ServiceInfo service = new ServiceInfo(serviceId, serviceName); + putForward(service); + } + + private CheckAndMutateResult putInverse(ServiceInfo service) { + TableName tableName = this.tableNameProvider.getTableName(DESCRIPTOR_INVERSE.getTable()); + byte[] rowKey = encodeStringAsRowKey(service.name()); + byte[] family = DESCRIPTOR_INVERSE.getName(); + byte[] qualifier = DESCRIPTOR_INVERSE.getName(); + byte[] value = service.id().toBytes(); + + Put put = new Put(rowKey); + put.addColumn(family, qualifier, value); + + CheckAndMutate checkAndMutate = CheckAndMutate.newBuilder(rowKey) + .ifNotExists(family, qualifier) + .build(put); + + return hbaseTemplate.checkAndMutate(tableName, checkAndMutate); + } + + private void putForward(ServiceInfo service) { + TableName tableName = this.tableNameProvider.getTableName(DESCRIPTOR_FORWARD.getTable()); + byte[] rowKey = service.id().toBytes(); + byte[] family = DESCRIPTOR_FORWARD.getName(); + byte[] qualifier = DESCRIPTOR_FORWARD.getName(); + byte[] value = BytesUtils.toBytes(service.name()); + + Put put = new Put(rowKey); + put.addColumn(family, qualifier, value); + + hbaseTemplate.put(tableName, put); + } + + private static byte[] encodeStringAsRowKey(String str) { + return BytesUtils.toBytes(str); + } + +} diff --git a/collector/src/main/java/com/navercorp/pinpoint/collector/dao/hbase/encode/ApplicationIndexRowKeyEncoderV2.java b/collector/src/main/java/com/navercorp/pinpoint/collector/dao/hbase/encode/ApplicationIndexRowKeyEncoderV2.java index 9c8dd3add65c..9991d4abc36a 100644 --- a/collector/src/main/java/com/navercorp/pinpoint/collector/dao/hbase/encode/ApplicationIndexRowKeyEncoderV2.java +++ b/collector/src/main/java/com/navercorp/pinpoint/collector/dao/hbase/encode/ApplicationIndexRowKeyEncoderV2.java @@ -17,6 +17,7 @@ package com.navercorp.pinpoint.collector.dao.hbase.encode; +import com.navercorp.pinpoint.common.id.ApplicationId; import com.navercorp.pinpoint.common.server.bo.SpanBo; import com.navercorp.pinpoint.common.server.bo.serializer.RowKeyEncoder; import com.navercorp.pinpoint.common.server.bo.serializer.agent.ApplicationNameRowKeyEncoder; @@ -27,7 +28,6 @@ import org.apache.logging.log4j.Logger; import java.util.Objects; -import java.util.UUID; public class ApplicationIndexRowKeyEncoderV2 implements RowKeyEncoder { @@ -46,17 +46,17 @@ public byte[] encodeRowKey(SpanBo span) { // distribute key evenly long acceptedTime = span.getCollectorAcceptTime(); byte fuzzyKey = fuzzyRowKeyFactory.getKey(span.getElapsed()); - final byte[] appTraceIndexRowKey = newRowKey(span.getApplicationId().value(), acceptedTime, fuzzyKey); + final byte[] appTraceIndexRowKey = newRowKey(span.getApplicationId(), acceptedTime, fuzzyKey); return rowKeyDistributor.getDistributedKey(appTraceIndexRowKey); } - byte[] newRowKey(UUID applicationId, long acceptedTime, byte fuzzySlotKey) { + byte[] newRowKey(ApplicationId applicationId, long acceptedTime, byte fuzzySlotKey) { Objects.requireNonNull(applicationId, "applicationId"); if (logger.isDebugEnabled()) { logger.debug("fuzzySlotKey:{}", fuzzySlotKey); } - byte[] rowKey = rowKeyEncoder.encodeRowKey(applicationId, acceptedTime); + byte[] rowKey = rowKeyEncoder.encodeRowKey(applicationId.value(), acceptedTime); byte[] fuzzyRowKey = new byte[rowKey.length + 1]; System.arraycopy(rowKey, 0, fuzzyRowKey, 0, rowKey.length); diff --git a/collector/src/main/java/com/navercorp/pinpoint/collector/dao/hbase/statistics/CallRowKey.java b/collector/src/main/java/com/navercorp/pinpoint/collector/dao/hbase/statistics/CallRowKey.java index a93577ddea5c..cbac7bc6e5eb 100644 --- a/collector/src/main/java/com/navercorp/pinpoint/collector/dao/hbase/statistics/CallRowKey.java +++ b/collector/src/main/java/com/navercorp/pinpoint/collector/dao/hbase/statistics/CallRowKey.java @@ -49,10 +49,7 @@ public boolean equals(Object o) { if (callServiceType != that.callServiceType) return false; if (rowTimeSlot != that.rowTimeSlot) return false; - if (callApplicationName != null ? !callApplicationName.equals(that.callApplicationName) : that.callApplicationName != null) - return false; - - return true; + return Objects.equals(callApplicationName, that.callApplicationName); } @Override @@ -60,7 +57,7 @@ public int hashCode() { if (hash != 0) { return hash; } - int result = callApplicationName != null ? callApplicationName.hashCode() : 0; + int result = callApplicationName.hashCode(); result = 31 * result + (int) callServiceType; result = 31 * result + (int) (rowTimeSlot ^ (rowTimeSlot >>> 32)); hash = result; @@ -69,11 +66,9 @@ public int hashCode() { @Override public String toString() { - final StringBuilder sb = new StringBuilder("CallRowKey{"); - sb.append("callApplicationName='").append(callApplicationName).append('\''); - sb.append(", callServiceType=").append(callServiceType); - sb.append(", rowTimeSlot=").append(rowTimeSlot); - sb.append('}'); - return sb.toString(); + return "CallRowKey{" + "callApplicationName='" + callApplicationName + '\'' + + ", callServiceType=" + callServiceType + + ", rowTimeSlot=" + rowTimeSlot + + '}'; } } diff --git a/collector/src/main/java/com/navercorp/pinpoint/collector/dao/hbase/statistics/CalleeColumnName.java b/collector/src/main/java/com/navercorp/pinpoint/collector/dao/hbase/statistics/CalleeColumnName.java index 1cd6e5cfb49c..296dbea0a077 100644 --- a/collector/src/main/java/com/navercorp/pinpoint/collector/dao/hbase/statistics/CalleeColumnName.java +++ b/collector/src/main/java/com/navercorp/pinpoint/collector/dao/hbase/statistics/CalleeColumnName.java @@ -75,14 +75,12 @@ public boolean equals(Object o) { if (columnSlotNumber != that.columnSlotNumber) return false; if (!callHost.equals(that.callHost)) return false; if (!calleeApplicationName.equals(that.calleeApplicationName)) return false; - if (!callerAgentId.equals(that.callerAgentId)) return false; - - return true; + return callerAgentId.equals(that.callerAgentId); } @Override public int hashCode() { - // take care when modifying this method - contains hashCodes for hbasekeys + // take care when modifying this method - contains hashCodes for hbase keys if (hash != 0) { return hash; } @@ -99,14 +97,12 @@ public int hashCode() { @Override public String toString() { - final StringBuilder sb = new StringBuilder("CalleeColumnName{"); - sb.append("callerAgentId=").append(callerAgentId); - sb.append(", calleeServiceType=").append(calleeServiceType); - sb.append(", calleeApplicationName='").append(calleeApplicationName).append('\''); - sb.append(", callHost='").append(callHost).append('\''); - sb.append(", columnSlotNumber=").append(columnSlotNumber); - sb.append(", callCount=").append(callCount); - sb.append('}'); - return sb.toString(); + return "CalleeColumnName{" + "callerAgentId=" + callerAgentId + + ", calleeServiceType=" + calleeServiceType + + ", calleeApplicationName='" + calleeApplicationName + '\'' + + ", callHost='" + callHost + '\'' + + ", columnSlotNumber=" + columnSlotNumber + + ", callCount=" + callCount + + '}'; } } diff --git a/collector/src/main/java/com/navercorp/pinpoint/collector/handler/grpc/GrpcApiMetaDataHandler.java b/collector/src/main/java/com/navercorp/pinpoint/collector/handler/grpc/GrpcApiMetaDataHandler.java index 7b030a7ddd93..b044605ea6ee 100644 --- a/collector/src/main/java/com/navercorp/pinpoint/collector/handler/grpc/GrpcApiMetaDataHandler.java +++ b/collector/src/main/java/com/navercorp/pinpoint/collector/handler/grpc/GrpcApiMetaDataHandler.java @@ -19,6 +19,7 @@ import com.google.protobuf.GeneratedMessageV3; import com.navercorp.pinpoint.collector.handler.RequestResponseHandler; import com.navercorp.pinpoint.collector.service.ApiMetaDataService; +import com.navercorp.pinpoint.common.id.AgentId; import com.navercorp.pinpoint.common.server.bo.ApiMetaDataBo; import com.navercorp.pinpoint.common.server.bo.MethodTypeEnum; import com.navercorp.pinpoint.common.util.LineNumber; @@ -76,13 +77,13 @@ PResult handleApiMetaData(final PApiMetaData apiMetaData) { try { final Header header = ServerContext.getAgentInfo(); - final String agentId = header.getAgentId(); + final AgentId agentId = header.getAgentId(); final long agentStartTime = header.getAgentStartTime(); final int line = LineNumber.defaultLineNumber(apiMetaData.getLine()); final MethodTypeEnum type = MethodTypeEnum.defaultValueOf(apiMetaData.getType()); - final ApiMetaDataBo apiMetaDataBo = new ApiMetaDataBo.Builder(agentId, agentStartTime, + final ApiMetaDataBo apiMetaDataBo = new ApiMetaDataBo.Builder(agentId.value(), agentStartTime, apiMetaData.getApiId(), line, type, apiMetaData.getApiInfo()) .setLocation(apiMetaData.getLocation()) .build(); diff --git a/collector/src/main/java/com/navercorp/pinpoint/collector/handler/grpc/GrpcExceptionMetaDataHandler.java b/collector/src/main/java/com/navercorp/pinpoint/collector/handler/grpc/GrpcExceptionMetaDataHandler.java index ab28ff21755f..94201a1cc288 100644 --- a/collector/src/main/java/com/navercorp/pinpoint/collector/handler/grpc/GrpcExceptionMetaDataHandler.java +++ b/collector/src/main/java/com/navercorp/pinpoint/collector/handler/grpc/GrpcExceptionMetaDataHandler.java @@ -18,6 +18,7 @@ import com.google.protobuf.GeneratedMessageV3; import com.navercorp.pinpoint.collector.handler.RequestResponseHandler; import com.navercorp.pinpoint.collector.service.ExceptionMetaDataService; +import com.navercorp.pinpoint.common.id.AgentId; import com.navercorp.pinpoint.common.profiler.util.TransactionId; import com.navercorp.pinpoint.common.server.bo.exception.ExceptionMetaDataBo; import com.navercorp.pinpoint.common.server.bo.exception.ExceptionWrapperBo; @@ -103,14 +104,14 @@ private PResult handleExceptionMetaData(final PExceptionMetaData exceptionMetaDa private ExceptionMetaDataBo mapExceptionMetaDataBo( Header agentInfo, PExceptionMetaData exceptionMetaData ) { - final String agentId = agentInfo.getAgentId(); + final AgentId agentId = agentInfo.getAgentId(); final TransactionId transactionId = newTransactionId(exceptionMetaData.getTransactionId(), agentId); return new ExceptionMetaDataBo( transactionId, exceptionMetaData.getSpanId(), (short) agentInfo.getServiceType(), agentInfo.getApplicationName(), - agentInfo.getAgentId(), + agentInfo.getAgentId().value(), StringUtils.defaultIfEmpty(exceptionMetaData.getUriTemplate(), EMPTY) ); } @@ -140,9 +141,9 @@ private List handleStackTraceElements(List { private final AcceptedTimeService acceptedTimeService; private final ApplicationInfoService applicationInfoService; + private final ServiceInfoService serviceInfoService; private final Sampler sampler; @@ -55,11 +58,13 @@ public GrpcSpanChunkHandler( GrpcSpanFactory spanFactory, AcceptedTimeService acceptedTimeService, SpanSamplerFactory spanSamplerFactory, - ApplicationInfoService applicationInfoService) { + ApplicationInfoService applicationInfoService, + ServiceInfoService serviceInfoService) { this.traceServices = Objects.requireNonNull(traceServices, "traceServices"); this.spanFactory = Objects.requireNonNull(spanFactory, "spanFactory"); this.acceptedTimeService = Objects.requireNonNull(acceptedTimeService, "acceptedTimeService"); this.applicationInfoService = Objects.requireNonNull(applicationInfoService, "applicationInfoService"); + this.serviceInfoService = Objects.requireNonNull(serviceInfoService, "serviceInfoService"); this.sampler = spanSamplerFactory.createBasicSpanSampler(); logger.info("TraceServices {}", Arrays.toString(traceServices)); @@ -84,7 +89,8 @@ private void handleSpanChunk(PSpanChunk spanChunk) { final Header header = ServerContext.getAgentInfo(); - final ApplicationId applicationId = this.applicationInfoService.getApplicationId(header.getApplicationName()); + final ServiceId serviceId = this.serviceInfoService.getServiceId(header.getServiceName()); + final ApplicationId applicationId = this.applicationInfoService.getApplicationId(serviceId, header.getApplicationName()); final BindAttribute attribute = BindAttribute.of(header, applicationId, acceptedTimeService.getAcceptedTime()); final SpanChunkBo spanChunkBo = spanFactory.buildSpanChunkBo(spanChunk, attribute); if (!sampler.isSampling(spanChunkBo)) { diff --git a/collector/src/main/java/com/navercorp/pinpoint/collector/handler/grpc/GrpcSpanHandler.java b/collector/src/main/java/com/navercorp/pinpoint/collector/handler/grpc/GrpcSpanHandler.java index a75b2ffc34d9..8dd69e20f187 100644 --- a/collector/src/main/java/com/navercorp/pinpoint/collector/handler/grpc/GrpcSpanHandler.java +++ b/collector/src/main/java/com/navercorp/pinpoint/collector/handler/grpc/GrpcSpanHandler.java @@ -21,8 +21,10 @@ import com.navercorp.pinpoint.collector.sampler.Sampler; import com.navercorp.pinpoint.collector.sampler.SpanSamplerFactory; import com.navercorp.pinpoint.collector.service.ApplicationInfoService; +import com.navercorp.pinpoint.collector.service.ServiceInfoService; import com.navercorp.pinpoint.collector.service.TraceService; import com.navercorp.pinpoint.common.id.ApplicationId; +import com.navercorp.pinpoint.common.id.ServiceId; import com.navercorp.pinpoint.common.profiler.logging.ThrottledLogger; import com.navercorp.pinpoint.common.server.bo.BasicSpan; import com.navercorp.pinpoint.common.server.bo.SpanBo; @@ -63,6 +65,7 @@ public class GrpcSpanHandler implements SimpleHandler { private final AcceptedTimeService acceptedTimeService; private final ApplicationInfoService applicationInfoService; + private final ServiceInfoService serviceInfoService; private final Sampler sampler; @@ -71,11 +74,13 @@ public GrpcSpanHandler( GrpcSpanFactory spanFactory, AcceptedTimeService acceptedTimeService, SpanSamplerFactory spanSamplerFactory, - ApplicationInfoService applicationInfoService) { + ApplicationInfoService applicationInfoService, + ServiceInfoService serviceInfoService) { this.traceServices = Objects.requireNonNull(traceServices, "traceServices"); this.spanFactory = Objects.requireNonNull(spanFactory, "spanFactory"); this.acceptedTimeService = Objects.requireNonNull(acceptedTimeService, "acceptedTimeService"); this.applicationInfoService = Objects.requireNonNull(applicationInfoService, "applicationInfoService"); + this.serviceInfoService = Objects.requireNonNull(serviceInfoService, "serviceInfoService"); this.sampler = spanSamplerFactory.createBasicSpanSampler(); logger.info("TraceServices {}", Arrays.toString(traceServices)); @@ -98,7 +103,8 @@ private void handleSpan(PSpan span) { } final Header header = ServerContext.getAgentInfo(); - final ApplicationId applicationId = this.applicationInfoService.getApplicationId(header.getApplicationName()); + final ServiceId serviceId = this.serviceInfoService.getServiceId(header.getServiceName()); + final ApplicationId applicationId = this.applicationInfoService.getApplicationId(serviceId, header.getApplicationName()); final BindAttribute attribute = BindAttribute.of(header, applicationId, acceptedTimeService.getAcceptedTime()); final SpanBo spanBo = spanFactory.buildSpanBo(span, attribute); if (!sampler.isSampling(spanBo)) { diff --git a/collector/src/main/java/com/navercorp/pinpoint/collector/handler/grpc/GrpcSqlMetaDataHandler.java b/collector/src/main/java/com/navercorp/pinpoint/collector/handler/grpc/GrpcSqlMetaDataHandler.java index 34e60139bdb3..7fb9191746d0 100644 --- a/collector/src/main/java/com/navercorp/pinpoint/collector/handler/grpc/GrpcSqlMetaDataHandler.java +++ b/collector/src/main/java/com/navercorp/pinpoint/collector/handler/grpc/GrpcSqlMetaDataHandler.java @@ -19,12 +19,15 @@ import com.google.protobuf.GeneratedMessageV3; import com.navercorp.pinpoint.collector.handler.RequestResponseHandler; import com.navercorp.pinpoint.collector.service.SqlMetaDataService; +import com.navercorp.pinpoint.common.id.AgentId; import com.navercorp.pinpoint.common.server.bo.SqlMetaDataBo; +import com.navercorp.pinpoint.common.server.bo.SqlUidMetaDataBo; import com.navercorp.pinpoint.grpc.Header; import com.navercorp.pinpoint.grpc.MessageFormatUtils; import com.navercorp.pinpoint.grpc.server.ServerContext; import com.navercorp.pinpoint.grpc.trace.PResult; import com.navercorp.pinpoint.grpc.trace.PSqlMetaData; +import com.navercorp.pinpoint.grpc.trace.PSqlUidMetaData; import com.navercorp.pinpoint.io.request.ServerRequest; import com.navercorp.pinpoint.io.request.ServerResponse; import com.navercorp.pinpoint.thrift.io.DefaultTBaseLocator; @@ -91,12 +94,22 @@ private PResult handleSqlMetaData(PSqlMetaData sqlMetaData) { } private static SqlMetaDataBo mapSqlMetaDataBo(Header agentInfo, PSqlMetaData sqlMetaData) { - final String agentId = agentInfo.getAgentId(); + final AgentId agentId = agentInfo.getAgentId(); final long agentStartTime = agentInfo.getAgentStartTime(); final int sqlId = sqlMetaData.getSqlId(); final String sql = sqlMetaData.getSql(); - return new SqlMetaDataBo(agentId, agentStartTime, sqlId, sql); + return new SqlMetaDataBo(agentId.value(), agentStartTime, sqlId, sql); + } + + private static SqlUidMetaDataBo mapSqlUidMetaDataBo(Header agentInfo, PSqlUidMetaData sqlUidMetaData) { + final AgentId agentId = agentInfo.getAgentId(); + final long agentStartTime = agentInfo.getAgentStartTime(); + final String applicationName = agentInfo.getApplicationName(); + final byte[] sqlUid = sqlUidMetaData.getSqlUid().toByteArray(); + final String sql = sqlUidMetaData.getSql(); + + return new SqlUidMetaDataBo(agentId.value(), agentStartTime, applicationName, sqlUid, sql); } private static PResult newResult(boolean success) { diff --git a/collector/src/main/java/com/navercorp/pinpoint/collector/handler/grpc/GrpcSqlUidMetaDataHandler.java b/collector/src/main/java/com/navercorp/pinpoint/collector/handler/grpc/GrpcSqlUidMetaDataHandler.java index 0b3c49e69bc0..dc45136ef8c0 100644 --- a/collector/src/main/java/com/navercorp/pinpoint/collector/handler/grpc/GrpcSqlUidMetaDataHandler.java +++ b/collector/src/main/java/com/navercorp/pinpoint/collector/handler/grpc/GrpcSqlUidMetaDataHandler.java @@ -19,6 +19,7 @@ import com.google.protobuf.GeneratedMessageV3; import com.navercorp.pinpoint.collector.handler.RequestResponseHandler; import com.navercorp.pinpoint.collector.service.SqlUidMetaDataService; +import com.navercorp.pinpoint.common.id.AgentId; import com.navercorp.pinpoint.common.server.bo.SqlUidMetaDataBo; import com.navercorp.pinpoint.grpc.Header; import com.navercorp.pinpoint.grpc.MessageFormatUtils; @@ -88,13 +89,13 @@ private PResult handleSqlUidMetaData(PSqlUidMetaData sqlUidMetaData) { } private static SqlUidMetaDataBo mapSqlUidMetaDataBo(Header agentInfo, PSqlUidMetaData sqlUidMetaData) { - final String agentId = agentInfo.getAgentId(); + final AgentId agentId = agentInfo.getAgentId(); final long agentStartTime = agentInfo.getAgentStartTime(); final String applicationName = agentInfo.getApplicationName(); final byte[] sqlUid = sqlUidMetaData.getSqlUid().toByteArray(); final String sql = sqlUidMetaData.getSql(); - return new SqlUidMetaDataBo(agentId, agentStartTime, applicationName, sqlUid, sql); + return new SqlUidMetaDataBo(agentId.value(), agentStartTime, applicationName, sqlUid, sql); } private static PResult newResult(boolean success) { diff --git a/collector/src/main/java/com/navercorp/pinpoint/collector/handler/grpc/GrpcStringMetaDataHandler.java b/collector/src/main/java/com/navercorp/pinpoint/collector/handler/grpc/GrpcStringMetaDataHandler.java index d228a4ff8158..8426961ab17d 100644 --- a/collector/src/main/java/com/navercorp/pinpoint/collector/handler/grpc/GrpcStringMetaDataHandler.java +++ b/collector/src/main/java/com/navercorp/pinpoint/collector/handler/grpc/GrpcStringMetaDataHandler.java @@ -19,6 +19,7 @@ import com.google.protobuf.GeneratedMessageV3; import com.navercorp.pinpoint.collector.handler.RequestResponseHandler; import com.navercorp.pinpoint.collector.service.StringMetaDataService; +import com.navercorp.pinpoint.common.id.AgentId; import com.navercorp.pinpoint.common.server.bo.StringMetaDataBo; import com.navercorp.pinpoint.grpc.Header; import com.navercorp.pinpoint.grpc.MessageFormatUtils; @@ -41,7 +42,6 @@ @Service public class GrpcStringMetaDataHandler implements RequestResponseHandler { private final Logger logger = LogManager.getLogger(getClass()); - private final boolean isDebug = logger.isDebugEnabled(); private final StringMetaDataService stringMetaDataService; @@ -73,12 +73,12 @@ private PResult handleStringMetaData(final PStringMetaData stringMetaData) { try { final Header agentInfo = ServerContext.getAgentInfo(); - final String agentId = agentInfo.getAgentId(); + final AgentId agentId = agentInfo.getAgentId(); final long agentStartTime = agentInfo.getAgentStartTime(); final String stringValue = stringMetaData.getStringValue(); - final StringMetaDataBo stringMetaDataBo = new StringMetaDataBo(agentId, agentStartTime, + final StringMetaDataBo stringMetaDataBo = new StringMetaDataBo(agentId.value(), agentStartTime, stringMetaData.getStringId(), stringValue); stringMetaDataService.insert(stringMetaDataBo); diff --git a/collector/src/main/java/com/navercorp/pinpoint/collector/mapper/grpc/GrpcAgentInfoBoMapper.java b/collector/src/main/java/com/navercorp/pinpoint/collector/mapper/grpc/GrpcAgentInfoBoMapper.java index 66026283a6e6..62d0940d3d5a 100644 --- a/collector/src/main/java/com/navercorp/pinpoint/collector/mapper/grpc/GrpcAgentInfoBoMapper.java +++ b/collector/src/main/java/com/navercorp/pinpoint/collector/mapper/grpc/GrpcAgentInfoBoMapper.java @@ -17,7 +17,10 @@ package com.navercorp.pinpoint.collector.mapper.grpc; import com.navercorp.pinpoint.collector.service.ApplicationInfoService; +import com.navercorp.pinpoint.collector.service.ServiceInfoService; +import com.navercorp.pinpoint.common.id.AgentId; import com.navercorp.pinpoint.common.id.ApplicationId; +import com.navercorp.pinpoint.common.id.ServiceId; import com.navercorp.pinpoint.common.server.bo.AgentInfoBo; import com.navercorp.pinpoint.grpc.Header; import com.navercorp.pinpoint.grpc.trace.PAgentInfo; @@ -36,22 +39,28 @@ public class GrpcAgentInfoBoMapper { private final GrpcServerMetaDataBoMapper serverMetaDataBoMapper; private final GrpcJvmInfoBoMapper jvmInfoBoMapper; private final ApplicationInfoService applicationInfoService; + private final ServiceInfoService serviceInfoService; public GrpcAgentInfoBoMapper( GrpcServerMetaDataBoMapper serverMetaDataBoMapper, GrpcJvmInfoBoMapper jvmInfoBoMapper, - ApplicationInfoService applicationInfoService) { + ApplicationInfoService applicationInfoService, + ServiceInfoService serviceInfoService + ) { this.serverMetaDataBoMapper = Objects.requireNonNull(serverMetaDataBoMapper, "serverMetaDataBoMapper"); this.jvmInfoBoMapper = Objects.requireNonNull(jvmInfoBoMapper, "jvmInfoBoMapper"); this.applicationInfoService = Objects.requireNonNull(applicationInfoService, "applicationInfoService"); + this.serviceInfoService = Objects.requireNonNull(serviceInfoService, "serviceInfoService"); } public AgentInfoBo map(final PAgentInfo agentInfo, final Header header) { - final String agentId = header.getAgentId(); + final AgentId agentId = header.getAgentId(); final String agentName = header.getAgentName(); final String applicationName = header.getApplicationName(); - final ApplicationId applicationId = this.applicationInfoService.getApplicationId(applicationName); - this.applicationInfoService.ensureApplicationIdInverseIndexed(applicationName, applicationId); + final String serviceName = header.getServiceName(); + final ServiceId serviceId = this.serviceInfoService.getServiceId(serviceName); + final ApplicationId applicationId = this.applicationInfoService.getApplicationId(serviceId, applicationName); + this.applicationInfoService.ensureApplicationIdInverseIndexed(serviceId, applicationName, applicationId); final long startTime = header.getAgentStartTime(); final String hostName = agentInfo.getHostname(); @@ -73,6 +82,8 @@ public AgentInfoBo map(final PAgentInfo agentInfo, final Header header) { builder.setAgentName(agentName); builder.setApplicationName(applicationName); builder.setApplicationId(applicationId); + builder.setServiceName(serviceName); + builder.setServiceId(serviceId); builder.setServiceTypeCode(serviceType); builder.setPid(pid); builder.setVmVersion(vmVersion); diff --git a/collector/src/main/java/com/navercorp/pinpoint/collector/mapper/grpc/event/GrpcAgentEventBatchMapper.java b/collector/src/main/java/com/navercorp/pinpoint/collector/mapper/grpc/event/GrpcAgentEventBatchMapper.java index 8e6ea68b5ea4..c4692a876ec5 100644 --- a/collector/src/main/java/com/navercorp/pinpoint/collector/mapper/grpc/event/GrpcAgentEventBatchMapper.java +++ b/collector/src/main/java/com/navercorp/pinpoint/collector/mapper/grpc/event/GrpcAgentEventBatchMapper.java @@ -16,6 +16,7 @@ package com.navercorp.pinpoint.collector.mapper.grpc.event; +import com.navercorp.pinpoint.common.id.AgentId; import com.navercorp.pinpoint.common.server.bo.event.AgentEventBo; import com.navercorp.pinpoint.common.util.CollectionUtils; import com.navercorp.pinpoint.grpc.Header; @@ -42,7 +43,7 @@ public GrpcAgentEventBatchMapper(GrpcDeadlockEventBoMapper deadlockEventBoMapper } public List map(final PAgentStatBatch agentStatBatch, final Header header) { - final String agentId = header.getAgentId(); + final AgentId agentId = header.getAgentId(); final long startTimestamp = header.getAgentStartTime(); final List agentStats = agentStatBatch.getAgentStatList(); @@ -56,7 +57,7 @@ public List map(final PAgentStatBatch agentStatBatch, final Header final long timestamp = agentStat.getTimestamp(); final PDeadlock deadlock = agentStat.getDeadlock(); if (CollectionUtils.hasLength(deadlock.getThreadDumpList())) { - agentEventBoList.add(deadlockEventBoMapper.map(agentId, startTimestamp, timestamp, deadlock)); + agentEventBoList.add(deadlockEventBoMapper.map(agentId.value(), startTimestamp, timestamp, deadlock)); } } } diff --git a/collector/src/main/java/com/navercorp/pinpoint/collector/mapper/grpc/event/GrpcAgentEventMapper.java b/collector/src/main/java/com/navercorp/pinpoint/collector/mapper/grpc/event/GrpcAgentEventMapper.java index 60417756e155..2e993cb3dc24 100644 --- a/collector/src/main/java/com/navercorp/pinpoint/collector/mapper/grpc/event/GrpcAgentEventMapper.java +++ b/collector/src/main/java/com/navercorp/pinpoint/collector/mapper/grpc/event/GrpcAgentEventMapper.java @@ -16,6 +16,7 @@ package com.navercorp.pinpoint.collector.mapper.grpc.event; +import com.navercorp.pinpoint.common.id.AgentId; import com.navercorp.pinpoint.common.server.bo.event.AgentEventBo; import com.navercorp.pinpoint.common.util.CollectionUtils; import com.navercorp.pinpoint.grpc.Header; @@ -38,14 +39,14 @@ public GrpcAgentEventMapper(GrpcDeadlockEventBoMapper deadlockEventBoMapper) { } public AgentEventBo map(final PAgentStat agentStat, final Header header) { - final String agentId = header.getAgentId(); + final AgentId agentId = header.getAgentId(); final long startTimestamp = header.getAgentStartTime(); final long timestamp = agentStat.getTimestamp(); if (agentStat.hasDeadlock()) { final PDeadlock deadlock = agentStat.getDeadlock(); if (CollectionUtils.hasLength(deadlock.getThreadDumpList())) { - return deadlockEventBoMapper.map(agentId, startTimestamp, timestamp, deadlock); + return deadlockEventBoMapper.map(agentId.value(), startTimestamp, timestamp, deadlock); } } return null; diff --git a/collector/src/main/java/com/navercorp/pinpoint/collector/mapper/grpc/stat/GrpcAgentStatBatchMapper.java b/collector/src/main/java/com/navercorp/pinpoint/collector/mapper/grpc/stat/GrpcAgentStatBatchMapper.java index 5d84f0856dcc..45c1e4d29294 100644 --- a/collector/src/main/java/com/navercorp/pinpoint/collector/mapper/grpc/stat/GrpcAgentStatBatchMapper.java +++ b/collector/src/main/java/com/navercorp/pinpoint/collector/mapper/grpc/stat/GrpcAgentStatBatchMapper.java @@ -16,6 +16,7 @@ package com.navercorp.pinpoint.collector.mapper.grpc.stat; +import com.navercorp.pinpoint.common.id.AgentId; import com.navercorp.pinpoint.common.server.bo.stat.AgentStatBo; import com.navercorp.pinpoint.grpc.Header; import com.navercorp.pinpoint.grpc.trace.PAgentStat; @@ -42,10 +43,10 @@ public AgentStatBo map(final PAgentStatBatch agentStatBatch, final Header header return null; } final String applicationName = header.getApplicationName(); - final String agentId = header.getAgentId(); + final AgentId agentId = header.getAgentId(); final long startTimestamp = header.getAgentStartTime(); - final AgentStatBo.Builder builder = new AgentStatBo.Builder(applicationName, agentId, startTimestamp); + final AgentStatBo.Builder builder = new AgentStatBo.Builder(applicationName, agentId.value(), startTimestamp); for (PAgentStat agentStat : agentStatBatch.getAgentStatList()) { this.mapper.map(agentStat, builder); } diff --git a/collector/src/main/java/com/navercorp/pinpoint/collector/mapper/grpc/stat/GrpcAgentStatMapper.java b/collector/src/main/java/com/navercorp/pinpoint/collector/mapper/grpc/stat/GrpcAgentStatMapper.java index c1016742742c..89e072a6f165 100644 --- a/collector/src/main/java/com/navercorp/pinpoint/collector/mapper/grpc/stat/GrpcAgentStatMapper.java +++ b/collector/src/main/java/com/navercorp/pinpoint/collector/mapper/grpc/stat/GrpcAgentStatMapper.java @@ -16,12 +16,13 @@ package com.navercorp.pinpoint.collector.mapper.grpc.stat; +import com.navercorp.pinpoint.common.id.AgentId; import com.navercorp.pinpoint.common.server.bo.stat.AgentStatBo; import com.navercorp.pinpoint.grpc.Header; import com.navercorp.pinpoint.grpc.server.ServerContext; import com.navercorp.pinpoint.grpc.trace.PAgentStat; -import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; import org.springframework.stereotype.Component; import java.util.Objects; @@ -46,12 +47,12 @@ public AgentStatBo map(PAgentStat agentStat) { final Header agentInfo = ServerContext.getAgentInfo(); final String applicationName = agentInfo.getApplicationName(); - final String agentId = agentInfo.getAgentId(); + final AgentId agentId = agentInfo.getAgentId(); final long startTimestamp = agentInfo.getAgentStartTime(); - final AgentStatBo.Builder builder = AgentStatBo.newBuilder(applicationName, agentId, startTimestamp); + final AgentStatBo.Builder builder = AgentStatBo.newBuilder(applicationName, agentId.value(), startTimestamp); this.map(agentStat, builder); diff --git a/collector/src/main/java/com/navercorp/pinpoint/collector/mapper/grpc/stat/GrpcAgentUriStatMapper.java b/collector/src/main/java/com/navercorp/pinpoint/collector/mapper/grpc/stat/GrpcAgentUriStatMapper.java index 262bcf211c85..07b05caefc0d 100644 --- a/collector/src/main/java/com/navercorp/pinpoint/collector/mapper/grpc/stat/GrpcAgentUriStatMapper.java +++ b/collector/src/main/java/com/navercorp/pinpoint/collector/mapper/grpc/stat/GrpcAgentUriStatMapper.java @@ -16,6 +16,7 @@ package com.navercorp.pinpoint.collector.mapper.grpc.stat; +import com.navercorp.pinpoint.common.id.AgentId; import com.navercorp.pinpoint.common.server.bo.stat.AgentUriStatBo; import com.navercorp.pinpoint.common.server.bo.stat.EachUriStatBo; import com.navercorp.pinpoint.common.server.bo.stat.UriStatHistogram; @@ -24,7 +25,6 @@ import com.navercorp.pinpoint.grpc.trace.PAgentUriStat; import com.navercorp.pinpoint.grpc.trace.PEachUriStat; import com.navercorp.pinpoint.grpc.trace.PUriHistogram; - import org.springframework.stereotype.Component; import java.util.List; @@ -38,7 +38,7 @@ public class GrpcAgentUriStatMapper { public AgentUriStatBo map(final PAgentUriStat agentUriStat) { final Header agentInfo = ServerContext.getAgentInfo(); - final String agentId = agentInfo.getAgentId(); + final AgentId agentId = agentInfo.getAgentId(); final String applicationName = agentInfo.getApplicationName(); int bucketVersion = agentUriStat.getBucketVersion(); @@ -46,7 +46,7 @@ public AgentUriStatBo map(final PAgentUriStat agentUriStat) { AgentUriStatBo agentUriStatBo = new AgentUriStatBo(); agentUriStatBo.setServiceName(""); // TODO: add serviceName when available agentUriStatBo.setApplicationName(applicationName); - agentUriStatBo.setAgentId(agentId); + agentUriStatBo.setAgentId(agentId.value()); agentUriStatBo.setBucketVersion((byte) bucketVersion); List eachUriStatList = agentUriStat.getEachUriStatList(); diff --git a/collector/src/main/java/com/navercorp/pinpoint/collector/receiver/grpc/service/KeepAliveService.java b/collector/src/main/java/com/navercorp/pinpoint/collector/receiver/grpc/service/KeepAliveService.java index 14120f8c3250..95b209c8fba1 100644 --- a/collector/src/main/java/com/navercorp/pinpoint/collector/receiver/grpc/service/KeepAliveService.java +++ b/collector/src/main/java/com/navercorp/pinpoint/collector/receiver/grpc/service/KeepAliveService.java @@ -21,14 +21,14 @@ import com.navercorp.pinpoint.collector.service.async.AgentProperty; import com.navercorp.pinpoint.collector.service.async.DefaultAgentProperty; import com.navercorp.pinpoint.collector.util.ManagedAgentLifeCycle; +import com.navercorp.pinpoint.common.id.AgentId; import com.navercorp.pinpoint.common.server.util.AgentEventType; import com.navercorp.pinpoint.common.server.util.AgentLifeCycleState; import com.navercorp.pinpoint.grpc.Header; import com.navercorp.pinpoint.grpc.server.lifecycle.PingSession; import com.navercorp.pinpoint.grpc.server.lifecycle.PingSessionRegistry; - -import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; import java.util.Collection; import java.util.Objects; @@ -62,7 +62,7 @@ public void updateState() { private AgentProperty newChannelProperties(Header header, short serviceType) { final String applicationName = header.getApplicationName(); - final String agentId = header.getAgentId(); + final AgentId agentId = header.getAgentId(); final long agentStartTime = header.getAgentStartTime(); return new DefaultAgentProperty(applicationName, serviceType, agentId, agentStartTime, header.getProperties()); } diff --git a/collector/src/main/java/com/navercorp/pinpoint/collector/service/AgentInfoService.java b/collector/src/main/java/com/navercorp/pinpoint/collector/service/AgentInfoService.java index 43726b85fd04..8684f4c1dc94 100644 --- a/collector/src/main/java/com/navercorp/pinpoint/collector/service/AgentInfoService.java +++ b/collector/src/main/java/com/navercorp/pinpoint/collector/service/AgentInfoService.java @@ -18,9 +18,9 @@ import com.navercorp.pinpoint.collector.dao.AgentInfoDao; import com.navercorp.pinpoint.collector.dao.ApplicationIndexDao; +import com.navercorp.pinpoint.common.id.AgentId; import com.navercorp.pinpoint.common.server.bo.AgentInfoBo; import jakarta.validation.Valid; -import jakarta.validation.constraints.NotBlank; import jakarta.validation.constraints.PositiveOrZero; import org.springframework.stereotype.Service; import org.springframework.validation.annotation.Validated; @@ -37,20 +37,26 @@ public class AgentInfoService { private final AgentInfoDao agentInfoDao; - private final ApplicationIndexDao applicationIndexDao; + private final ServiceInfoService serviceInfoService; - public AgentInfoService(AgentInfoDao agentInfoDao, ApplicationIndexDao applicationIndexDao) { + public AgentInfoService( + AgentInfoDao agentInfoDao, + ApplicationIndexDao applicationIndexDao, + ServiceInfoService serviceInfoService + ) { this.agentInfoDao = Objects.requireNonNull(agentInfoDao, "agentInfoDao"); this.applicationIndexDao = Objects.requireNonNull(applicationIndexDao, "applicationIndexDao"); + this.serviceInfoService = Objects.requireNonNull(serviceInfoService, "serviceInfoService"); } public void insert(@Valid final AgentInfoBo agentInfoBo) { agentInfoDao.insert(agentInfoBo); applicationIndexDao.insert(agentInfoBo); + serviceInfoService.insertAgentInfo(agentInfoBo); } - public AgentInfoBo getAgentInfo(@NotBlank final String agentId, @PositiveOrZero final long timestamp) { + public AgentInfoBo getAgentInfo(AgentId agentId, @PositiveOrZero final long timestamp) { return agentInfoDao.getAgentInfo(agentId, timestamp); } } diff --git a/collector/src/main/java/com/navercorp/pinpoint/collector/service/ApplicationInfoService.java b/collector/src/main/java/com/navercorp/pinpoint/collector/service/ApplicationInfoService.java index 5320c0d1022c..57b5cc4956dc 100644 --- a/collector/src/main/java/com/navercorp/pinpoint/collector/service/ApplicationInfoService.java +++ b/collector/src/main/java/com/navercorp/pinpoint/collector/service/ApplicationInfoService.java @@ -18,6 +18,9 @@ import com.navercorp.pinpoint.collector.dao.ApplicationInfoDao; import com.navercorp.pinpoint.common.id.ApplicationId; +import com.navercorp.pinpoint.common.id.ServiceId; +import com.navercorp.pinpoint.common.server.bo.ApplicationInfo; +import com.navercorp.pinpoint.common.server.bo.ApplicationSelector; import com.navercorp.pinpoint.common.util.UuidUtils; import org.springframework.cache.annotation.Cacheable; import org.springframework.stereotype.Service; @@ -37,23 +40,26 @@ public ApplicationInfoService(ApplicationInfoDao applicationInfoDao) { } @Cacheable(value = "applicationNameById", key = "#applicationId") - public String getApplicationName(ApplicationId applicationId) { - return this.applicationInfoDao.getApplicationName(applicationId); + public ApplicationInfo getApplication(ApplicationId applicationId) { + return this.applicationInfoDao.getApplication(applicationId); } @Cacheable(value = "applicationIdByName", key = "#applicationName") - public ApplicationId getApplicationId(String applicationName) { - ApplicationId applicationId = this.applicationInfoDao.getApplicationId(applicationName); + public ApplicationId getApplicationId(ServiceId serviceId, String applicationName) { + ApplicationSelector tuple = new ApplicationSelector(serviceId, applicationName); + ApplicationId applicationId = this.applicationInfoDao.getApplicationId(tuple); if (applicationId != null) { return applicationId; } ApplicationId newApplicationId = ApplicationId.of(UuidUtils.createV4()); - return this.applicationInfoDao.putApplicationIdIfAbsent(applicationName, newApplicationId); + ApplicationInfo newApplication = new ApplicationInfo(newApplicationId, serviceId, applicationName); + return this.applicationInfoDao.putApplicationIdIfAbsent(newApplication); } - public void ensureApplicationIdInverseIndexed(String applicationName, ApplicationId applicationId) { - this.applicationInfoDao.ensureInverse(applicationName, applicationId); + public void ensureApplicationIdInverseIndexed(ServiceId serviceId, String applicationName, ApplicationId applicationId) { + ApplicationInfo application = new ApplicationInfo(applicationId, serviceId, applicationName); + this.applicationInfoDao.ensureInverse(application); } } diff --git a/collector/src/main/java/com/navercorp/pinpoint/collector/service/ChainServiceInfoService.java b/collector/src/main/java/com/navercorp/pinpoint/collector/service/ChainServiceInfoService.java new file mode 100644 index 000000000000..5fba9e06d479 --- /dev/null +++ b/collector/src/main/java/com/navercorp/pinpoint/collector/service/ChainServiceInfoService.java @@ -0,0 +1,68 @@ +/* + * Copyright 2024 NAVER Corp. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.navercorp.pinpoint.collector.service; + +import com.navercorp.pinpoint.common.id.ServiceId; +import com.navercorp.pinpoint.common.server.bo.AgentInfoBo; +import com.navercorp.pinpoint.common.server.bo.ServiceInfo; +import org.springframework.beans.factory.annotation.Qualifier; +import org.springframework.context.annotation.Primary; +import org.springframework.stereotype.Service; + +import java.util.Objects; + +/** + * @author youngjin.kim2 + */ +@Service +@Primary +public class ChainServiceInfoService implements ServiceInfoService { + + private final ServiceInfoService delegate; + private final ServiceInfoService staticServiceInfoService; + + public ChainServiceInfoService( + @Qualifier("serviceInfoServiceImpl") ServiceInfoService delegate, + @Qualifier("staticServiceInfoService") ServiceInfoService staticServiceInfoService + ) { + this.delegate = Objects.requireNonNull(delegate, "delegate"); + this.staticServiceInfoService = Objects.requireNonNull(staticServiceInfoService, "staticServiceInfoService"); + } + + @Override + public ServiceId getServiceId(String serviceName) { + ServiceId serviceId = staticServiceInfoService.getServiceId(serviceName); + if (serviceId != null) { + return serviceId; + } + return delegate.getServiceId(serviceName); + } + + @Override + public ServiceInfo getServiceInfo(ServiceId serviceId) { + ServiceInfo service = staticServiceInfoService.getServiceInfo(serviceId); + if (service != null) { + return service; + } + return delegate.getServiceInfo(serviceId); + } + + @Override + public void insertAgentInfo(AgentInfoBo agent) { + delegate.insertAgentInfo(agent); + } + +} diff --git a/collector/src/main/java/com/navercorp/pinpoint/collector/service/HbaseTraceService.java b/collector/src/main/java/com/navercorp/pinpoint/collector/service/HbaseTraceService.java index 91f20aa24191..498ed3f3a8f6 100644 --- a/collector/src/main/java/com/navercorp/pinpoint/collector/service/HbaseTraceService.java +++ b/collector/src/main/java/com/navercorp/pinpoint/collector/service/HbaseTraceService.java @@ -20,6 +20,7 @@ import com.navercorp.pinpoint.collector.dao.HostApplicationMapDao; import com.navercorp.pinpoint.collector.dao.TraceDao; import com.navercorp.pinpoint.collector.event.SpanStorePublisher; +import com.navercorp.pinpoint.common.id.AgentId; import com.navercorp.pinpoint.common.profiler.logging.ThrottledLogger; import com.navercorp.pinpoint.common.server.bo.SpanBo; import com.navercorp.pinpoint.common.server.bo.SpanChunkBo; @@ -86,7 +87,7 @@ public void insertSpanChunk(@Valid final SpanChunkBo spanChunkBo) { final List spanEventList = spanChunkBo.getSpanEventBoList(); if (spanEventList != null) { // TODO need to batch update later. - insertSpanEventList(spanEventList, applicationServiceType, spanChunkBo.getApplicationName(), spanChunkBo.getAgentId(), spanChunkBo.getEndPoint()); + insertSpanEventList(spanEventList, applicationServiceType, spanChunkBo.getApplicationName(), AgentId.unwrap(spanChunkBo.getAgentId()), spanChunkBo.getEndPoint()); } // TODO should be able to tell whether the span chunk is successfully inserted @@ -166,13 +167,13 @@ private void insertSpanStat(SpanBo span) { // create virtual queue node statisticsService.updateCaller(span.getAcceptorHost(), spanServiceType, span.getRemoteAddr(), span.getApplicationName(), applicationServiceType, span.getEndPoint(), span.getElapsed(), isError); - statisticsService.updateCallee(span.getApplicationName(), applicationServiceType, span.getAcceptorHost(), spanServiceType, span.getAgentId(), span.getElapsed(), isError); + statisticsService.updateCallee(span.getApplicationName(), applicationServiceType, span.getAcceptorHost(), spanServiceType, AgentId.unwrap(span.getAgentId()), span.getElapsed(), isError); } else { // create virtual user - statisticsService.updateCaller(span.getApplicationName(), ServiceType.USER, span.getAgentId(), span.getApplicationName(), applicationServiceType, span.getAgentId(), span.getElapsed(), isError); + statisticsService.updateCaller(span.getApplicationName(), ServiceType.USER, AgentId.unwrap(span.getAgentId()), span.getApplicationName(), applicationServiceType, AgentId.unwrap(span.getAgentId()), span.getElapsed(), isError); // update the span information of the current node (self) - statisticsService.updateCallee(span.getApplicationName(), applicationServiceType, span.getApplicationName(), ServiceType.USER, span.getAgentId(), span.getElapsed(), isError); + statisticsService.updateCallee(span.getApplicationName(), applicationServiceType, span.getApplicationName(), ServiceType.USER, AgentId.unwrap(span.getAgentId()), span.getElapsed(), isError); } bugCheck++; } @@ -199,7 +200,7 @@ private void insertSpanStat(SpanBo span) { } } - statisticsService.updateCallee(span.getApplicationName(), applicationServiceType, parentApplicationName, parentApplicationType, span.getAgentId(), span.getElapsed(), isError); + statisticsService.updateCallee(span.getApplicationName(), applicationServiceType, parentApplicationName, parentApplicationType, AgentId.unwrap(span.getAgentId()), span.getElapsed(), isError); bugCheck++; } @@ -208,7 +209,7 @@ private void insertSpanStat(SpanBo span) { // it is odd to record reversely, because of already recording the caller data at previous node. // the data may be different due to timeout or network error. - statisticsService.updateResponseTime(span.getApplicationName(), applicationServiceType, span.getAgentId(), span.getElapsed(), isError); + statisticsService.updateResponseTime(span.getApplicationName(), applicationServiceType, AgentId.unwrap(span.getAgentId()), span.getElapsed(), isError); if (bugCheck != 1) { logger.info("ambiguous span found(bug). span:{}", span); @@ -227,7 +228,7 @@ private void insertSpanEventStat(SpanBo span) { final ServiceType applicationServiceType = getApplicationServiceType(span); // TODO need to batch update later. - insertSpanEventList(spanEventList, applicationServiceType, span.getApplicationName(), span.getAgentId(), span.getEndPoint()); + insertSpanEventList(spanEventList, applicationServiceType, span.getApplicationName(), AgentId.unwrap(span.getAgentId()), span.getEndPoint()); } private void insertSpanEventList(List spanEventList, ServiceType applicationServiceType, String applicationName, String agentId, String endPoint) { diff --git a/collector/src/main/java/com/navercorp/pinpoint/collector/service/ServiceInfoService.java b/collector/src/main/java/com/navercorp/pinpoint/collector/service/ServiceInfoService.java new file mode 100644 index 000000000000..5152993d5312 --- /dev/null +++ b/collector/src/main/java/com/navercorp/pinpoint/collector/service/ServiceInfoService.java @@ -0,0 +1,33 @@ +/* + * Copyright 2024 NAVER Corp. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.navercorp.pinpoint.collector.service; + +import com.navercorp.pinpoint.common.id.ServiceId; +import com.navercorp.pinpoint.common.server.bo.AgentInfoBo; +import com.navercorp.pinpoint.common.server.bo.ServiceInfo; + +/** + * @author youngjin.kim2 + */ +public interface ServiceInfoService { + + ServiceId getServiceId(String serviceName); + + ServiceInfo getServiceInfo(ServiceId serviceId); + + void insertAgentInfo(AgentInfoBo agent); + +} diff --git a/collector/src/main/java/com/navercorp/pinpoint/collector/service/ServiceInfoServiceImpl.java b/collector/src/main/java/com/navercorp/pinpoint/collector/service/ServiceInfoServiceImpl.java new file mode 100644 index 000000000000..ac526a448418 --- /dev/null +++ b/collector/src/main/java/com/navercorp/pinpoint/collector/service/ServiceInfoServiceImpl.java @@ -0,0 +1,62 @@ +/* + * Copyright 2024 NAVER Corp. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.navercorp.pinpoint.collector.service; + +import com.navercorp.pinpoint.collector.dao.ServiceInfoDao; +import com.navercorp.pinpoint.common.id.ServiceId; +import com.navercorp.pinpoint.common.server.bo.AgentInfoBo; +import com.navercorp.pinpoint.common.server.bo.ServiceInfo; +import com.navercorp.pinpoint.common.util.UuidUtils; +import org.springframework.stereotype.Service; + +import java.util.Objects; + +/** + * @author youngjin.kim2 + */ +@Service +public class ServiceInfoServiceImpl implements ServiceInfoService { + + private final ServiceInfoDao serviceInfoDao; + + public ServiceInfoServiceImpl(ServiceInfoDao serviceInfoDao) { + this.serviceInfoDao = Objects.requireNonNull(serviceInfoDao, "serviceInfoDao"); + } + + @Override + public ServiceId getServiceId(String serviceName) { + ServiceId serviceId = this.serviceInfoDao.getServiceId(serviceName); + if (serviceId != null) { + return serviceId; + } + + ServiceId newServiceId = ServiceId.of(UuidUtils.createV4()); + return this.serviceInfoDao.putServiceIdIfAbsent(serviceName, newServiceId); + } + + @Override + public void insertAgentInfo(AgentInfoBo agent) { + ServiceId serviceId = agent.getServiceId(); + String serviceName = agent.getServiceName(); + this.serviceInfoDao.ensurePut(serviceName, serviceId); + } + + @Override + public ServiceInfo getServiceInfo(ServiceId serviceId) { + return this.serviceInfoDao.getServiceInfo(serviceId); + } + +} diff --git a/collector/src/main/java/com/navercorp/pinpoint/collector/service/StaticServiceInfoService.java b/collector/src/main/java/com/navercorp/pinpoint/collector/service/StaticServiceInfoService.java new file mode 100644 index 000000000000..199b96269458 --- /dev/null +++ b/collector/src/main/java/com/navercorp/pinpoint/collector/service/StaticServiceInfoService.java @@ -0,0 +1,58 @@ +/* + * Copyright 2024 NAVER Corp. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.navercorp.pinpoint.collector.service; + +import com.navercorp.pinpoint.common.id.ServiceId; +import com.navercorp.pinpoint.common.server.bo.AgentInfoBo; +import com.navercorp.pinpoint.common.server.bo.ServiceInfo; +import org.springframework.stereotype.Service; + +/** + * @author youngjin.kim2 + */ +@Service +public class StaticServiceInfoService implements ServiceInfoService { + + private static final ServiceInfo[] reservations = new ServiceInfo[] { + new ServiceInfo(ServiceId.DEFAULT_ID, ServiceId.DEFAULT_SERVICE_NAME), + }; + + @Override + public ServiceId getServiceId(String serviceName) { + for (ServiceInfo reservation : reservations) { + if (reservation.name().equals(serviceName)) { + return reservation.id(); + } + } + return null; + } + + @Override + public ServiceInfo getServiceInfo(ServiceId serviceId) { + for (ServiceInfo reservation : reservations) { + if (reservation.id().equals(serviceId)) { + return reservation; + } + } + return null; + } + + @Override + public void insertAgentInfo(AgentInfoBo agent) { + throw new UnsupportedOperationException("insertAgentInfo"); + } + +} diff --git a/collector/src/main/java/com/navercorp/pinpoint/collector/service/async/AgentEventAsyncTaskService.java b/collector/src/main/java/com/navercorp/pinpoint/collector/service/async/AgentEventAsyncTaskService.java index 39c91ad89764..ea77e16196db 100644 --- a/collector/src/main/java/com/navercorp/pinpoint/collector/service/async/AgentEventAsyncTaskService.java +++ b/collector/src/main/java/com/navercorp/pinpoint/collector/service/async/AgentEventAsyncTaskService.java @@ -17,10 +17,11 @@ package com.navercorp.pinpoint.collector.service.async; import com.navercorp.pinpoint.collector.service.AgentEventService; +import com.navercorp.pinpoint.common.id.AgentId; import com.navercorp.pinpoint.common.server.bo.event.AgentEventBo; import com.navercorp.pinpoint.common.server.util.AgentEventType; -import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; import org.springframework.scheduling.annotation.Async; import org.springframework.stereotype.Service; @@ -45,9 +46,9 @@ public void handleEvent(final AgentProperty agentProperty, long eventTimestamp, Objects.requireNonNull(agentProperty, "agentProperty"); Objects.requireNonNull(eventType, "eventType"); - final String agentId = agentProperty.getAgentId(); + final AgentId agentId = agentProperty.getAgentId(); final long startTimestamp = agentProperty.getStartTime(); - final AgentEventBo agentEventBo = newAgentEventBo(agentId, startTimestamp, eventTimestamp, eventType); + final AgentEventBo agentEventBo = newAgentEventBo(agentId.value(), startTimestamp, eventTimestamp, eventType); this.agentEventService.insert(agentEventBo); } diff --git a/collector/src/main/java/com/navercorp/pinpoint/collector/service/async/AgentLifeCycleAsyncTaskService.java b/collector/src/main/java/com/navercorp/pinpoint/collector/service/async/AgentLifeCycleAsyncTaskService.java index 973228f73cfd..b924d43034f4 100644 --- a/collector/src/main/java/com/navercorp/pinpoint/collector/service/async/AgentLifeCycleAsyncTaskService.java +++ b/collector/src/main/java/com/navercorp/pinpoint/collector/service/async/AgentLifeCycleAsyncTaskService.java @@ -19,6 +19,7 @@ import com.navercorp.pinpoint.collector.config.CollectorProperties; import com.navercorp.pinpoint.collector.service.AgentLifeCycleService; import com.navercorp.pinpoint.collector.service.StatisticsService; +import com.navercorp.pinpoint.common.id.AgentId; import com.navercorp.pinpoint.common.server.bo.AgentLifeCycleBo; import com.navercorp.pinpoint.common.server.util.AgentLifeCycleState; import com.navercorp.pinpoint.common.trace.ServiceType; @@ -60,7 +61,7 @@ public void handleLifeCycleEvent(AgentProperty agentProperty, long eventTimestam Objects.requireNonNull(agentProperty, "agentProperty"); Objects.requireNonNull(agentLifeCycleState, "agentLifeCycleState"); - final String agentId = agentProperty.getAgentId(); + final AgentId agentId = agentProperty.getAgentId(); if (agentId == null) { logger.warn("Failed to handle event of agent life cycle, agentId is null. agentProperty={}", agentProperty); return; @@ -72,12 +73,12 @@ public void handleLifeCycleEvent(AgentProperty agentProperty, long eventTimestam } final long startTimestamp = agentProperty.getStartTime(); - final AgentLifeCycleBo agentLifeCycleBo = new AgentLifeCycleBo(agentId, startTimestamp, eventTimestamp, eventIdentifier, agentLifeCycleState); + final AgentLifeCycleBo agentLifeCycleBo = new AgentLifeCycleBo(agentId.value(), startTimestamp, eventTimestamp, eventIdentifier, agentLifeCycleState); agentLifeCycleService.insert(agentLifeCycleBo); final ServiceType serviceType = registry.findServiceType(agentProperty.getServiceType()); if (isUpdateAgentState(serviceType)) { - statisticsService.updateAgentState(applicationName, serviceType, agentId); + statisticsService.updateAgentState(applicationName, serviceType, agentId.value()); } } @@ -85,7 +86,7 @@ public void handleLifeCycleEvent(AgentProperty agentProperty, long eventTimestam public void handlePingEvent(AgentProperty agentProperty) { Objects.requireNonNull(agentProperty, "agentProperty"); - final String agentId = agentProperty.getAgentId(); + final AgentId agentId = agentProperty.getAgentId(); if (agentId == null) { logger.warn("Failed to handle event of agent ping, agentId is null. agentProperty={}", agentProperty); return; @@ -99,7 +100,7 @@ public void handlePingEvent(AgentProperty agentProperty) { final ServiceType serviceType = registry.findServiceType(agentProperty.getServiceType()); if (isUpdateAgentState(serviceType)) { - statisticsService.updateAgentState(applicationName, serviceType, agentId); + statisticsService.updateAgentState(applicationName, serviceType, agentId.value()); } } diff --git a/collector/src/main/java/com/navercorp/pinpoint/collector/service/async/AgentProperty.java b/collector/src/main/java/com/navercorp/pinpoint/collector/service/async/AgentProperty.java index 6e4726e18374..7aa0933bcc53 100644 --- a/collector/src/main/java/com/navercorp/pinpoint/collector/service/async/AgentProperty.java +++ b/collector/src/main/java/com/navercorp/pinpoint/collector/service/async/AgentProperty.java @@ -16,13 +16,15 @@ package com.navercorp.pinpoint.collector.service.async; +import com.navercorp.pinpoint.common.id.AgentId; + /** * @author Woonduk Kang(emeroad) * @author jaehong.kim */ public interface AgentProperty { String getApplicationName(); - String getAgentId(); + AgentId getAgentId(); long getStartTime(); Object get(String key); short getServiceType(); diff --git a/collector/src/main/java/com/navercorp/pinpoint/collector/service/async/AgentPropertyChannelAdaptor.java b/collector/src/main/java/com/navercorp/pinpoint/collector/service/async/AgentPropertyChannelAdaptor.java index d87ce4722c0e..3472b851009d 100644 --- a/collector/src/main/java/com/navercorp/pinpoint/collector/service/async/AgentPropertyChannelAdaptor.java +++ b/collector/src/main/java/com/navercorp/pinpoint/collector/service/async/AgentPropertyChannelAdaptor.java @@ -16,6 +16,7 @@ package com.navercorp.pinpoint.collector.service.async; +import com.navercorp.pinpoint.common.id.AgentId; import com.navercorp.pinpoint.rpc.server.ChannelProperties; import java.util.Objects; @@ -38,8 +39,8 @@ public String getApplicationName() { } @Override - public String getAgentId() { - return channelProperties.getAgentId(); + public AgentId getAgentId() { + return AgentId.of(channelProperties.getAgentId()); } @Override @@ -59,9 +60,7 @@ public short getServiceType() { @Override public String toString() { - final StringBuilder sb = new StringBuilder("AgentPropertyChannelAdaptor{"); - sb.append("channelProperties=").append(channelProperties); - sb.append('}'); - return sb.toString(); + return "AgentPropertyChannelAdaptor{" + "channelProperties=" + channelProperties + + '}'; } } \ No newline at end of file diff --git a/collector/src/main/java/com/navercorp/pinpoint/collector/service/async/DefaultAgentProperty.java b/collector/src/main/java/com/navercorp/pinpoint/collector/service/async/DefaultAgentProperty.java index 1ca6283de879..3b9eed9e4f75 100644 --- a/collector/src/main/java/com/navercorp/pinpoint/collector/service/async/DefaultAgentProperty.java +++ b/collector/src/main/java/com/navercorp/pinpoint/collector/service/async/DefaultAgentProperty.java @@ -16,6 +16,8 @@ package com.navercorp.pinpoint.collector.service.async; +import com.navercorp.pinpoint.common.id.AgentId; + import java.util.Map; import java.util.Objects; @@ -25,12 +27,12 @@ */ public class DefaultAgentProperty implements AgentProperty { private final String applicationName; - private final String agentId; + private final AgentId agentId; private final long agentStartTime; private final Map properties; private final short serviceType; - public DefaultAgentProperty(String applicationName, short serviceType, String agentId, long agentStartTime, Map properties) { + public DefaultAgentProperty(String applicationName, short serviceType, AgentId agentId, long agentStartTime, Map properties) { this.applicationName = Objects.requireNonNull(applicationName, "applicationName"); this.serviceType = serviceType; this.agentId = Objects.requireNonNull(agentId, "agentId"); @@ -49,7 +51,7 @@ public short getServiceType() { } @Override - public String getAgentId() { + public AgentId getAgentId() { return agentId; } @@ -65,13 +67,11 @@ public Object get(String key) { @Override public String toString() { - final StringBuilder sb = new StringBuilder("DefaultAgentProperty{"); - sb.append("applicationName='").append(applicationName).append('\''); - sb.append(", agentId='").append(agentId).append('\''); - sb.append(", agentStartTime=").append(agentStartTime); - sb.append(", properties=").append(properties); - sb.append(", serviceType=").append(serviceType); - sb.append('}'); - return sb.toString(); + return "DefaultAgentProperty{" + "applicationName='" + applicationName + '\'' + + ", agentId='" + agentId + '\'' + + ", agentStartTime=" + agentStartTime + + ", properties=" + properties + + ", serviceType=" + serviceType + + '}'; } } diff --git a/collector/src/main/java/com/navercorp/pinpoint/collector/util/CollectorUtils.java b/collector/src/main/java/com/navercorp/pinpoint/collector/util/CollectorUtils.java index 64243cd6ebac..b337a4de4f39 100644 --- a/collector/src/main/java/com/navercorp/pinpoint/collector/util/CollectorUtils.java +++ b/collector/src/main/java/com/navercorp/pinpoint/collector/util/CollectorUtils.java @@ -17,6 +17,7 @@ package com.navercorp.pinpoint.collector.util; import com.navercorp.pinpoint.common.PinpointConstants; +import com.navercorp.pinpoint.common.id.AgentId; import com.navercorp.pinpoint.common.util.IdValidateUtils; import com.navercorp.pinpoint.common.util.StringUtils; @@ -50,6 +51,10 @@ public static String getHumanFriendlyServerIdentifier() { return hostName + "@" + pid; } + public static void checkAgentId(final AgentId agentId) { + checkAgentId(agentId.value()); + } + public static void checkAgentId(final String agentId) { if (!IdValidateUtils.validateId(agentId)) { throw new IllegalArgumentException("invalid agentId. agentId=" + agentId); diff --git a/collector/src/test/java/com/navercorp/pinpoint/collector/dao/hbase/encode/ApplicationIndexRowKeyEncoderV2Test.java b/collector/src/test/java/com/navercorp/pinpoint/collector/dao/hbase/encode/ApplicationIndexRowKeyEncoderV2Test.java index 6f249be0109a..e5a2015853af 100644 --- a/collector/src/test/java/com/navercorp/pinpoint/collector/dao/hbase/encode/ApplicationIndexRowKeyEncoderV2Test.java +++ b/collector/src/test/java/com/navercorp/pinpoint/collector/dao/hbase/encode/ApplicationIndexRowKeyEncoderV2Test.java @@ -18,6 +18,7 @@ package com.navercorp.pinpoint.collector.dao.hbase.encode; import com.navercorp.pinpoint.common.PinpointConstants; +import com.navercorp.pinpoint.common.id.ApplicationId; import com.sematext.hbase.wd.AbstractRowKeyDistributor; import com.sematext.hbase.wd.RowKeyDistributorByHashPrefix; import org.apache.hadoop.hbase.util.Bytes; @@ -46,8 +47,7 @@ private AbstractRowKeyDistributor applicationTraceIndexDistributor() { @Test void newRowKey() { - - byte[] rowKey = encoder.newRowKey(new UUID(100, 100), 100, (byte) 10); + byte[] rowKey = encoder.newRowKey(ApplicationId.of(new UUID(100, 100)), 100, (byte) 10); int fuzzySize = PinpointConstants.APPLICATION_NAME_MAX_LEN + Bytes.SIZEOF_LONG + 1; assertThat(rowKey).hasSize(fuzzySize); diff --git a/collector/src/test/java/com/navercorp/pinpoint/collector/handler/grpc/GrpcAgentUriMetricHandlerV2Test.java b/collector/src/test/java/com/navercorp/pinpoint/collector/handler/grpc/GrpcAgentUriMetricHandlerV2Test.java index 8bc276c376fe..73fa80ddf3e4 100644 --- a/collector/src/test/java/com/navercorp/pinpoint/collector/handler/grpc/GrpcAgentUriMetricHandlerV2Test.java +++ b/collector/src/test/java/com/navercorp/pinpoint/collector/handler/grpc/GrpcAgentUriMetricHandlerV2Test.java @@ -26,6 +26,7 @@ import com.navercorp.pinpoint.collector.mapper.grpc.stat.GrpcAgentUriStatMapper; import com.navercorp.pinpoint.collector.service.AgentStatService; import com.navercorp.pinpoint.collector.service.AgentUriStatService; +import com.navercorp.pinpoint.common.id.AgentId; import com.navercorp.pinpoint.common.trace.ServiceType; import com.navercorp.pinpoint.common.trace.UriStatHistogramBucket; import com.navercorp.pinpoint.grpc.Header; @@ -95,7 +96,8 @@ public void skipTest() { public void handleTest() { AgentUriStatService mockAgentUriStatService = mock(AgentUriStatService.class); - attachContext(new Header("name", "agentId", "agentName", "applicationName", ServiceType.UNKNOWN.getCode(), System.currentTimeMillis(), Header.SOCKET_ID_NOT_EXIST, new ArrayList<>())); + attachContext(new Header("name", AgentId.of("agentId"), "agentName", "applicationName", "serviceName", + ServiceType.UNKNOWN.getCode(), System.currentTimeMillis(), Header.SOCKET_ID_NOT_EXIST, new ArrayList<>())); PAgentUriStat pAgentUriStat = createPAgentUriStat(); diff --git a/collector/src/test/java/com/navercorp/pinpoint/collector/handler/grpc/GrpcApiMetaDataHandlerTest.java b/collector/src/test/java/com/navercorp/pinpoint/collector/handler/grpc/GrpcApiMetaDataHandlerTest.java index 97a36fb1c259..40ba50ba6dca 100644 --- a/collector/src/test/java/com/navercorp/pinpoint/collector/handler/grpc/GrpcApiMetaDataHandlerTest.java +++ b/collector/src/test/java/com/navercorp/pinpoint/collector/handler/grpc/GrpcApiMetaDataHandlerTest.java @@ -1,6 +1,7 @@ package com.navercorp.pinpoint.collector.handler.grpc; import com.navercorp.pinpoint.collector.service.ApiMetaDataService; +import com.navercorp.pinpoint.common.id.AgentId; import com.navercorp.pinpoint.common.server.bo.ApiMetaDataBo; import com.navercorp.pinpoint.common.server.bo.MethodTypeEnum; import com.navercorp.pinpoint.grpc.Header; @@ -34,7 +35,7 @@ public void stubToApiMetaData() { .setLocation("/Users/workspace/pinpoint/@pinpoint-naver-apm/pinpoint-agent-node/samples/express/src/routes/index.js") .build(); - Header header = new Header("name", "express-node-sample-id", "agentName", "applicationName", 0, 1668495162817L, 0, Collections.emptyList()); + Header header = new Header("name", AgentId.of("express-node-sample-id"), "agentName", "applicationName", "serviceName", 0, 1668495162817L, 0, Collections.emptyList()); Context headerContext = Context.current().withValue(ServerContext.AGENT_INFO_KEY, header); headerContext.run(new Runnable() { @Override diff --git a/collector/src/test/java/com/navercorp/pinpoint/collector/receiver/grpc/AgentClientMock.java b/collector/src/test/java/com/navercorp/pinpoint/collector/receiver/grpc/AgentClientMock.java index 5a0e5a72a10e..1b0352fa773d 100644 --- a/collector/src/test/java/com/navercorp/pinpoint/collector/receiver/grpc/AgentClientMock.java +++ b/collector/src/test/java/com/navercorp/pinpoint/collector/receiver/grpc/AgentClientMock.java @@ -16,6 +16,7 @@ package com.navercorp.pinpoint.collector.receiver.grpc; +import com.navercorp.pinpoint.common.id.AgentId; import com.navercorp.pinpoint.common.trace.ServiceType; import com.navercorp.pinpoint.grpc.AgentHeaderFactory; import com.navercorp.pinpoint.grpc.client.HeaderFactory; @@ -66,7 +67,7 @@ public AgentClientMock(final String host, final int port, final boolean agentHea NettyChannelBuilder builder = NettyChannelBuilder.forAddress(host, port); if (agentHeader) { - HeaderFactory headerFactory = new AgentHeaderFactory("mockAgentId", "mockAgentName", "mockApplicationName", ServiceType.UNDEFINED.getCode(), System.currentTimeMillis()); + HeaderFactory headerFactory = new AgentHeaderFactory(AgentId.of("mockAgentId"), "mockAgentName", "mockApplicationName", "mockServiceName", ServiceType.UNDEFINED.getCode(), System.currentTimeMillis()); final Metadata extraHeaders = headerFactory.newHeader(); final ClientInterceptor headersInterceptor = MetadataUtils.newAttachHeadersInterceptor(extraHeaders); builder.intercept(headersInterceptor); diff --git a/collector/src/test/java/com/navercorp/pinpoint/collector/receiver/grpc/MetadataClientMock.java b/collector/src/test/java/com/navercorp/pinpoint/collector/receiver/grpc/MetadataClientMock.java index 6bdb7c43ca88..2874bff3cb22 100644 --- a/collector/src/test/java/com/navercorp/pinpoint/collector/receiver/grpc/MetadataClientMock.java +++ b/collector/src/test/java/com/navercorp/pinpoint/collector/receiver/grpc/MetadataClientMock.java @@ -18,6 +18,7 @@ import com.google.common.util.concurrent.Uninterruptibles; import com.google.protobuf.GeneratedMessageV3; +import com.navercorp.pinpoint.common.id.AgentId; import com.navercorp.pinpoint.common.profiler.concurrent.PinpointThreadFactory; import com.navercorp.pinpoint.common.trace.ServiceType; import com.navercorp.pinpoint.grpc.AgentHeaderFactory; @@ -44,9 +45,7 @@ import java.util.ArrayList; import java.util.List; -import java.util.concurrent.Executors; import java.util.concurrent.RejectedExecutionException; -import java.util.concurrent.ScheduledExecutorService; import java.util.concurrent.ThreadFactory; import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicInteger; @@ -55,8 +54,6 @@ public class MetadataClientMock { private static final int MAX_TOTAL_ATTEMPTS = 3; - private static final ScheduledExecutorService RECONNECT_SCHEDULER - = Executors.newScheduledThreadPool(1, new PinpointThreadFactory("Pinpoint-reconnect-thread")); private final Logger logger = LogManager.getLogger(this.getClass()); @@ -67,18 +64,15 @@ public class MetadataClientMock { private final MetadataGrpc.MetadataStub metadataStub; private final AtomicInteger requestCounter = new AtomicInteger(0); - private final AtomicInteger responseCounter = new AtomicInteger(0); private final List responseList = new ArrayList<>(); - public MetadataClientMock(final String host, final int port, final boolean agentHeader) { - - + public MetadataClientMock(final String host, final int port) { this.retryTimer = newTimer(this.getClass().getName()); this.channelFactory = newChannelFactory(); this.channel = channelFactory.build(host, port); this.metadataStub = MetadataGrpc.newStub(channel); - this.retryScheduler = new RetryScheduler() { + this.retryScheduler = new RetryScheduler<>() { @Override public boolean isSuccess(PResult response) { return response.getSuccess(); @@ -92,7 +86,7 @@ public void scheduleNextRetry(GeneratedMessageV3 request, int remainingRetryCoun } private ChannelFactory newChannelFactory() { - HeaderFactory headerFactory = new AgentHeaderFactory("mockAgentId", "mockAgentName", "mockApplicationName", ServiceType.UNDEFINED.getCode(), System.currentTimeMillis()); + HeaderFactory headerFactory = new AgentHeaderFactory(AgentId.of("mockAgentId"), "mockAgentName", "mockApplicationName", "mockServiceName", ServiceType.UNDEFINED.getCode(), System.currentTimeMillis()); ChannelFactoryBuilder channelFactoryBuilder = new DefaultChannelFactoryBuilder("MetadataClientMock"); channelFactoryBuilder.setHeaderFactory(headerFactory); channelFactoryBuilder.setClientOption(new ClientOption()); @@ -114,10 +108,6 @@ private Timer newTimer(String name) { return new HashedWheelTimer(threadFactory, 100, TimeUnit.MILLISECONDS, 512, false, 100); } - public void apiMetaData() { - apiMetaData(1); - } - public void apiMetaData(final int count) { for (int i = 0; i < count; i++) { PApiMetaData request = PApiMetaData.newBuilder().setApiId(i).build(); diff --git a/collector/src/test/java/com/navercorp/pinpoint/collector/receiver/grpc/MetadataClientTestMain.java b/collector/src/test/java/com/navercorp/pinpoint/collector/receiver/grpc/MetadataClientTestMain.java index c7885773a924..3180705d17af 100644 --- a/collector/src/test/java/com/navercorp/pinpoint/collector/receiver/grpc/MetadataClientTestMain.java +++ b/collector/src/test/java/com/navercorp/pinpoint/collector/receiver/grpc/MetadataClientTestMain.java @@ -26,7 +26,7 @@ public class MetadataClientTestMain { public static void main(String[] args) { - MetadataClientMock clientMock = new MetadataClientMock("localhost", 9997, true); + MetadataClientMock clientMock = new MetadataClientMock("localhost", 9997); clientMock.apiMetaData(100); Uninterruptibles.sleepUninterruptibly(60, SECONDS); diff --git a/collector/src/test/java/com/navercorp/pinpoint/collector/receiver/grpc/SpanClientMock.java b/collector/src/test/java/com/navercorp/pinpoint/collector/receiver/grpc/SpanClientMock.java index 9e8efa57ffef..dddea21b9ac5 100644 --- a/collector/src/test/java/com/navercorp/pinpoint/collector/receiver/grpc/SpanClientMock.java +++ b/collector/src/test/java/com/navercorp/pinpoint/collector/receiver/grpc/SpanClientMock.java @@ -18,6 +18,7 @@ import com.google.protobuf.ByteString; import com.google.protobuf.Empty; +import com.navercorp.pinpoint.common.id.AgentId; import com.navercorp.pinpoint.common.trace.ServiceType; import com.navercorp.pinpoint.grpc.AgentHeaderFactory; import com.navercorp.pinpoint.grpc.client.ChannelFactory; @@ -61,8 +62,6 @@ public class SpanClientMock { private final ScheduledExecutorService scheduledExecutorService = Executors.newSingleThreadScheduledExecutor(); private final ReconnectExecutor reconnectExecutor = new ReconnectExecutor(scheduledExecutorService); - - private final ManagedChannel channel; private final SpanGrpc.SpanStub spanStub; private final ChannelFactory channelFactory; @@ -133,7 +132,7 @@ private StreamObserver newSpanStream() { System.out.println("NEW SpanStream"); System.out.println("###"); StreamId spanId = StreamId.newStreamId("SpanStream"); - StreamEventListener listener = new StreamEventListener() { + StreamEventListener listener = new StreamEventListener<>() { @Override public void start(ClientCallStreamObserver requestStream) { @@ -156,7 +155,7 @@ public void onCompleted() { private ChannelFactory newChannelFactory() { - HeaderFactory headerFactory = new AgentHeaderFactory("mockAgentId", "mockAgentName", "mockApplicationName", ServiceType.UNDEFINED.getCode(), System.currentTimeMillis()); + HeaderFactory headerFactory = new AgentHeaderFactory(AgentId.of("mockAgentId"), "mockAgentName", "mockApplicationName", "mockServiceName", ServiceType.UNDEFINED.getCode(), System.currentTimeMillis()); ChannelFactoryBuilder channelFactoryBuilder = new DefaultChannelFactoryBuilder("SpanClientMock"); final ClientInterceptor unaryCallDeadlineInterceptor = new UnaryCallDeadlineInterceptor(1000); diff --git a/collector/src/test/java/com/navercorp/pinpoint/collector/receiver/grpc/StatClientMock.java b/collector/src/test/java/com/navercorp/pinpoint/collector/receiver/grpc/StatClientMock.java index 96cb98a28c2e..c00747f695d7 100644 --- a/collector/src/test/java/com/navercorp/pinpoint/collector/receiver/grpc/StatClientMock.java +++ b/collector/src/test/java/com/navercorp/pinpoint/collector/receiver/grpc/StatClientMock.java @@ -17,6 +17,7 @@ package com.navercorp.pinpoint.collector.receiver.grpc; import com.google.protobuf.Empty; +import com.navercorp.pinpoint.common.id.AgentId; import com.navercorp.pinpoint.common.trace.ServiceType; import com.navercorp.pinpoint.grpc.AgentHeaderFactory; import com.navercorp.pinpoint.grpc.client.HeaderFactory; @@ -30,8 +31,8 @@ import io.grpc.netty.NettyChannelBuilder; import io.grpc.stub.MetadataUtils; import io.grpc.stub.StreamObserver; -import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; import java.util.concurrent.TimeUnit; @@ -43,7 +44,7 @@ public class StatClientMock { public StatClientMock(final String host, final int port) { NettyChannelBuilder builder = NettyChannelBuilder.forAddress(host, port); - HeaderFactory headerFactory = new AgentHeaderFactory("mockAgentId", "mockAgentName", "mockApplicationName", ServiceType.UNDEFINED.getCode(), System.currentTimeMillis()); + HeaderFactory headerFactory = new AgentHeaderFactory(AgentId.of("mockAgentId"), "mockAgentName", "mockApplicationName", "mockServiceName", ServiceType.UNDEFINED.getCode(), System.currentTimeMillis()); final Metadata extraHeaders = headerFactory.newHeader(); final ClientInterceptor headersInterceptor = MetadataUtils.newAttachHeadersInterceptor(extraHeaders); builder.intercept(headersInterceptor); diff --git a/collector/src/test/java/com/navercorp/pinpoint/collector/sampler/SimpleSpanFactoryTest.java b/collector/src/test/java/com/navercorp/pinpoint/collector/sampler/SimpleSpanFactoryTest.java index 1bf9c64cc3a9..8e645a8f168e 100644 --- a/collector/src/test/java/com/navercorp/pinpoint/collector/sampler/SimpleSpanFactoryTest.java +++ b/collector/src/test/java/com/navercorp/pinpoint/collector/sampler/SimpleSpanFactoryTest.java @@ -1,6 +1,7 @@ package com.navercorp.pinpoint.collector.sampler; import com.navercorp.pinpoint.collector.config.CollectorProperties; +import com.navercorp.pinpoint.common.id.AgentId; import com.navercorp.pinpoint.common.profiler.util.TransactionId; import com.navercorp.pinpoint.common.profiler.util.TransactionIdUtils; import com.navercorp.pinpoint.common.server.bo.BasicSpan; @@ -38,7 +39,7 @@ public void TransactionIdSampleTest() { SpanSamplerFactory spanSamplerFactory = new SimpleSpanSamplerFactory(mockProperties); Sampler sampler = spanSamplerFactory.createBasicSpanSampler(); - String agentId = "testAgentId"; + AgentId agentId = AgentId.of("testAgentId"); long time = System.currentTimeMillis(); SpanChunkBo mockSpanChunkBo = mock(SpanChunkBo.class); SpanBo mockSpanBo = mock(SpanBo.class); @@ -54,7 +55,7 @@ public void TransactionIdSampleTest() { verify(mockSpanChunkBo, atLeastOnce()).getTransactionId(); } - private TransactionId createTransactionId(String agentId, long agentStartTime, long sequenceId) { + private TransactionId createTransactionId(AgentId agentId, long agentStartTime, long sequenceId) { return TransactionIdUtils.parseTransactionId(TransactionIdUtils.formatString(agentId, agentStartTime, sequenceId)); } diff --git a/commons-hbase/src/main/java/com/navercorp/pinpoint/common/hbase/HbaseColumnFamily.java b/commons-hbase/src/main/java/com/navercorp/pinpoint/common/hbase/HbaseColumnFamily.java index 25fd9c91e494..b6dac4629e15 100644 --- a/commons-hbase/src/main/java/com/navercorp/pinpoint/common/hbase/HbaseColumnFamily.java +++ b/commons-hbase/src/main/java/com/navercorp/pinpoint/common/hbase/HbaseColumnFamily.java @@ -97,6 +97,14 @@ private ApplicationId(HbaseTable hBaseTable, byte[] columnFamilyName) { } } + public static final ServiceId SERVICE_ID_FORWARD = new ServiceId(HbaseTable.SERVICE_ID, Bytes.toBytes("F")); + public static final ServiceId SERVICE_ID_INVERSE = new ServiceId(HbaseTable.SERVICE_ID, Bytes.toBytes("I")); + public static class ServiceId extends HbaseColumnFamily { + private ServiceId(HbaseTable hBaseTable, byte[] columnFamilyName) { + super(hBaseTable, columnFamilyName); + } + } + public static final ApplicationStatStatistics APPLICATION_STAT_STATISTICS = new ApplicationStatStatistics(HbaseTable.APPLICATION_STAT_AGGRE, Bytes.toBytes("S")); public static class ApplicationStatStatistics extends HbaseColumnFamily { public int TIMESPAN_MS = 5 * 60 * 1000; diff --git a/commons-hbase/src/main/java/com/navercorp/pinpoint/common/hbase/HbaseTable.java b/commons-hbase/src/main/java/com/navercorp/pinpoint/common/hbase/HbaseTable.java index 5e8d05562d93..3485a0ef2b8c 100644 --- a/commons-hbase/src/main/java/com/navercorp/pinpoint/common/hbase/HbaseTable.java +++ b/commons-hbase/src/main/java/com/navercorp/pinpoint/common/hbase/HbaseTable.java @@ -31,6 +31,7 @@ public enum HbaseTable { APPLICATION_INDEX("ApplicationIndex"), APPLICATION_INDEX_VER2("ApplicationIndex_Ver2"), APPLICATION_ID("ApplicationId"), + SERVICE_ID("ServiceId"), APPLICATION_STAT_AGGRE("ApplicationStatAggre"), APPLICATION_TRACE_INDEX("ApplicationTraceIndex"), APPLICATION_TRACE_INDEX_VER2("ApplicationTraceIndex_Ver2"), diff --git a/commons-hbase/src/main/java/com/navercorp/pinpoint/common/hbase/util/CellUtils.java b/commons-hbase/src/main/java/com/navercorp/pinpoint/common/hbase/util/CellUtils.java index 8a9d8fdd0d97..b18b2df0952b 100644 --- a/commons-hbase/src/main/java/com/navercorp/pinpoint/common/hbase/util/CellUtils.java +++ b/commons-hbase/src/main/java/com/navercorp/pinpoint/common/hbase/util/CellUtils.java @@ -1,5 +1,7 @@ package com.navercorp.pinpoint.common.hbase.util; +import com.navercorp.pinpoint.common.buffer.Buffer; +import com.navercorp.pinpoint.common.buffer.OffsetFixedBuffer; import com.navercorp.pinpoint.common.util.ArrayUtils; import org.apache.hadoop.hbase.Cell; import org.apache.hadoop.hbase.CellUtil; @@ -7,6 +9,7 @@ import org.apache.hadoop.hbase.util.Bytes; import java.util.Objects; +import java.util.UUID; public final class CellUtils { private CellUtils() { @@ -52,6 +55,12 @@ public static String valueToString(Cell cell) { return Bytes.toString(cell.getValueArray(), cell.getValueOffset(), cell.getValueLength()); } + public static UUID valueToUUID(Cell cell) { + Objects.requireNonNull(cell, "cell"); + Buffer buffer = new OffsetFixedBuffer(cell.getValueArray(), cell.getValueOffset(), cell.getValueLength()); + return buffer.readUUID(); + } + public static Cell lastCell(Cell[] rawCells, byte[] columnFamily) { Cell last = null; diff --git a/commons-profiler/src/main/java/com/navercorp/pinpoint/common/profiler/util/TransactionId.java b/commons-profiler/src/main/java/com/navercorp/pinpoint/common/profiler/util/TransactionId.java index d2cca5c4525e..cd23f0b56d1e 100644 --- a/commons-profiler/src/main/java/com/navercorp/pinpoint/common/profiler/util/TransactionId.java +++ b/commons-profiler/src/main/java/com/navercorp/pinpoint/common/profiler/util/TransactionId.java @@ -16,6 +16,7 @@ package com.navercorp.pinpoint.common.profiler.util; +import com.navercorp.pinpoint.common.id.AgentId; import com.navercorp.pinpoint.common.util.IdValidateUtils; /** @@ -23,11 +24,15 @@ */ public class TransactionId { - private final String agentId; + private final AgentId agentId; private final long agentStartTime; private final long transactionSequence; public TransactionId(String agentId, long agentStartTime, long transactionSequence) { + this(AgentId.of(agentId), agentStartTime, transactionSequence); + } + + public TransactionId(AgentId agentId, long agentStartTime, long transactionSequence) { if (!IdValidateUtils.validateId(agentId)) { throw new IllegalArgumentException("invalid agentId"); } @@ -36,7 +41,7 @@ public TransactionId(String agentId, long agentStartTime, long transactionSequen this.transactionSequence = transactionSequence; } - public String getAgentId() { + public AgentId getAgentId() { return agentId; } @@ -58,9 +63,7 @@ public boolean equals(Object o) { if (agentStartTime != that.agentStartTime) return false; if (transactionSequence != that.transactionSequence) return false; - if (!agentId.equals(that.agentId)) return false; - - return true; + return agentId.equals(that.agentId); } @Override diff --git a/commons-profiler/src/main/java/com/navercorp/pinpoint/common/profiler/util/TransactionIdUtils.java b/commons-profiler/src/main/java/com/navercorp/pinpoint/common/profiler/util/TransactionIdUtils.java index 838f5f480963..323c11f3a4b0 100644 --- a/commons-profiler/src/main/java/com/navercorp/pinpoint/common/profiler/util/TransactionIdUtils.java +++ b/commons-profiler/src/main/java/com/navercorp/pinpoint/common/profiler/util/TransactionIdUtils.java @@ -19,6 +19,7 @@ import com.navercorp.pinpoint.common.PinpointConstants; import com.navercorp.pinpoint.common.buffer.Buffer; import com.navercorp.pinpoint.common.buffer.FixedBuffer; +import com.navercorp.pinpoint.common.id.AgentId; import com.navercorp.pinpoint.common.util.ArrayUtils; import com.navercorp.pinpoint.common.util.BytesUtils; import com.navercorp.pinpoint.common.util.IdValidateUtils; @@ -44,7 +45,7 @@ public static String formatString(TransactionId transactionId) { return formatString(transactionId.getAgentId(), transactionId.getAgentStartTime(), transactionId.getTransactionSequence()); } - public static String formatString(String agentId, long agentStartTime, long transactionSequence) { + public static String formatString(AgentId agentId, long agentStartTime, long transactionSequence) { Objects.requireNonNull(agentId, "agentId"); return agentId + @@ -54,19 +55,19 @@ public static String formatString(String agentId, long agentStartTime, long tran transactionSequence; } - public static byte[] formatBytes(String agentId, long agentStartTime, long transactionSequence) { + public static byte[] formatBytes(AgentId agentId, long agentStartTime, long transactionSequence) { return writeTransactionId(agentId, agentStartTime, transactionSequence); } - public static ByteBuffer formatByteBuffer(String agentId, long agentStartTime, long transactionSequence) { + public static ByteBuffer formatByteBuffer(AgentId agentId, long agentStartTime, long transactionSequence) { final byte[] buffer = writeTransactionId(agentId, agentStartTime, transactionSequence); return ByteBuffer.wrap(buffer); } - private static byte[] writeTransactionId(String agentId, long agentStartTime, long transactionSequence) { + private static byte[] writeTransactionId(AgentId agentId, long agentStartTime, long transactionSequence) { // agentId may be null // version + prefixed size + string + long + long - final byte[] agentIdBytes = BytesUtils.toBytes(agentId); + final byte[] agentIdBytes = toBytes(agentId); final int agentIdLength = ArrayUtils.getLength(agentIdBytes, Buffer.NULL); final int zigZagAgentIdLength = BytesUtils.intToZigZag(agentIdLength); final int agentIdPrefixSize = BytesUtils.computeVar32Size(zigZagAgentIdLength); @@ -88,7 +89,14 @@ private static byte[] writeTransactionId(String agentId, long agentStartTime, lo return buffer; } - public static TransactionId parseTransactionId(final byte[] transactionId, String defaultAgentId) { + private static byte[] toBytes(AgentId agentId) { + if (agentId == null) { + return null; + } + return BytesUtils.toBytes(agentId.value()); + } + + public static TransactionId parseTransactionId(final byte[] transactionId, AgentId defaultAgentId) { Objects.requireNonNull(transactionId, "transactionId"); final Buffer buffer = new FixedBuffer(transactionId); @@ -98,7 +106,7 @@ public static TransactionId parseTransactionId(final byte[] transactionId, Strin } String agentId = buffer.readPrefixedString(); - agentId = StringUtils.defaultString(agentId, defaultAgentId); + agentId = StringUtils.defaultString(agentId, defaultAgentId.value()); if (!IdValidateUtils.validateId(agentId)) { throw new IllegalArgumentException("invalid transactionId:" + Arrays.toString(transactionId)); } @@ -106,7 +114,7 @@ public static TransactionId parseTransactionId(final byte[] transactionId, Strin final long agentStartTime = buffer.readVLong(); final long transactionSequence = buffer.readVLong(); - return new TransactionId(agentId, agentStartTime,transactionSequence); + return new TransactionId(AgentId.of(agentId), agentStartTime,transactionSequence); } public static TransactionId parseTransactionId(final String transactionId) { @@ -122,7 +130,7 @@ public static TransactionId parseTransactionId(final String transactionId) { if (!IdValidateUtils.checkId(transactionId, 0, agentIdIndex)) { throw new IllegalArgumentException("invalid transactionId:" + transactionId); } - final String agentId = transactionId.substring(0, agentIdIndex); + final AgentId agentId = AgentId.of(transactionId.substring(0, agentIdIndex)); final int agentStartTimeIndex = nextIndex(transactionId, agentIdIndex + 1); if (agentStartTimeIndex == -1) { diff --git a/commons-profiler/src/test/java/com/navercorp/pinpoint/common/profiler/util/TransactionIdComparatorTest.java b/commons-profiler/src/test/java/com/navercorp/pinpoint/common/profiler/util/TransactionIdComparatorTest.java index 8b2aae1e1897..35d2f8eba1bd 100644 --- a/commons-profiler/src/test/java/com/navercorp/pinpoint/common/profiler/util/TransactionIdComparatorTest.java +++ b/commons-profiler/src/test/java/com/navercorp/pinpoint/common/profiler/util/TransactionIdComparatorTest.java @@ -16,6 +16,7 @@ package com.navercorp.pinpoint.common.profiler.util; +import com.navercorp.pinpoint.common.id.AgentId; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import org.junit.jupiter.api.Assertions; @@ -33,37 +34,37 @@ public class TransactionIdComparatorTest { @Test public void sameAll() { - TransactionId id1 = new TransactionId("A1", 1, 1); - TransactionId id2 = new TransactionId("A1", 1, 1); + TransactionId id1 = new TransactionId(AgentId.of("A1"), 1, 1); + TransactionId id2 = new TransactionId(AgentId.of("A1"), 1, 1); Assertions.assertEquals(0, comparator.compare(id1, id2)); } @Test public void diffAgentStartTimeAsc() { - TransactionId id1 = new TransactionId("A1", 1, 1); - TransactionId id2 = new TransactionId("A1", 2, 1); + TransactionId id1 = new TransactionId(AgentId.of("A1"), 1, 1); + TransactionId id2 = new TransactionId(AgentId.of("A1"), 2, 1); Assertions.assertEquals(-1, comparator.compare(id1, id2)); } @Test public void diffAgentStartTimeDesc() { - TransactionId id1 = new TransactionId("A1", 2, 1); - TransactionId id2 = new TransactionId("A1", 1, 1); + TransactionId id1 = new TransactionId(AgentId.of("A1"), 2, 1); + TransactionId id2 = new TransactionId(AgentId.of("A1"), 1, 1); Assertions.assertEquals(1, comparator.compare(id1, id2)); } @Test public void diffSeqAsc() { - TransactionId id1 = new TransactionId("A1", 1, 1); - TransactionId id2 = new TransactionId("A1", 1, 2); + TransactionId id1 = new TransactionId(AgentId.of("A1"), 1, 1); + TransactionId id2 = new TransactionId(AgentId.of("A1"), 1, 2); Assertions.assertEquals(-1, comparator.compare(id1, id2)); } @Test public void diffSeqDesc() { - TransactionId id1 = new TransactionId("A1", 1, 2); - TransactionId id2 = new TransactionId("A1", 1, 1); + TransactionId id1 = new TransactionId(AgentId.of("A1"), 1, 2); + TransactionId id2 = new TransactionId(AgentId.of("A1"), 1, 1); Assertions.assertEquals(1, comparator.compare(id1, id2)); } @@ -77,7 +78,7 @@ public void order() { List list = new ArrayList<>(); for (int i = 0; i < 10; i++) { - list.add(new TransactionId("A", 1, numbers.get(i))); + list.add(new TransactionId(AgentId.of("A"), 1, numbers.get(i))); } logger.debug("{}", list); diff --git a/commons-profiler/src/test/java/com/navercorp/pinpoint/common/profiler/util/TransactionIdUtilsTest.java b/commons-profiler/src/test/java/com/navercorp/pinpoint/common/profiler/util/TransactionIdUtilsTest.java index c3472e447cfe..de96a386022a 100644 --- a/commons-profiler/src/test/java/com/navercorp/pinpoint/common/profiler/util/TransactionIdUtilsTest.java +++ b/commons-profiler/src/test/java/com/navercorp/pinpoint/common/profiler/util/TransactionIdUtilsTest.java @@ -19,6 +19,7 @@ import com.navercorp.pinpoint.common.PinpointConstants; import com.navercorp.pinpoint.common.buffer.AutomaticBuffer; import com.navercorp.pinpoint.common.buffer.Buffer; +import com.navercorp.pinpoint.common.id.AgentId; import org.apache.commons.lang3.StringUtils; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; @@ -30,12 +31,12 @@ */ public class TransactionIdUtilsTest { - public static final String AGENT_ID = "test"; + public static final AgentId AGENT_ID = AgentId.of("test"); @Test public void testParseTransactionId() { TransactionId transactionId = TransactionIdUtils.parseTransactionId(AGENT_ID + TransactionIdUtils.TRANSACTION_ID_DELIMITER + "1" + TransactionIdUtils.TRANSACTION_ID_DELIMITER + "2"); - Assertions.assertEquals(transactionId.getAgentId(), "test"); + Assertions.assertEquals(transactionId.getAgentId().value(), "test"); Assertions.assertEquals(transactionId.getAgentStartTime(), 1L); Assertions.assertEquals(transactionId.getTransactionSequence(), 2L); } @@ -56,7 +57,7 @@ public void testParseTransactionId_RpcHeaderDuplicateAdd_BugReproduce() { String id1 = AGENT_ID + TransactionIdUtils.TRANSACTION_ID_DELIMITER + "1" + TransactionIdUtils.TRANSACTION_ID_DELIMITER + "2"; String id2 = AGENT_ID + TransactionIdUtils.TRANSACTION_ID_DELIMITER + "1" + TransactionIdUtils.TRANSACTION_ID_DELIMITER + "3"; TransactionId transactionId = TransactionIdUtils.parseTransactionId(id1 + ", " + id2); - Assertions.assertEquals(transactionId.getAgentId(), "test"); + Assertions.assertEquals(transactionId.getAgentId().value(), "test"); Assertions.assertEquals(transactionId.getAgentStartTime(), 1L); Assertions.assertEquals(transactionId.getTransactionSequence(), 2L); }); @@ -120,10 +121,10 @@ public void testParseTransactionIdByte_compatibility2() { } - private static ByteBuffer writeTransactionId_for_compatibility(String agentId, long agentStartTime, long transactionSequence) { + private static ByteBuffer writeTransactionId_for_compatibility(AgentId agentId, long agentStartTime, long transactionSequence) { final Buffer buffer = new AutomaticBuffer(1 + 5 + 24 + 10 + 10); buffer.putByte(TransactionIdUtils.VERSION); - buffer.putPrefixedString(agentId); + buffer.putPrefixedString(AgentId.unwrap(agentId)); buffer.putVLong(agentStartTime); buffer.putVLong(transactionSequence); return buffer.wrapByteBuffer(); @@ -138,7 +139,7 @@ public void validateAgentId() { @Test public void longAgentId() { - String agentId = StringUtils.repeat('a', PinpointConstants.AGENT_ID_MAX_LEN); + AgentId agentId = AgentId.of(StringUtils.repeat('a', PinpointConstants.AGENT_ID_MAX_LEN)); TransactionId transactionId = TransactionIdUtils.parseTransactionId(agentId + "^1^2"); Assertions.assertEquals(agentId, transactionId.getAgentId()); } @@ -146,7 +147,7 @@ public void longAgentId() { @Test public void tooLongAgentId() { Assertions.assertThrows(IllegalArgumentException.class, () -> { - String agentId = StringUtils.repeat('a', PinpointConstants.AGENT_ID_MAX_LEN + 1); + AgentId agentId = AgentId.of(StringUtils.repeat('a', PinpointConstants.AGENT_ID_MAX_LEN + 1)); TransactionId transactionId = TransactionIdUtils.parseTransactionId(agentId + "^1^2"); Assertions.assertEquals(agentId, transactionId.getAgentId()); }); diff --git a/commons-server/src/main/java/com/navercorp/pinpoint/common/server/bo/AgentInfoBo.java b/commons-server/src/main/java/com/navercorp/pinpoint/common/server/bo/AgentInfoBo.java index 80878dfc5b7e..ef7de767b3df 100644 --- a/commons-server/src/main/java/com/navercorp/pinpoint/common/server/bo/AgentInfoBo.java +++ b/commons-server/src/main/java/com/navercorp/pinpoint/common/server/bo/AgentInfoBo.java @@ -18,7 +18,9 @@ import com.navercorp.pinpoint.common.buffer.AutomaticBuffer; import com.navercorp.pinpoint.common.buffer.Buffer; +import com.navercorp.pinpoint.common.id.AgentId; import com.navercorp.pinpoint.common.id.ApplicationId; +import com.navercorp.pinpoint.common.id.ServiceId; import jakarta.validation.constraints.NotBlank; /** @@ -30,10 +32,12 @@ public class AgentInfoBo { private final String hostName; private final String ip; private final String ports; - @NotBlank private final String agentId; + private final AgentId agentId; private final String agentName; @NotBlank private final String applicationName; private final ApplicationId applicationId; + @NotBlank private final String serviceName; + private final ServiceId serviceId; private final short serviceTypeCode; private final int pid; private final String vmVersion; @@ -58,6 +62,8 @@ private AgentInfoBo(Builder builder) { this.agentName = builder.agentName; this.applicationName = builder.applicationName; this.applicationId = builder.applicationId; + this.serviceName = builder.serviceName; + this.serviceId = builder.serviceId; this.serviceTypeCode = builder.serviceTypeCode; this.pid = builder.pid; this.vmVersion = builder.vmVersion; @@ -82,7 +88,7 @@ public String getPorts() { return ports; } - public String getAgentId() { + public AgentId getAgentId() { return agentId; } @@ -98,6 +104,14 @@ public ApplicationId getApplicationId() { return applicationId; } + public String getServiceName() { + return serviceName; + } + + public ServiceId getServiceId() { + return serviceId; + } + public long getStartTime() { return startTime; } @@ -159,6 +173,8 @@ public byte[] writeValue() { buffer.putPrefixedString(this.getAgentName()); buffer.putUUID(this.getApplicationId().value()); + buffer.putPrefixedString(this.getServiceName()); + buffer.putUUID(this.getServiceId().value()); return buffer.getBuffer(); } @@ -181,11 +197,8 @@ public boolean equals(Object obj) { return false; AgentInfoBo other = (AgentInfoBo) obj; if (agentId == null) { - if (other.agentId != null) - return false; - } else if (!agentId.equals(other.agentId)) - return false; - return true; + return other.agentId == null; + } else return agentId.equals(other.agentId); } @Override @@ -198,6 +211,8 @@ public String toString() { ", agentName='" + agentName + '\'' + ", applicationName='" + applicationName + '\'' + ", applicationId='" + applicationId + '\'' + + ", serviceName='" + serviceName + '\'' + + ", serviceId='" + serviceId + '\'' + ", serviceTypeCode=" + serviceTypeCode + ", pid=" + pid + ", vmVersion='" + vmVersion + '\'' + @@ -215,10 +230,12 @@ public static class Builder { private String hostName; private String ip; private String ports; - private String agentId; + private AgentId agentId; private String agentName; private String applicationName; private ApplicationId applicationId; + private String serviceName; + private ServiceId serviceId; private short serviceTypeCode; private int pid; private String vmVersion; @@ -249,7 +266,7 @@ public void setPorts(String ports) { this.ports = ports; } - public void setAgentId(String agentId) { + public void setAgentId(AgentId agentId) { this.agentId = agentId; } @@ -265,6 +282,14 @@ public void setApplicationId(ApplicationId applicationId) { this.applicationId = applicationId; } + public void setServiceName(String serviceName) { + this.serviceName = serviceName; + } + + public void setServiceId(ServiceId serviceId) { + this.serviceId = serviceId; + } + public void setServiceTypeCode(short serviceTypeCode) { this.serviceTypeCode = serviceTypeCode; } @@ -317,13 +342,18 @@ public AgentInfoBo build() { if (this.ports == null) this.ports = ""; if (this.agentId == null) - this.agentId = ""; + this.agentId = AgentId.of(""); if (this.agentName == null) this.agentName = ""; if (this.applicationName == null) this.applicationName = ""; if (this.applicationId == null) { - this.applicationId = ApplicationId.NOT_EXIST_APPLICATION_ID; + this.applicationId = ApplicationId.NOT_EXIST; + } + if (this.serviceName == null) + this.serviceName = ""; + if (this.serviceId == null) { + this.serviceId = ServiceId.NOT_EXIST; } if (this.vmVersion == null) this.vmVersion = ""; diff --git a/commons-server/src/main/java/com/navercorp/pinpoint/common/server/bo/ApplicationInfo.java b/commons-server/src/main/java/com/navercorp/pinpoint/common/server/bo/ApplicationInfo.java new file mode 100644 index 000000000000..4f655a6b4c32 --- /dev/null +++ b/commons-server/src/main/java/com/navercorp/pinpoint/common/server/bo/ApplicationInfo.java @@ -0,0 +1,38 @@ +/* + * Copyright 2024 NAVER Corp. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.navercorp.pinpoint.common.server.bo; + +import com.navercorp.pinpoint.common.id.ApplicationId; +import com.navercorp.pinpoint.common.id.ServiceId; + +import java.util.Objects; + +/** + * @author youngjin.kim2 + */ +public record ApplicationInfo( + ApplicationId id, + ServiceId serviceId, + String name +) { + + public ApplicationInfo(ApplicationId id, ServiceId serviceId, String name) { + this.id = Objects.requireNonNull(id, "id"); + this.serviceId = Objects.requireNonNull(serviceId, "serviceId"); + this.name = Objects.requireNonNull(name, "name"); + } + +} diff --git a/commons-server/src/main/java/com/navercorp/pinpoint/common/server/bo/ApplicationSelector.java b/commons-server/src/main/java/com/navercorp/pinpoint/common/server/bo/ApplicationSelector.java new file mode 100644 index 000000000000..3f263e3bb9b9 --- /dev/null +++ b/commons-server/src/main/java/com/navercorp/pinpoint/common/server/bo/ApplicationSelector.java @@ -0,0 +1,64 @@ +/* + * Copyright 2024 NAVER Corp. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.navercorp.pinpoint.common.server.bo; + +import com.navercorp.pinpoint.common.buffer.AutomaticBuffer; +import com.navercorp.pinpoint.common.buffer.Buffer; +import com.navercorp.pinpoint.common.id.ServiceId; +import com.navercorp.pinpoint.common.util.BytesUtils; + +import java.util.Objects; + +/** + * @author youngjin.kim2 + */ +public record ApplicationSelector(ServiceId serviceId, String name) { + + public ApplicationSelector(ServiceId serviceId, String name) { + this.serviceId = Objects.requireNonNull(serviceId, "serviceId"); + this.name = Objects.requireNonNull(name, "name"); + } + + public byte[] toBytes() { + Buffer buffer = new AutomaticBuffer(); + buffer.putUUID(serviceId.value()); + buffer.putBytes(BytesUtils.toBytes(name)); + return buffer.getBuffer(); + } + + public static ApplicationSelector fromBuffer(Buffer buffer) { + final ServiceId serviceId = new ServiceId(buffer.readUUID()); + final String name = buffer.readPadString(buffer.remaining()); + return new ApplicationSelector(serviceId, name); + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + ApplicationSelector that = (ApplicationSelector) o; + return Objects.equals(serviceId, that.serviceId) && Objects.equals(name, that.name); + } + + @Override + public String toString() { + return "ApplicationUniqueTuple{" + + "serviceId=" + serviceId + + ", applicationName='" + name + '\'' + + '}'; + } + +} diff --git a/commons-server/src/main/java/com/navercorp/pinpoint/common/server/bo/BasicSpan.java b/commons-server/src/main/java/com/navercorp/pinpoint/common/server/bo/BasicSpan.java index be934417f849..dd3c6eea97aa 100644 --- a/commons-server/src/main/java/com/navercorp/pinpoint/common/server/bo/BasicSpan.java +++ b/commons-server/src/main/java/com/navercorp/pinpoint/common/server/bo/BasicSpan.java @@ -16,6 +16,7 @@ package com.navercorp.pinpoint.common.server.bo; +import com.navercorp.pinpoint.common.id.AgentId; import com.navercorp.pinpoint.common.id.ApplicationId; import com.navercorp.pinpoint.common.profiler.util.TransactionId; @@ -26,8 +27,8 @@ public interface BasicSpan { int getVersion(); - String getAgentId(); - void setAgentId(String agentId); + AgentId getAgentId(); + void setAgentId(AgentId agentId); String getAgentName(); void setAgentName(String agentName); diff --git a/commons-server/src/main/java/com/navercorp/pinpoint/common/server/bo/ServiceInfo.java b/commons-server/src/main/java/com/navercorp/pinpoint/common/server/bo/ServiceInfo.java new file mode 100644 index 000000000000..c16ed9466aef --- /dev/null +++ b/commons-server/src/main/java/com/navercorp/pinpoint/common/server/bo/ServiceInfo.java @@ -0,0 +1,35 @@ +/* + * Copyright 2024 NAVER Corp. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.navercorp.pinpoint.common.server.bo; + +import com.navercorp.pinpoint.common.id.ServiceId; + +import java.util.Objects; + +/** + * @author youngjin.kim2 + */ +public record ServiceInfo( + ServiceId id, + String name +) { + + public ServiceInfo(ServiceId id, String name) { + this.id = Objects.requireNonNull(id, "id"); + this.name = Objects.requireNonNull(name, "name"); + } + +} diff --git a/commons-server/src/main/java/com/navercorp/pinpoint/common/server/bo/SpanBo.java b/commons-server/src/main/java/com/navercorp/pinpoint/common/server/bo/SpanBo.java index c3d1530c8e06..139efbc25a5f 100644 --- a/commons-server/src/main/java/com/navercorp/pinpoint/common/server/bo/SpanBo.java +++ b/commons-server/src/main/java/com/navercorp/pinpoint/common/server/bo/SpanBo.java @@ -16,6 +16,7 @@ package com.navercorp.pinpoint.common.server.bo; +import com.navercorp.pinpoint.common.id.AgentId; import com.navercorp.pinpoint.common.id.ApplicationId; import com.navercorp.pinpoint.common.profiler.util.TransactionId; import jakarta.validation.constraints.NotBlank; @@ -33,7 +34,7 @@ public class SpanBo implements Event, BasicSpan { private byte version = 0; // private AgentKeyBo agentKeyBo; - @NotBlank private String agentId; + private AgentId agentId; private String agentName; @NotBlank private String applicationName; private ApplicationId applicationId; @@ -111,12 +112,12 @@ public void setTransactionId(TransactionId transactionId) { } @Override - public String getAgentId() { + public AgentId getAgentId() { return agentId; } @Override - public void setAgentId(String agentId) { + public void setAgentId(AgentId agentId) { this.agentId = agentId; } @@ -430,7 +431,7 @@ public static class Builder { private int version = 0; - private String agentId; + private AgentId agentId; private String agentName; private String applicationName; private ApplicationId applicationId; @@ -482,7 +483,7 @@ public Builder setVersion(int version) { return this; } - public Builder setAgentId(String agentId) { + public Builder setAgentId(AgentId agentId) { this.agentId = agentId; return this; } diff --git a/commons-server/src/main/java/com/navercorp/pinpoint/common/server/bo/SpanChunkBo.java b/commons-server/src/main/java/com/navercorp/pinpoint/common/server/bo/SpanChunkBo.java index 0b8c05034bd8..74d6c2bc7b1b 100644 --- a/commons-server/src/main/java/com/navercorp/pinpoint/common/server/bo/SpanChunkBo.java +++ b/commons-server/src/main/java/com/navercorp/pinpoint/common/server/bo/SpanChunkBo.java @@ -16,6 +16,7 @@ package com.navercorp.pinpoint.common.server.bo; +import com.navercorp.pinpoint.common.id.AgentId; import com.navercorp.pinpoint.common.id.ApplicationId; import com.navercorp.pinpoint.common.profiler.util.TransactionId; import jakarta.validation.constraints.NotBlank; @@ -31,7 +32,7 @@ public class SpanChunkBo implements BasicSpan { private byte version = 0; - @NotBlank private String agentId; + private AgentId agentId; private String agentName; @NotBlank private String applicationName; private ApplicationId applicationId; @@ -69,11 +70,11 @@ public void setVersion(int version) { } @Override - public String getAgentId() { + public AgentId getAgentId() { return agentId; } - public void setAgentId(String agentId) { + public void setAgentId(AgentId agentId) { this.agentId = agentId; } diff --git a/commons-server/src/main/java/com/navercorp/pinpoint/common/server/bo/grpc/BindAttribute.java b/commons-server/src/main/java/com/navercorp/pinpoint/common/server/bo/grpc/BindAttribute.java index aaf7baea374c..1f515cb54fc7 100644 --- a/commons-server/src/main/java/com/navercorp/pinpoint/common/server/bo/grpc/BindAttribute.java +++ b/commons-server/src/main/java/com/navercorp/pinpoint/common/server/bo/grpc/BindAttribute.java @@ -1,12 +1,13 @@ package com.navercorp.pinpoint.common.server.bo.grpc; +import com.navercorp.pinpoint.common.id.AgentId; import com.navercorp.pinpoint.common.id.ApplicationId; import com.navercorp.pinpoint.grpc.Header; import java.util.Objects; public class BindAttribute { - private final String agentId; + private final AgentId agentId; private final String applicationName; private final ApplicationId applicationId; private final long agentStartTime; @@ -20,7 +21,7 @@ public static BindAttribute of(Header header, ApplicationId applicationId, long acceptedTime); } - public BindAttribute(String agentId, String applicationName, ApplicationId applicationId, long agentStartTime, long acceptedTime) { + public BindAttribute(AgentId agentId, String applicationName, ApplicationId applicationId, long agentStartTime, long acceptedTime) { this.agentId = Objects.requireNonNull(agentId, "agentId"); this.applicationName = Objects.requireNonNull(applicationName, "applicationName"); this.applicationId = Objects.requireNonNull(applicationId, "applicationId"); @@ -32,7 +33,7 @@ public long getAcceptedTime() { return acceptedTime; } - public String getAgentId() { + public AgentId getAgentId() { return this.agentId; } diff --git a/commons-server/src/main/java/com/navercorp/pinpoint/common/server/bo/grpc/GrpcSpanBinder.java b/commons-server/src/main/java/com/navercorp/pinpoint/common/server/bo/grpc/GrpcSpanBinder.java index c75444510ab0..40a7d6a48738 100644 --- a/commons-server/src/main/java/com/navercorp/pinpoint/common/server/bo/grpc/GrpcSpanBinder.java +++ b/commons-server/src/main/java/com/navercorp/pinpoint/common/server/bo/grpc/GrpcSpanBinder.java @@ -17,6 +17,7 @@ package com.navercorp.pinpoint.common.server.bo.grpc; +import com.navercorp.pinpoint.common.id.AgentId; import com.navercorp.pinpoint.common.profiler.util.TransactionId; import com.navercorp.pinpoint.common.server.bo.AnnotationBo; import com.navercorp.pinpoint.common.server.bo.AnnotationComparator; @@ -268,7 +269,7 @@ SpanChunkBo newSpanChunkBo(PSpanChunk pSpanChunk, BindAttribute attribute) { return spanChunkBo; } - private TransactionId newTransactionId(PTransactionId pTransactionId, String spanAgentId) { + private TransactionId newTransactionId(PTransactionId pTransactionId, AgentId spanAgentId) { final String transactionAgentId = pTransactionId.getAgentId(); if (StringUtils.hasLength(transactionAgentId)) { return new TransactionId(transactionAgentId, pTransactionId.getAgentStartTime(), pTransactionId.getSequence()); diff --git a/commons-server/src/main/java/com/navercorp/pinpoint/common/server/bo/serializer/trace/v2/SpanDecoderV0.java b/commons-server/src/main/java/com/navercorp/pinpoint/common/server/bo/serializer/trace/v2/SpanDecoderV0.java index cb4af2ff7918..4485308bd166 100644 --- a/commons-server/src/main/java/com/navercorp/pinpoint/common/server/bo/serializer/trace/v2/SpanDecoderV0.java +++ b/commons-server/src/main/java/com/navercorp/pinpoint/common/server/bo/serializer/trace/v2/SpanDecoderV0.java @@ -17,6 +17,7 @@ package com.navercorp.pinpoint.common.server.bo.serializer.trace.v2; import com.navercorp.pinpoint.common.buffer.Buffer; +import com.navercorp.pinpoint.common.id.AgentId; import com.navercorp.pinpoint.common.profiler.util.TransactionId; import com.navercorp.pinpoint.common.server.bo.AnnotationBo; import com.navercorp.pinpoint.common.server.bo.AnnotationTranscoder; @@ -373,7 +374,7 @@ private void readQualifier(BasicSpan basicSpan, Buffer buffer) { String applicationId = buffer.readPrefixedString(); basicSpan.setApplicationName(applicationId); - String agentId = buffer.readPrefixedString(); + AgentId agentId = AgentId.of(buffer.readPrefixedString()); basicSpan.setAgentId(agentId); long agentStartTime = buffer.readVLong(); diff --git a/commons-server/src/main/java/com/navercorp/pinpoint/common/server/bo/serializer/trace/v2/SpanEncoderV0.java b/commons-server/src/main/java/com/navercorp/pinpoint/common/server/bo/serializer/trace/v2/SpanEncoderV0.java index ae7ab7b6e126..61148c83fcb8 100644 --- a/commons-server/src/main/java/com/navercorp/pinpoint/common/server/bo/serializer/trace/v2/SpanEncoderV0.java +++ b/commons-server/src/main/java/com/navercorp/pinpoint/common/server/bo/serializer/trace/v2/SpanEncoderV0.java @@ -53,7 +53,7 @@ private ByteBuffer encodeQualifier(byte type, BasicSpan basicSpan, SpanEventBo f final Buffer buffer = new AutomaticBuffer(128); buffer.putByte(type); buffer.putPrefixedString(basicSpan.getApplicationName()); - buffer.putPrefixedString(basicSpan.getAgentId()); + buffer.putPrefixedString(basicSpan.getAgentId().value()); buffer.putVLong(basicSpan.getAgentStartTime()); buffer.putLong(basicSpan.getSpanId()); diff --git a/commons-server/src/main/java/com/navercorp/pinpoint/common/server/bo/serializer/trace/v2/TraceRowKeyDecoderV2.java b/commons-server/src/main/java/com/navercorp/pinpoint/common/server/bo/serializer/trace/v2/TraceRowKeyDecoderV2.java index 042c7e32a979..94bc19f2099e 100644 --- a/commons-server/src/main/java/com/navercorp/pinpoint/common/server/bo/serializer/trace/v2/TraceRowKeyDecoderV2.java +++ b/commons-server/src/main/java/com/navercorp/pinpoint/common/server/bo/serializer/trace/v2/TraceRowKeyDecoderV2.java @@ -16,6 +16,7 @@ package com.navercorp.pinpoint.common.server.bo.serializer.trace.v2; +import com.navercorp.pinpoint.common.id.AgentId; import com.navercorp.pinpoint.common.profiler.util.TransactionId; import com.navercorp.pinpoint.common.server.bo.serializer.RowKeyDecoder; import com.navercorp.pinpoint.common.util.BytesUtils; @@ -53,7 +54,7 @@ public TransactionId decodeRowKey(byte[] rowkey) { private TransactionId readTransactionId(byte[] rowKey, int offset) { - String agentId = BytesUtils.toStringAndRightTrim(rowKey, offset, AGENT_ID_MAX_LEN); + AgentId agentId = AgentId.of(BytesUtils.toStringAndRightTrim(rowKey, offset, AGENT_ID_MAX_LEN)); long agentStartTime = BytesUtils.bytesToLong(rowKey, offset + AGENT_ID_MAX_LEN); long transactionSequence = BytesUtils.bytesToLong(rowKey, offset + BytesUtils.LONG_BYTE_LENGTH + AGENT_ID_MAX_LEN); diff --git a/commons-server/src/main/java/com/navercorp/pinpoint/common/server/bo/serializer/trace/v2/TraceRowKeyEncoderV2.java b/commons-server/src/main/java/com/navercorp/pinpoint/common/server/bo/serializer/trace/v2/TraceRowKeyEncoderV2.java index 864605a67b1e..deeac347406b 100644 --- a/commons-server/src/main/java/com/navercorp/pinpoint/common/server/bo/serializer/trace/v2/TraceRowKeyEncoderV2.java +++ b/commons-server/src/main/java/com/navercorp/pinpoint/common/server/bo/serializer/trace/v2/TraceRowKeyEncoderV2.java @@ -42,7 +42,7 @@ public byte[] encodeRowKey(TransactionId transactionId) { Objects.requireNonNull(transactionId, "transactionId"); byte[] rowKey = BytesUtils.stringLongLongToBytes( - transactionId.getAgentId(), AGENT_ID_MAX_LEN, transactionId.getAgentStartTime(), transactionId.getTransactionSequence()); + transactionId.getAgentId().value(), AGENT_ID_MAX_LEN, transactionId.getAgentStartTime(), transactionId.getTransactionSequence()); return wrapDistributedRowKey(rowKey); } diff --git a/commons-server/src/main/java/com/navercorp/pinpoint/common/server/bo/thrift/SpanFactory.java b/commons-server/src/main/java/com/navercorp/pinpoint/common/server/bo/thrift/SpanFactory.java index 84ee2a3d8c5e..bafa2dc79393 100644 --- a/commons-server/src/main/java/com/navercorp/pinpoint/common/server/bo/thrift/SpanFactory.java +++ b/commons-server/src/main/java/com/navercorp/pinpoint/common/server/bo/thrift/SpanFactory.java @@ -17,6 +17,7 @@ package com.navercorp.pinpoint.common.server.bo.thrift; +import com.navercorp.pinpoint.common.id.AgentId; import com.navercorp.pinpoint.common.profiler.util.TransactionId; import com.navercorp.pinpoint.common.profiler.util.TransactionIdUtils; import com.navercorp.pinpoint.common.server.bo.AnnotationBo; @@ -72,7 +73,7 @@ public SpanBo buildSpanBo(TSpan tSpan, long acceptedTime, SpanEventFilter spanEv // for test SpanBo newSpanBo(TSpan tSpan) { final SpanBo spanBo = new SpanBo(); - spanBo.setAgentId(tSpan.getAgentId()); + spanBo.setAgentId(AgentId.of(tSpan.getAgentId())); spanBo.setApplicationName(tSpan.getApplicationName()); spanBo.setAgentStartTime(tSpan.getAgentStartTime()); @@ -201,7 +202,7 @@ private LocalAsyncIdBo getLocalAsyncId(TSpanChunk tSpanChunk) { // for test SpanChunkBo newSpanChunkBo(TSpanChunk tSpanChunk) { final SpanChunkBo spanChunkBo = new SpanChunkBo(); - spanChunkBo.setAgentId(tSpanChunk.getAgentId()); + spanChunkBo.setAgentId(AgentId.of(tSpanChunk.getAgentId())); spanChunkBo.setApplicationName(tSpanChunk.getApplicationName()); spanChunkBo.setAgentStartTime(tSpanChunk.getAgentStartTime()); spanChunkBo.setServiceType(tSpanChunk.getServiceType()); @@ -220,7 +221,7 @@ SpanChunkBo newSpanChunkBo(TSpanChunk tSpanChunk) { return spanChunkBo; } - private TransactionId newTransactionId(byte[] transactionIdBytes, String spanAgentId) { + private TransactionId newTransactionId(byte[] transactionIdBytes, AgentId spanAgentId) { return TransactionIdUtils.parseTransactionId(transactionIdBytes, spanAgentId); } diff --git a/commons-server/src/main/java/com/navercorp/pinpoint/common/server/cluster/ClusterKey.java b/commons-server/src/main/java/com/navercorp/pinpoint/common/server/cluster/ClusterKey.java index 90885bfd9ae2..5461b141a66b 100644 --- a/commons-server/src/main/java/com/navercorp/pinpoint/common/server/cluster/ClusterKey.java +++ b/commons-server/src/main/java/com/navercorp/pinpoint/common/server/cluster/ClusterKey.java @@ -1,5 +1,6 @@ package com.navercorp.pinpoint.common.server.cluster; +import com.navercorp.pinpoint.common.id.AgentId; import org.springframework.util.Assert; import java.util.Objects; @@ -33,6 +34,10 @@ public ClusterKey(String applicationName, String agentId, long startTimestamp) { this.startTimestamp = startTimestamp; } + public ClusterKey(String applicationName, AgentId agentId, long startTimestamp) { + this(applicationName, Objects.requireNonNull(agentId, "agentId").value(), startTimestamp); + } + public String getApplicationName() { return applicationName; } diff --git a/commons-server/src/main/java/com/navercorp/pinpoint/common/server/config/CommonCacheManagerConfiguration.java b/commons-server/src/main/java/com/navercorp/pinpoint/common/server/config/CommonCacheManagerConfiguration.java index bbd7747872b2..f52450ab8da7 100644 --- a/commons-server/src/main/java/com/navercorp/pinpoint/common/server/config/CommonCacheManagerConfiguration.java +++ b/commons-server/src/main/java/com/navercorp/pinpoint/common/server/config/CommonCacheManagerConfiguration.java @@ -25,6 +25,7 @@ import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Primary; +import java.util.List; import java.util.concurrent.TimeUnit; @Configuration @@ -33,12 +34,17 @@ public class CommonCacheManagerConfiguration { @Bean @Primary - public CacheManager cacheManager() { + public CacheManager cacheManager(List registrations) { CaffeineCacheManager cacheManager = new CaffeineCacheManager(); cacheManager.setCaffeine(Caffeine.newBuilder() .expireAfterWrite(600, TimeUnit.SECONDS) .initialCapacity(200) .maximumSize(1000)); + + for (CustomCacheRegistration registration : registrations) { + cacheManager.registerCustomCache(registration.name(), registration.cache()); + } + return cacheManager; } diff --git a/commons-server/src/main/java/com/navercorp/pinpoint/common/server/config/CustomCacheRegistration.java b/commons-server/src/main/java/com/navercorp/pinpoint/common/server/config/CustomCacheRegistration.java new file mode 100644 index 000000000000..61a1a1827e82 --- /dev/null +++ b/commons-server/src/main/java/com/navercorp/pinpoint/common/server/config/CustomCacheRegistration.java @@ -0,0 +1,29 @@ +/* + * Copyright 2024 NAVER Corp. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.navercorp.pinpoint.common.server.config; + +import com.github.benmanes.caffeine.cache.Cache; + +/** + * @author youngjin.kim2 + */ +public interface CustomCacheRegistration { + + String name(); + + Cache cache(); + +} diff --git a/commons-server/src/main/java/com/navercorp/pinpoint/common/server/config/DefaultCustomCacheRegistration.java b/commons-server/src/main/java/com/navercorp/pinpoint/common/server/config/DefaultCustomCacheRegistration.java new file mode 100644 index 000000000000..b3f9a72ed3b3 --- /dev/null +++ b/commons-server/src/main/java/com/navercorp/pinpoint/common/server/config/DefaultCustomCacheRegistration.java @@ -0,0 +1,35 @@ +/* + * Copyright 2024 NAVER Corp. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.navercorp.pinpoint.common.server.config; + +import com.github.benmanes.caffeine.cache.Cache; + +import java.util.Objects; + +/** + * @author youngjin.kim2 + */ +public record DefaultCustomCacheRegistration( + String name, + Cache cache +) implements CustomCacheRegistration { + + public DefaultCustomCacheRegistration(String name, Cache cache) { + this.name = Objects.requireNonNull(name, "name"); + this.cache = Objects.requireNonNull(cache, "cache"); + } + +} diff --git a/commons-server/src/main/java/com/navercorp/pinpoint/common/server/dao/hbase/mapper/AgentInfoBoMapper.java b/commons-server/src/main/java/com/navercorp/pinpoint/common/server/dao/hbase/mapper/AgentInfoBoMapper.java index f222c43f1d6a..6953926776e0 100644 --- a/commons-server/src/main/java/com/navercorp/pinpoint/common/server/dao/hbase/mapper/AgentInfoBoMapper.java +++ b/commons-server/src/main/java/com/navercorp/pinpoint/common/server/dao/hbase/mapper/AgentInfoBoMapper.java @@ -21,7 +21,9 @@ import com.navercorp.pinpoint.common.buffer.FixedBuffer; import com.navercorp.pinpoint.common.hbase.HbaseTableConstants; import com.navercorp.pinpoint.common.hbase.RowMapper; +import com.navercorp.pinpoint.common.id.AgentId; import com.navercorp.pinpoint.common.id.ApplicationId; +import com.navercorp.pinpoint.common.id.ServiceId; import com.navercorp.pinpoint.common.server.bo.AgentInfoBo; import com.navercorp.pinpoint.common.server.bo.JvmInfoBo; import com.navercorp.pinpoint.common.server.bo.ServerMetaDataBo; @@ -42,7 +44,7 @@ public class AgentInfoBoMapper implements RowMapper { @Override public AgentInfoBo mapRow(Result result, int rowNum) throws Exception { byte[] rowKey = result.getRow(); - String agentId = BytesUtils.toStringAndRightTrim(rowKey, 0, PinpointConstants.AGENT_ID_MAX_LEN); + AgentId agentId = AgentId.of(BytesUtils.toStringAndRightTrim(rowKey, 0, PinpointConstants.AGENT_ID_MAX_LEN)); long reverseStartTime = BytesUtils.bytesToLong(rowKey, HbaseTableConstants.AGENT_ID_MAX_LEN); long startTime = TimeUtils.recoveryTimeMillis(reverseStartTime); @@ -91,6 +93,8 @@ private AgentInfoBo.Builder createBuilderFromValue(byte[] serializedAgentInfo) { // 2024.03.11 added application id if (buffer.hasRemaining()) { builder.setApplicationId(ApplicationId.of(buffer.readUUID())); + builder.setServiceName(buffer.readPrefixedString()); + builder.setServiceId(ServiceId.of(buffer.readUUID())); } return builder; } diff --git a/commons-server/src/main/java/com/navercorp/pinpoint/common/server/dao/hbase/mapper/ApplicationIdForwardMapper.java b/commons-server/src/main/java/com/navercorp/pinpoint/common/server/dao/hbase/mapper/ApplicationIdForwardMapper.java index 6aa4e45c94a3..ab803d789406 100644 --- a/commons-server/src/main/java/com/navercorp/pinpoint/common/server/dao/hbase/mapper/ApplicationIdForwardMapper.java +++ b/commons-server/src/main/java/com/navercorp/pinpoint/common/server/dao/hbase/mapper/ApplicationIdForwardMapper.java @@ -16,9 +16,13 @@ package com.navercorp.pinpoint.common.server.dao.hbase.mapper; +import com.navercorp.pinpoint.common.buffer.Buffer; +import com.navercorp.pinpoint.common.buffer.OffsetFixedBuffer; import com.navercorp.pinpoint.common.hbase.HbaseColumnFamily; import com.navercorp.pinpoint.common.hbase.RowMapper; -import com.navercorp.pinpoint.common.util.BytesUtils; +import com.navercorp.pinpoint.common.id.ApplicationId; +import com.navercorp.pinpoint.common.server.bo.ApplicationInfo; +import com.navercorp.pinpoint.common.server.bo.ApplicationSelector; import org.apache.hadoop.hbase.Cell; import org.apache.hadoop.hbase.client.Result; import org.springframework.stereotype.Component; @@ -29,12 +33,12 @@ * @author youngjin.kim2 */ @Component -public class ApplicationIdForwardMapper implements RowMapper { +public class ApplicationIdForwardMapper implements RowMapper { private static final HbaseColumnFamily.ApplicationId DESCRIPTOR = HbaseColumnFamily.APPLICATION_ID_FORWARD; @Override - public UUID mapRow(Result result, int rowNum) throws Exception { + public ApplicationInfo mapRow(Result result, int rowNum) throws Exception { byte[] family = DESCRIPTOR.getName(); byte[] qualifier = DESCRIPTOR.getName(); Cell cell = result.getColumnLatestCell(family, qualifier); @@ -42,11 +46,19 @@ public UUID mapRow(Result result, int rowNum) throws Exception { return null; } - if (cell.getValueLength() < 16) { - throw new IllegalArgumentException("Invalid bytes length: " + cell.getValueLength()); - } + return parseCell(cell); + } + + private static ApplicationInfo parseCell(Cell cell) { + Buffer valueBuffer = new OffsetFixedBuffer(cell.getValueArray(), cell.getValueOffset(), cell.getValueLength()); + + ApplicationSelector application = ApplicationSelector.fromBuffer(valueBuffer); + + Buffer rowBuffer = new OffsetFixedBuffer(cell.getRowArray(), cell.getRowOffset(), cell.getRowOffset()); + UUID value = rowBuffer.readUUID(); + ApplicationId id = ApplicationId.of(value); - return BytesUtils.bytesToUUID(cell.getValueArray(), cell.getValueOffset()); + return new ApplicationInfo(id, application.serviceId(), application.name()); } } diff --git a/commons-server/src/main/java/com/navercorp/pinpoint/common/server/dao/hbase/mapper/ApplicationIdInverseMapper.java b/commons-server/src/main/java/com/navercorp/pinpoint/common/server/dao/hbase/mapper/ApplicationIdInverseMapper.java index 919cbca8e8b9..9477f2789249 100644 --- a/commons-server/src/main/java/com/navercorp/pinpoint/common/server/dao/hbase/mapper/ApplicationIdInverseMapper.java +++ b/commons-server/src/main/java/com/navercorp/pinpoint/common/server/dao/hbase/mapper/ApplicationIdInverseMapper.java @@ -18,28 +18,37 @@ import com.navercorp.pinpoint.common.hbase.HbaseColumnFamily; import com.navercorp.pinpoint.common.hbase.RowMapper; +import com.navercorp.pinpoint.common.id.ApplicationId; import com.navercorp.pinpoint.common.util.BytesUtils; import org.apache.hadoop.hbase.Cell; import org.apache.hadoop.hbase.client.Result; import org.springframework.stereotype.Component; +import java.util.UUID; + /** * @author youngjin.kim2 */ @Component -public class ApplicationIdInverseMapper implements RowMapper { +public class ApplicationIdInverseMapper implements RowMapper { private static final HbaseColumnFamily.ApplicationId DESCRIPTOR = HbaseColumnFamily.APPLICATION_ID_INVERSE; @Override - public String mapRow(Result result, int rowNum) throws Exception { + public ApplicationId mapRow(Result result, int rowNum) throws Exception { byte[] family = DESCRIPTOR.getName(); byte[] qualifier = DESCRIPTOR.getName(); Cell cell = result.getColumnLatestCell(family, qualifier); if (cell == null) { return null; } - return BytesUtils.toString(cell.getValueArray(), cell.getValueOffset(), cell.getValueLength()); + + if (cell.getValueLength() < 16) { + throw new IllegalArgumentException("Invalid bytes length: " + cell.getValueLength()); + } + + UUID value = BytesUtils.bytesToUUID(cell.getValueArray(), cell.getValueOffset()); + return ApplicationId.of(value); } } diff --git a/web/src/main/java/com/navercorp/pinpoint/web/dao/hbase/mapper/ApplicationForwardMapper.java b/commons-server/src/main/java/com/navercorp/pinpoint/common/server/dao/hbase/mapper/ServiceIdForwardMapper.java similarity index 64% rename from web/src/main/java/com/navercorp/pinpoint/web/dao/hbase/mapper/ApplicationForwardMapper.java rename to commons-server/src/main/java/com/navercorp/pinpoint/common/server/dao/hbase/mapper/ServiceIdForwardMapper.java index f391f6025b69..fb0ac00613c1 100644 --- a/web/src/main/java/com/navercorp/pinpoint/web/dao/hbase/mapper/ApplicationForwardMapper.java +++ b/commons-server/src/main/java/com/navercorp/pinpoint/common/server/dao/hbase/mapper/ServiceIdForwardMapper.java @@ -5,21 +5,22 @@ * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express implied. * See the License for the specific language governing permissions and * limitations under the License. */ -package com.navercorp.pinpoint.web.dao.hbase.mapper; + +package com.navercorp.pinpoint.common.server.dao.hbase.mapper; import com.navercorp.pinpoint.common.hbase.HbaseColumnFamily; import com.navercorp.pinpoint.common.hbase.RowMapper; -import com.navercorp.pinpoint.common.trace.ServiceType; +import com.navercorp.pinpoint.common.id.ServiceId; +import com.navercorp.pinpoint.common.server.bo.ServiceInfo; import com.navercorp.pinpoint.common.util.BytesUtils; -import com.navercorp.pinpoint.web.vo.Application; import org.apache.hadoop.hbase.Cell; import org.apache.hadoop.hbase.client.Result; import org.springframework.stereotype.Component; @@ -30,16 +31,12 @@ * @author youngjin.kim2 */ @Component -public class ApplicationForwardMapper implements RowMapper { +public class ServiceIdForwardMapper implements RowMapper { private static final HbaseColumnFamily.ApplicationId DESCRIPTOR = HbaseColumnFamily.APPLICATION_ID_FORWARD; - - // TODO: This value is temporary, and the service type should be removed - private static final ServiceType DEFAULT_SERVICE_TYPE = ServiceType.SERVLET; - @Override - public Application mapRow(Result result, int rowNum) throws Exception { + public ServiceInfo mapRow(Result result, int rowNum) throws Exception { byte[] family = DESCRIPTOR.getName(); byte[] qualifier = DESCRIPTOR.getName(); Cell cell = result.getColumnLatestCell(family, qualifier); @@ -51,9 +48,11 @@ public Application mapRow(Result result, int rowNum) throws Exception { throw new IllegalArgumentException("Invalid bytes length: " + cell.getValueLength()); } - String applicationName = BytesUtils.toString(result.getRow()); - UUID applicationId = BytesUtils.bytesToUUID(cell.getValueArray(), cell.getValueOffset()); - return new Application(applicationId, applicationName, DEFAULT_SERVICE_TYPE); + UUID serviceIdValue = BytesUtils.bytesToUUID(cell.getRowArray(), cell.getRowOffset()); + ServiceId serviceId = ServiceId.of(serviceIdValue); + String serviceName = BytesUtils.toString(cell.getValueArray(), cell.getValueOffset(), cell.getValueLength()); + + return new ServiceInfo(serviceId, serviceName); } } diff --git a/commons-server/src/main/java/com/navercorp/pinpoint/common/server/dao/hbase/mapper/ServiceIdInverseMapper.java b/commons-server/src/main/java/com/navercorp/pinpoint/common/server/dao/hbase/mapper/ServiceIdInverseMapper.java new file mode 100644 index 000000000000..d2b5d5049dde --- /dev/null +++ b/commons-server/src/main/java/com/navercorp/pinpoint/common/server/dao/hbase/mapper/ServiceIdInverseMapper.java @@ -0,0 +1,49 @@ +/* + * Copyright 2024 NAVER Corp. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.navercorp.pinpoint.common.server.dao.hbase.mapper; + +import com.navercorp.pinpoint.common.hbase.HbaseColumnFamily; +import com.navercorp.pinpoint.common.hbase.RowMapper; +import com.navercorp.pinpoint.common.id.ServiceId; +import com.navercorp.pinpoint.common.util.BytesUtils; +import org.apache.hadoop.hbase.Cell; +import org.apache.hadoop.hbase.client.Result; +import org.springframework.stereotype.Component; + +import java.util.UUID; + +/** + * @author youngjin.kim2 + */ +@Component +public class ServiceIdInverseMapper implements RowMapper { + + private static final HbaseColumnFamily.ApplicationId DESCRIPTOR = HbaseColumnFamily.APPLICATION_ID_INVERSE; + + @Override + public ServiceId mapRow(Result result, int rowNum) throws Exception { + byte[] family = DESCRIPTOR.getName(); + byte[] qualifier = DESCRIPTOR.getName(); + Cell cell = result.getColumnLatestCell(family, qualifier); + if (cell == null) { + return null; + } + UUID serviceIdValue = BytesUtils.bytesToUUID(cell.getValueArray(), cell.getValueOffset()); + return ServiceId.of(serviceIdValue); + } + +} diff --git a/commons-server/src/main/java/com/navercorp/pinpoint/common/server/util/SpanUtils.java b/commons-server/src/main/java/com/navercorp/pinpoint/common/server/util/SpanUtils.java index 5b182632b33c..0ed63729cced 100644 --- a/commons-server/src/main/java/com/navercorp/pinpoint/common/server/util/SpanUtils.java +++ b/commons-server/src/main/java/com/navercorp/pinpoint/common/server/util/SpanUtils.java @@ -18,6 +18,7 @@ import com.navercorp.pinpoint.common.buffer.AutomaticBuffer; import com.navercorp.pinpoint.common.buffer.Buffer; +import com.navercorp.pinpoint.common.id.AgentId; import com.navercorp.pinpoint.common.profiler.util.TransactionId; import com.navercorp.pinpoint.common.server.bo.SpanBo; @@ -37,13 +38,13 @@ public static byte[] getVarTransactionId(SpanBo span) { Objects.requireNonNull(span, "span"); final TransactionId transactionId = span.getTransactionId(); - String agentId = transactionId.getAgentId(); + AgentId agentId = transactionId.getAgentId(); if (agentId == null) { agentId = span.getAgentId(); } final Buffer buffer = new AutomaticBuffer(32); - buffer.putPrefixedString(agentId); + buffer.putPrefixedString(agentId.value()); buffer.putSVLong(transactionId.getAgentStartTime()); buffer.putVLong(transactionId.getTransactionSequence()); return buffer.getBuffer(); diff --git a/commons-server/src/test/java/com/navercorp/pinpoint/common/server/bo/ApplicationSelectorTest.java b/commons-server/src/test/java/com/navercorp/pinpoint/common/server/bo/ApplicationSelectorTest.java new file mode 100644 index 000000000000..36eef2e9b177 --- /dev/null +++ b/commons-server/src/test/java/com/navercorp/pinpoint/common/server/bo/ApplicationSelectorTest.java @@ -0,0 +1,42 @@ +/* + * Copyright 2024 NAVER Corp. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.navercorp.pinpoint.common.server.bo; + +import com.navercorp.pinpoint.common.buffer.Buffer; +import com.navercorp.pinpoint.common.buffer.OffsetFixedBuffer; +import com.navercorp.pinpoint.common.id.ServiceId; +import org.junit.jupiter.api.Test; + +import java.util.UUID; + +import static org.assertj.core.api.Assertions.assertThat; + +/** + * @author youngjin.kim2 + */ +public class ApplicationSelectorTest { + + @Test + public void ApplicationSelectorSerdeTest() { + UUID serviceIdValue = new UUID(0, 1); + ApplicationSelector selector = new ApplicationSelector(ServiceId.of(serviceIdValue), "sampleApplication"); + Buffer buffer = new OffsetFixedBuffer(selector.toBytes()); + ApplicationSelector deserializedSelector = ApplicationSelector.fromBuffer(buffer); + + assertThat(deserializedSelector).isEqualTo(selector); + } + +} diff --git a/commons-server/src/test/java/com/navercorp/pinpoint/common/server/bo/RandomTSpan.java b/commons-server/src/test/java/com/navercorp/pinpoint/common/server/bo/RandomTSpan.java index 5c9a23b98a32..941686065ca8 100644 --- a/commons-server/src/test/java/com/navercorp/pinpoint/common/server/bo/RandomTSpan.java +++ b/commons-server/src/test/java/com/navercorp/pinpoint/common/server/bo/RandomTSpan.java @@ -16,6 +16,7 @@ package com.navercorp.pinpoint.common.server.bo; +import com.navercorp.pinpoint.common.id.AgentId; import com.navercorp.pinpoint.common.profiler.util.TransactionIdUtils; import com.navercorp.pinpoint.thrift.dto.TAnnotation; import com.navercorp.pinpoint.thrift.dto.TAnnotationValue; @@ -44,7 +45,7 @@ public TSpan randomTSpan() { tSpan.setApplicationName("appName"); tSpan.setAgentStartTime(System.currentTimeMillis()); - tSpan.setTransactionId(TransactionIdUtils.formatByteBuffer("agent", System.currentTimeMillis(), RandomUtils.nextLong(0, Long.MAX_VALUE))); + tSpan.setTransactionId(TransactionIdUtils.formatByteBuffer(AgentId.of("agent"), System.currentTimeMillis(), RandomUtils.nextLong(0, Long.MAX_VALUE))); tSpan.setSpanId(random.nextLong()); tSpan.setParentSpanId(RandomUtils.nextInt(0, 100000)); tSpan.setStartTime(System.currentTimeMillis() + RandomUtils.nextInt(0, 1000)); @@ -152,7 +153,7 @@ public TSpanChunk randomTSpanChunk() { tSpanChunk.setApplicationName("appName"); tSpanChunk.setAgentStartTime(System.currentTimeMillis()); - tSpanChunk.setTransactionId(TransactionIdUtils.formatByteBuffer("agent", System.currentTimeMillis(), RandomUtils.nextLong(0, Long.MAX_VALUE))); + tSpanChunk.setTransactionId(TransactionIdUtils.formatByteBuffer(AgentId.of("agent"), System.currentTimeMillis(), RandomUtils.nextLong(0, Long.MAX_VALUE))); tSpanChunk.setSpanId(random.nextLong()); tSpanChunk.setEndPoint(RandomStringUtils.random(20)); diff --git a/commons-server/src/test/java/com/navercorp/pinpoint/common/server/bo/SpanFactoryAssert.java b/commons-server/src/test/java/com/navercorp/pinpoint/common/server/bo/SpanFactoryAssert.java index 720569c1b219..27a9d62ea81c 100644 --- a/commons-server/src/test/java/com/navercorp/pinpoint/common/server/bo/SpanFactoryAssert.java +++ b/commons-server/src/test/java/com/navercorp/pinpoint/common/server/bo/SpanFactoryAssert.java @@ -36,7 +36,7 @@ public class SpanFactoryAssert { public void assertSpan(TSpan tSpan, SpanBo spanBo) { - Assertions.assertEquals(tSpan.getAgentId(), spanBo.getAgentId()); + Assertions.assertEquals(tSpan.getAgentId(), spanBo.getAgentId().value()); Assertions.assertEquals(tSpan.getApplicationName(), spanBo.getApplicationName()); Assertions.assertEquals(tSpan.getAgentStartTime(), spanBo.getAgentStartTime()); @@ -131,7 +131,7 @@ public void assertSpanEvent(TSpanEvent tSpanEvent, SpanEventBo spanEventBo) { public void assertSpanChunk(TSpanChunk tSpanChunk, SpanChunkBo spanChunkBo) { - Assertions.assertEquals(tSpanChunk.getAgentId(), spanChunkBo.getAgentId()); + Assertions.assertEquals(tSpanChunk.getAgentId(), spanChunkBo.getAgentId().value()); Assertions.assertEquals(tSpanChunk.getApplicationName(), spanChunkBo.getApplicationName()); Assertions.assertEquals(tSpanChunk.getAgentStartTime(), spanChunkBo.getAgentStartTime()); diff --git a/commons-server/src/test/java/com/navercorp/pinpoint/common/server/bo/grpc/CollectorGrpcSpanFactoryTest.java b/commons-server/src/test/java/com/navercorp/pinpoint/common/server/bo/grpc/CollectorGrpcSpanFactoryTest.java index 75f309778c9c..7e68bfaa156f 100644 --- a/commons-server/src/test/java/com/navercorp/pinpoint/common/server/bo/grpc/CollectorGrpcSpanFactoryTest.java +++ b/commons-server/src/test/java/com/navercorp/pinpoint/common/server/bo/grpc/CollectorGrpcSpanFactoryTest.java @@ -16,6 +16,7 @@ package com.navercorp.pinpoint.common.server.bo.grpc; +import com.navercorp.pinpoint.common.id.AgentId; import com.navercorp.pinpoint.common.id.ApplicationId; import com.navercorp.pinpoint.common.server.bo.SpanChunkBo; import com.navercorp.pinpoint.common.server.bo.SpanEventBo; @@ -44,7 +45,7 @@ public class CollectorGrpcSpanFactoryTest { private final BindAttribute attribute = newAttribute(); private BindAttribute newAttribute() { - return new BindAttribute("agentId", "applicationName", APPLICATION_ID, 88, System.currentTimeMillis()); + return new BindAttribute(AgentId.of("agentId"), "applicationName", APPLICATION_ID, 88, System.currentTimeMillis()); } private final GrpcSpanFactory factory = new CollectorGrpcSpanFactory(binder, filter); diff --git a/commons-server/src/test/java/com/navercorp/pinpoint/common/server/bo/thrift/SpanFactoryTest.java b/commons-server/src/test/java/com/navercorp/pinpoint/common/server/bo/thrift/SpanFactoryTest.java index 429c3d5feb53..144cdf9d75eb 100644 --- a/commons-server/src/test/java/com/navercorp/pinpoint/common/server/bo/thrift/SpanFactoryTest.java +++ b/commons-server/src/test/java/com/navercorp/pinpoint/common/server/bo/thrift/SpanFactoryTest.java @@ -16,6 +16,7 @@ package com.navercorp.pinpoint.common.server.bo.thrift; +import com.navercorp.pinpoint.common.id.AgentId; import com.navercorp.pinpoint.common.profiler.util.TransactionId; import com.navercorp.pinpoint.common.profiler.util.TransactionIdUtils; import com.navercorp.pinpoint.common.server.bo.RandomTSpan; @@ -158,7 +159,7 @@ public void testTransactionId_skip_agentId() { SpanBo spanBo = spanFactory.newSpanBo(tSpan); TransactionId transactionId = spanBo.getTransactionId(); - Assertions.assertEquals(transactionId.getAgentId(), "agentId"); + Assertions.assertEquals(transactionId.getAgentId().value(), "agentId"); Assertions.assertEquals(transactionId.getAgentStartTime(), 1); Assertions.assertEquals(transactionId.getTransactionSequence(), 2); } @@ -167,13 +168,14 @@ public void testTransactionId_skip_agentId() { public void testTransactionId_include_agentId() { TSpan tSpan = new TSpan(); tSpan.setAgentId("agentId"); - byte[] transactionIdBytes = TransactionIdUtils.formatBytes("transactionAgentId", 1, 2); + AgentId transactionAgentId = AgentId.of("transactionAgentId"); + byte[] transactionIdBytes = TransactionIdUtils.formatBytes(transactionAgentId, 1, 2); tSpan.setTransactionId(transactionIdBytes); SpanBo spanBo = spanFactory.newSpanBo(tSpan); TransactionId transactionId = spanBo.getTransactionId(); - Assertions.assertEquals(transactionId.getAgentId(), "transactionAgentId"); + Assertions.assertEquals(transactionId.getAgentId(), transactionAgentId); Assertions.assertEquals(transactionId.getAgentStartTime(), 1); Assertions.assertEquals(transactionId.getTransactionSequence(), 2); } diff --git a/commons/src/main/java/com/navercorp/pinpoint/common/PinpointConstants.java b/commons/src/main/java/com/navercorp/pinpoint/common/PinpointConstants.java index 9243b97d3d17..55d162cc3f19 100644 --- a/commons/src/main/java/com/navercorp/pinpoint/common/PinpointConstants.java +++ b/commons/src/main/java/com/navercorp/pinpoint/common/PinpointConstants.java @@ -23,6 +23,8 @@ public final class PinpointConstants { public static final int APPLICATION_NAME_MAX_LEN = 255; + public static final int SERVICE_NAME_MAX_LEN = 255; + public static final int AGENT_ID_MAX_LEN = 24; public static final int AGENT_NAME_MAX_LEN = 255; diff --git a/commons/src/main/java/com/navercorp/pinpoint/common/id/AgentId.java b/commons/src/main/java/com/navercorp/pinpoint/common/id/AgentId.java index 3faf4d6e07ca..826b715a9ba4 100644 --- a/commons/src/main/java/com/navercorp/pinpoint/common/id/AgentId.java +++ b/commons/src/main/java/com/navercorp/pinpoint/common/id/AgentId.java @@ -16,6 +16,10 @@ package com.navercorp.pinpoint.common.id; import com.navercorp.pinpoint.common.PinpointConstants; +import com.navercorp.pinpoint.common.util.AgentUuidUtils; +import com.navercorp.pinpoint.common.util.UuidUtils; + +import java.util.UUID; /** * @author youngjin.kim2 @@ -24,7 +28,7 @@ public class AgentId extends StringPinpointIdentifier { private static final int MAX_LENGTH = PinpointConstants.AGENT_ID_MAX_LEN; - public AgentId(String value) { + private AgentId(String value) { super(value); if (value().length() > MAX_LENGTH) { @@ -32,4 +36,21 @@ public AgentId(String value) { } } + public static AgentId random() { + UUID uuid = UuidUtils.createV4(); + String str = AgentUuidUtils.encode(uuid); + return new AgentId(str); + } + + public static AgentId of(String value) { + return new AgentId(value); + } + + public static String unwrap(AgentId agentId) { + if (agentId == null) { + return null; + } + return agentId.value(); + } + } diff --git a/commons/src/main/java/com/navercorp/pinpoint/common/id/ApplicationId.java b/commons/src/main/java/com/navercorp/pinpoint/common/id/ApplicationId.java index e18ed4aab8d5..5e8955dd5162 100644 --- a/commons/src/main/java/com/navercorp/pinpoint/common/id/ApplicationId.java +++ b/commons/src/main/java/com/navercorp/pinpoint/common/id/ApplicationId.java @@ -23,7 +23,7 @@ * @author youngjin.kim2 */ public class ApplicationId extends UUIDPinpointIdentifier { - public static final ApplicationId NOT_EXIST_APPLICATION_ID = new ApplicationId(UuidUtils.EMPTY); + public static final ApplicationId NOT_EXIST = new ApplicationId(UuidUtils.EMPTY); public ApplicationId(UUID value) { super(value); @@ -33,4 +33,8 @@ public static ApplicationId of(UUID value) { return new ApplicationId(value); } + public byte[] toBytes() { + return UuidUtils.toBytes(this.value()); + } + } diff --git a/commons/src/main/java/com/navercorp/pinpoint/common/id/ServiceId.java b/commons/src/main/java/com/navercorp/pinpoint/common/id/ServiceId.java new file mode 100644 index 000000000000..c1bd2e0b505b --- /dev/null +++ b/commons/src/main/java/com/navercorp/pinpoint/common/id/ServiceId.java @@ -0,0 +1,43 @@ +/* + * Copyright 2024 NAVER Corp. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.navercorp.pinpoint.common.id; + +import com.navercorp.pinpoint.common.util.UuidUtils; + +import java.util.UUID; + +/** + * @author youngjin.kim2 + */ +public class ServiceId extends UUIDPinpointIdentifier { + + public static final ServiceId NOT_EXIST = new ServiceId(UuidUtils.EMPTY); + public static final ServiceId DEFAULT_ID = new ServiceId(new UUID(0L, 1L)); + public static final String DEFAULT_SERVICE_NAME = "DEFAULT_SERVICE"; + + public ServiceId(UUID value) { + super(value); + } + + public static ServiceId of(UUID value) { + return new ServiceId(value); + } + + public byte[] toBytes() { + return UuidUtils.toBytes(this.value()); + } + +} diff --git a/commons/src/main/java/com/navercorp/pinpoint/common/id/StringPinpointIdentifier.java b/commons/src/main/java/com/navercorp/pinpoint/common/id/StringPinpointIdentifier.java index 67062eb8eed3..5ad36538f527 100644 --- a/commons/src/main/java/com/navercorp/pinpoint/common/id/StringPinpointIdentifier.java +++ b/commons/src/main/java/com/navercorp/pinpoint/common/id/StringPinpointIdentifier.java @@ -18,7 +18,7 @@ /** * @author youngjin.kim2 */ -public class StringPinpointIdentifier extends AbstractPinpointIdentifier { +public class StringPinpointIdentifier extends AbstractPinpointIdentifier implements Comparable { public StringPinpointIdentifier(String value) { super(value); @@ -29,4 +29,9 @@ public String toString() { return value(); } + @Override + public int compareTo(StringPinpointIdentifier other) { + return value().compareTo(other.value()); + } + } diff --git a/commons/src/main/java/com/navercorp/pinpoint/common/id/UUIDPinpointIdentifier.java b/commons/src/main/java/com/navercorp/pinpoint/common/id/UUIDPinpointIdentifier.java index 79114354d0cc..746dd4bfa8d3 100644 --- a/commons/src/main/java/com/navercorp/pinpoint/common/id/UUIDPinpointIdentifier.java +++ b/commons/src/main/java/com/navercorp/pinpoint/common/id/UUIDPinpointIdentifier.java @@ -20,7 +20,7 @@ /** * @author youngjin.kim2 */ -public class UUIDPinpointIdentifier extends AbstractPinpointIdentifier { +public class UUIDPinpointIdentifier extends AbstractPinpointIdentifier implements Comparable { public UUIDPinpointIdentifier(UUID value) { super(value); @@ -31,4 +31,9 @@ public String toString() { return value().toString(); } + @Override + public int compareTo(UUIDPinpointIdentifier other) { + return value().compareTo(other.value()); + } + } diff --git a/commons/src/main/java/com/navercorp/pinpoint/common/util/IdValidateUtils.java b/commons/src/main/java/com/navercorp/pinpoint/common/util/IdValidateUtils.java index b05de2d9eaeb..0da163619982 100644 --- a/commons/src/main/java/com/navercorp/pinpoint/common/util/IdValidateUtils.java +++ b/commons/src/main/java/com/navercorp/pinpoint/common/util/IdValidateUtils.java @@ -17,6 +17,7 @@ package com.navercorp.pinpoint.common.util; import com.navercorp.pinpoint.common.PinpointConstants; +import com.navercorp.pinpoint.common.id.AgentId; import java.util.Objects; import java.util.regex.Matcher; @@ -42,6 +43,10 @@ public static boolean validateId(String id) { return validateId(id, DEFAULT_MAX_LENGTH); } + public static boolean validateId(AgentId agentId) { + return validateId(agentId.value()); + } + public static boolean validateId(String id, int maxLength) { final CheckResult result = checkId(id, maxLength); return result == CheckResult.SUCCESS; diff --git a/grpc/src/main/java/com/navercorp/pinpoint/grpc/AgentHeaderFactory.java b/grpc/src/main/java/com/navercorp/pinpoint/grpc/AgentHeaderFactory.java index a68afbecd952..776f11e1dfda 100644 --- a/grpc/src/main/java/com/navercorp/pinpoint/grpc/AgentHeaderFactory.java +++ b/grpc/src/main/java/com/navercorp/pinpoint/grpc/AgentHeaderFactory.java @@ -16,6 +16,7 @@ package com.navercorp.pinpoint.grpc; +import com.navercorp.pinpoint.common.id.AgentId; import com.navercorp.pinpoint.common.util.StringUtils; import com.navercorp.pinpoint.grpc.client.HeaderFactory; import io.grpc.Metadata; @@ -28,24 +29,28 @@ */ public class AgentHeaderFactory implements HeaderFactory { - private final String agentId; + private final AgentId agentId; private final String agentName; private final String applicationName; + private final String serviceName; private final long agentStartTime; private final int serviceType; - public AgentHeaderFactory(String agentId, String agentName, String applicationName, int serviceType, long agentStartTime) { + public AgentHeaderFactory(AgentId agentId, String agentName, String applicationName, String serviceName, + int serviceType, long agentStartTime) { this.agentId = Objects.requireNonNull(agentId, "agentId"); this.agentName = agentName; this.applicationName = Objects.requireNonNull(applicationName, "applicationName"); + this.serviceName = Objects.requireNonNull(serviceName, "serviceName"); this.serviceType = serviceType; this.agentStartTime = agentStartTime; } public Metadata newHeader() { Metadata headers = new Metadata(); - headers.put(Header.AGENT_ID_KEY, agentId); + headers.put(Header.AGENT_ID_KEY, agentId.value()); headers.put(Header.APPLICATION_NAME_KEY, applicationName); + headers.put(Header.SERVICE_NAME_KEY, serviceName); headers.put(Header.SERVICE_TYPE_KEY, Integer.toString(serviceType)); headers.put(Header.AGENT_START_TIME_KEY, Long.toString(agentStartTime)); if (!StringUtils.isEmpty(agentName)) { diff --git a/grpc/src/main/java/com/navercorp/pinpoint/grpc/Header.java b/grpc/src/main/java/com/navercorp/pinpoint/grpc/Header.java index 62cf07f59876..c34c87710473 100644 --- a/grpc/src/main/java/com/navercorp/pinpoint/grpc/Header.java +++ b/grpc/src/main/java/com/navercorp/pinpoint/grpc/Header.java @@ -16,6 +16,7 @@ package com.navercorp.pinpoint.grpc; +import com.navercorp.pinpoint.common.id.AgentId; import io.grpc.Metadata; import java.util.Collections; @@ -32,6 +33,7 @@ public class Header { public static final Metadata.Key AGENT_ID_KEY = newStringKey("agentid"); public static final Metadata.Key AGENT_NAME_KEY = newStringKey("agentname"); public static final Metadata.Key APPLICATION_NAME_KEY = newStringKey("applicationname"); + public static final Metadata.Key SERVICE_NAME_KEY = newStringKey("servicename"); public static final Metadata.Key AGENT_START_TIME_KEY = newStringKey("starttime"); // optional header @@ -51,25 +53,26 @@ private static Metadata.Key newStringKey(String s) { public static final List SUPPORT_COMMAND_CODE_LIST_PARSE_ERROR = Collections.emptyList(); private final String name; - private final String agentId; + private final AgentId agentId; private final String agentName; private final String applicationName; + private final String serviceName; private final long agentStartTime; private final long socketId; private final int serviceType; private final List supportCommandCodeList; private final Map properties; - public Header(String name, String agentId, String agentName, String applicationName, + public Header(String name, AgentId agentId, String agentName, String applicationName, String serviceName, int serviceType, long agentStartTime, long socketId, List supportCommandCodeList) { - this(name, agentId, agentName, applicationName, + this(name, agentId, agentName, applicationName, serviceName, serviceType, agentStartTime, socketId, supportCommandCodeList, Collections.emptyMap()); } public Header(String name, - String agentId, String agentName, String applicationName, + AgentId agentId, String agentName, String applicationName, String serviceName, int serviceType, long agentStartTime, long socketId, List supportCommandCodeList, @@ -77,6 +80,7 @@ public Header(String name, this.name = Objects.requireNonNull(name, "name"); this.agentId = Objects.requireNonNull(agentId, "agentId"); this.applicationName = Objects.requireNonNull(applicationName, "applicationName"); + this.serviceName = Objects.requireNonNull(serviceName, "serviceName"); this.serviceType = serviceType; this.agentStartTime = agentStartTime; this.socketId = socketId; @@ -86,7 +90,7 @@ public Header(String name, this.properties = Objects.requireNonNull(properties, "properties"); } - public String getAgentId() { + public AgentId getAgentId() { return agentId; } @@ -98,6 +102,10 @@ public String getApplicationName() { return applicationName; } + public String getServiceName() { + return serviceName; + } + public long getAgentStartTime() { return agentStartTime; } @@ -129,6 +137,7 @@ public String toString() { ", agentId='" + agentId + '\'' + ", agentName='" + agentName + '\'' + ", applicationName='" + applicationName + '\'' + + ", serviceName='" + serviceName + '\'' + ", agentStartTime=" + agentStartTime + ", socketId=" + socketId + ", serviceType=" + serviceType + @@ -151,6 +160,8 @@ public boolean equals(Object o) { if (agentId != null ? !agentId.equals(header.agentId) : header.agentId != null) return false; if (applicationName != null ? !applicationName.equals(header.applicationName) : header.applicationName != null) return false; + if (serviceName != null ? !serviceName.equals(header.serviceName) : header.serviceName != null) + return false; if (supportCommandCodeList != null ? !supportCommandCodeList.equals(header.supportCommandCodeList) : header.supportCommandCodeList != null) return false; return properties != null ? properties.equals(header.properties) : header.properties == null; @@ -161,6 +172,7 @@ public int hashCode() { int result = name != null ? name.hashCode() : 0; result = 31 * result + (agentId != null ? agentId.hashCode() : 0); result = 31 * result + (applicationName != null ? applicationName.hashCode() : 0); + result = 31 * result + (serviceName != null ? serviceName.hashCode() : 0); result = 31 * result + (int) (agentStartTime ^ (agentStartTime >>> 32)); result = 31 * result + (int) (socketId ^ (socketId >>> 32)); result = 31 * result + serviceType; diff --git a/grpc/src/main/java/com/navercorp/pinpoint/grpc/server/AgentHeaderReader.java b/grpc/src/main/java/com/navercorp/pinpoint/grpc/server/AgentHeaderReader.java index 1dcee81161d9..674ca6e844ec 100644 --- a/grpc/src/main/java/com/navercorp/pinpoint/grpc/server/AgentHeaderReader.java +++ b/grpc/src/main/java/com/navercorp/pinpoint/grpc/server/AgentHeaderReader.java @@ -17,6 +17,8 @@ package com.navercorp.pinpoint.grpc.server; import com.navercorp.pinpoint.common.PinpointConstants; +import com.navercorp.pinpoint.common.id.AgentId; +import com.navercorp.pinpoint.common.id.ServiceId; import com.navercorp.pinpoint.common.trace.ServiceType; import com.navercorp.pinpoint.common.util.IdValidateUtils; import com.navercorp.pinpoint.common.util.StringUtils; @@ -57,12 +59,13 @@ public Header extract(Metadata headers) { final String agentId = getId(headers, Header.AGENT_ID_KEY, PinpointConstants.AGENT_ID_MAX_LEN); final String agentName = getAgentName(headers, Header.AGENT_NAME_KEY); final String applicationName = getId(headers, Header.APPLICATION_NAME_KEY, PinpointConstants.APPLICATION_NAME_MAX_LEN); + final String serviceName = getServiceName(headers, Header.SERVICE_NAME_KEY); final long startTime = getTime(headers, Header.AGENT_START_TIME_KEY); final int serviceType = getServiceType(headers); final long socketId = getSocketId(headers); final List supportCommandCodeList = getSupportCommandCodeList(headers); final Map properties = metadataConverter.apply(headers); - return new Header(name, agentId, agentName, applicationName, serviceType, startTime, socketId, supportCommandCodeList, properties); + return new Header(name, AgentId.of(agentId), agentName, applicationName, serviceName, serviceType, startTime, socketId, supportCommandCodeList, properties); } public static Map emptyProperties(Metadata headers) { @@ -90,6 +93,14 @@ protected String getId(Metadata headers, Metadata.Key idKey, int maxLen) return validateId(id, idKey, maxLen); } + protected String getServiceName(Metadata headers, Metadata.Key idKey) { + final String name = headers.get(idKey); + if (name == null) { + return ServiceId.DEFAULT_SERVICE_NAME; + } + return validateId(name, idKey, PinpointConstants.SERVICE_NAME_MAX_LEN); + } + protected String getAgentName(Metadata headers, Metadata.Key idKey) { final String name = headers.get(idKey); if (!StringUtils.isEmpty(name)) { diff --git a/grpc/src/test/java/com/navercorp/pinpoint/grpc/ChannelFactoryTest.java b/grpc/src/test/java/com/navercorp/pinpoint/grpc/ChannelFactoryTest.java index 8a378289bd12..4e549fa36936 100644 --- a/grpc/src/test/java/com/navercorp/pinpoint/grpc/ChannelFactoryTest.java +++ b/grpc/src/test/java/com/navercorp/pinpoint/grpc/ChannelFactoryTest.java @@ -17,6 +17,7 @@ package com.navercorp.pinpoint.grpc; import com.google.protobuf.Empty; +import com.navercorp.pinpoint.common.id.AgentId; import com.navercorp.pinpoint.common.profiler.concurrent.PinpointThreadFactory; import com.navercorp.pinpoint.common.trace.ServiceType; import com.navercorp.pinpoint.grpc.client.ChannelFactory; @@ -104,7 +105,8 @@ public static void tearDown() throws Exception { @Test public void build() throws InterruptedException { - HeaderFactory headerFactory = new AgentHeaderFactory("agentId", "agentName", "appName", ServiceType.UNDEFINED.getCode(), System.currentTimeMillis()); + HeaderFactory headerFactory = new AgentHeaderFactory(AgentId.of("agentId"), "agentName", "appName", "serviceName", + ServiceType.UNDEFINED.getCode(), System.currentTimeMillis()); CountRecordClientInterceptor countRecordClientInterceptor = new CountRecordClientInterceptor(); @@ -140,7 +142,9 @@ public void build() throws InterruptedException { Assertions.assertEquals(1, countRecordClientInterceptor.getExecutedInterceptCallCount()); logger.debug("state:{}", managedChannel.getState(true)); - spanService.awaitOnCompleted(); + if (!spanService.awaitOnCompleted()) { + Assertions.fail("awaitOnCompleted"); + } logger.debug("managedChannel shutdown"); managedChannel.shutdown(); managedChannel.awaitTermination(1000, TimeUnit.MILLISECONDS); @@ -171,8 +175,7 @@ private static Server serverStart(ExecutorService executorService) serverFactory.addService(spanService); addFilter(serverFactory); - Server server = serverFactory.build(); - return server; + return serverFactory.build(); } private static void addFilter(ServerFactory serverFactory) { diff --git a/grpc/src/test/java/com/navercorp/pinpoint/grpc/server/AgentHeaderReaderTest.java b/grpc/src/test/java/com/navercorp/pinpoint/grpc/server/AgentHeaderReaderTest.java index 85102522e7ff..fa997827f749 100644 --- a/grpc/src/test/java/com/navercorp/pinpoint/grpc/server/AgentHeaderReaderTest.java +++ b/grpc/src/test/java/com/navercorp/pinpoint/grpc/server/AgentHeaderReaderTest.java @@ -43,7 +43,7 @@ public void extract() { Metadata metadata = newMetadata(); Header header = reader.extract(metadata); - Assertions.assertEquals(header.getAgentId(), AGENT_ID); + Assertions.assertEquals(header.getAgentId().value(), AGENT_ID); Assertions.assertEquals(header.getAgentName(), AGENT_NAME); Assertions.assertEquals(header.getApplicationName(), APPLICATION_NAME); Assertions.assertEquals(header.getAgentStartTime(), AGENT_START_TIME); diff --git a/hbase/scripts/hbase-create.hbase b/hbase/scripts/hbase-create.hbase index 2c72d1664102..9390dff511da 100644 --- a/hbase/scripts/hbase-create.hbase +++ b/hbase/scripts/hbase-create.hbase @@ -26,6 +26,8 @@ create 'ApplicationIndex_Ver2', { NAME => 'Agents', TTL => 31536000, DATA_BLOCK_ create 'ApplicationId', { NAME => 'F', TTL => 5184000, DATA_BLOCK_ENCODING => 'PREFIX' }, { NAME => 'I', TTL => 5184000, DATA_BLOCK_ENCODING => 'PREFIX' }, {SPLITS=>["\x02\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00","\x04\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00","\x06\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00","\x08\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00","\x0a\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00","\x0c\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00","\x0e\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00","\x10\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00","\x12\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00","\x14\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00","\x16\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00","\x18\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00","\x1a\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00","\x1c\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00","\x1e\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"]} create 'ApplicationTraceIndex_Ver2', { NAME => 'I', TTL => 5184000, DATA_BLOCK_ENCODING => 'PREFIX' }, { NAME => 'M', TTL => 5184000, DATA_BLOCK_ENCODING => 'PREFIX' }, {SPLITS=>["\x02\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00","\x04\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00","\x06\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00","\x08\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00","\x0a\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00","\x0c\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00","\x0e\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00","\x10\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00","\x12\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00","\x14\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00","\x16\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00","\x18\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00","\x1a\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00","\x1c\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00","\x1e\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"]} +create 'ServiceId', { NAME => 'F', TTL => 5184000, DATA_BLOCK_ENCODING => 'PREFIX' }, { NAME => 'I', TTL => 5184000, DATA_BLOCK_ENCODING => 'PREFIX' }, {SPLITS=>["\x02\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00","\x04\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00","\x06\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00","\x08\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00","\x0a\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00","\x0c\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00","\x0e\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00","\x10\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00","\x12\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00","\x14\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00","\x16\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00","\x18\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00","\x1a\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00","\x1c\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00","\x1e\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"]} + list exit diff --git a/hbase/scripts/hbase-drop.hbase b/hbase/scripts/hbase-drop.hbase index a2a3bcb9c928..849ffb2ab2a2 100644 --- a/hbase/scripts/hbase-drop.hbase +++ b/hbase/scripts/hbase-drop.hbase @@ -20,6 +20,12 @@ disable 'ApplicationMapStatisticsSelf_Ver2' disable 'HostApplicationMap_Ver2' +disable 'ApplicationIndex_Ver2' +disable 'ApplicationId' +disable 'ApplicationTraceIndex_Ver2' + +disable 'ServiceId' + drop 'AgentInfo' drop 'AgentStatV2' @@ -43,4 +49,11 @@ drop 'ApplicationMapStatisticsSelf_Ver2' drop 'HostApplicationMap_Ver2' +drop 'ApplicationIndex_Ver2' +drop 'ApplicationId' +drop 'ApplicationTraceIndex_Ver2' + +drop 'ServiceId' + + exit diff --git a/realtime/realtime-collector/src/test/java/com/navercorp/pinpoint/realtime/collector/receiver/grpc/GrpcCommandServiceTest.java b/realtime/realtime-collector/src/test/java/com/navercorp/pinpoint/realtime/collector/receiver/grpc/GrpcCommandServiceTest.java index 9ae391b88a9b..7f8f0fbaeecc 100644 --- a/realtime/realtime-collector/src/test/java/com/navercorp/pinpoint/realtime/collector/receiver/grpc/GrpcCommandServiceTest.java +++ b/realtime/realtime-collector/src/test/java/com/navercorp/pinpoint/realtime/collector/receiver/grpc/GrpcCommandServiceTest.java @@ -17,6 +17,7 @@ import com.google.protobuf.Empty; import com.google.protobuf.StringValue; +import com.navercorp.pinpoint.common.id.AgentId; import com.navercorp.pinpoint.common.trace.ServiceType; import com.navercorp.pinpoint.grpc.Header; import com.navercorp.pinpoint.grpc.server.DefaultTransportMetadata; @@ -324,9 +325,10 @@ public ServerCall.Listener interceptCall(ServerCall filterAgentInfos(Set agentInfos, Instant times Set filteredAgentInfos = new HashSet<>(); List agentsToCheckStatus = new ArrayList<>(); for (AgentInfo agentInfo : agentInfos) { - String agentId = agentInfo.getAgentId(); + String agentId = agentInfo.getAgentId().value(); if (agentHistogramMap.containsKey(agentId)) { filteredAgentInfos.add(agentInfo); } else { diff --git a/web/src/main/java/com/navercorp/pinpoint/web/applicationmap/map/FilteredMapBuilder.java b/web/src/main/java/com/navercorp/pinpoint/web/applicationmap/map/FilteredMapBuilder.java index 4fcbf0ce8e74..d8c0faeadbe4 100644 --- a/web/src/main/java/com/navercorp/pinpoint/web/applicationmap/map/FilteredMapBuilder.java +++ b/web/src/main/java/com/navercorp/pinpoint/web/applicationmap/map/FilteredMapBuilder.java @@ -159,7 +159,7 @@ private void addLinkData(LinkDataMap linkDataMap, SpanBo span, Application paren // we need to convert to time window's timestamp. If not, it may lead to OOM due to mismatch in timeslots. long timestamp = timeWindow.refineTimestamp(span.getCollectorAcceptTime()); - final String spanAgentId = span.getAgentId(); + final String spanAgentId = span.getAgentId().value(); linkDataMap.addLinkData(parentApplication, spanAgentId, spanApplication, spanAgentId, timestamp, slotTime, 1); final HistogramSchema histogramSchema = spanApplication.serviceType().getHistogramSchema(); @@ -323,7 +323,7 @@ private void addNode(SpanBo span, MultiValueMap transactionSpanMap } // endPoint may be null final String destinationAgentId = StringUtils.defaultString(spanEvent.getEndPoint(), destApplication.name()); - sourceLinkDataMap.addLinkData(srcApplication, span.getAgentId(), destApplication, destinationAgentId, spanEventTimeStamp, slotTime, 1); + sourceLinkDataMap.addLinkData(srcApplication, span.getAgentId().value(), destApplication, destinationAgentId, spanEventTimeStamp, slotTime, 1); } public FilteredMap build() { diff --git a/web/src/main/java/com/navercorp/pinpoint/web/applicationmap/nodes/ServerInstance.java b/web/src/main/java/com/navercorp/pinpoint/web/applicationmap/nodes/ServerInstance.java index 99385da1dd98..61e942fb07f3 100644 --- a/web/src/main/java/com/navercorp/pinpoint/web/applicationmap/nodes/ServerInstance.java +++ b/web/src/main/java/com/navercorp/pinpoint/web/applicationmap/nodes/ServerInstance.java @@ -51,7 +51,7 @@ public ServerInstance(AgentInfo agentInfo, AgentStatus agentStatus) { Objects.requireNonNull(agentInfo, "agentInfo"); this.hostName = agentInfo.getHostName(); this.ip = agentInfo.getIp(); - this.name = agentInfo.getAgentId(); + this.name = agentInfo.getAgentId().value(); this.agentName = agentInfo.getAgentName(); this.serviceType = agentInfo.getServiceType(); this.status = getAgentLifeCycleState(agentStatus); diff --git a/web/src/main/java/com/navercorp/pinpoint/web/authorization/controller/AdminController.java b/web/src/main/java/com/navercorp/pinpoint/web/authorization/controller/AdminController.java index d9808f0668a0..6afbae9d1144 100644 --- a/web/src/main/java/com/navercorp/pinpoint/web/authorization/controller/AdminController.java +++ b/web/src/main/java/com/navercorp/pinpoint/web/authorization/controller/AdminController.java @@ -16,7 +16,12 @@ package com.navercorp.pinpoint.web.authorization.controller; +import com.navercorp.pinpoint.common.id.ApplicationId; +import com.navercorp.pinpoint.common.id.ServiceId; +import com.navercorp.pinpoint.common.server.bo.ApplicationSelector; import com.navercorp.pinpoint.web.service.AdminService; +import com.navercorp.pinpoint.web.service.ApplicationInfoService; +import com.navercorp.pinpoint.web.service.ServiceInfoService; import com.navercorp.pinpoint.web.vo.Application; import jakarta.validation.constraints.Min; import jakarta.validation.constraints.NotBlank; @@ -46,16 +51,27 @@ public class AdminController { private final Logger logger = LogManager.getLogger(this.getClass()); private final AdminService adminService; + private final ServiceInfoService serviceInfoService; + private final ApplicationInfoService applicationInfoService; - public AdminController(AdminService adminService) { + public AdminController( + AdminService adminService, + ServiceInfoService serviceInfoService, + ApplicationInfoService applicationInfoService + ) { this.adminService = Objects.requireNonNull(adminService, "adminService"); + this.serviceInfoService = Objects.requireNonNull(serviceInfoService, "serviceInfoService"); + this.applicationInfoService = Objects.requireNonNull(applicationInfoService, "applicationInfoService"); } @RequestMapping(value = "/removeApplicationName") - public String removeApplicationName(@RequestParam("applicationName") @NotBlank String applicationName) { - logger.info("Removing application - applicationName: [{}]", applicationName); + public String removeApplicationName( + @RequestParam(value = "serviceName", defaultValue = ServiceId.DEFAULT_SERVICE_NAME) String serviceName, + @RequestParam("applicationName") @NotBlank String applicationName + ) { try { - this.adminService.removeApplicationName(applicationName); + ApplicationId applicationId = this.getApplicationId(serviceName, applicationName); + this.adminService.removeApplicationName(applicationId); return "OK"; } catch (Exception e) { logger.error("error while removing applicationName", e); @@ -65,12 +81,14 @@ public String removeApplicationName(@RequestParam("applicationName") @NotBlank S @RequestMapping(value = "/removeAgentId") public String removeAgentId( + @RequestParam(value = "serviceName", defaultValue = ServiceId.DEFAULT_SERVICE_NAME) String serviceName, @RequestParam(value = "applicationName") @NotBlank String applicationName, @RequestParam(value = "agentId") @NotBlank String agentId ) { logger.info("Removing agent - applicationName: [{}], agentId: [{}]", applicationName, agentId); try { - this.adminService.removeAgentId(applicationName, agentId); + ApplicationId applicationId = this.getApplicationId(serviceName, applicationName); + this.adminService.removeAgentId(applicationId, agentId); return "OK"; } catch (Exception e) { logger.error("error while removing agentId", e); @@ -106,6 +124,7 @@ public Map> duplicateAgentIdMap() { @RequestMapping(value = "/getInactiveAgents") public Map> getInactiveAgents( + @RequestParam(value = "serviceName", defaultValue = ServiceId.DEFAULT_SERVICE_NAME) String serviceName, @RequestParam(value = "applicationName") @NotBlank String applicationName, @RequestParam(value = "durationDays", defaultValue = AdminService.MIN_DURATION_DAYS_FOR_INACTIVITY_STR) @Min(AdminService.MIN_DURATION_DAYS_FOR_INACTIVITY) @@ -113,7 +132,22 @@ public Map> getInactiveAgents( ) { logger.info("Getting in-active agents - applicationName: [{}], duration: {} days.", applicationName, durationDays); - return this.adminService.getInactiveAgents(applicationName, durationDays); + ApplicationId applicationId = this.getApplicationId(serviceName, applicationName); + return this.adminService.getInactiveAgents(applicationId, durationDays); + } + + private ApplicationId getApplicationId(String serviceName, String applicationName) { + ServiceId serviceId = this.serviceInfoService.getServiceId(serviceName); + if (serviceId == null) { + throw new ResponseStatusException(HttpStatus.NOT_FOUND, "Service [" + serviceName + "] not found"); + } + + ApplicationId applicationId = this.applicationInfoService.getApplicationId(new ApplicationSelector(serviceId, applicationName)); + if (applicationId == null) { + throw new ResponseStatusException(HttpStatus.NOT_FOUND, "Application [" + applicationName + "] not found"); + } + + return applicationId; } } \ No newline at end of file diff --git a/web/src/main/java/com/navercorp/pinpoint/web/cache/CacheConfiguration.java b/web/src/main/java/com/navercorp/pinpoint/web/cache/CacheConfiguration.java index 026a626aa2d7..1d421ba81628 100644 --- a/web/src/main/java/com/navercorp/pinpoint/web/cache/CacheConfiguration.java +++ b/web/src/main/java/com/navercorp/pinpoint/web/cache/CacheConfiguration.java @@ -16,8 +16,11 @@ package com.navercorp.pinpoint.web.cache; +import com.github.benmanes.caffeine.cache.Cache; import com.github.benmanes.caffeine.cache.Caffeine; import com.navercorp.pinpoint.common.server.config.CommonCacheManagerConfiguration; +import com.navercorp.pinpoint.common.server.config.CustomCacheRegistration; +import com.navercorp.pinpoint.common.server.config.DefaultCustomCacheRegistration; import org.springframework.cache.CacheManager; import org.springframework.cache.annotation.CachingConfigurer; import org.springframework.cache.annotation.EnableCaching; @@ -46,6 +49,16 @@ public CacheManager apiMetaData() { return caffeineCacheManager; } + @Bean + public CustomCacheRegistration apiMetadataCache() { + Cache cache = Caffeine.newBuilder() + .expireAfterWrite(600, TimeUnit.SECONDS) + .initialCapacity(500) + .maximumSize(10000) + .build(); + return new DefaultCustomCacheRegistration(API_METADATA_CACHE_NAME, cache); + } + @Bean public CacheManager applicationNameList() { CaffeineCacheManager caffeineCacheManager = new CaffeineCacheManager(APPLICATION_LIST_CACHE_NAME); @@ -56,4 +69,14 @@ public CacheManager applicationNameList() { return caffeineCacheManager; } + @Bean + public CustomCacheRegistration applicationNameListCache() { + Cache cache = Caffeine.newBuilder() + .expireAfterWrite(120, TimeUnit.SECONDS) + .initialCapacity(10) + .maximumSize(200) + .build(); + return new DefaultCustomCacheRegistration(APPLICATION_LIST_CACHE_NAME, cache); + } + } diff --git a/web/src/main/java/com/navercorp/pinpoint/web/calltree/span/MetaSpanCallTreeFactory.java b/web/src/main/java/com/navercorp/pinpoint/web/calltree/span/MetaSpanCallTreeFactory.java index 14f921490524..5a238c5547c6 100644 --- a/web/src/main/java/com/navercorp/pinpoint/web/calltree/span/MetaSpanCallTreeFactory.java +++ b/web/src/main/java/com/navercorp/pinpoint/web/calltree/span/MetaSpanCallTreeFactory.java @@ -16,6 +16,7 @@ package com.navercorp.pinpoint.web.calltree.span; +import com.navercorp.pinpoint.common.id.AgentId; import com.navercorp.pinpoint.common.profiler.util.TransactionId; import com.navercorp.pinpoint.common.server.bo.AnnotationBo; import com.navercorp.pinpoint.common.server.bo.ApiMetaDataBo; @@ -33,13 +34,13 @@ * @author jaehong.kim */ public class MetaSpanCallTreeFactory { - private static final long DEFAULT_TIMEOUT_MILLISEC = 60 * 1000; + private static final long DEFAULT_TIMEOUT_MILLI = 60 * 1000; - private static final String UNKNOWN_AGENT_ID = "UNKNOWN"; - private static final String CORRUPTED_AGENT_ID = "CORRUPTED"; + private static final AgentId UNKNOWN_AGENT_ID = AgentId.of("UNKNOWN"); + private static final AgentId CORRUPTED_AGENT_ID = AgentId.of("CORRUPTED"); private static final long AGENT_START_TIME = 0; - private long timeoutMillisec = DEFAULT_TIMEOUT_MILLISEC; + private final long timeoutMilli = DEFAULT_TIMEOUT_MILLI; public CallTree unknown(final long startTimeMillis) { final SpanBo rootSpan = new SpanBo(); @@ -50,7 +51,7 @@ public CallTree unknown(final long startTimeMillis) { rootSpan.setServiceType(ServiceType.UNKNOWN.getCode()); List annotations = new ArrayList<>(); - ApiMetaDataBo apiMetaData = new ApiMetaDataBo(UNKNOWN_AGENT_ID, AGENT_START_TIME, 0, LineNumber.NO_LINE_NUMBER, + ApiMetaDataBo apiMetaData = new ApiMetaDataBo(UNKNOWN_AGENT_ID.value(), AGENT_START_TIME, 0, LineNumber.NO_LINE_NUMBER, MethodTypeEnum.WEB_REQUEST, "Unknown"); final AnnotationBo apiMetaDataAnnotation = AnnotationBo.of(AnnotationKey.API_METADATA.getCode(), apiMetaData); @@ -76,7 +77,7 @@ public SpanCallTree corrupted(final String title, final long parentSpanId, final List annotations = new ArrayList<>(); - ApiMetaDataBo apiMetaData = new ApiMetaDataBo(CORRUPTED_AGENT_ID, AGENT_START_TIME, 0, LineNumber.NO_LINE_NUMBER, + ApiMetaDataBo apiMetaData = new ApiMetaDataBo(CORRUPTED_AGENT_ID.value(), AGENT_START_TIME, 0, LineNumber.NO_LINE_NUMBER, MethodTypeEnum.CORRUPTED, "..."); final AnnotationBo apiMetaDataAnnotation = AnnotationBo.of(AnnotationKey.API_METADATA.getCode(), apiMetaData); @@ -92,7 +93,7 @@ public SpanCallTree corrupted(final String title, final long parentSpanId, final } private String getErrorMessage(String title, long startTimeMillis) { - if (System.currentTimeMillis() - startTimeMillis < timeoutMillisec) { + if (System.currentTimeMillis() - startTimeMillis < timeoutMilli) { return "Corrupted(waiting for packet) "; } else { if (title != null) { diff --git a/web/src/main/java/com/navercorp/pinpoint/web/calltree/span/SpanAlign.java b/web/src/main/java/com/navercorp/pinpoint/web/calltree/span/SpanAlign.java index 049a72814099..57088a097e2f 100644 --- a/web/src/main/java/com/navercorp/pinpoint/web/calltree/span/SpanAlign.java +++ b/web/src/main/java/com/navercorp/pinpoint/web/calltree/span/SpanAlign.java @@ -16,6 +16,7 @@ package com.navercorp.pinpoint.web.calltree.span; +import com.navercorp.pinpoint.common.id.AgentId; import com.navercorp.pinpoint.common.server.bo.AnnotationBo; import com.navercorp.pinpoint.common.server.bo.SpanBo; import com.navercorp.pinpoint.common.server.bo.SpanChunkBo; @@ -168,10 +169,10 @@ public long getElapsed() { @Override public String getAgentId() { if (isMeta()) { - return " "; + return AgentId.of(" ").value(); } - return spanBo.getAgentId(); + return spanBo.getAgentId().value(); } @Override diff --git a/web/src/main/java/com/navercorp/pinpoint/web/calltree/span/SpanEventAlign.java b/web/src/main/java/com/navercorp/pinpoint/web/calltree/span/SpanEventAlign.java index 22185421d614..b3df4f236b6c 100644 --- a/web/src/main/java/com/navercorp/pinpoint/web/calltree/span/SpanEventAlign.java +++ b/web/src/main/java/com/navercorp/pinpoint/web/calltree/span/SpanEventAlign.java @@ -144,7 +144,7 @@ public long getElapsed() { @Override public String getAgentId() { - return spanBo.getAgentId(); + return spanBo.getAgentId().value(); } @Override diff --git a/web/src/main/java/com/navercorp/pinpoint/web/component/ApplicationFactory.java b/web/src/main/java/com/navercorp/pinpoint/web/component/ApplicationFactory.java index d2def1697381..5e89b5f97991 100644 --- a/web/src/main/java/com/navercorp/pinpoint/web/component/ApplicationFactory.java +++ b/web/src/main/java/com/navercorp/pinpoint/web/component/ApplicationFactory.java @@ -17,17 +17,16 @@ package com.navercorp.pinpoint.web.component; +import com.navercorp.pinpoint.common.id.ApplicationId; import com.navercorp.pinpoint.common.trace.ServiceType; import com.navercorp.pinpoint.web.vo.Application; -import java.util.UUID; - /** * @author emeroad */ public interface ApplicationFactory { - Application createApplication(UUID applicationId, String applicationName, short serviceTypeCode); + Application createApplication(ApplicationId applicationId, String applicationName, short serviceTypeCode); Application createApplication(String applicationName, short serviceTypeCode); diff --git a/web/src/main/java/com/navercorp/pinpoint/web/component/DefaultApplicationFactory.java b/web/src/main/java/com/navercorp/pinpoint/web/component/DefaultApplicationFactory.java index 795215b66ab0..c6292285107a 100644 --- a/web/src/main/java/com/navercorp/pinpoint/web/component/DefaultApplicationFactory.java +++ b/web/src/main/java/com/navercorp/pinpoint/web/component/DefaultApplicationFactory.java @@ -17,13 +17,13 @@ package com.navercorp.pinpoint.web.component; +import com.navercorp.pinpoint.common.id.ApplicationId; import com.navercorp.pinpoint.common.trace.ServiceType; import com.navercorp.pinpoint.loader.service.ServiceTypeRegistryService; import com.navercorp.pinpoint.web.vo.Application; import org.springframework.stereotype.Component; import java.util.Objects; -import java.util.UUID; /** * @author emeroad @@ -38,7 +38,7 @@ public DefaultApplicationFactory(ServiceTypeRegistryService registry) { } @Override - public Application createApplication(UUID applicationId, String applicationName, short serviceTypeCode) { + public Application createApplication(ApplicationId applicationId, String applicationName, short serviceTypeCode) { final ServiceType serviceType = registry.findServiceType(serviceTypeCode); return new Application(applicationId, applicationName, serviceType); } diff --git a/web/src/main/java/com/navercorp/pinpoint/web/controller/ApplicationController.java b/web/src/main/java/com/navercorp/pinpoint/web/controller/ApplicationController.java index 3242af980c96..c2998520643c 100644 --- a/web/src/main/java/com/navercorp/pinpoint/web/controller/ApplicationController.java +++ b/web/src/main/java/com/navercorp/pinpoint/web/controller/ApplicationController.java @@ -16,10 +16,15 @@ package com.navercorp.pinpoint.web.controller; import com.navercorp.pinpoint.common.PinpointConstants; +import com.navercorp.pinpoint.common.id.ApplicationId; +import com.navercorp.pinpoint.common.id.ServiceId; +import com.navercorp.pinpoint.common.server.bo.ApplicationSelector; import com.navercorp.pinpoint.common.util.IdValidateUtils; import com.navercorp.pinpoint.web.response.CodeResult; import com.navercorp.pinpoint.web.service.AgentInfoService; +import com.navercorp.pinpoint.web.service.ApplicationInfoService; import com.navercorp.pinpoint.web.service.ApplicationService; +import com.navercorp.pinpoint.web.service.ServiceInfoService; import com.navercorp.pinpoint.web.vo.tree.ApplicationAgentHostList; import jakarta.validation.constraints.NotBlank; import jakarta.validation.constraints.Positive; @@ -44,11 +49,19 @@ public class ApplicationController { public static final int MAX_PAGING_LIMIT = 100; + private final ServiceInfoService serviceInfoService; + private final ApplicationInfoService applicationInfoService; private final AgentInfoService agentInfoService; - private final ApplicationService applicationService; - public ApplicationController(AgentInfoService agentInfoService, ApplicationService applicationService) { + public ApplicationController( + ServiceInfoService serviceInfoService, + ApplicationInfoService applicationInfoService, + AgentInfoService agentInfoService, + ApplicationService applicationService + ) { + this.serviceInfoService = Objects.requireNonNull(serviceInfoService, "serviceInfoService"); + this.applicationInfoService = Objects.requireNonNull(applicationInfoService, "applicationInfoService"); this.agentInfoService = Objects.requireNonNull(agentInfoService, "agentInfoService"); this.applicationService = Objects.requireNonNull(applicationService, "applicationService"); } @@ -67,6 +80,7 @@ public ApplicationAgentHostList getApplicationHostInfo ( @RequestMapping(value = "/isAvailableApplicationName") public CodeResult isAvailableApplicationName( + @RequestParam(value = "serviceName", defaultValue = ServiceId.DEFAULT_SERVICE_NAME) String serviceName, @RequestParam("applicationName") @NotBlank String applicationName ) { final IdValidateUtils.CheckResult result = @@ -81,7 +95,15 @@ public CodeResult isAvailableApplicationName( ); } - if (applicationService.isExistApplicationName(applicationName)) { + ServiceId serviceId = this.serviceInfoService.getServiceId(serviceName); + if (serviceId == null) { + throw new ResponseStatusException(HttpStatus.BAD_REQUEST, "serviceName not found"); + } + + ApplicationId applicationId = this.applicationInfoService.getApplicationId(new ApplicationSelector(serviceId, applicationName)); + + + if (applicationService.isExistApplicationName(applicationId)) { throw new ResponseStatusException(HttpStatus.INTERNAL_SERVER_ERROR, "applicationName already exists"); } diff --git a/web/src/main/java/com/navercorp/pinpoint/web/dao/AgentLifeCycleDao.java b/web/src/main/java/com/navercorp/pinpoint/web/dao/AgentLifeCycleDao.java index 9fcc58ec3a1d..b9e86cddecb2 100644 --- a/web/src/main/java/com/navercorp/pinpoint/web/dao/AgentLifeCycleDao.java +++ b/web/src/main/java/com/navercorp/pinpoint/web/dao/AgentLifeCycleDao.java @@ -16,6 +16,7 @@ package com.navercorp.pinpoint.web.dao; +import com.navercorp.pinpoint.common.id.AgentId; import com.navercorp.pinpoint.web.vo.agent.AgentStatus; import com.navercorp.pinpoint.web.vo.agent.AgentStatusQuery; @@ -29,7 +30,7 @@ public interface AgentLifeCycleDao { AgentStatus getAgentStatus(String agentId, long timestamp); - Optional getAgentStatus(String agentId, long agentStartTimestamp, long timestamp); + Optional getAgentStatus(AgentId agentId, long agentStartTimestamp, long timestamp); List> getAgentStatus(AgentStatusQuery agentStatusQuery); diff --git a/web/src/main/java/com/navercorp/pinpoint/web/dao/ApplicationIndexDao.java b/web/src/main/java/com/navercorp/pinpoint/web/dao/ApplicationIndexDao.java index 640d40b96976..d09ffa4017a8 100644 --- a/web/src/main/java/com/navercorp/pinpoint/web/dao/ApplicationIndexDao.java +++ b/web/src/main/java/com/navercorp/pinpoint/web/dao/ApplicationIndexDao.java @@ -16,20 +16,20 @@ package com.navercorp.pinpoint.web.dao; +import com.navercorp.pinpoint.web.vo.Application; + import java.util.List; import java.util.Map; -import com.navercorp.pinpoint.web.vo.Application; - /** * * @author netspider * */ public interface ApplicationIndexDao { - List selectAllApplicationNames(); + List selectAllApplications(); - List selectApplicationName(String applicationName); + List selectApplicationByName(String applicationName); List selectAgentIds(String applicationName); diff --git a/web/src/main/java/com/navercorp/pinpoint/web/dao/ApplicationIndexDaoV2.java b/web/src/main/java/com/navercorp/pinpoint/web/dao/ApplicationIndexDaoV2.java index 4d411800c332..f3ada07d3c2a 100644 --- a/web/src/main/java/com/navercorp/pinpoint/web/dao/ApplicationIndexDaoV2.java +++ b/web/src/main/java/com/navercorp/pinpoint/web/dao/ApplicationIndexDaoV2.java @@ -16,11 +16,11 @@ package com.navercorp.pinpoint.web.dao; +import com.navercorp.pinpoint.common.id.ApplicationId; import com.navercorp.pinpoint.web.vo.Application; import java.util.List; import java.util.Map; -import java.util.UUID; /** * @@ -31,14 +31,14 @@ public interface ApplicationIndexDaoV2 { List selectAllApplicationNames(); - List selectApplicationName(UUID applicationId); + List selectApplicationName(ApplicationId applicationId); - List selectAgentIds(UUID applicationId); + List selectAgentIds(ApplicationId applicationId); - void deleteApplication(UUID applicationId); + void deleteApplication(ApplicationId applicationId); - void deleteAgentIds(Map> applicationAgentIdMap); + void deleteAgentIds(Map> applicationAgentIdMap); - void deleteAgentId(UUID applicationId, String agentId); + void deleteAgentId(ApplicationId applicationId, String agentId); } diff --git a/web/src/main/java/com/navercorp/pinpoint/web/dao/ApplicationInfoDao.java b/web/src/main/java/com/navercorp/pinpoint/web/dao/ApplicationInfoDao.java index a1e8348245df..31148a1e5c34 100644 --- a/web/src/main/java/com/navercorp/pinpoint/web/dao/ApplicationInfoDao.java +++ b/web/src/main/java/com/navercorp/pinpoint/web/dao/ApplicationInfoDao.java @@ -15,20 +15,27 @@ */ package com.navercorp.pinpoint.web.dao; +import com.navercorp.pinpoint.common.id.ApplicationId; +import com.navercorp.pinpoint.common.id.ServiceId; +import com.navercorp.pinpoint.common.server.bo.ApplicationInfo; +import com.navercorp.pinpoint.common.server.bo.ApplicationSelector; import com.navercorp.pinpoint.web.vo.Application; import java.util.List; -import java.util.UUID; /** * @author youngjin.kim2 */ public interface ApplicationInfoDao { - UUID getApplicationId(String applicationName); + ApplicationId getApplicationId(ApplicationSelector application); - String getApplicationName(UUID applicationId); + Application getApplication(ApplicationId application); + + ApplicationId putApplicationIdIfAbsent(ApplicationInfo application); List getApplications(); + + List getApplications(ServiceId serviceId); } diff --git a/web/src/main/java/com/navercorp/pinpoint/web/dao/ApplicationTraceIndexDaoV2.java b/web/src/main/java/com/navercorp/pinpoint/web/dao/ApplicationTraceIndexDaoV2.java index 89381c4cea31..af815d71b771 100644 --- a/web/src/main/java/com/navercorp/pinpoint/web/dao/ApplicationTraceIndexDaoV2.java +++ b/web/src/main/java/com/navercorp/pinpoint/web/dao/ApplicationTraceIndexDaoV2.java @@ -16,6 +16,7 @@ package com.navercorp.pinpoint.web.dao; +import com.navercorp.pinpoint.common.id.ApplicationId; import com.navercorp.pinpoint.common.profiler.util.TransactionId; import com.navercorp.pinpoint.common.server.util.time.Range; import com.navercorp.pinpoint.web.scatter.DragArea; @@ -25,7 +26,6 @@ import com.navercorp.pinpoint.web.vo.scatter.DotMetaData; import java.util.List; -import java.util.UUID; /** * @author emeroad @@ -33,19 +33,19 @@ */ public interface ApplicationTraceIndexDaoV2 { - boolean hasTraceIndex(UUID applicationId, Range range, boolean backwardDirection); + boolean hasTraceIndex(ApplicationId applicationId, Range range, boolean backwardDirection); - LimitedScanResult> scanTraceIndex(UUID applicationId, Range range, int limit, boolean backwardDirection); + LimitedScanResult> scanTraceIndex(ApplicationId applicationId, Range range, int limit, boolean backwardDirection); - LimitedScanResult> scanTraceScatterData(UUID applicationId, Range range, int limit, boolean scanBackward); + LimitedScanResult> scanTraceScatterData(ApplicationId applicationId, Range range, int limit, boolean scanBackward); - LimitedScanResult> scanTraceIndex(UUID applicationId, DragArea dragArea, int limit); + LimitedScanResult> scanTraceIndex(ApplicationId applicationId, DragArea dragArea, int limit); @Deprecated - LimitedScanResult> scanScatterData(UUID applicationId, DragAreaQuery dragAreaQuery, int limit); + LimitedScanResult> scanScatterData(ApplicationId applicationId, DragAreaQuery dragAreaQuery, int limit); - LimitedScanResult> scanScatterDataV2(UUID applicationId, DragAreaQuery dragAreaQuery, int limit); + LimitedScanResult> scanScatterDataV2(ApplicationId applicationId, DragAreaQuery dragAreaQuery, int limit); } diff --git a/web/src/main/java/com/navercorp/pinpoint/web/dao/ServiceInfoDao.java b/web/src/main/java/com/navercorp/pinpoint/web/dao/ServiceInfoDao.java new file mode 100644 index 000000000000..a0cf92976379 --- /dev/null +++ b/web/src/main/java/com/navercorp/pinpoint/web/dao/ServiceInfoDao.java @@ -0,0 +1,34 @@ +/* + * Copyright 2024 NAVER Corp. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.navercorp.pinpoint.web.dao; + +import com.navercorp.pinpoint.common.id.ServiceId; +import com.navercorp.pinpoint.common.server.bo.ServiceInfo; + +import java.util.List; + +/** + * @author youngjin.kim2 + */ +public interface ServiceInfoDao { + + ServiceId getServiceId(String serviceName); + + ServiceInfo getServiceInfo(ServiceId serviceId); + + List getServiceInfos(); + +} diff --git a/web/src/main/java/com/navercorp/pinpoint/web/dao/hbase/HbaseAgentLifeCycleDao.java b/web/src/main/java/com/navercorp/pinpoint/web/dao/hbase/HbaseAgentLifeCycleDao.java index ea7d0daedcbc..5062c6ec425d 100644 --- a/web/src/main/java/com/navercorp/pinpoint/web/dao/hbase/HbaseAgentLifeCycleDao.java +++ b/web/src/main/java/com/navercorp/pinpoint/web/dao/hbase/HbaseAgentLifeCycleDao.java @@ -21,6 +21,7 @@ import com.navercorp.pinpoint.common.hbase.ResultsExtractor; import com.navercorp.pinpoint.common.hbase.RowMapper; import com.navercorp.pinpoint.common.hbase.TableNameProvider; +import com.navercorp.pinpoint.common.id.AgentId; import com.navercorp.pinpoint.common.server.bo.AgentLifeCycleBo; import com.navercorp.pinpoint.common.server.bo.SimpleAgentKey; import com.navercorp.pinpoint.common.server.bo.serializer.agent.AgentIdRowKeyEncoder; @@ -83,7 +84,7 @@ public AgentStatus getAgentStatus(String agentId, long timestamp) { } @Override - public Optional getAgentStatus(String agentId, long agentStartTimestamp, long timestamp) { + public Optional getAgentStatus(AgentId agentId, long agentStartTimestamp, long timestamp) { if (agentId == null) { return Optional.empty(); } @@ -91,11 +92,11 @@ public Optional getAgentStatus(String agentId, long agentStartTimes // startTimestamp is stored in reverse order final long toTimestamp = agentStartTimestamp; final long fromTimestamp = toTimestamp - 1; - Scan scan = createScan(agentId, fromTimestamp, toTimestamp); + Scan scan = createScan(agentId.value(), fromTimestamp, toTimestamp); TableName agentLifeCycleTableName = tableNameProvider.getTableName(DESCRIPTOR.getTable()); AgentLifeCycleBo agentLifeCycleBo = this.hbaseOperations.find(agentLifeCycleTableName, scan, new MostRecentAgentLifeCycleResultsExtractor(this.agentLifeCycleMapper, timestamp)); - AgentStatus agentStatus = createAgentStatus(agentId, agentLifeCycleBo); + AgentStatus agentStatus = createAgentStatus(agentId.value(), agentLifeCycleBo); return Optional.of(agentStatus); } diff --git a/web/src/main/java/com/navercorp/pinpoint/web/dao/hbase/HbaseApplicationIndexDao.java b/web/src/main/java/com/navercorp/pinpoint/web/dao/hbase/HbaseApplicationIndexDao.java index e151784700a3..4723f6b640d2 100644 --- a/web/src/main/java/com/navercorp/pinpoint/web/dao/hbase/HbaseApplicationIndexDao.java +++ b/web/src/main/java/com/navercorp/pinpoint/web/dao/hbase/HbaseApplicationIndexDao.java @@ -68,7 +68,7 @@ public HbaseApplicationIndexDao(HbaseOperations hbaseOperations, } @Override - public List selectAllApplicationNames() { + public List selectAllApplications() { Scan scan = new Scan(); scan.setCaching(30); scan.addFamily(DESCRIPTOR.getName()); @@ -80,7 +80,7 @@ public List selectAllApplicationNames() { } @Override - public List selectApplicationName(String applicationName) { + public List selectApplicationByName(String applicationName) { return selectApplicationIndex0(applicationName, applicationNameMapper); } diff --git a/web/src/main/java/com/navercorp/pinpoint/web/dao/hbase/HbaseApplicationIndexDaoV2.java b/web/src/main/java/com/navercorp/pinpoint/web/dao/hbase/HbaseApplicationIndexDaoV2.java index 996009b5800f..a92479cbe71c 100644 --- a/web/src/main/java/com/navercorp/pinpoint/web/dao/hbase/HbaseApplicationIndexDaoV2.java +++ b/web/src/main/java/com/navercorp/pinpoint/web/dao/hbase/HbaseApplicationIndexDaoV2.java @@ -20,8 +20,8 @@ import com.navercorp.pinpoint.common.hbase.HbaseOperations; import com.navercorp.pinpoint.common.hbase.RowMapper; import com.navercorp.pinpoint.common.hbase.TableNameProvider; +import com.navercorp.pinpoint.common.id.ApplicationId; import com.navercorp.pinpoint.common.util.StringUtils; -import com.navercorp.pinpoint.common.util.UuidUtils; import com.navercorp.pinpoint.web.dao.ApplicationIndexDaoV2; import com.navercorp.pinpoint.web.util.ListListUtils; import com.navercorp.pinpoint.web.vo.Application; @@ -40,7 +40,6 @@ import java.util.List; import java.util.Map; import java.util.Objects; -import java.util.UUID; /** * @author netspider @@ -81,20 +80,20 @@ public List selectAllApplicationNames() { } @Override - public List selectApplicationName(UUID applicationId) { + public List selectApplicationName(ApplicationId applicationId) { return selectApplicationIndex0(applicationId, applicationNameMapper); } @Override - public List selectAgentIds(UUID applicationId) { + public List selectAgentIds(ApplicationId applicationId) { return selectApplicationIndex0(applicationId, agentIdMapper); } - private List selectApplicationIndex0(UUID applicationId, RowMapper> rowMapper) { + private List selectApplicationIndex0(ApplicationId applicationId, RowMapper> rowMapper) { Objects.requireNonNull(applicationId, "applicationId"); Objects.requireNonNull(rowMapper, "rowMapper"); - byte[] rowKey = UuidUtils.toBytes(applicationId); + byte[] rowKey = applicationId.toBytes(); Get get = new Get(rowKey); get.addFamily(DESCRIPTOR.getName()); @@ -104,10 +103,10 @@ private List selectApplicationIndex0(UUID applicationId, RowMapper> applicationAgentIdMap) { + public void deleteAgentIds(Map> applicationAgentIdMap) { if (MapUtils.isEmpty(applicationAgentIdMap)) { return; } List deletes = new ArrayList<>(applicationAgentIdMap.size()); - for (Map.Entry> entry : applicationAgentIdMap.entrySet()) { - UUID applicationId = entry.getKey(); + for (Map.Entry> entry : applicationAgentIdMap.entrySet()) { + ApplicationId applicationId = entry.getKey(); List agentIds = entry.getValue(); if (applicationId == null || CollectionUtils.isEmpty(agentIds)) { continue; } - Delete delete = new Delete(UuidUtils.toBytes(applicationId)); + Delete delete = new Delete(applicationId.toBytes()); for (String agentId : agentIds) { if (StringUtils.hasLength(agentId)) { delete.addColumns(DESCRIPTOR.getName(), Bytes.toBytes(agentId)); @@ -145,11 +144,11 @@ public void deleteAgentIds(Map> applicationAgentIdMap) { } @Override - public void deleteAgentId(UUID applicationId, String agentId) { + public void deleteAgentId(ApplicationId applicationId, String agentId) { Objects.requireNonNull(applicationId, "applicationId"); Assert.hasLength(agentId, "agentId"); - byte[] rowKey = UuidUtils.toBytes(applicationId); + byte[] rowKey = applicationId.toBytes(); Delete delete = new Delete(rowKey); byte[] qualifier = Bytes.toBytes(agentId); delete.addColumns(DESCRIPTOR.getName(), qualifier); diff --git a/web/src/main/java/com/navercorp/pinpoint/web/dao/hbase/HbaseApplicationInfoDao.java b/web/src/main/java/com/navercorp/pinpoint/web/dao/hbase/HbaseApplicationInfoDao.java index 28c786a9ee57..aaa9a84e0294 100644 --- a/web/src/main/java/com/navercorp/pinpoint/web/dao/hbase/HbaseApplicationInfoDao.java +++ b/web/src/main/java/com/navercorp/pinpoint/web/dao/hbase/HbaseApplicationInfoDao.java @@ -20,22 +20,27 @@ import com.navercorp.pinpoint.common.hbase.HbaseOperations; import com.navercorp.pinpoint.common.hbase.RowMapper; import com.navercorp.pinpoint.common.hbase.TableNameProvider; -import com.navercorp.pinpoint.common.server.util.HashUtils; -import com.navercorp.pinpoint.common.util.BytesUtils; -import com.navercorp.pinpoint.common.util.UuidUtils; +import com.navercorp.pinpoint.common.id.ApplicationId; +import com.navercorp.pinpoint.common.id.ServiceId; +import com.navercorp.pinpoint.common.server.bo.ApplicationInfo; +import com.navercorp.pinpoint.common.server.bo.ApplicationSelector; +import com.navercorp.pinpoint.common.trace.ServiceType; import com.navercorp.pinpoint.web.dao.ApplicationInfoDao; import com.navercorp.pinpoint.web.vo.Application; import org.apache.hadoop.hbase.TableName; +import org.apache.hadoop.hbase.client.CheckAndMutate; +import org.apache.hadoop.hbase.client.CheckAndMutateResult; import org.apache.hadoop.hbase.client.Get; +import org.apache.hadoop.hbase.client.Put; import org.apache.hadoop.hbase.client.Scan; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.stereotype.Repository; +import java.util.ArrayList; import java.util.List; import java.util.Objects; -import java.util.UUID; /** * @author youngjin.kim2 @@ -44,65 +49,72 @@ public class HbaseApplicationInfoDao implements ApplicationInfoDao { private final Logger logger = LogManager.getLogger(this.getClass()); + // TODO: This value is temporary, and the service type should be removed + private static final ServiceType DEFAULT_SERVICE_TYPE = ServiceType.STAND_ALONE; + private static final HbaseColumnFamily.ApplicationId DESCRIPTOR_FORWARD = HbaseColumnFamily.APPLICATION_ID_FORWARD; private static final HbaseColumnFamily.ApplicationId DESCRIPTOR_INVERSE = HbaseColumnFamily.APPLICATION_ID_INVERSE; private final HbaseOperations hbaseTemplate; private final TableNameProvider tableNameProvider; - private final RowMapper forwardRowMapper; - private final RowMapper inverseRowMapper; - private final RowMapper applicationRowMapper; + private final RowMapper forwardRowMapper; + private final RowMapper inverseRowMapper; public HbaseApplicationInfoDao( HbaseOperations hbaseTemplate, TableNameProvider tableNameProvider, - @Qualifier("applicationIdForwardMapper") RowMapper forwardRowMapper, - @Qualifier("applicationIdInverseMapper") RowMapper inverseRowMapper, - @Qualifier("applicationForwardMapper") RowMapper applicationRowMapper + @Qualifier("applicationIdForwardMapper") RowMapper forwardRowMapper, + @Qualifier("applicationIdInverseMapper") RowMapper inverseRowMapper ) { this.hbaseTemplate = Objects.requireNonNull(hbaseTemplate, "hbaseTemplate"); this.tableNameProvider = Objects.requireNonNull(tableNameProvider, "tableNameProvider"); this.forwardRowMapper = Objects.requireNonNull(forwardRowMapper, "forwardRowMapper"); this.inverseRowMapper = Objects.requireNonNull(inverseRowMapper, "inverseRowMapper"); - this.applicationRowMapper = Objects.requireNonNull(applicationRowMapper, "applicationRowMapper"); } @Override - public UUID getApplicationId(String applicationName) { - Objects.requireNonNull(applicationName, "applicationName"); + public ApplicationId getApplicationId(ApplicationSelector selector) { + Objects.requireNonNull(selector, "selector"); + Objects.requireNonNull(selector.serviceId(), "selector.serviceId"); + Objects.requireNonNull(selector.name(), "selector.applicationName"); if (logger.isDebugEnabled()) { - logger.debug("getApplicationId() applicationName:{}", applicationName); + logger.debug("getApplicationId() serviceId: {}, applicationName: {}", selector.serviceId(), selector.name()); } - TableName tableName = this.tableNameProvider.getTableName(DESCRIPTOR_FORWARD.getTable()); - byte[] rowKey = encodeStringAsRowKey(applicationName); - byte[] family = DESCRIPTOR_FORWARD.getName(); - byte[] qualifier = DESCRIPTOR_FORWARD.getName(); + TableName tableName = this.tableNameProvider.getTableName(DESCRIPTOR_INVERSE.getTable()); + byte[] rowKey = selector.toBytes(); + byte[] family = DESCRIPTOR_INVERSE.getName(); + byte[] qualifier = DESCRIPTOR_INVERSE.getName(); Get get = new Get(rowKey); get.addColumn(family, qualifier); - return hbaseTemplate.get(tableName, get, this.forwardRowMapper); + return hbaseTemplate.get(tableName, get, this.inverseRowMapper); } @Override - public String getApplicationName(UUID applicationId) { + public Application getApplication(ApplicationId applicationId) { Objects.requireNonNull(applicationId, "applicationId"); if (logger.isDebugEnabled()) { - logger.debug("getApplicationName() applicationId:{}", applicationId); + logger.debug("getApplication() applicationId:{}", applicationId); } - TableName tableName = this.tableNameProvider.getTableName(DESCRIPTOR_INVERSE.getTable()); - byte[] rowKey = UuidUtils.toBytes(applicationId); - byte[] family = DESCRIPTOR_INVERSE.getName(); - byte[] qualifier = DESCRIPTOR_INVERSE.getName(); + TableName tableName = this.tableNameProvider.getTableName(DESCRIPTOR_FORWARD.getTable()); + byte[] rowKey = applicationId.toBytes(); + byte[] family = DESCRIPTOR_FORWARD.getName(); + byte[] qualifier = DESCRIPTOR_FORWARD.getName(); Get get = new Get(rowKey); get.addColumn(family, qualifier); - return hbaseTemplate.get(tableName, get, this.inverseRowMapper); + ApplicationInfo info = hbaseTemplate.get(tableName, get, this.forwardRowMapper); + if (info == null) { + return null; + } + + return new Application(info.id(), info.name(), DEFAULT_SERVICE_TYPE); } @Override @@ -115,11 +127,83 @@ public List getApplications() { scan.setCaching(30); scan.addColumn(family, qualifier); - return hbaseTemplate.find(tableName, scan, this.applicationRowMapper); + List infos = hbaseTemplate.find(tableName, scan, this.forwardRowMapper); + return mapApplicationInfos(infos); + } + + @Override + public ApplicationId putApplicationIdIfAbsent(ApplicationInfo application) { + Objects.requireNonNull(application, "application"); + + if (logger.isDebugEnabled()) { + logger.debug("putApplicationIdIfAbsent() serviceId: {}, applicationName:{}, applicationId:{}", + application.serviceId(), application.name(), application.id()); + } + + CheckAndMutateResult camResult = putInverse(application); + if (camResult.isSuccess()) { + putForward(application); + } + + return getApplicationId(new ApplicationSelector(application.serviceId(), application.name())); } - private static byte[] encodeStringAsRowKey(String str) { - return HashUtils.hashBytes(BytesUtils.toBytes(str)).asBytes(); + @Override + public List getApplications(ServiceId serviceId) { + Objects.requireNonNull(serviceId, "serviceId"); + + if (logger.isDebugEnabled()) { + logger.debug("getApplications() serviceId:{}", serviceId); + } + + TableName tableName = this.tableNameProvider.getTableName(DESCRIPTOR_INVERSE.getTable()); + + Scan scan = new Scan(); + scan.setStartStopRowForPrefixScan(serviceId.toBytes()); + + return hbaseTemplate.find(tableName, scan, this.inverseRowMapper); + } + + private CheckAndMutateResult putInverse(ApplicationInfo application) { + ApplicationSelector selector = new ApplicationSelector(application.serviceId(), application.name()); + + TableName tableName = this.tableNameProvider.getTableName(DESCRIPTOR_INVERSE.getTable()); + byte[] rowKey = selector.toBytes(); + byte[] family = DESCRIPTOR_INVERSE.getName(); + byte[] qualifier = DESCRIPTOR_INVERSE.getName(); + byte[] value = application.id().toBytes(); + + Put put = new Put(rowKey); + put.addColumn(family, qualifier, value); + + CheckAndMutate checkAndMutate = CheckAndMutate.newBuilder(rowKey) + .ifNotExists(family, qualifier) + .build(put); + + return hbaseTemplate.checkAndMutate(tableName, checkAndMutate); + } + + private void putForward(ApplicationInfo application) { + ApplicationSelector selector = new ApplicationSelector(application.serviceId(), application.name()); + + TableName tableName = this.tableNameProvider.getTableName(DESCRIPTOR_FORWARD.getTable()); + byte[] rowKey = application.id().toBytes(); + byte[] family = DESCRIPTOR_FORWARD.getName(); + byte[] qualifier = DESCRIPTOR_FORWARD.getName(); + byte[] value = selector.toBytes(); + + Put put = new Put(rowKey); + put.addColumn(family, qualifier, value); + + hbaseTemplate.put(tableName, put); + } + + private List mapApplicationInfos(List infos) { + List applications = new ArrayList<>(infos.size()); + for (ApplicationInfo info : infos) { + applications.add(new Application(info.id(), info.name(), DEFAULT_SERVICE_TYPE)); + } + return applications; } } diff --git a/web/src/main/java/com/navercorp/pinpoint/web/dao/hbase/HbaseApplicationTraceIndexDaoV2.java b/web/src/main/java/com/navercorp/pinpoint/web/dao/hbase/HbaseApplicationTraceIndexDaoV2.java index b345aa1153fb..e28ad5356adc 100644 --- a/web/src/main/java/com/navercorp/pinpoint/web/dao/hbase/HbaseApplicationTraceIndexDaoV2.java +++ b/web/src/main/java/com/navercorp/pinpoint/web/dao/hbase/HbaseApplicationTraceIndexDaoV2.java @@ -23,6 +23,7 @@ import com.navercorp.pinpoint.common.hbase.RowMapper; import com.navercorp.pinpoint.common.hbase.TableNameProvider; import com.navercorp.pinpoint.common.hbase.util.CellUtils; +import com.navercorp.pinpoint.common.id.ApplicationId; import com.navercorp.pinpoint.common.profiler.util.TransactionId; import com.navercorp.pinpoint.common.server.bo.serializer.agent.ApplicationNameRowKeyEncoder; import com.navercorp.pinpoint.common.server.scatter.FuzzyRowKeyBuilder; @@ -56,7 +57,6 @@ import java.util.List; import java.util.Objects; -import java.util.UUID; import java.util.function.Predicate; /** @@ -104,12 +104,13 @@ public HbaseApplicationTraceIndexDaoV2(ScatterChartProperties scatterChartProper this.traceIdRowKeyDistributor = Objects.requireNonNull(traceIdRowKeyDistributor, "traceIdRowKeyDistributor"); } + @SuppressWarnings("unused") // used by spring public void setScanCacheSize(int scanCacheSize) { this.scanCacheSize = scanCacheSize; } @Override - public boolean hasTraceIndex(UUID applicationId, Range range, boolean backwardDirection) { + public boolean hasTraceIndex(ApplicationId applicationId, Range range, boolean backwardDirection) { Objects.requireNonNull(applicationId, "applicationId"); Objects.requireNonNull(range, "range"); logger.debug("hasTraceIndex {}", range); @@ -125,7 +126,7 @@ public boolean hasTraceIndex(UUID applicationId, Range range, boolean backwardDi } @Override - public LimitedScanResult> scanTraceIndex(final UUID applicationId, Range range, int limit, boolean scanBackward) { + public LimitedScanResult> scanTraceIndex(ApplicationId applicationId, Range range, int limit, boolean scanBackward) { Objects.requireNonNull(applicationId, "applicationId"); Objects.requireNonNull(range, "range"); if (limit < 0) { @@ -202,13 +203,13 @@ public int getLastTransactionElapsed() { } - private Scan createScan(UUID applicationId, Range range, boolean scanBackward, int limit) { + private Scan createScan(ApplicationId applicationId, Range range, boolean scanBackward, int limit) { Scan scan = new Scan(); scan.setCaching(this.scanCacheSize); applyLimitForScan(scan, limit); - byte[] traceIndexStartKey = rowKeyEncoder.encodeRowKey(applicationId, range.getFrom()); - byte[] traceIndexEndKey = rowKeyEncoder.encodeRowKey(applicationId, range.getTo()); + byte[] traceIndexStartKey = rowKeyEncoder.encodeRowKey(applicationId.value(), range.getFrom()); + byte[] traceIndexEndKey = rowKeyEncoder.encodeRowKey(applicationId.value(), range.getTo()); if (scanBackward) { // start key is replaced by end key because key has been reversed @@ -237,7 +238,7 @@ private void applyLimitForScan(Scan scan, int limit) { } @Override - public LimitedScanResult> scanTraceScatterData(UUID applicationId, Range range, int limit, boolean scanBackward) { + public LimitedScanResult> scanTraceScatterData(ApplicationId applicationId, Range range, int limit, boolean scanBackward) { Objects.requireNonNull(applicationId, "applicationId"); Objects.requireNonNull(range, "range"); if (limit < 0) { @@ -258,15 +259,15 @@ public LimitedScanResult> scanTraceScatterData(UUID applicationId, Ran } @Override - public LimitedScanResult> scanTraceIndex(UUID applicationName, DragArea dragArea, int limit) { - Objects.requireNonNull(applicationName, "applicationName"); + public LimitedScanResult> scanTraceIndex(ApplicationId applicationId, DragArea dragArea, int limit) { + Objects.requireNonNull(applicationId, "applicationId"); Objects.requireNonNull(dragArea, "dragArea"); LastRowAccessor lastRowAccessor = new LastRowAccessor(); final Range range = Range.newUncheckedRange(dragArea.getXLow(), dragArea.getXHigh()); logger.debug("scanTraceIndex range:{}", range); - final Scan scan = newFuzzyScanner(applicationName, dragArea, range); + final Scan scan = newFuzzyScanner(applicationId, dragArea, range); // TODO @@ -285,7 +286,7 @@ public LimitedScanResult> scanTraceIndex(UUID applicationNam @Deprecated @Override - public LimitedScanResult> scanScatterData(UUID applicationId, DragAreaQuery dragAreaQuery, int limit) { + public LimitedScanResult> scanScatterData(ApplicationId applicationId, DragAreaQuery dragAreaQuery, int limit) { Objects.requireNonNull(applicationId, "applicationId"); Objects.requireNonNull(dragAreaQuery, "dragAreaQuery"); @@ -307,7 +308,7 @@ private Predicate buildDotPredicate(DragAreaQuery dragAreaQuery) { } @Override - public LimitedScanResult> scanScatterDataV2(UUID applicationId, DragAreaQuery dragAreaQuery, int limit) { + public LimitedScanResult> scanScatterDataV2(ApplicationId applicationId, DragAreaQuery dragAreaQuery, int limit) { Objects.requireNonNull(applicationId, "applicationId"); Objects.requireNonNull(dragAreaQuery, "dragAreaQuery"); @@ -318,7 +319,7 @@ public LimitedScanResult> scanScatterDataV2(UUID applicationId return scanScatterData0(applicationId, dragAreaQuery, limit, true, mapper); } - private LimitedScanResult> scanScatterData0(UUID applicationId, DragAreaQuery dragAreaQuery, int limit, + private LimitedScanResult> scanScatterData0(ApplicationId applicationId, DragAreaQuery dragAreaQuery, int limit, boolean metadataScan, RowMapper> mapper) { Objects.requireNonNull(applicationId, "applicationId"); Objects.requireNonNull(dragAreaQuery, "dragAreaQuery"); @@ -376,7 +377,7 @@ public boolean test(Dot dot) { } } - private Scan newFuzzyScanner(UUID applicationId, DragArea dragArea, Range range) { + private Scan newFuzzyScanner(ApplicationId applicationId, DragArea dragArea, Range range) { final Scan scan = createScan(applicationId, range, true, -1); if (scatterChartProperties.isEnableFuzzyRowFilter()) { Filter filter = newFuzzyFilter(dragArea); diff --git a/web/src/main/java/com/navercorp/pinpoint/web/dao/hbase/HbaseHostApplicationMapDao.java b/web/src/main/java/com/navercorp/pinpoint/web/dao/hbase/HbaseHostApplicationMapDao.java index af16db143606..c421f2c7750a 100644 --- a/web/src/main/java/com/navercorp/pinpoint/web/dao/hbase/HbaseHostApplicationMapDao.java +++ b/web/src/main/java/com/navercorp/pinpoint/web/dao/hbase/HbaseHostApplicationMapDao.java @@ -56,7 +56,6 @@ public class HbaseHostApplicationMapDao implements HostApplicationMapDao { private static final int HOST_APPLICATION_MAP_VER2_NUM_PARTITIONS = 4; private final Logger logger = LogManager.getLogger(this.getClass()); - private int scanCacheSize = 10; private final HbaseOperations hbaseOperations; @@ -109,15 +108,16 @@ private Scan createScan(Application parentApplication, Range range) { logger.debug("scan parentApplication:{}, range:{}", parentApplication, range); } - // TODO need common logic for creating scanner + // TODO: need common logic for creating scanner final long startTime = TimeUtils.reverseTimeMillis(timeSlot.getTimeSlot(range.getFrom())); final long endTime = TimeUtils.reverseTimeMillis(timeSlot.getTimeSlot(range.getTo()) + 1); + // start key is replaced by end key because timestamp has been reversed final byte[] startKey = createKey(parentApplication, endTime); final byte[] endKey = createKey(parentApplication, startTime); Scan scan = new Scan(); - scan.setCaching(this.scanCacheSize); + scan.setCaching(10); scan.withStartRow(startKey); scan.withStopRow(endKey); scan.setId("HostApplicationScan_Ver2"); diff --git a/web/src/main/java/com/navercorp/pinpoint/web/dao/hbase/HbaseServiceInfoDao.java b/web/src/main/java/com/navercorp/pinpoint/web/dao/hbase/HbaseServiceInfoDao.java new file mode 100644 index 000000000000..cc7166f64d26 --- /dev/null +++ b/web/src/main/java/com/navercorp/pinpoint/web/dao/hbase/HbaseServiceInfoDao.java @@ -0,0 +1,120 @@ +/* + * Copyright 2024 NAVER Corp. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.navercorp.pinpoint.web.dao.hbase; + +import com.navercorp.pinpoint.common.hbase.HbaseColumnFamily; +import com.navercorp.pinpoint.common.hbase.HbaseOperations; +import com.navercorp.pinpoint.common.hbase.RowMapper; +import com.navercorp.pinpoint.common.hbase.TableNameProvider; +import com.navercorp.pinpoint.common.id.ServiceId; +import com.navercorp.pinpoint.common.server.bo.ServiceInfo; +import com.navercorp.pinpoint.common.util.BytesUtils; +import com.navercorp.pinpoint.web.dao.ServiceInfoDao; +import org.apache.hadoop.hbase.TableName; +import org.apache.hadoop.hbase.client.Get; +import org.apache.hadoop.hbase.client.Scan; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; +import org.springframework.beans.factory.annotation.Qualifier; +import org.springframework.stereotype.Repository; + +import java.util.List; +import java.util.Objects; + +/** + * @author youngjin.kim2 + */ +@Repository +public class HbaseServiceInfoDao implements ServiceInfoDao { + + private final Logger logger = LogManager.getLogger(this.getClass()); + + private static final HbaseColumnFamily.ServiceId DESCRIPTOR_FORWARD = HbaseColumnFamily.SERVICE_ID_FORWARD; + private static final HbaseColumnFamily.ServiceId DESCRIPTOR_INVERSE = HbaseColumnFamily.SERVICE_ID_INVERSE; + + private final HbaseOperations hbaseTemplate; + private final TableNameProvider tableNameProvider; + private final RowMapper forwardRowMapper; + private final RowMapper inverseRowMapper; + + public HbaseServiceInfoDao( + HbaseOperations hbaseTemplate, + TableNameProvider tableNameProvider, + @Qualifier("serviceIdForwardMapper") RowMapper forwardRowMapper, + @Qualifier("serviceIdInverseMapper") RowMapper inverseRowMapper + ) { + this.hbaseTemplate = Objects.requireNonNull(hbaseTemplate, "hbaseTemplate"); + this.tableNameProvider = Objects.requireNonNull(tableNameProvider, "tableNameProvider"); + this.forwardRowMapper = Objects.requireNonNull(forwardRowMapper, "forwardRowMapper"); + this.inverseRowMapper = Objects.requireNonNull(inverseRowMapper, "inverseRowMapper"); + } + + @Override + public ServiceId getServiceId(String serviceName) { + Objects.requireNonNull(serviceName, "serviceName"); + + if (logger.isDebugEnabled()) { + logger.debug("getServiceId() serviceName:{}", serviceName); + } + + TableName tableName = this.tableNameProvider.getTableName(DESCRIPTOR_INVERSE.getTable()); + byte[] rowKey = encodeStringAsRowKey(serviceName); + byte[] family = DESCRIPTOR_INVERSE.getName(); + byte[] qualifier = DESCRIPTOR_INVERSE.getName(); + + Get get = new Get(rowKey); + get.addColumn(family, qualifier); + + return hbaseTemplate.get(tableName, get, this.inverseRowMapper); + } + + @Override + public ServiceInfo getServiceInfo(ServiceId serviceId) { + Objects.requireNonNull(serviceId, "serviceId"); + + if (logger.isDebugEnabled()) { + logger.debug("getServiceInfo() serviceId:{}", serviceId); + } + + TableName tableName = this.tableNameProvider.getTableName(DESCRIPTOR_FORWARD.getTable()); + byte[] rowKey = serviceId.toBytes(); + byte[] family = DESCRIPTOR_FORWARD.getName(); + byte[] qualifier = DESCRIPTOR_FORWARD.getName(); + + Get get = new Get(rowKey); + get.addColumn(family, qualifier); + + return hbaseTemplate.get(tableName, get, this.forwardRowMapper); + } + + @Override + public List getServiceInfos() { + TableName tableName = this.tableNameProvider.getTableName(DESCRIPTOR_FORWARD.getTable()); + byte[] family = DESCRIPTOR_FORWARD.getName(); + byte[] qualifier = DESCRIPTOR_FORWARD.getName(); + + Scan scan = new Scan(); + scan.setCaching(30); + scan.addColumn(family, qualifier); + + return this.hbaseTemplate.find(tableName, scan, this.forwardRowMapper); + } + + private static byte[] encodeStringAsRowKey(String str) { + return BytesUtils.toBytes(str); + } + +} diff --git a/web/src/main/java/com/navercorp/pinpoint/web/filter/transaction/SpanContext.java b/web/src/main/java/com/navercorp/pinpoint/web/filter/transaction/SpanContext.java index 15fdd29d0555..c3f3bdd25075 100644 --- a/web/src/main/java/com/navercorp/pinpoint/web/filter/transaction/SpanContext.java +++ b/web/src/main/java/com/navercorp/pinpoint/web/filter/transaction/SpanContext.java @@ -16,6 +16,7 @@ package com.navercorp.pinpoint.web.filter.transaction; +import com.navercorp.pinpoint.common.id.AgentId; import com.navercorp.pinpoint.common.server.bo.SpanBo; import com.navercorp.pinpoint.common.trace.ServiceType; import com.navercorp.pinpoint.loader.service.ServiceTypeRegistryService; @@ -46,7 +47,7 @@ public List findNode(String findApplicationName, List findS final ServiceType applicationServiceType = serviceTypeRegistryService.findServiceType(span.getApplicationServiceType()); if (findApplicationName.equals(span.getApplicationName()) && includeServiceType(findServiceCode, applicationServiceType)) { // apply preAgentFilter - if (agentFilter.accept(span.getAgentId())) { + if (agentFilter.accept(AgentId.unwrap(span.getAgentId()))) { if (findList == null) { findList = new ArrayList<>(); } diff --git a/web/src/main/java/com/navercorp/pinpoint/web/mapper/ApplicationNameMapperV2.java b/web/src/main/java/com/navercorp/pinpoint/web/mapper/ApplicationNameMapperV2.java index 95ec0cf9e858..c95f996c726e 100644 --- a/web/src/main/java/com/navercorp/pinpoint/web/mapper/ApplicationNameMapperV2.java +++ b/web/src/main/java/com/navercorp/pinpoint/web/mapper/ApplicationNameMapperV2.java @@ -18,6 +18,7 @@ import com.navercorp.pinpoint.common.hbase.RowMapper; import com.navercorp.pinpoint.common.hbase.util.CellUtils; +import com.navercorp.pinpoint.common.id.ApplicationId; import com.navercorp.pinpoint.common.util.UuidUtils; import com.navercorp.pinpoint.web.component.ApplicationFactory; import com.navercorp.pinpoint.web.vo.Application; @@ -31,7 +32,6 @@ import java.util.List; import java.util.Objects; import java.util.Set; -import java.util.UUID; /** * @@ -51,7 +51,7 @@ public List mapRow(Result result, int rowNum) throws Exception { return Collections.emptyList(); } Set uniqueTypeCodes = new HashSet<>(); - UUID applicationId = UuidUtils.fromBytes(result.getRow()); + ApplicationId applicationId = ApplicationId.of(UuidUtils.fromBytes(result.getRow())); Cell[] rawCells = result.rawCells(); for (Cell cell : rawCells) { diff --git a/web/src/main/java/com/navercorp/pinpoint/web/mapper/SpanMapperV2.java b/web/src/main/java/com/navercorp/pinpoint/web/mapper/SpanMapperV2.java index 4177cacbe024..9ffbd1a993e7 100644 --- a/web/src/main/java/com/navercorp/pinpoint/web/mapper/SpanMapperV2.java +++ b/web/src/main/java/com/navercorp/pinpoint/web/mapper/SpanMapperV2.java @@ -242,7 +242,7 @@ private boolean isChildSpanChunk(SpanBo spanBo, SpanChunkBo spanChunkBo) { if (spanBo.getAgentStartTime() != spanChunkBo.getAgentStartTime()) { return false; } - if (!StringUtils.equals(spanBo.getAgentId(), spanChunkBo.getAgentId())) { + if (!StringUtils.equals(spanBo.getAgentId().value(), spanChunkBo.getAgentId().value())) { return false; } if (!StringUtils.equals(spanBo.getApplicationName(), spanChunkBo.getApplicationName())) { @@ -252,7 +252,7 @@ private boolean isChildSpanChunk(SpanBo spanBo, SpanChunkBo spanChunkBo) { } private AgentKey newAgentKey(BasicSpan basicSpan) { - return new AgentKey(basicSpan.getApplicationName(), basicSpan.getAgentId(), basicSpan.getAgentStartTime(), basicSpan.getSpanId()); + return new AgentKey(basicSpan.getApplicationName(), basicSpan.getAgentId().value(), basicSpan.getAgentStartTime(), basicSpan.getSpanId()); } public static class AgentKey { diff --git a/web/src/main/java/com/navercorp/pinpoint/web/service/AdminService.java b/web/src/main/java/com/navercorp/pinpoint/web/service/AdminService.java index 347f7d3cabc2..d949a3f585e7 100644 --- a/web/src/main/java/com/navercorp/pinpoint/web/service/AdminService.java +++ b/web/src/main/java/com/navercorp/pinpoint/web/service/AdminService.java @@ -16,6 +16,7 @@ package com.navercorp.pinpoint.web.service; +import com.navercorp.pinpoint.common.id.ApplicationId; import com.navercorp.pinpoint.web.vo.Application; import java.util.List; @@ -30,20 +31,20 @@ public interface AdminService { int MIN_DURATION_DAYS_FOR_INACTIVITY = 30; String MIN_DURATION_DAYS_FOR_INACTIVITY_STR = "" + MIN_DURATION_DAYS_FOR_INACTIVITY; - void removeApplicationName(String applicationName); + void removeApplicationName(ApplicationId applicationId); - void removeAgentId(String applicationName, String agentId); + void removeAgentId(ApplicationId applicationId, String agentId); @Deprecated void removeInactiveAgents(int durationDays); @Deprecated - int removeInactiveAgentInApplication(String applicationName, int durationDays); + int removeInactiveAgentInApplication(ApplicationId applicationId, int durationDays); Map> getAgentIdMap(); Map> getDuplicateAgentIdMap(); - Map> getInactiveAgents(String applicationName, int durationDays); + Map> getInactiveAgents(ApplicationId applicationId, int durationDays); } diff --git a/web/src/main/java/com/navercorp/pinpoint/web/service/AdminServiceImpl.java b/web/src/main/java/com/navercorp/pinpoint/web/service/AdminServiceImpl.java index 09ef432eb1f2..d18818055b9d 100644 --- a/web/src/main/java/com/navercorp/pinpoint/web/service/AdminServiceImpl.java +++ b/web/src/main/java/com/navercorp/pinpoint/web/service/AdminServiceImpl.java @@ -16,6 +16,8 @@ package com.navercorp.pinpoint.web.service; +import com.navercorp.pinpoint.common.id.AgentId; +import com.navercorp.pinpoint.common.id.ApplicationId; import com.navercorp.pinpoint.common.server.util.time.Range; import com.navercorp.pinpoint.common.util.CollectionUtils; import com.navercorp.pinpoint.web.vo.Application; @@ -29,7 +31,6 @@ import java.util.Map; import java.util.Objects; import java.util.TreeMap; -import java.util.UUID; import java.util.concurrent.TimeUnit; import java.util.stream.Collectors; @@ -42,29 +43,24 @@ public class AdminServiceImpl implements AdminService { private final Logger logger = LogManager.getLogger(this.getClass()); - private final ApplicationInfoService applicationInfoService; private final ApplicationService applicationService; private final AgentInfoService agentInfoService; public AdminServiceImpl( - ApplicationInfoService applicationInfoService, ApplicationService applicationService, AgentInfoService agentInfoService ) { - this.applicationInfoService = Objects.requireNonNull(applicationInfoService, "applicationInfoService"); this.applicationService = Objects.requireNonNull(applicationService, "applicationService"); this.agentInfoService = Objects.requireNonNull(agentInfoService, "agentInfoService"); } @Override - public void removeApplicationName(String applicationName) { - UUID applicationId = this.applicationInfoService.getApplicationId(applicationName); + public void removeApplicationName(ApplicationId applicationId) { this.applicationService.deleteApplication(applicationId); } @Override - public void removeAgentId(String applicationName, String agentId) { - UUID applicationId = this.applicationInfoService.getApplicationId(applicationName); + public void removeAgentId(ApplicationId applicationId, String agentId) { this.applicationService.deleteAgent(applicationId, agentId); } @@ -75,38 +71,37 @@ public void removeInactiveAgents(int durationDays) { throw new IllegalArgumentException("duration may not be less than " + MIN_DURATION_DAYS_FOR_INACTIVITY + " days"); } - List applicationNames = this.applicationService.getApplications() + List applicationIds = this.applicationService.getApplications() .stream() - .map(Application::name) + .map(Application::id) .distinct() .collect(Collectors.toList()); - Collections.shuffle(applicationNames); + Collections.shuffle(applicationIds); int index = 1; - for (String applicationName: applicationNames) { - logger.info("Cleaning {} ({}/{})", applicationName, index++, applicationNames.size()); - removeInactiveAgentInApplication(applicationName, durationDays); + for (ApplicationId applicationId: applicationIds) { + logger.info("Cleaning {} ({}/{})", applicationId, index++, applicationIds.size()); + removeInactiveAgentInApplication(applicationId, durationDays); } } @Override - public int removeInactiveAgentInApplication(String applicationName, int durationDays) { + public int removeInactiveAgentInApplication(ApplicationId applicationId, int durationDays) { try { - UUID applicationId = this.applicationInfoService.getApplicationId(applicationName); return removeInactiveAgentInApplication0(applicationId, durationDays); } catch (Exception e) { - logger.error("Backoff to remove inactive agents in application {}", applicationName, e); + logger.error("Backoff to remove inactive agents in application {}", applicationId, e); } return 0; } - private int removeInactiveAgentInApplication0(UUID applicationId, int durationDays) { + private int removeInactiveAgentInApplication0(ApplicationId applicationId, int durationDays) { final List agentsToDelete = new ArrayList<>(100); int deleteCount = 0; final List agentIds = this.applicationService.getAgents(applicationId); for (String agentId: agentIds) { - if (!isInactiveAgent(agentId, durationDays)) { + if (!isInactiveAgent(AgentId.of(agentId), durationDays)) { continue; } @@ -158,13 +153,13 @@ public Map> getDuplicateAgentIdMap() { } @Override - public Map> getInactiveAgents(String applicationName, int durationDays) { - Objects.requireNonNull(applicationName, "applicationName"); + public Map> getInactiveAgents(ApplicationId applicationId, int durationDays) { + Objects.requireNonNull(applicationId, "applicationId"); if (durationDays < MIN_DURATION_DAYS_FOR_INACTIVITY) { throw new IllegalArgumentException("duration may not be less than " + MIN_DURATION_DAYS_FOR_INACTIVITY + " days"); } - UUID applicationId = this.applicationInfoService.getApplicationId(applicationName); + List agentIds = this.applicationService.getAgents(applicationId); if (CollectionUtils.isEmpty(agentIds)) { return Collections.emptyMap(); @@ -185,11 +180,11 @@ private List filterInactiveAgents(List agentIds, int durationDay } return agentIds.stream() - .filter(agentId -> isInactiveAgent(agentId, durationDays)) + .filter(agentId -> isInactiveAgent(AgentId.of(agentId), durationDays)) .collect(Collectors.toList()); } - private boolean isInactiveAgent(String agentId, int durationDays) { + private boolean isInactiveAgent(AgentId agentId, int durationDays) { long now = System.currentTimeMillis(); Range range = Range.between(now - TimeUnit.DAYS.toMillis(durationDays), now); diff --git a/web/src/main/java/com/navercorp/pinpoint/web/service/AgentIdStartTimeKey.java b/web/src/main/java/com/navercorp/pinpoint/web/service/AgentIdStartTimeKey.java index 01f841d46dc0..67f18ae2ef55 100644 --- a/web/src/main/java/com/navercorp/pinpoint/web/service/AgentIdStartTimeKey.java +++ b/web/src/main/java/com/navercorp/pinpoint/web/service/AgentIdStartTimeKey.java @@ -1,5 +1,6 @@ package com.navercorp.pinpoint.web.service; +import com.navercorp.pinpoint.common.id.AgentId; import com.navercorp.pinpoint.common.server.bo.SpanBo; import java.util.Objects; @@ -13,6 +14,10 @@ public AgentIdStartTimeKey(String agentId, long agentStartTime) { this.agentStartTime = agentStartTime; } + public AgentIdStartTimeKey(AgentId agentId, long agentStartTime) { + this(agentId.value(), agentStartTime); + } + public String getAgentId() { return agentId; } diff --git a/web/src/main/java/com/navercorp/pinpoint/web/service/AgentInfoService.java b/web/src/main/java/com/navercorp/pinpoint/web/service/AgentInfoService.java index ff4ce23f240f..02156ee9502c 100644 --- a/web/src/main/java/com/navercorp/pinpoint/web/service/AgentInfoService.java +++ b/web/src/main/java/com/navercorp/pinpoint/web/service/AgentInfoService.java @@ -16,6 +16,7 @@ package com.navercorp.pinpoint.web.service; +import com.navercorp.pinpoint.common.id.AgentId; import com.navercorp.pinpoint.common.server.util.time.Range; import com.navercorp.pinpoint.web.vo.agent.AgentAndStatus; import com.navercorp.pinpoint.web.vo.agent.AgentInfo; @@ -66,7 +67,7 @@ public interface AgentInfoService { List> getAgentStatus(AgentStatusQuery query); - boolean isActiveAgent(String agentId, Range range); + boolean isActiveAgent(AgentId agentId, Range range); InspectorTimeline getAgentStatusTimeline(String agentId, Range range, int... excludeAgentEventTypeCodes); diff --git a/web/src/main/java/com/navercorp/pinpoint/web/service/AgentInfoServiceImpl.java b/web/src/main/java/com/navercorp/pinpoint/web/service/AgentInfoServiceImpl.java index a2926e892056..c0e0f495753b 100644 --- a/web/src/main/java/com/navercorp/pinpoint/web/service/AgentInfoServiceImpl.java +++ b/web/src/main/java/com/navercorp/pinpoint/web/service/AgentInfoServiceImpl.java @@ -17,6 +17,10 @@ package com.navercorp.pinpoint.web.service; +import com.navercorp.pinpoint.common.id.AgentId; +import com.navercorp.pinpoint.common.id.ApplicationId; +import com.navercorp.pinpoint.common.id.ServiceId; +import com.navercorp.pinpoint.common.server.bo.ApplicationSelector; import com.navercorp.pinpoint.common.server.bo.stat.JvmGcBo; import com.navercorp.pinpoint.common.server.util.AgentEventType; import com.navercorp.pinpoint.common.server.util.time.Range; @@ -62,7 +66,6 @@ import java.util.Objects; import java.util.Optional; import java.util.Set; -import java.util.UUID; import java.util.concurrent.TimeUnit; import java.util.stream.Collectors; @@ -209,7 +212,7 @@ private ApplicationAgentHostList.Builder newBuilder(int offset, int endIndex, in return ApplicationAgentHostList.newBuilder(offset, endIndex, totalApplications); } - private List getAgentIdList(UUID applicationId, int durationDays) { + private List getAgentIdList(ApplicationId applicationId, int durationDays) { List agentIds = this.applicationService.getAgents(applicationId); if (CollectionUtils.isEmpty(agentIds)) { return Collections.emptyList(); @@ -232,13 +235,13 @@ private List getAgentIdList(UUID applicationId, int durationDays) { // FIXME This needs to be done with a more accurate information. // If at any time a non-java agent is introduced, or an agent that does not collect jvm data, // this will fail - boolean dataExists = isActiveAgent(agentId, fastRange); + boolean dataExists = isActiveAgent(AgentId.of(agentId), fastRange); if (dataExists) { activeAgentIdList.add(agentId); continue; } - dataExists = isActiveAgent(agentId, queryRange); + dataExists = isActiveAgent(AgentId.of(agentId), queryRange); if (dataExists) { activeAgentIdList.add(agentId); } @@ -254,7 +257,8 @@ private List getSortedApplicationList(List application @Override public Set getAgentsByApplicationName(String applicationName, long timestamp) { - UUID applicationId = this.applicationInfoService.getApplicationId(applicationName); + ApplicationId applicationId = this.applicationInfoService.getApplicationId( + new ApplicationSelector(ServiceId.DEFAULT_ID, applicationName)); List agentInfos = this.getAgentsByApplicationNameWithoutStatus0(applicationId, timestamp); List result = new ArrayList<>(agentInfos.size()); @@ -273,12 +277,12 @@ public Set getAgentsByApplicationName(String applicationName, lo @Override public Set getAgentsByApplicationNameWithoutStatus(String applicationName, long timestamp) { - UUID applicationId = this.applicationInfoService.getApplicationId(applicationName); + ApplicationId applicationId = this.applicationInfoService.getApplicationId(new ApplicationSelector(ServiceId.DEFAULT_ID, applicationName)); List agentInfos = getAgentsByApplicationNameWithoutStatus0(applicationId, timestamp); return new HashSet<>(agentInfos); } - public List getAgentsByApplicationNameWithoutStatus0(UUID applicationId, long timestamp) { + public List getAgentsByApplicationNameWithoutStatus0(ApplicationId applicationId, long timestamp) { Objects.requireNonNull(applicationId, "applicationId"); if (timestamp < 0) { throw new IllegalArgumentException("timestamp must not be less than 0"); @@ -316,7 +320,7 @@ public List getDetailedAgentsByApplicationNameWithoutStatus0( throw new IllegalArgumentException("timestamp must not be less than 0"); } - UUID applicationId = this.applicationInfoService.getApplicationId(applicationName); + ApplicationId applicationId = this.applicationInfoService.getApplicationId(new ApplicationSelector(ServiceId.DEFAULT_ID, applicationName)); List agentIds = this.applicationService.getAgents(applicationId); List agentInfos = this.agentInfoDao.getDetailedAgentInfos(agentIds, timestamp, false, true); @@ -392,18 +396,18 @@ public List> getAgentStatus(AgentStatusQuery query) { } @Override - public boolean isActiveAgent(String agentId, Range range) { + public boolean isActiveAgent(AgentId agentId, Range range) { Objects.requireNonNull(agentId, "agentId"); return isActiveAgentByGcStat(agentId, range) || isActiveAgentByPing(agentId, range); } - private boolean isActiveAgentByGcStat(String agentId, Range range) { - return this.jvmGcDao.agentStatExists(agentId, range); + private boolean isActiveAgentByGcStat(AgentId agentId, Range range) { + return this.jvmGcDao.agentStatExists(agentId.value(), range); } - private boolean isActiveAgentByPing(String agentId, Range range) { - return this.agentEventService.getAgentEvents(agentId, range) + private boolean isActiveAgentByPing(AgentId agentId, Range range) { + return this.agentEventService.getAgentEvents(agentId.value(), range) .stream() .anyMatch(e -> e.getEventTypeCode() == AgentEventType.AGENT_PING.getCode()); } diff --git a/web/src/main/java/com/navercorp/pinpoint/web/service/AgentServiceImpl.java b/web/src/main/java/com/navercorp/pinpoint/web/service/AgentServiceImpl.java index 281376114b35..21662794f68a 100644 --- a/web/src/main/java/com/navercorp/pinpoint/web/service/AgentServiceImpl.java +++ b/web/src/main/java/com/navercorp/pinpoint/web/service/AgentServiceImpl.java @@ -48,7 +48,7 @@ public ClusterKey getClusterKey(String applicationName, String agentId) { if (!agentInfo.getApplicationName().equals(applicationName)) { continue; } - if (!agentInfo.getAgentId().equals(agentId)) { + if (!agentInfo.getAgentId().value().equals(agentId)) { continue; } @@ -76,7 +76,7 @@ public ClusterKey getClusterKey(String applicationName, String agentId, long sta if (!agentInfo.getApplicationName().equals(applicationName)) { continue; } - if (!agentInfo.getAgentId().equals(agentId)) { + if (!agentInfo.getAgentId().value().equals(agentId)) { continue; } if (agentInfo.getStartTimestamp() != startTimeStamp) { diff --git a/web/src/main/java/com/navercorp/pinpoint/web/service/ApplicationInfoService.java b/web/src/main/java/com/navercorp/pinpoint/web/service/ApplicationInfoService.java index a2ae0216f6fd..5fe98372c3c5 100644 --- a/web/src/main/java/com/navercorp/pinpoint/web/service/ApplicationInfoService.java +++ b/web/src/main/java/com/navercorp/pinpoint/web/service/ApplicationInfoService.java @@ -15,12 +15,16 @@ */ package com.navercorp.pinpoint.web.service; +import com.navercorp.pinpoint.common.id.ApplicationId; +import com.navercorp.pinpoint.common.server.bo.ApplicationInfo; +import com.navercorp.pinpoint.common.server.bo.ApplicationSelector; +import com.navercorp.pinpoint.common.util.UuidUtils; import com.navercorp.pinpoint.web.dao.ApplicationInfoDao; +import com.navercorp.pinpoint.web.vo.Application; import org.springframework.cache.annotation.Cacheable; import org.springframework.stereotype.Component; import java.util.Objects; -import java.util.UUID; /** * @author youngjin.kim2 @@ -34,14 +38,21 @@ public ApplicationInfoService(ApplicationInfoDao applicationInfoDao) { this.applicationInfoDao = Objects.requireNonNull(applicationInfoDao, "applicationInfoDao"); } - @Cacheable(value = "applicationNameById", key = "#applicationId") - public String getApplicationName(UUID applicationId) { - return this.applicationInfoDao.getApplicationName(applicationId); + @Cacheable(value = "applicationById", key = "#applicationId") + public Application getApplication(ApplicationId applicationId) { + return this.applicationInfoDao.getApplication(applicationId); } - @Cacheable(value = "applicationIdByName", key = "#applicationName") - public UUID getApplicationId(String applicationName) { - return this.applicationInfoDao.getApplicationId(applicationName); + @Cacheable(value = "applicationIdBySelector", key = "#application") + public ApplicationId getApplicationId(ApplicationSelector application) { + ApplicationId applicationId = this.applicationInfoDao.getApplicationId(application); + if (applicationId != null) { + return applicationId; + } + + ApplicationId newApplicationId = ApplicationId.of(UuidUtils.createV4()); + ApplicationInfo newApplication = new ApplicationInfo(newApplicationId, application.serviceId(), application.name()); + return this.applicationInfoDao.putApplicationIdIfAbsent(newApplication); } } diff --git a/web/src/main/java/com/navercorp/pinpoint/web/service/ApplicationService.java b/web/src/main/java/com/navercorp/pinpoint/web/service/ApplicationService.java index 004666ef056a..633595fc66ba 100644 --- a/web/src/main/java/com/navercorp/pinpoint/web/service/ApplicationService.java +++ b/web/src/main/java/com/navercorp/pinpoint/web/service/ApplicationService.java @@ -16,12 +16,13 @@ package com.navercorp.pinpoint.web.service; +import com.navercorp.pinpoint.common.id.ApplicationId; +import com.navercorp.pinpoint.common.id.ServiceId; import com.navercorp.pinpoint.web.vo.Application; import org.springframework.stereotype.Service; import java.util.List; import java.util.Map; -import java.util.UUID; /** * @author Taejin Koo @@ -29,16 +30,18 @@ @Service public interface ApplicationService { - boolean isExistApplicationName(String applicationName); + boolean isExistApplicationName(ApplicationId applicationId); + + List getApplications(ServiceId serviceId); List getApplications(); - List getAgents(UUID applicationId); + List getAgents(ApplicationId applicationId); - void deleteApplication(UUID applicationId); + void deleteApplication(ApplicationId applicationId); - void deleteAgents(Map> applicationAgentIdMap); + void deleteAgents(Map> applicationAgentIdMap); - void deleteAgent(UUID applicationId, String agentId); + void deleteAgent(ApplicationId applicationId, String agentId); } diff --git a/web/src/main/java/com/navercorp/pinpoint/web/service/ApplicationServiceImpl.java b/web/src/main/java/com/navercorp/pinpoint/web/service/ApplicationServiceImpl.java index 655390269cd6..92554ea4a152 100644 --- a/web/src/main/java/com/navercorp/pinpoint/web/service/ApplicationServiceImpl.java +++ b/web/src/main/java/com/navercorp/pinpoint/web/service/ApplicationServiceImpl.java @@ -16,6 +16,9 @@ package com.navercorp.pinpoint.web.service; +import com.navercorp.pinpoint.common.id.ApplicationId; +import com.navercorp.pinpoint.common.id.ServiceId; +import com.navercorp.pinpoint.common.server.bo.ApplicationSelector; import com.navercorp.pinpoint.web.dao.ApplicationIndexDao; import com.navercorp.pinpoint.web.dao.ApplicationIndexDaoV2; import com.navercorp.pinpoint.web.vo.Application; @@ -26,7 +29,6 @@ import java.util.List; import java.util.Map; import java.util.Objects; -import java.util.UUID; /** * @author Taejin Koo @@ -37,32 +39,30 @@ public class ApplicationServiceImpl implements ApplicationService { private final ApplicationIndexDao applicationIndexDao; private final ApplicationIndexDaoV2 applicationIndexDaoV2; private final ApplicationInfoService applicationInfoService; + private final ServiceInfoService serviceInfoService; public ApplicationServiceImpl( ApplicationIndexDao applicationIndexDao, ApplicationIndexDaoV2 applicationIndexDaoV2, - ApplicationInfoService applicationInfoService + ApplicationInfoService applicationInfoService, + ServiceInfoService serviceInfoService ) { this.applicationIndexDao = Objects.requireNonNull(applicationIndexDao, "applicationIndexDao"); this.applicationIndexDaoV2 = Objects.requireNonNull(applicationIndexDaoV2, "applicationIndexDaoV2"); this.applicationInfoService = Objects.requireNonNull(applicationInfoService, "applicationInfoService"); + this.serviceInfoService = Objects.requireNonNull(serviceInfoService, "serviceInfoService"); } @Override - public boolean isExistApplicationName(String applicationName) { - if (applicationName == null) { - return false; - } - - UUID applicationId = this.applicationInfoService.getApplicationId(applicationName); + public boolean isExistApplicationName(ApplicationId applicationId) { + String applicationName = this.applicationInfoService.getApplication(applicationId).name(); List applicationsV2 = this.applicationIndexDaoV2.selectApplicationName(applicationId); - List applications = this.applicationIndexDao.selectApplicationName(applicationName); - + List applications = this.applicationIndexDao.selectApplicationByName(applicationName); return applicationsV2.size() > 0 || applications.size() > 0; } @Override public List getApplications() { - List applications1Origin = this.applicationIndexDao.selectAllApplicationNames(); + List applications1Origin = this.applicationIndexDao.selectAllApplications(); List applications1 = augmentApplicationId(applications1Origin); List applications2Origin = applicationIndexDaoV2.selectAllApplicationNames(); @@ -78,10 +78,27 @@ public List getApplications() { } @Override - public List getAgents(UUID applicationId) { - String applicationName = this.applicationInfoService.getApplicationName(applicationId); + public List getApplications(ServiceId serviceId) { + List applications = new ArrayList<>(); + if (serviceId.equals(ServiceId.DEFAULT_ID)) { + List legacyApplications = this.applicationIndexDao.selectAllApplications(); + applications.addAll(augmentApplicationId(legacyApplications)); + } + List applicationIds = this.serviceInfoService.getApplicationIds(serviceId); + for (ApplicationId applicationId : applicationIds) { + Application application = this.applicationInfoService.getApplication(applicationId); + if (application != null) { + applications.add(application); + } + } + return applications.stream().distinct().toList(); + } + + @Override + public List getAgents(ApplicationId applicationId) { + Application application = this.applicationInfoService.getApplication(applicationId); - List agents1 = this.applicationIndexDao.selectAgentIds(applicationName); + List agents1 = this.applicationIndexDao.selectAgentIds(application.name()); List agents2 = this.applicationIndexDaoV2.selectAgentIds(applicationId); List agents = new ArrayList<>(agents1.size() + agents2.size()); @@ -94,19 +111,19 @@ public List getAgents(UUID applicationId) { } @Override - public void deleteApplication(UUID applicationId) { - String applicationName = this.applicationInfoService.getApplicationName(applicationId); - this.applicationIndexDao.deleteApplicationName(applicationName); + public void deleteApplication(ApplicationId applicationId) { + Application application = this.applicationInfoService.getApplication(applicationId); + this.applicationIndexDao.deleteApplicationName(application.name()); this.applicationIndexDaoV2.deleteApplication(applicationId); } @Override - public void deleteAgents(Map> applicationAgentIdMap) { + public void deleteAgents(Map> applicationAgentIdMap) { Map> applicationAgentIdMap2 = new HashMap<>(); - for (Map.Entry> entry : applicationAgentIdMap.entrySet()) { - UUID applicationId = entry.getKey(); - String applicationName = this.applicationInfoService.getApplicationName(applicationId); - applicationAgentIdMap2.put(applicationName, entry.getValue()); + for (Map.Entry> entry : applicationAgentIdMap.entrySet()) { + ApplicationId applicationId = entry.getKey(); + Application application = this.applicationInfoService.getApplication(applicationId); + applicationAgentIdMap2.put(application.name(), entry.getValue()); } this.applicationIndexDao.deleteAgentIds(applicationAgentIdMap2); @@ -114,18 +131,20 @@ public void deleteAgents(Map> applicationAgentIdMap) { } @Override - public void deleteAgent(UUID applicationId, String agentId) { - String applicationName = this.applicationInfoService.getApplicationName(applicationId); + public void deleteAgent(ApplicationId applicationId, String agentId) { + Application application = this.applicationInfoService.getApplication(applicationId); - this.applicationIndexDao.deleteAgentId(applicationName, agentId); + this.applicationIndexDao.deleteAgentId(application.name(), agentId); this.applicationIndexDaoV2.deleteAgentId(applicationId, agentId); } private List augmentApplicationName(List applications) { List result = new ArrayList<>(applications.size()); for (Application application : applications) { - String applicationName = this.applicationInfoService.getApplicationName(application.id()); - result.add(new Application(application.id(), applicationName, application.serviceType())); + Application helper = this.applicationInfoService.getApplication(application.id()); + if (helper != null) { + result.add(new Application(helper.id(), helper.name(), helper.serviceType())); + } } return result; } @@ -133,7 +152,7 @@ private List augmentApplicationName(List applications) private List augmentApplicationId(List applications) { List result = new ArrayList<>(applications.size()); for (Application application : applications) { - UUID applicationId = this.applicationInfoService.getApplicationId(application.name()); + ApplicationId applicationId = this.applicationInfoService.getApplicationId(new ApplicationSelector(ServiceId.DEFAULT_ID, application.name())); result.add(new Application(applicationId, application.name(), application.serviceType())); } return result; diff --git a/web/src/main/java/com/navercorp/pinpoint/web/service/ApplicationTraceIndexServiceImpl.java b/web/src/main/java/com/navercorp/pinpoint/web/service/ApplicationTraceIndexServiceImpl.java index 480edc451634..9c31e7a29e62 100644 --- a/web/src/main/java/com/navercorp/pinpoint/web/service/ApplicationTraceIndexServiceImpl.java +++ b/web/src/main/java/com/navercorp/pinpoint/web/service/ApplicationTraceIndexServiceImpl.java @@ -15,7 +15,10 @@ */ package com.navercorp.pinpoint.web.service; +import com.navercorp.pinpoint.common.id.ApplicationId; +import com.navercorp.pinpoint.common.id.ServiceId; import com.navercorp.pinpoint.common.profiler.util.TransactionId; +import com.navercorp.pinpoint.common.server.bo.ApplicationSelector; import com.navercorp.pinpoint.common.server.util.time.Range; import com.navercorp.pinpoint.web.dao.ApplicationTraceIndexDao; import com.navercorp.pinpoint.web.dao.ApplicationTraceIndexDaoV2; @@ -29,7 +32,6 @@ import java.util.ArrayList; import java.util.List; import java.util.Objects; -import java.util.UUID; /** * @author youngjin.kim2 @@ -53,13 +55,13 @@ public ApplicationTraceIndexServiceImpl( @Override public boolean hasTraceIndex(String applicationName, Range range, boolean backwardDirection) { - UUID applicationId = getApplicationId(applicationName); + ApplicationId applicationId = getApplicationId(applicationName); return applicationTraceIndexDao.hasTraceIndex(applicationName, range, backwardDirection) || applicationTraceIndexDaoV2.hasTraceIndex(applicationId, range, backwardDirection); } @Override public LimitedScanResult> scanTraceIndex(String applicationName, Range range, int limit, boolean backwardDirection) { - UUID applicationId = getApplicationId(applicationName); + ApplicationId applicationId = getApplicationId(applicationName); LimitedScanResult> r1 = applicationTraceIndexDao.scanTraceIndex(applicationName, range, limit, backwardDirection); LimitedScanResult> r2 = applicationTraceIndexDaoV2.scanTraceIndex(applicationId, range, limit, backwardDirection); return merge(r1, r2); @@ -67,7 +69,7 @@ public LimitedScanResult> scanTraceIndex(String applicationN @Override public LimitedScanResult> scanTraceScatterData(String applicationName, Range range, int limit, boolean scanBackward) { - UUID applicationId = getApplicationId(applicationName); + ApplicationId applicationId = getApplicationId(applicationName); LimitedScanResult> r1 = applicationTraceIndexDao.scanTraceScatterData(applicationName, range, limit, scanBackward); LimitedScanResult> r2 = applicationTraceIndexDaoV2.scanTraceScatterData(applicationId, range, limit, scanBackward); return merge(r1, r2); @@ -75,7 +77,7 @@ public LimitedScanResult> scanTraceScatterData(String applicationName, @Override public LimitedScanResult> scanTraceIndex(String applicationName, DragArea dragArea, int limit) { - UUID applicationId = getApplicationId(applicationName); + ApplicationId applicationId = getApplicationId(applicationName); LimitedScanResult> r1 = applicationTraceIndexDao.scanTraceIndex(applicationName, dragArea, limit); LimitedScanResult> r2 = applicationTraceIndexDaoV2.scanTraceIndex(applicationId, dragArea, limit); return merge(r1, r2); @@ -83,7 +85,7 @@ public LimitedScanResult> scanTraceIndex(String applicationN @Override public LimitedScanResult> scanScatterData(String applicationName, DragAreaQuery dragAreaQuery, int limit) { - UUID applicationId = getApplicationId(applicationName); + ApplicationId applicationId = getApplicationId(applicationName); LimitedScanResult> r1 = applicationTraceIndexDao.scanScatterData(applicationName, dragAreaQuery, limit); LimitedScanResult> r2 = applicationTraceIndexDaoV2.scanScatterData(applicationId, dragAreaQuery, limit); return merge(r1, r2); @@ -91,14 +93,14 @@ public LimitedScanResult> scanScatterData(String applicationName, Drag @Override public LimitedScanResult> scanScatterDataV2(String applicationName, DragAreaQuery dragAreaQuery, int limit) { - UUID applicationId = getApplicationId(applicationName); + ApplicationId applicationId = getApplicationId(applicationName); LimitedScanResult> r1 = applicationTraceIndexDao.scanScatterDataV2(applicationName, dragAreaQuery, limit); LimitedScanResult> r2 = applicationTraceIndexDaoV2.scanScatterDataV2(applicationId, dragAreaQuery, limit); return merge(r1, r2); } - private UUID getApplicationId(String applicationName) { - return this.applicationInfoService.getApplicationId(applicationName); + private ApplicationId getApplicationId(String applicationName) { + return applicationInfoService.getApplicationId(new ApplicationSelector(ServiceId.DEFAULT_ID, applicationName)); } private LimitedScanResult> merge(LimitedScanResult> r1, LimitedScanResult> r2) { diff --git a/web/src/main/java/com/navercorp/pinpoint/web/service/CommonService.java b/web/src/main/java/com/navercorp/pinpoint/web/service/CommonService.java index 0b32080bee3b..ea20cd74b57c 100644 --- a/web/src/main/java/com/navercorp/pinpoint/web/service/CommonService.java +++ b/web/src/main/java/com/navercorp/pinpoint/web/service/CommonService.java @@ -16,10 +16,10 @@ package com.navercorp.pinpoint.web.service; -import java.util.List; - import com.navercorp.pinpoint.web.vo.Application; +import java.util.List; + /** * @author netspider */ diff --git a/web/src/main/java/com/navercorp/pinpoint/web/service/CommonServiceImpl.java b/web/src/main/java/com/navercorp/pinpoint/web/service/CommonServiceImpl.java index bbdebd5f4743..90206d442b25 100644 --- a/web/src/main/java/com/navercorp/pinpoint/web/service/CommonServiceImpl.java +++ b/web/src/main/java/com/navercorp/pinpoint/web/service/CommonServiceImpl.java @@ -16,6 +16,7 @@ package com.navercorp.pinpoint.web.service; +import com.navercorp.pinpoint.common.id.ServiceId; import com.navercorp.pinpoint.web.vo.Application; import org.springframework.stereotype.Service; @@ -37,7 +38,7 @@ public CommonServiceImpl(ApplicationService applicationService) { @Override public List selectAllApplicationNames() { - return applicationService.getApplications(); + return applicationService.getApplications(ServiceId.DEFAULT_ID); } } diff --git a/web/src/main/java/com/navercorp/pinpoint/web/service/DotExtractor.java b/web/src/main/java/com/navercorp/pinpoint/web/service/DotExtractor.java index 42fd19de04d7..29e34164a51e 100644 --- a/web/src/main/java/com/navercorp/pinpoint/web/service/DotExtractor.java +++ b/web/src/main/java/com/navercorp/pinpoint/web/service/DotExtractor.java @@ -60,12 +60,11 @@ public Dot newDot(SpanBo span) { Objects.requireNonNull(span, "span"); final TransactionId transactionId = span.getTransactionId(); - return new Dot(transactionId, span.getCollectorAcceptTime(), span.getElapsed(), span.getErrCode(), span.getAgentId()); + return new Dot(transactionId, span.getCollectorAcceptTime(), span.getElapsed(), span.getErrCode(), span.getAgentId().value()); } private List getDotList(Application spanApplication) { - List dotList = this.dotMap.computeIfAbsent(spanApplication, k -> new ArrayList<>()); - return dotList; + return this.dotMap.computeIfAbsent(spanApplication, k -> new ArrayList<>()); } public List getApplicationScatterScanResult(long from, long to) { diff --git a/web/src/main/java/com/navercorp/pinpoint/web/service/ScatterChartServiceImpl.java b/web/src/main/java/com/navercorp/pinpoint/web/service/ScatterChartServiceImpl.java index 3f78eabef90e..190831be744d 100644 --- a/web/src/main/java/com/navercorp/pinpoint/web/service/ScatterChartServiceImpl.java +++ b/web/src/main/java/com/navercorp/pinpoint/web/service/ScatterChartServiceImpl.java @@ -79,7 +79,7 @@ public List selectScatterData(List transactionIdList, String for (SpanBo span : trace) { if (applicationName.equals(span.getApplicationName())) { final TransactionId transactionId = span.getTransactionId(); - final Dot dot = new Dot(transactionId, span.getCollectorAcceptTime(), span.getElapsed(), span.getErrCode(), span.getAgentId()); + final Dot dot = new Dot(transactionId, span.getCollectorAcceptTime(), span.getElapsed(), span.getErrCode(), span.getAgentId().value()); result.add(dot); } } @@ -137,7 +137,7 @@ public ScatterData selectScatterData(List transactionIdList, Stri for (SpanBo span : trace) { if (applicationName.equals(span.getApplicationName())) { final TransactionId transactionId = span.getTransactionId(); - final Dot dot = new Dot(transactionId, span.getCollectorAcceptTime(), span.getElapsed(), span.getErrCode(), span.getAgentId()); + final Dot dot = new Dot(transactionId, span.getCollectorAcceptTime(), span.getElapsed(), span.getErrCode(), span.getAgentId().value()); scatterData.addDot(dot); } } diff --git a/web/src/main/java/com/navercorp/pinpoint/web/service/ServiceInfoService.java b/web/src/main/java/com/navercorp/pinpoint/web/service/ServiceInfoService.java new file mode 100644 index 000000000000..55b0fdcbb6fe --- /dev/null +++ b/web/src/main/java/com/navercorp/pinpoint/web/service/ServiceInfoService.java @@ -0,0 +1,35 @@ +/* + * Copyright 2024 NAVER Corp. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.navercorp.pinpoint.web.service; + +import com.navercorp.pinpoint.common.id.ApplicationId; +import com.navercorp.pinpoint.common.id.ServiceId; +import com.navercorp.pinpoint.common.server.bo.ServiceInfo; + +import java.util.List; + +/** + * @author youngjin.kim2 + */ +public interface ServiceInfoService { + + ServiceInfo getServiceInfo(ServiceId id); + + ServiceId getServiceId(String serviceName); + + List getApplicationIds(ServiceId serviceId); + +} diff --git a/web/src/main/java/com/navercorp/pinpoint/web/service/ServiceInfoServiceImpl.java b/web/src/main/java/com/navercorp/pinpoint/web/service/ServiceInfoServiceImpl.java new file mode 100644 index 000000000000..d03e71851954 --- /dev/null +++ b/web/src/main/java/com/navercorp/pinpoint/web/service/ServiceInfoServiceImpl.java @@ -0,0 +1,65 @@ +/* + * Copyright 2024 NAVER Corp. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.navercorp.pinpoint.web.service; + +import com.navercorp.pinpoint.common.id.ApplicationId; +import com.navercorp.pinpoint.common.id.ServiceId; +import com.navercorp.pinpoint.common.server.bo.ServiceInfo; +import com.navercorp.pinpoint.web.dao.ApplicationInfoDao; +import com.navercorp.pinpoint.web.dao.ServiceInfoDao; +import org.springframework.cache.annotation.Cacheable; +import org.springframework.stereotype.Service; + +import java.util.List; +import java.util.Objects; + +/** + * @author youngjin.kim2 + */ +@Service +public class ServiceInfoServiceImpl implements ServiceInfoService { + + private final ServiceInfoDao serviceInfoDao; + private final ApplicationInfoDao applicationInfoDao; + + + public ServiceInfoServiceImpl( + ServiceInfoDao serviceInfoDao, + ApplicationInfoDao applicationInfoDao + ) { + this.serviceInfoDao = Objects.requireNonNull(serviceInfoDao, "serviceInfoDao"); + this.applicationInfoDao = Objects.requireNonNull(applicationInfoDao, "applicationInfoDao"); + } + + @Override + @Cacheable(value = "serviceInfoById", key = "#id") + public ServiceInfo getServiceInfo(ServiceId id) { + return this.serviceInfoDao.getServiceInfo(id); + } + + @Override + @Cacheable(value = "serviceIdByName", key = "#serviceName") + public ServiceId getServiceId(String serviceName) { + return this.serviceInfoDao.getServiceId(serviceName); + } + + @Override + @Cacheable(value = "applicationIdsByServiceId", key = "#serviceId") + public List getApplicationIds(ServiceId serviceId) { + return this.applicationInfoDao.getApplications(serviceId); + } + +} diff --git a/web/src/main/java/com/navercorp/pinpoint/web/view/ApplicationSerializer.java b/web/src/main/java/com/navercorp/pinpoint/web/view/ApplicationSerializer.java index 6496718e6ced..6a661efe7cc3 100644 --- a/web/src/main/java/com/navercorp/pinpoint/web/view/ApplicationSerializer.java +++ b/web/src/main/java/com/navercorp/pinpoint/web/view/ApplicationSerializer.java @@ -32,9 +32,9 @@ public class ApplicationSerializer extends JsonSerializer { public void serialize(Application application, JsonGenerator jgen, SerializerProvider provider) throws IOException { jgen.writeStartObject(); if (application.id() != null) { - jgen.writeStringField("applicationId", application.id().toString()); + jgen.writeStringField("id", application.id().toString()); } else { - jgen.writeNullField("applicationId"); + jgen.writeNullField("id"); } jgen.writeStringField("applicationName", application.name()); jgen.writeStringField("serviceType", application.serviceType().getDesc()); diff --git a/web/src/main/java/com/navercorp/pinpoint/web/view/transactionlist/TransactionMetaDataViewModel.java b/web/src/main/java/com/navercorp/pinpoint/web/view/transactionlist/TransactionMetaDataViewModel.java index 1631d83e4928..361459c94b8a 100644 --- a/web/src/main/java/com/navercorp/pinpoint/web/view/transactionlist/TransactionMetaDataViewModel.java +++ b/web/src/main/java/com/navercorp/pinpoint/web/view/transactionlist/TransactionMetaDataViewModel.java @@ -81,7 +81,7 @@ public String getApplication() { @Override public String getAgentId() { - return span.getAgentId(); + return span.getAgentId().value(); } @Override diff --git a/web/src/main/java/com/navercorp/pinpoint/web/vo/Application.java b/web/src/main/java/com/navercorp/pinpoint/web/vo/Application.java index 5819b33a5372..45bf290b09ba 100644 --- a/web/src/main/java/com/navercorp/pinpoint/web/vo/Application.java +++ b/web/src/main/java/com/navercorp/pinpoint/web/vo/Application.java @@ -17,11 +17,11 @@ package com.navercorp.pinpoint.web.vo; import com.fasterxml.jackson.databind.annotation.JsonSerialize; +import com.navercorp.pinpoint.common.id.ApplicationId; import com.navercorp.pinpoint.common.trace.ServiceType; import com.navercorp.pinpoint.web.view.ApplicationSerializer; import java.util.Objects; -import java.util.UUID; /** * @author netspider @@ -29,9 +29,9 @@ * @author jaehong.kim */ @JsonSerialize(using = ApplicationSerializer.class) -public record Application(UUID id, String name, ServiceType serviceType) { +public record Application(ApplicationId id, String name, ServiceType serviceType) { - public Application(UUID id, String name, ServiceType serviceType) { + public Application(ApplicationId id, String name, ServiceType serviceType) { this.id = id; this.name = name; this.serviceType = Objects.requireNonNull(serviceType, "serviceType"); diff --git a/web/src/main/java/com/navercorp/pinpoint/web/vo/ResponseHistograms.java b/web/src/main/java/com/navercorp/pinpoint/web/vo/ResponseHistograms.java index 09e99e161d0f..69780424f56d 100644 --- a/web/src/main/java/com/navercorp/pinpoint/web/vo/ResponseHistograms.java +++ b/web/src/main/java/com/navercorp/pinpoint/web/vo/ResponseHistograms.java @@ -72,7 +72,7 @@ public Builder addHistogram(Application application, SpanBo span, long timestamp if (span.getErrCode() != 0) { error = true; } - responseTime.addResponseTime(span.getAgentId(), span.getElapsed(), error); + responseTime.addResponseTime(span.getAgentId().value(), span.getElapsed(), error); return this; } diff --git a/web/src/main/java/com/navercorp/pinpoint/web/vo/agent/AgentInfo.java b/web/src/main/java/com/navercorp/pinpoint/web/vo/agent/AgentInfo.java index 71a0ffff848c..7373599b3f52 100644 --- a/web/src/main/java/com/navercorp/pinpoint/web/vo/agent/AgentInfo.java +++ b/web/src/main/java/com/navercorp/pinpoint/web/vo/agent/AgentInfo.java @@ -17,6 +17,7 @@ package com.navercorp.pinpoint.web.vo.agent; import com.fasterxml.jackson.databind.annotation.JsonSerialize; +import com.navercorp.pinpoint.common.id.AgentId; import com.navercorp.pinpoint.common.trace.ServiceType; import com.navercorp.pinpoint.web.view.ServiceTypeDescView; @@ -28,7 +29,7 @@ public class AgentInfo { private String applicationName; - private String agentId; + private AgentId agentId; private String agentName; private long startTimestamp; private String hostName; @@ -51,11 +52,11 @@ public void setApplicationName(String applicationName) { this.applicationName = applicationName; } - public String getAgentId() { + public AgentId getAgentId() { return agentId; } - public void setAgentId(String agentId) { + public void setAgentId(AgentId agentId) { this.agentId = agentId; } diff --git a/web/src/main/java/com/navercorp/pinpoint/web/vo/agent/AgentStatus.java b/web/src/main/java/com/navercorp/pinpoint/web/vo/agent/AgentStatus.java index 62f6b394a94c..411271b90376 100644 --- a/web/src/main/java/com/navercorp/pinpoint/web/vo/agent/AgentStatus.java +++ b/web/src/main/java/com/navercorp/pinpoint/web/vo/agent/AgentStatus.java @@ -16,6 +16,7 @@ package com.navercorp.pinpoint.web.vo.agent; +import com.navercorp.pinpoint.common.id.AgentId; import com.navercorp.pinpoint.common.server.util.AgentLifeCycleState; import java.util.Objects; @@ -27,19 +28,23 @@ */ public class AgentStatus { - private final String agentId; + private final AgentId agentId; private long eventTimestamp; private final AgentLifeCycleState state; - public AgentStatus(String agentId, AgentLifeCycleState state, long eventTimestamp) { + public AgentStatus(AgentId agentId, AgentLifeCycleState state, long eventTimestamp) { this.agentId = Objects.requireNonNull(agentId, "agentId"); this.state = Objects.requireNonNull(state, "state"); this.eventTimestamp = eventTimestamp; } - public String getAgentId() { + public AgentStatus(String agentId, AgentLifeCycleState state, long eventTimestamp) { + this(AgentId.of(agentId), state, eventTimestamp); + } + + public AgentId getAgentId() { return agentId; } @@ -73,11 +78,9 @@ public int hashCode() { @Override public String toString() { - final StringBuilder sb = new StringBuilder("AgentStatus{"); - sb.append("agentId='").append(agentId).append('\''); - sb.append(", eventTimestamp=").append(eventTimestamp); - sb.append(", state=").append(state); - sb.append('}'); - return sb.toString(); + return "AgentStatus{" + "agentId='" + agentId + '\'' + + ", eventTimestamp=" + eventTimestamp + + ", state=" + state + + '}'; } } diff --git a/web/src/main/java/com/navercorp/pinpoint/web/vo/agent/AgentStatusQuery.java b/web/src/main/java/com/navercorp/pinpoint/web/vo/agent/AgentStatusQuery.java index 86d0fdbde31a..6a2fdeb4b21c 100644 --- a/web/src/main/java/com/navercorp/pinpoint/web/vo/agent/AgentStatusQuery.java +++ b/web/src/main/java/com/navercorp/pinpoint/web/vo/agent/AgentStatusQuery.java @@ -64,7 +64,7 @@ private static SimpleAgentKey apply(AgentInfo agentInfo) { if (agentInfo == null) { return null; } - return new SimpleAgentKey(agentInfo.getAgentId(), agentInfo.getStartTimestamp()); + return new SimpleAgentKey(agentInfo.getAgentId().value(), agentInfo.getStartTimestamp()); } public static AgentStatusQuery buildQuery(Collection agentInfos, Function transform, Instant timestamp) { diff --git a/web/src/main/java/com/navercorp/pinpoint/web/vo/scatter/DotAgentInfo.java b/web/src/main/java/com/navercorp/pinpoint/web/vo/scatter/DotAgentInfo.java index 2e0e1b5cca08..6da6758b34e7 100644 --- a/web/src/main/java/com/navercorp/pinpoint/web/vo/scatter/DotAgentInfo.java +++ b/web/src/main/java/com/navercorp/pinpoint/web/vo/scatter/DotAgentInfo.java @@ -25,7 +25,7 @@ public class DotAgentInfo { private final long transactionAgentStartTime; public DotAgentInfo(Dot dot) { - this(dot.getAgentId(), dot.getTransactionId().getAgentId(), dot.getTransactionId().getAgentStartTime()); + this(dot.getAgentId(), dot.getTransactionId().getAgentId().value(), dot.getTransactionId().getAgentStartTime()); } public DotAgentInfo(String agentId, String transactionAgentId, long transactionAgentStartTime) { diff --git a/web/src/main/java/com/navercorp/pinpoint/web/vo/tree/ApplicationAgentHostList.java b/web/src/main/java/com/navercorp/pinpoint/web/vo/tree/ApplicationAgentHostList.java index 0d196b2ca934..6ca2a93d5229 100644 --- a/web/src/main/java/com/navercorp/pinpoint/web/vo/tree/ApplicationAgentHostList.java +++ b/web/src/main/java/com/navercorp/pinpoint/web/vo/tree/ApplicationAgentHostList.java @@ -16,6 +16,7 @@ package com.navercorp.pinpoint.web.vo.tree; import com.fasterxml.jackson.annotation.JsonProperty; +import com.navercorp.pinpoint.common.id.AgentId; import com.navercorp.pinpoint.common.util.StringUtils; import com.navercorp.pinpoint.web.vo.agent.AgentInfo; @@ -112,7 +113,7 @@ public void addAgentInfo(String applicationName, List agentInfoList) } private AgentHost newAgentHost(AgentInfo agentInfo) { - String agentId = StringUtils.defaultString(agentInfo.getAgentId(), ""); + AgentId agentId = agentInfo.getAgentId(); String hostName = StringUtils.defaultString(agentInfo.getHostName(), ""); String ip = StringUtils.defaultString(agentInfo.getIp(), ""); String serviceType = agentInfo.getServiceType().getDesc(); @@ -121,17 +122,15 @@ private AgentHost newAgentHost(AgentInfo agentInfo) { public ApplicationAgentHostList build() { List applicationInfos = buildApplicationInfo(this.map); - ApplicationAgentHostList agents = new ApplicationAgentHostList(startApplicationIndex, endApplicationIndex, totalApplications, + return new ApplicationAgentHostList(startApplicationIndex, endApplicationIndex, totalApplications, applicationInfos); - return agents; } private List buildApplicationInfo(Map> map) { - List applications = map.entrySet().stream() + return map.entrySet().stream() .map(Builder::newApplication) .sorted(Comparator.comparing(ApplicationInfo::getApplicationName)) .collect(Collectors.toList()); - return applications; } @@ -164,19 +163,19 @@ public List getAgents() { } public static class AgentHost { - private final String agentId; + private final AgentId agentId; private final String hostName; private final String ip; private final String serviceType; - public AgentHost(String agentId, String hostName, String ip, String serviceType) { + public AgentHost(AgentId agentId, String hostName, String ip, String serviceType) { this.agentId = Objects.requireNonNull(agentId, "agentId"); this.hostName = Objects.requireNonNull(hostName, "hostName"); this.ip = Objects.requireNonNull(ip, "ip"); this.serviceType = Objects.requireNonNull(serviceType, "serviceType"); } - public String getAgentId() { + public AgentId getAgentId() { return agentId; } diff --git a/web/src/test/java/com/navercorp/pinpoint/web/TestTraceUtils.java b/web/src/test/java/com/navercorp/pinpoint/web/TestTraceUtils.java index 3710eed177a0..dc80b467cdcf 100644 --- a/web/src/test/java/com/navercorp/pinpoint/web/TestTraceUtils.java +++ b/web/src/test/java/com/navercorp/pinpoint/web/TestTraceUtils.java @@ -17,11 +17,12 @@ package com.navercorp.pinpoint.web; import com.navercorp.pinpoint.bootstrap.context.SpanId; +import com.navercorp.pinpoint.common.id.AgentId; +import com.navercorp.pinpoint.common.profiler.util.TransactionId; import com.navercorp.pinpoint.common.server.bo.SpanBo; import com.navercorp.pinpoint.common.server.bo.SpanEventBo; -import com.navercorp.pinpoint.loader.service.ServiceTypeRegistryService; import com.navercorp.pinpoint.common.trace.ServiceType; -import com.navercorp.pinpoint.common.profiler.util.TransactionId; +import com.navercorp.pinpoint.loader.service.ServiceTypeRegistryService; import com.navercorp.pinpoint.web.util.ServiceTypeRegistryMockFactory; import org.assertj.core.matcher.AssertionMatcher; @@ -159,7 +160,7 @@ public SpanBo build() { SpanBo spanBo = new SpanBo(); spanBo.setVersion(version); spanBo.setApplicationName(applicationName); - spanBo.setAgentId(agentId); + spanBo.setAgentId(AgentId.of(agentId)); long spanId = this.spanId; if (spanId == SpanId.NULL) { spanId = random.nextLong(); diff --git a/web/src/test/java/com/navercorp/pinpoint/web/applicationmap/ApplicationMapBuilderTest.java b/web/src/test/java/com/navercorp/pinpoint/web/applicationmap/ApplicationMapBuilderTest.java index 2092620bcac6..5d3ccc185295 100644 --- a/web/src/test/java/com/navercorp/pinpoint/web/applicationmap/ApplicationMapBuilderTest.java +++ b/web/src/test/java/com/navercorp/pinpoint/web/applicationmap/ApplicationMapBuilderTest.java @@ -79,7 +79,7 @@ public class ApplicationMapBuilderTest { private AgentInfoServerGroupListDataSource agentInfoServerGroupListDataSource; - private long buildTimeoutMillis = 1000; + private final long buildTimeoutMillis = 1000; @BeforeEach public void setUp() { diff --git a/web/src/test/java/com/navercorp/pinpoint/web/applicationmap/ApplicationMapBuilderTestHelper.java b/web/src/test/java/com/navercorp/pinpoint/web/applicationmap/ApplicationMapBuilderTestHelper.java index 341e39bd25b2..21e7da446cb0 100644 --- a/web/src/test/java/com/navercorp/pinpoint/web/applicationmap/ApplicationMapBuilderTestHelper.java +++ b/web/src/test/java/com/navercorp/pinpoint/web/applicationmap/ApplicationMapBuilderTestHelper.java @@ -16,6 +16,7 @@ package com.navercorp.pinpoint.web.applicationmap; +import com.navercorp.pinpoint.common.id.AgentId; import com.navercorp.pinpoint.common.server.util.time.Range; import com.navercorp.pinpoint.common.trace.ServiceType; import com.navercorp.pinpoint.common.trace.ServiceTypeFactory; @@ -204,7 +205,7 @@ public static AgentInfo createAgentInfoFromApplicationName(String applicationNam String hostName = createHostnameFromDepth(depth); AgentInfo agentInfo = new AgentInfo(); agentInfo.setApplicationName(applicationName); - agentInfo.setAgentId(agentId); + agentInfo.setAgentId(AgentId.of(agentId)); agentInfo.setHostName(hostName); return agentInfo; } diff --git a/web/src/test/java/com/navercorp/pinpoint/web/applicationmap/ServerGroupListTest.java b/web/src/test/java/com/navercorp/pinpoint/web/applicationmap/ServerGroupListTest.java index 8c098aacf6ba..dfdb58addb28 100644 --- a/web/src/test/java/com/navercorp/pinpoint/web/applicationmap/ServerGroupListTest.java +++ b/web/src/test/java/com/navercorp/pinpoint/web/applicationmap/ServerGroupListTest.java @@ -16,6 +16,7 @@ package com.navercorp.pinpoint.web.applicationmap; +import com.navercorp.pinpoint.common.id.AgentId; import com.navercorp.pinpoint.common.server.bo.AgentInfoBo; import com.navercorp.pinpoint.common.trace.ServiceType; import com.navercorp.pinpoint.loader.service.ServiceTypeRegistryService; @@ -58,7 +59,7 @@ public void testGetAgentIdList() { public static AgentAndStatus createAgentInfo(String agentId, String hostName) { AgentInfoBo.Builder agentInfoBuilder = new AgentInfoBo.Builder(); - agentInfoBuilder.setAgentId(agentId); + agentInfoBuilder.setAgentId(AgentId.of(agentId)); ServiceType serviceType = ServiceType.TEST_STAND_ALONE; agentInfoBuilder.setServiceTypeCode(serviceType.getCode()); diff --git a/web/src/test/java/com/navercorp/pinpoint/web/calltree/span/SpanCallTreeTest.java b/web/src/test/java/com/navercorp/pinpoint/web/calltree/span/SpanCallTreeTest.java index 4df2fe5d24e7..af3e80ddf3a5 100644 --- a/web/src/test/java/com/navercorp/pinpoint/web/calltree/span/SpanCallTreeTest.java +++ b/web/src/test/java/com/navercorp/pinpoint/web/calltree/span/SpanCallTreeTest.java @@ -1,5 +1,6 @@ package com.navercorp.pinpoint.web.calltree.span; +import com.navercorp.pinpoint.common.id.AgentId; import com.navercorp.pinpoint.common.server.bo.SpanBo; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; @@ -12,7 +13,7 @@ public class SpanCallTreeTest { @Test public void hasFocusSpan1() { SpanBo root = new SpanBo(); - root.setAgentId("root"); + root.setAgentId(AgentId.of("root")); Align rootAlign = new SpanAlign(root); SpanCallTree callTreeNodes = new SpanCallTree(rootAlign); @@ -24,7 +25,7 @@ public void hasFocusSpan1() { @Test public void hasFocusSpan2() { SpanBo root = new SpanBo(); - root.setAgentId("root"); + root.setAgentId(AgentId.of("root")); Align rootAlign = new SpanAlign(root); SpanCallTree callTreeNodes = new SpanCallTree(rootAlign); @@ -58,14 +59,14 @@ public void hasFocusSpan_child_travel_not_found() { private SpanCallTree childTree(String parentAgentId, String childAgentId1, String childAgentId2) { SpanBo root = new SpanBo(); // root.setSpanId(100); - root.setAgentId(parentAgentId); + root.setAgentId(AgentId.of(parentAgentId)); Align rootAlign = new SpanAlign(root); SpanCallTree rootCallTreeNodes = new SpanCallTree(rootAlign); SpanBo childSpan1 = new SpanBo(); // childSpan1.setParentSpanId(100); // childSpan1.setSpanId(200); - childSpan1.setAgentId(childAgentId1); + childSpan1.setAgentId(AgentId.of(childAgentId1)); Align childAlign1 = new SpanAlign(childSpan1); SpanCallTree childCallTreeNodes1 = new SpanCallTree(childAlign1); rootCallTreeNodes.add(childCallTreeNodes1); @@ -73,7 +74,7 @@ private SpanCallTree childTree(String parentAgentId, String childAgentId1, Strin SpanBo childSpan2 = new SpanBo(); // childSpan2.setParentSpanId(200); // childSpan2.setSpanId(300); - childSpan2.setAgentId(childAgentId2); + childSpan2.setAgentId(AgentId.of(childAgentId2)); Align childAlign2 = new SpanAlign(childSpan2); SpanCallTree childCallTreeNodes2 = new SpanCallTree(childAlign2); rootCallTreeNodes.add(childCallTreeNodes2); diff --git a/web/src/test/java/com/navercorp/pinpoint/web/calltree/span/SpanFiltersTest.java b/web/src/test/java/com/navercorp/pinpoint/web/calltree/span/SpanFiltersTest.java index 34b3f99bf520..d5af074e69fe 100644 --- a/web/src/test/java/com/navercorp/pinpoint/web/calltree/span/SpanFiltersTest.java +++ b/web/src/test/java/com/navercorp/pinpoint/web/calltree/span/SpanFiltersTest.java @@ -1,5 +1,6 @@ package com.navercorp.pinpoint.web.calltree.span; +import com.navercorp.pinpoint.common.id.AgentId; import com.navercorp.pinpoint.common.server.bo.SpanBo; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; @@ -31,7 +32,7 @@ public void buildViewPointFilter() { Predicate filter = SpanFilters.spanFilter(spanId, agentId, collectorAcceptTime); SpanBo spanBo = new SpanBo(); spanBo.setCollectorAcceptTime(collectorAcceptTime); - spanBo.setAgentId(agentId); + spanBo.setAgentId(AgentId.of(agentId)); spanBo.setSpanId(spanId); Assertions.assertTrue(filter.test(spanBo)); } @@ -41,7 +42,7 @@ public void buildViewPointFilter_empty_spanId() { Predicate filter = SpanFilters.spanFilter(-1, agentId, collectorAcceptTime); SpanBo spanBo = new SpanBo(); spanBo.setCollectorAcceptTime(collectorAcceptTime); - spanBo.setAgentId(agentId); + spanBo.setAgentId(AgentId.of(agentId)); spanBo.setSpanId(1234); Assertions.assertTrue(filter.test(spanBo)); } diff --git a/web/src/test/java/com/navercorp/pinpoint/web/dao/hbase/HbaseAgentLifeCycleDaoTest.java b/web/src/test/java/com/navercorp/pinpoint/web/dao/hbase/HbaseAgentLifeCycleDaoTest.java index e9723f08303f..037ec902326d 100644 --- a/web/src/test/java/com/navercorp/pinpoint/web/dao/hbase/HbaseAgentLifeCycleDaoTest.java +++ b/web/src/test/java/com/navercorp/pinpoint/web/dao/hbase/HbaseAgentLifeCycleDaoTest.java @@ -21,6 +21,7 @@ import com.navercorp.pinpoint.common.hbase.ResultsExtractor; import com.navercorp.pinpoint.common.hbase.RowMapper; import com.navercorp.pinpoint.common.hbase.TableNameProvider; +import com.navercorp.pinpoint.common.id.AgentId; import com.navercorp.pinpoint.common.server.bo.AgentLifeCycleBo; import com.navercorp.pinpoint.common.server.util.AgentLifeCycleState; import com.navercorp.pinpoint.web.dao.AgentLifeCycleDao; @@ -110,7 +111,7 @@ public void agentInfo_should_be_populated_appropriately_if_status_is_known() { when(this.hbaseOperations.find(any(TableName.class), any(Scan.class), any(ResultsExtractor.class))).thenReturn(scannedLifeCycleBo); // When AgentInfo givenAgentInfo = new AgentInfo(); - givenAgentInfo.setAgentId(expectedAgentId); + givenAgentInfo.setAgentId(AgentId.of(expectedAgentId)); givenAgentInfo.setStartTimestamp(expectedTimestamp); Optional agentStatus = this.agentLifeCycleDao.getAgentStatus(givenAgentInfo.getAgentId(), givenAgentInfo.getStartTimestamp(), expectedTimestamp); AgentStatus givenStatus = agentStatus.get(); @@ -136,7 +137,7 @@ public void agentInfo_should_be_populated_as_unknown_if_status_cannot_be_found() when(this.hbaseOperations.find(any(TableName.class), any(Scan.class), any(ResultsExtractor.class))).thenReturn(scannedLifeCycleBo); AgentInfo givenAgentInfo = new AgentInfo(); - givenAgentInfo.setAgentId(expectedAgentId); + givenAgentInfo.setAgentId(AgentId.of(expectedAgentId)); givenAgentInfo.setStartTimestamp(expectedTimestamp); // When Optional agentStatus = this.agentLifeCycleDao.getAgentStatus(givenAgentInfo.getAgentId(), givenAgentInfo.getStartTimestamp(), expectedTimestamp); @@ -157,7 +158,7 @@ public void agentInfos_should_be_populated_accordingly_even_with_nulls() { when(this.hbaseOperations.findParallel(any(TableName.class), anyList(), any(ResultsExtractor.class))).thenReturn(List.of(scannedLifeCycleBo, scannedLifeCycleBo)); AgentInfo nonNullAgentInfo = new AgentInfo(); - nonNullAgentInfo.setAgentId(expectedAgentId); + nonNullAgentInfo.setAgentId(AgentId.of(expectedAgentId)); nonNullAgentInfo.setStartTimestamp(expectedTimestamp); AgentInfo nullAgentInfo = null; List givenAgentInfos = Arrays.asList(nonNullAgentInfo, nullAgentInfo, nonNullAgentInfo, nullAgentInfo); diff --git a/web/src/test/java/com/navercorp/pinpoint/web/dao/hbase/SpanQueryBuilderTest.java b/web/src/test/java/com/navercorp/pinpoint/web/dao/hbase/SpanQueryBuilderTest.java index 3be4f22a18d1..7a18020da00f 100644 --- a/web/src/test/java/com/navercorp/pinpoint/web/dao/hbase/SpanQueryBuilderTest.java +++ b/web/src/test/java/com/navercorp/pinpoint/web/dao/hbase/SpanQueryBuilderTest.java @@ -1,5 +1,6 @@ package com.navercorp.pinpoint.web.dao.hbase; +import com.navercorp.pinpoint.common.id.AgentId; import com.navercorp.pinpoint.common.profiler.util.TransactionId; import com.navercorp.pinpoint.common.server.bo.SpanBo; import com.navercorp.pinpoint.web.calltree.span.SpanFilters; @@ -30,7 +31,7 @@ public void spanQuery_build() { span.setCollectorAcceptTime(100); span.setElapsed(200); span.setApplicationName("appName"); - span.setAgentId("agentId"); + span.setAgentId(AgentId.of("agentId")); Assertions.assertEquals(spanQuery.getTransactionId(), span.getTransactionId()); Assertions.assertTrue(spanQuery.getSpanFilter().test(span)); @@ -118,7 +119,7 @@ public void spanFilter_agentId() { Predicate filter = SpanFilters.agentIdFilter("agentId"); SpanBo span = new SpanBo(); - span.setAgentId("agentId"); + span.setAgentId(AgentId.of("agentId")); Assertions.assertTrue(filter.test(span)); } diff --git a/web/src/test/java/com/navercorp/pinpoint/web/filter/LinkFilterTest.java b/web/src/test/java/com/navercorp/pinpoint/web/filter/LinkFilterTest.java index 72e7cfe15015..d3edd19b2171 100644 --- a/web/src/test/java/com/navercorp/pinpoint/web/filter/LinkFilterTest.java +++ b/web/src/test/java/com/navercorp/pinpoint/web/filter/LinkFilterTest.java @@ -1,5 +1,6 @@ package com.navercorp.pinpoint.web.filter; +import com.navercorp.pinpoint.common.id.AgentId; import com.navercorp.pinpoint.common.server.bo.AnnotationBo; import com.navercorp.pinpoint.common.server.bo.SpanBo; import com.navercorp.pinpoint.common.server.bo.SpanEventBo; @@ -77,19 +78,19 @@ public void fromToFilterTest() { fromSpanBo.setApplicationName("APP_A"); fromSpanBo.setServiceType(tomcatServiceType); - fromSpanBo.setAgentId("AGENT_A"); + fromSpanBo.setAgentId(AgentId.of("AGENT_A")); fromSpanBo.setSpanId(100); SpanBo toSpanBO = new SpanBo(); toSpanBO.setApplicationName("APP_B"); toSpanBO.setServiceType(tomcatServiceType); - toSpanBO.setAgentId("AGENT_B"); + toSpanBO.setAgentId(AgentId.of("AGENT_B")); toSpanBO.setParentSpanId(100); SpanBo spanBoC = new SpanBo(); spanBoC.setApplicationName("APP_C"); spanBoC.setServiceType(tomcatServiceType); - spanBoC.setAgentId("AGENT_C"); + spanBoC.setAgentId(AgentId.of("AGENT_C")); Assertions.assertTrue(linkFilter.include(List.of(fromSpanBo, toSpanBO))); Assertions.assertFalse(linkFilter.include(List.of(fromSpanBo, spanBoC))); @@ -117,19 +118,19 @@ public void fromToFilterAgentTest() { fromSpanBo.setApplicationName("APP_A"); fromSpanBo.setServiceType(tomcatServiceType); - fromSpanBo.setAgentId("AGENT_A"); + fromSpanBo.setAgentId(AgentId.of("AGENT_A")); fromSpanBo.setSpanId(100); SpanBo toSpanBO = new SpanBo(); toSpanBO.setApplicationName("APP_B"); toSpanBO.setServiceType(tomcatServiceType); - toSpanBO.setAgentId("AGENT_B"); + toSpanBO.setAgentId(AgentId.of("AGENT_B")); toSpanBO.setParentSpanId(100); SpanBo spanBoC = new SpanBo(); spanBoC.setApplicationName("APP_C"); spanBoC.setServiceType(tomcatServiceType); - spanBoC.setAgentId("AGENT_C"); + spanBoC.setAgentId(AgentId.of("AGENT_C")); Assertions.assertTrue(linkFilter.include(List.of(fromSpanBo, toSpanBO))); Assertions.assertFalse(linkFilter.include(List.of(fromSpanBo, spanBoC))); diff --git a/web/src/test/java/com/navercorp/pinpoint/web/service/AdminServiceImplTest.java b/web/src/test/java/com/navercorp/pinpoint/web/service/AdminServiceImplTest.java index d9aeb934adfc..9aef2ee9491d 100644 --- a/web/src/test/java/com/navercorp/pinpoint/web/service/AdminServiceImplTest.java +++ b/web/src/test/java/com/navercorp/pinpoint/web/service/AdminServiceImplTest.java @@ -1,5 +1,6 @@ package com.navercorp.pinpoint.web.service; +import com.navercorp.pinpoint.common.id.ApplicationId; import com.navercorp.pinpoint.common.trace.ServiceType; import com.navercorp.pinpoint.web.vo.Application; import org.junit.jupiter.api.BeforeEach; @@ -30,15 +31,12 @@ public class AdminServiceImplTest { final String APPLICATION_NAME2 = "TEST_APP2"; final String APPLICATION_NAME3 = "TEST_APP3"; - final UUID APPLICATION_UUID1 = new UUID(1, 1); - final UUID APPLICATION_UUID2 = new UUID(2, 2); - final UUID APPLICATION_UUID3 = new UUID(3, 3); + final ApplicationId APPLICATION_UUID1 = ApplicationId.of(new UUID(1, 1)); + final ApplicationId APPLICATION_UUID2 = ApplicationId.of(new UUID(2, 2)); + final ApplicationId APPLICATION_UUID3 = ApplicationId.of(new UUID(3, 3)); AdminService adminService; - @Mock - ApplicationInfoService applicationInfoService; - @Mock ApplicationService applicationService; @@ -47,17 +45,16 @@ public class AdminServiceImplTest { @BeforeEach public void setUp() { - adminService = new AdminServiceImpl(applicationInfoService, applicationService, agentInfoService); + adminService = new AdminServiceImpl(applicationService, agentInfoService); } @Test public void removeApplicationName() { // given - when(applicationInfoService.getApplicationId(APPLICATION_NAME1)).thenReturn(APPLICATION_UUID1); doNothing().when(applicationService).deleteApplication(APPLICATION_UUID1); // when - adminService.removeApplicationName(APPLICATION_NAME1); + adminService.removeApplicationName(APPLICATION_UUID1); // then verify(applicationService).deleteApplication(APPLICATION_UUID1); @@ -66,11 +63,10 @@ public void removeApplicationName() { @Test public void removeAgentId() { // given - when(applicationInfoService.getApplicationId(APPLICATION_NAME1)).thenReturn(APPLICATION_UUID1); doNothing().when(applicationService).deleteAgent(APPLICATION_UUID1, AGENT_ID1); // when - adminService.removeAgentId(APPLICATION_NAME1, AGENT_ID1); + adminService.removeAgentId(APPLICATION_UUID1, AGENT_ID1); // then verify(applicationService).deleteAgent(APPLICATION_UUID1, AGENT_ID1); diff --git a/web/src/test/java/com/navercorp/pinpoint/web/vo/AgentsMapByApplicationTest.java b/web/src/test/java/com/navercorp/pinpoint/web/vo/AgentsMapByApplicationTest.java index 9a73873d1b2f..84050d75a3bd 100644 --- a/web/src/test/java/com/navercorp/pinpoint/web/vo/AgentsMapByApplicationTest.java +++ b/web/src/test/java/com/navercorp/pinpoint/web/vo/AgentsMapByApplicationTest.java @@ -1,5 +1,6 @@ package com.navercorp.pinpoint.web.vo; +import com.navercorp.pinpoint.common.id.AgentId; import com.navercorp.pinpoint.web.vo.agent.AgentAndStatus; import com.navercorp.pinpoint.web.vo.agent.AgentInfo; import com.navercorp.pinpoint.web.vo.agent.AgentStatusFilter; @@ -59,7 +60,7 @@ private static AgentAndStatus createAgentInfo(String applicationName, String age private static AgentAndStatus createAgentInfo(String applicationName, String agentId, String hostname, boolean container, long startTimestamp) { AgentInfo agentInfo = new AgentInfo(); agentInfo.setApplicationName(applicationName); - agentInfo.setAgentId(agentId); + agentInfo.setAgentId(AgentId.of(agentId)); agentInfo.setHostName(hostname); agentInfo.setContainer(container); agentInfo.setStartTimestamp(startTimestamp); diff --git a/web/src/test/java/com/navercorp/pinpoint/web/vo/AgentsMapByHostTest.java b/web/src/test/java/com/navercorp/pinpoint/web/vo/AgentsMapByHostTest.java index d79ea65ae661..694f550deee9 100644 --- a/web/src/test/java/com/navercorp/pinpoint/web/vo/AgentsMapByHostTest.java +++ b/web/src/test/java/com/navercorp/pinpoint/web/vo/AgentsMapByHostTest.java @@ -1,5 +1,6 @@ package com.navercorp.pinpoint.web.vo; +import com.navercorp.pinpoint.common.id.AgentId; import com.navercorp.pinpoint.web.hyperlink.HyperLinkFactory; import com.navercorp.pinpoint.web.vo.agent.AgentAndStatus; import com.navercorp.pinpoint.web.vo.agent.AgentInfo; @@ -71,7 +72,7 @@ private static AgentAndStatus createAgentInfo(String applicationName, String age private static AgentAndStatus createAgentInfo(String applicationName, String agentId, String hostname, boolean container, long startTimestamp) { AgentInfo agentInfo = new AgentInfo(); agentInfo.setApplicationName(applicationName); - agentInfo.setAgentId(agentId); + agentInfo.setAgentId(AgentId.of(agentId)); agentInfo.setHostName(hostname); agentInfo.setContainer(container); agentInfo.setStartTimestamp(startTimestamp); diff --git a/web/src/test/java/com/navercorp/pinpoint/web/vo/callstacks/RecordFactoryTest.java b/web/src/test/java/com/navercorp/pinpoint/web/vo/callstacks/RecordFactoryTest.java index d596b4b225d3..dbcdd92a41e0 100644 --- a/web/src/test/java/com/navercorp/pinpoint/web/vo/callstacks/RecordFactoryTest.java +++ b/web/src/test/java/com/navercorp/pinpoint/web/vo/callstacks/RecordFactoryTest.java @@ -16,6 +16,7 @@ package com.navercorp.pinpoint.web.vo.callstacks; +import com.navercorp.pinpoint.common.id.AgentId; import com.navercorp.pinpoint.common.profiler.trace.AnnotationKeyRegistry; import com.navercorp.pinpoint.common.profiler.trace.TraceMetadataLoader; import com.navercorp.pinpoint.common.profiler.util.TransactionId; @@ -218,7 +219,7 @@ public void testMakeRecord() { .build(); SpanBo.Builder spanBoBuilder = new SpanBo.Builder(8174884636707391L) .setVersion(1) - .setAgentId("express-node-sample-id") + .setAgentId(AgentId.of("express-node-sample-id")) .setAgentName("") .setApplicationName("express-node-sample-name") .setAgentStartTime(1670293953108L)