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..38e740919136 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,6 +17,7 @@ package com.navercorp.pinpoint.bootstrap; import com.navercorp.pinpoint.common.PinpointConstants; +import com.navercorp.pinpoint.common.id.ServiceId; import com.navercorp.pinpoint.common.util.AgentUuidUtils; import com.navercorp.pinpoint.common.util.StringUtils; import com.navercorp.pinpoint.common.util.UuidUtils; @@ -30,16 +31,19 @@ */ public class AgentIdResolver { public static final String APPLICATION_NAME = "applicationName"; + public static final String SERVICE_NAME = "serviceName"; public static final String AGENT_ID = "agentId"; 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 SERVICE_NAME_SYSTEM_PROPERTY = SYSTEM_PROPERTY_PREFIX + "serviceName"; public static final String AGENT_ID_SYSTEM_PROPERTY = SYSTEM_PROPERTY_PREFIX + "agentId"; 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 SERVICE_NAME_ENV_PROPERTY = ENV_PROPERTY_PREFIX + "SERVICE_NAME"; public static final String AGENT_ID_ENV_PROPERTY = ENV_PROPERTY_PREFIX + "AGENT_ID"; public static final String AGENT_NAME_ENV_PROPERTY = ENV_PROPERTY_PREFIX + "AGENT_NAME"; @@ -49,6 +53,7 @@ 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"); @@ -68,12 +73,19 @@ public AgentIds resolve() { 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='" + agentId + "'"); + } + final String agentName = getAgentName(); if (StringUtils.isEmpty(agentName)) { logger.info("No AgentName(-Dpinpoint.agentName) provided, it's optional!"); } - return new AgentIds(agentId, agentName, applicationName); + return new AgentIds(agentId, agentName, applicationName, serviceName); } private String newRandomAgentId() { @@ -123,4 +135,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..f2a52c1d4a23 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 @@ -34,7 +34,8 @@ public void addSystemProperties(Properties 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); } @@ -44,7 +45,8 @@ public void addEnvProperties(Map 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); } @@ -54,7 +56,8 @@ public void addAgentArgument(Map 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..b17d202cad85 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 @@ -25,14 +25,15 @@ 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) { + public AgentIds(String agentId, String agentName, String applicationName, String serviceName) { this.agentId = Objects.requireNonNull(agentId, "agentId"); this.agentName = agentName; this.applicationName = Objects.requireNonNull(applicationName, "applicationName"); + this.serviceName = Objects.requireNonNull(serviceName, "serviceName"); } - public String getAgentId() { return agentId; } @@ -44,4 +45,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..10f087036f16 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 @@ -34,6 +34,8 @@ public interface AgentOption { 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..b293125023c2 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 @@ -29,17 +29,19 @@ public class AgentProperties { 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 agentIdKey, 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 agentIdKey, String agentNameKey, String applicationNameKey, String serviceNameKey) { + this(type, toProperties(properties), agentIdKey, agentNameKey, applicationNameKey, serviceNameKey); } private static Properties toProperties(Map properties) { @@ -78,6 +80,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 +97,12 @@ 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 + + ", agentIdKey='" + agentIdKey + '\'' + + ", 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..f71936e9e719 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 @@ -32,6 +32,7 @@ public class DefaultAgentOption implements AgentOption { private final String agentId; private final String agentName; private final String applicationName; + private final String serviceName; private final boolean isContainer; private final ProfilerConfig profilerConfig; @@ -39,12 +40,13 @@ public class DefaultAgentOption implements AgentOption { private final List bootstrapJarPaths; public DefaultAgentOption(final Instrumentation instrumentation, - String agentId, String agentName, String applicationName, final boolean isContainer, + String 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"); @@ -71,6 +73,11 @@ public String getApplicationName() { return applicationName; } + @Override + public String getServiceName() { + return serviceName; + } + @Override public boolean isContainer() { return isContainer; @@ -93,16 +100,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..fb219049af44 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 @@ -109,6 +109,11 @@ boolean start() { 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(); @@ -144,7 +149,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 +263,16 @@ private String getAgentType() { } - private AgentOption createAgentOption(String agentId, String agentName, String applicationName, boolean isContainer, + private AgentOption createAgentOption(String 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) { 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..397a8aabae67 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 @@ -50,7 +50,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, "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..0f67cecd6a15 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 @@ -4,6 +4,7 @@ import org.junit.jupiter.api.Test; import java.util.Arrays; +import java.util.Collections; import java.util.Properties; public class AgentIdResolverTest { @@ -14,9 +15,9 @@ public void resolve() { 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_ID, 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()); @@ -29,9 +30,9 @@ 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_ID, 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()); @@ -44,9 +45,9 @@ 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_ID, 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); @@ -57,11 +58,11 @@ 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_ID, 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_ID, AgentIdResolver.AGENT_NAME, AgentIdResolver.APPLICATION_NAME, AgentIdResolver.SERVICE_NAME); AgentIdResolver resolver = new AgentIdResolver(Arrays.asList(ap, ap2)); AgentIds resolve = resolver.resolve(); @@ -76,14 +77,14 @@ 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_ID, 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_ID, AgentIdResolver.AGENT_NAME, AgentIdResolver.APPLICATION_NAME, AgentIdResolver.SERVICE_NAME); AgentIdResolver resolver = new AgentIdResolver(Arrays.asList(ap, ap2)); AgentIds resolve = resolver.resolve(); 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..3b3c8ad84a84 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 @@ -67,8 +67,9 @@ public DefaultApplicationContext build(ProfilerConfig config, ModuleFactory modu String mockAgentId = "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); } 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..6366d5d0cc5d 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 @@ -30,6 +30,7 @@ public class TestAgentInformation extends DefaultAgentInformation { private static final String AGENT_ID = "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 +40,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..47497bd8bf6c 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 @@ -53,7 +53,7 @@ public void test() { Instrumentation instrumentation = Mockito.mock(Instrumentation.class); AgentOption agentOption = new DefaultAgentOption(instrumentation, - "mockAgentId", "mockAgentName", "mockApplicationName", false, + "mockAgentId", "mockAgentName", "mockApplicationName", "mockServiceName", false, profilerConfig, Collections.emptyList(), Collections.emptyList()); PluginTestAgent pluginTestAgent = new PluginTestAgent(agentOption); @@ -71,7 +71,7 @@ public void testMockApplicationContext() { Instrumentation instrumentation = Mockito.mock(Instrumentation.class); AgentOption agentOption = new DefaultAgentOption(instrumentation, - "mockAgentId", "mockAgentName", "mockApplicationName", false, + "mockAgentId", "mockAgentName", "mockApplicationName", "mockServiceName", false, profilerConfig, Collections.emptyList(), Collections.emptyList()); Module pluginModule = new PluginApplicationContextModule(); 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..449750aa06d0 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 @@ -29,6 +29,8 @@ public interface AgentInformation { 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..28a9e320f7ec 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 @@ -29,6 +29,7 @@ public class DefaultAgentInformation implements AgentInformation { private final String 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; @@ -42,6 +43,7 @@ public DefaultAgentInformation( String agentId, String agentName, String applicationName, + String serviceName, boolean isContainer, long startTime, int pid, @@ -53,6 +55,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; @@ -78,6 +81,11 @@ public String getApplicationName() { return applicationName; } + @Override + public String getServiceName() { + return serviceName; + } + @Override public boolean isContainer() { return isContainer; @@ -120,19 +128,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/module/ServiceName.java b/agent-module/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/module/ServiceName.java new file mode 100644 index 000000000000..9b0c8257a070 --- /dev/null +++ b/agent-module/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/module/ServiceName.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 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..4c839743722d 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 @@ -35,6 +35,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 +131,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 +161,12 @@ private void bindConstants(ContextConfig contextConfig) { bindConstant().annotatedWith(DeadlockMonitorInterval.class).to(contextConfig.getDeadlockMonitorInterval()); } - private void bindAgentInformation(String agentId, String agentName, String applicationName, boolean isContainer) { + private void bindAgentInformation(String agentId, String agentName, String applicationName, String serviceName, boolean isContainer) { bind(String.class).annotatedWith(AgentId.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..955ad51c9362 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 @@ -33,6 +33,7 @@ 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; @@ -45,18 +46,27 @@ public class AgentInformationProvider implements Provider { private final String 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( + @AgentId String 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 +84,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) { 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/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..5915c20e6156 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 @@ -40,7 +40,8 @@ public DefaultApplicationContext build(ProfilerConfig config, ModuleFactory modu String mockAgentId = "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..34fccb6299b4 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 @@ -32,6 +32,7 @@ public class TestAgentInformation extends DefaultAgentInformation { private static final String AGENT_ID = "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 +42,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/graph/DependencyGraph.java b/agent-module/profiler/src/test/java/com/navercorp/pinpoint/profiler/context/graph/DependencyGraph.java index c68e5f03b1ab..6a1035eb99a3 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 @@ -83,7 +83,7 @@ private DefaultApplicationContext newApplicationContext() { Instrumentation instrumentation = mock(Instrumentation.class); AgentOption agentOption = new DefaultAgentOption(instrumentation, - "mockAgentId", "mockAgentName", "mockApplicationName", false, + "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/module/DefaultApplicationContextTest.java b/agent-module/profiler/src/test/java/com/navercorp/pinpoint/profiler/context/module/DefaultApplicationContextTest.java index bf0ab6d93dea..87b89c39c55b 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 @@ -89,7 +89,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, "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/sender/grpc/AgentGrpcDataSenderTestMain.java b/agent-module/profiler/src/test/java/com/navercorp/pinpoint/profiler/sender/grpc/AgentGrpcDataSenderTestMain.java index 7d37c71b2532..6888a74cca97 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 @@ -49,6 +49,7 @@ public class AgentGrpcDataSenderTestMain { private static final String AGENT_ID = "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 +59,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 +83,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/src/main/java/com/navercorp/pinpoint/batch/alarm/AlarmProcessor.java b/batch/src/main/java/com/navercorp/pinpoint/batch/alarm/AlarmProcessor.java index 004f8d68c87b..02344a4bc0cd 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,7 @@ 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.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 +38,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,7 +106,7 @@ 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)) 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..61adbf675650 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,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.common.server.util.time.Range; import com.navercorp.pinpoint.web.service.AgentInfoService; import com.navercorp.pinpoint.web.service.ApplicationService; @@ -25,13 +26,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,7 +52,7 @@ public AgentCountProcessor( } @Override - public Integer process(@Nonnull UUID applicationId) { + public Integer process(@Nonnull ApplicationId applicationId) { long localCount = applicationService.getAgents(applicationId) .stream() .filter(this::isActive) 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..f8a9d84789ff 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,7 @@ 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.ApplicationId; import com.navercorp.pinpoint.common.server.cluster.ClusterKey; import com.navercorp.pinpoint.common.server.util.time.Range; import jakarta.annotation.Nonnull; @@ -30,12 +31,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,7 +54,7 @@ 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(); @@ -80,7 +80,7 @@ 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); } @@ -88,7 +88,7 @@ private boolean isAgentTarget(String 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..bfcc80c0c1b8 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,20 @@ package com.navercorp.pinpoint.batch.service; +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); - 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..db13924669b5 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,13 @@ 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.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,7 +41,7 @@ public BatchAgentServiceImpl( } @Override - public List getIds(UUID applicationId) { + public List getIds(ApplicationId applicationId) { return this.applicationService.getAgents(applicationId); } @@ -51,7 +51,7 @@ public boolean isActive(String agentId, Range 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..9c9d95979020 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,8 @@ package com.navercorp.pinpoint.batch.alarm; +import com.navercorp.pinpoint.common.id.ApplicationId; +import com.navercorp.pinpoint.common.id.ServiceId; import com.navercorp.pinpoint.common.trace.ServiceType; import com.navercorp.pinpoint.web.service.AlarmService; import com.navercorp.pinpoint.web.service.ApplicationService; @@ -46,10 +48,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(ServiceId.of(UUID.randomUUID()), ApplicationId.of(UUID.randomUUID()), "testApplication0", ServiceType.TEST), + new Application(ServiceId.of(UUID.randomUUID()), ApplicationId.of(UUID.randomUUID()), "testApplication1", ServiceType.TEST), + new Application(ServiceId.of(UUID.randomUUID()), ApplicationId.of(UUID.randomUUID()), "testApplication2", ServiceType.TEST), + new Application(ServiceId.of(UUID.randomUUID()), ApplicationId.of(UUID.randomUUID()), "testApplication3", ServiceType.TEST) ); private static final List applicationIds = mockApplications.stream() 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..f4efde9bbde7 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,20 @@ package com.navercorp.pinpoint.collector.dao; import com.navercorp.pinpoint.common.id.ApplicationId; +import com.navercorp.pinpoint.common.server.bo.ApplicationInfo; +import com.navercorp.pinpoint.common.server.bo.ApplicationSelector; /** * @author youngjin.kim2 */ public interface ApplicationInfoDao { - ApplicationId getApplicationId(String applicationName); + ApplicationId getApplicationId(ApplicationSelector application); - String getApplicationName(ApplicationId applicationId); + ApplicationInfo getApplication(ApplicationId applicationId); - ApplicationId putApplicationIdIfAbsent(String applicationName, ApplicationId applicationId); + ApplicationId putApplicationIdIfAbsent(ApplicationInfo application); - void ensureInverse(String applicationName, ApplicationId applicationId); + void ensureInverse(ApplicationInfo application); } 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..015fef6b2758 --- /dev/null +++ b/collector/src/main/java/com/navercorp/pinpoint/collector/dao/ServiceInfoDao.java @@ -0,0 +1,41 @@ +/* + * 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.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 ServiceInfoDao { + + ServiceId getServiceId(String serviceName); + + ServiceInfo getServiceInfo(ServiceId serviceId); + + ServiceId putServiceIdIfAbsent(String serviceName, ServiceId serviceId); + + void ensurePut(String serviceName, ServiceId serviceId); + + List getApplications(ServiceId serviceId); + + void insertApplicationIntoService(ServiceId serviceId, ApplicationId applicationId); + +} 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..ed9e3cdfc2bc 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,7 +69,7 @@ public void insert(final AgentInfoBo agentInfo) { // Assert applicationName CollectorUtils.checkApplicationName(agentInfo.getApplicationName()); - final Put put = new Put(UuidUtils.toBytes(agentInfo.getApplicationId().value())); + final Put put = new Put(agentInfo.getApplicationId().toBytes()); final byte[] qualifier = Bytes.toBytes(agentInfo.getAgentId()); 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..fc5b3328246a 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,10 +22,9 @@ 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.bo.ApplicationInfo; +import com.navercorp.pinpoint.common.server.bo.ApplicationSelector; 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 org.apache.hadoop.hbase.TableName; import org.apache.hadoop.hbase.client.CheckAndMutate; import org.apache.hadoop.hbase.client.CheckAndMutateResult; @@ -37,7 +36,6 @@ import org.springframework.stereotype.Repository; import java.util.Objects; -import java.util.UUID; /** * @author youngjin.kim2 @@ -51,14 +49,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 +64,85 @@ 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 = encodeSelectorRowKey(application); + 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 = putForward(applicationName, applicationId); - + CheckAndMutateResult camResult = putInverse(application); if (camResult.isSuccess()) { - putInverse(applicationId, applicationName); + putForward(application); } - Cell cell = camResult.getResult().getColumnLatestCell(family, qualifier); - return ApplicationId.of(UuidUtils.fromBytes(cell.getValueArray())); + ApplicationId applicationId = getApplicationId(new ApplicationSelector(application.serviceId(), application.name())); + if (applicationId == null) { + throw new IllegalStateException("Failed to put applicationId: " + application); + } + + return applicationId; } @Override - public void ensureInverse(String applicationName, ApplicationId applicationId) { - Objects.requireNonNull(applicationName, "applicationName"); - Objects.requireNonNull(applicationId, "applicationId"); + public void ensureInverse(ApplicationInfo application) { + Objects.requireNonNull(application, "application"); if (logger.isDebugEnabled()) { - logger.debug("ensureInverse() applicationName:{}, applicationId:{}", applicationName, applicationId); + logger.debug("ensurePut() serviceId: {}, applicationName:{}, applicationId:{}", + application.serviceId(), application.name(), application.id()); } - putInverse(applicationId, applicationName); + putInverse(application); } - 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 = encodeSelectorRowKey(selector); + 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 +154,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 +169,8 @@ 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[] encodeSelectorRowKey(ApplicationSelector tuple) { + return HashUtils.hashBytes(tuple.toBytes()).asBytes(); } - private static byte[] encodeUuidAsRowKey(UUID uuid) { - return UuidUtils.toBytes(uuid); - } } 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..e92aaf0da98c --- /dev/null +++ b/collector/src/main/java/com/navercorp/pinpoint/collector/dao/hbase/HbaseServiceInfoDao.java @@ -0,0 +1,215 @@ +/* + * 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.ApplicationId; +import com.navercorp.pinpoint.common.id.ServiceId; +import com.navercorp.pinpoint.common.server.bo.ServiceInfo; +import com.navercorp.pinpoint.common.server.util.HashUtils; +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.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 static final HbaseColumnFamily.ServiceApplicationIndex DESCRIPTOR_INDEX = HbaseColumnFamily.SERVICE_APPLICATION_INDEX; + + private final HbaseOperations hbaseTemplate; + private final TableNameProvider tableNameProvider; + private final RowMapper forwardRowMapper; + private final RowMapper inverseRowMapper; + private final RowMapper> serviceIndexMapper; + + public HbaseServiceInfoDao( + HbaseOperations hbaseTemplate, + TableNameProvider tableNameProvider, + @Qualifier("serviceIdForwardMapper") RowMapper forwardRowMapper, + @Qualifier("serviceIdInverseMapper") RowMapper inverseRowMapper, + @Qualifier("serviceIndexMapper") RowMapper> serviceIndexMapper) { + 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.serviceIndexMapper = Objects.requireNonNull(serviceIndexMapper, "serviceIndexMapper"); + } + + @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); + } + + @Override + public List getApplications(ServiceId serviceId) { + Objects.requireNonNull(serviceId, "serviceId"); + + if (logger.isDebugEnabled()) { + logger.debug("getApplications() serviceId:{}", serviceId); + } + + TableName tableName = this.tableNameProvider.getTableName(DESCRIPTOR_INDEX.getTable()); + byte[] rowKey = serviceId.toBytes(); + byte[] family = DESCRIPTOR_INDEX.getName(); + + Get get = new Get(rowKey); + get.addFamily(family); + + return hbaseTemplate.get(tableName, get, this.serviceIndexMapper); + } + + @Override + public void insertApplicationIntoService(ServiceId serviceId, ApplicationId applicationId) { + Objects.requireNonNull(serviceId, "serviceId"); + Objects.requireNonNull(applicationId, "applicationId"); + + if (logger.isDebugEnabled()) { + logger.debug("insertApplicationIntoService() serviceId:{}, applicationId:{}", serviceId, applicationId); + } + + TableName tableName = this.tableNameProvider.getTableName(DESCRIPTOR_INDEX.getTable()); + byte[] rowKey = serviceId.toBytes(); + byte[] family = DESCRIPTOR_INDEX.getName(); + byte[] qualifier = applicationId.toBytes(); + byte[] value = new byte[]{ 0x00 }; + + Put put = new Put(rowKey); + put.addColumn(family, qualifier, value); + + hbaseTemplate.put(tableName, put); + } + + 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 HashUtils.hashBytes(BytesUtils.toBytes(str)).asBytes(); + } + +} 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/handler/grpc/GrpcSpanChunkHandler.java b/collector/src/main/java/com/navercorp/pinpoint/collector/handler/grpc/GrpcSpanChunkHandler.java index 4039e38a9948..0910b3e5686c 100644 --- a/collector/src/main/java/com/navercorp/pinpoint/collector/handler/grpc/GrpcSpanChunkHandler.java +++ b/collector/src/main/java/com/navercorp/pinpoint/collector/handler/grpc/GrpcSpanChunkHandler.java @@ -6,8 +6,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.SpanChunkBo; @@ -47,6 +49,7 @@ public class GrpcSpanChunkHandler implements SimpleHandler { 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/mapper/grpc/GrpcAgentInfoBoMapper.java b/collector/src/main/java/com/navercorp/pinpoint/collector/mapper/grpc/GrpcAgentInfoBoMapper.java index 66026283a6e6..fe3705e5b131 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,9 @@ 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.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 +38,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 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 +81,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/service/AgentInfoService.java b/collector/src/main/java/com/navercorp/pinpoint/collector/service/AgentInfoService.java index 43726b85fd04..06498a32875e 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 @@ -37,17 +37,23 @@ 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) { 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/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..d4a74088416c --- /dev/null +++ b/collector/src/main/java/com/navercorp/pinpoint/collector/service/ServiceInfoServiceImpl.java @@ -0,0 +1,71 @@ +/* + * 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.ApplicationId; +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.List; +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(); + ApplicationId applicationId = agent.getApplicationId(); + + this.serviceInfoDao.ensurePut(serviceName, serviceId); + + List applicationIds = this.serviceInfoDao.getApplications(serviceId); + if (!applicationIds.contains(applicationId)) { + this.serviceInfoDao.insertApplicationIntoService(serviceId, applicationId); + } + } + + @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/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..4d4f42343f91 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 @@ -95,7 +95,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", "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..ef31bf502ff1 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 @@ -34,7 +34,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", "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..71d71e9b4a15 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 @@ -66,7 +66,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("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..89e398fdea20 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 @@ -92,7 +92,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("mockAgentId", "mockAgentName", "mockApplicationName", "mockServiceName", ServiceType.UNDEFINED.getCode(), System.currentTimeMillis()); ChannelFactoryBuilder channelFactoryBuilder = new DefaultChannelFactoryBuilder("MetadataClientMock"); channelFactoryBuilder.setHeaderFactory(headerFactory); channelFactoryBuilder.setClientOption(new ClientOption()); 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..d6ed75c26ea9 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 @@ -156,7 +156,7 @@ public void onCompleted() { private ChannelFactory newChannelFactory() { - HeaderFactory headerFactory = new AgentHeaderFactory("mockAgentId", "mockAgentName", "mockApplicationName", ServiceType.UNDEFINED.getCode(), System.currentTimeMillis()); + HeaderFactory headerFactory = new AgentHeaderFactory("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..f39646f94536 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 @@ -30,8 +30,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 +43,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("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/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..450f7508a1d1 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,21 @@ 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 ServiceApplicationIndex SERVICE_APPLICATION_INDEX = new ServiceApplicationIndex(HbaseTable.SERVICE_APPLICATION_INDEX, Bytes.toBytes("I")); + public static class ServiceApplicationIndex extends HbaseColumnFamily { + private ServiceApplicationIndex(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..8bdc7174447f 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,8 @@ public enum HbaseTable { APPLICATION_INDEX("ApplicationIndex"), APPLICATION_INDEX_VER2("ApplicationIndex_Ver2"), APPLICATION_ID("ApplicationId"), + SERVICE_ID("ServiceId"), + SERVICE_APPLICATION_INDEX("ServiceApplicationIndex"), 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-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..3846b9e7daf4 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 @@ -19,6 +19,7 @@ import com.navercorp.pinpoint.common.buffer.AutomaticBuffer; import com.navercorp.pinpoint.common.buffer.Buffer; import com.navercorp.pinpoint.common.id.ApplicationId; +import com.navercorp.pinpoint.common.id.ServiceId; import jakarta.validation.constraints.NotBlank; /** @@ -34,6 +35,8 @@ public class AgentInfoBo { 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 +61,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; @@ -98,6 +103,14 @@ public ApplicationId getApplicationId() { return applicationId; } + public String getServiceName() { + return serviceName; + } + + public ServiceId getServiceId() { + return serviceId; + } + public long getStartTime() { return startTime; } @@ -159,6 +172,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 +196,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 +210,8 @@ public String toString() { ", agentName='" + agentName + '\'' + ", applicationName='" + applicationName + '\'' + ", applicationId='" + applicationId + '\'' + + ", serviceName='" + serviceName + '\'' + + ", serviceId='" + serviceId + '\'' + ", serviceTypeCode=" + serviceTypeCode + ", pid=" + pid + ", vmVersion='" + vmVersion + '\'' + @@ -219,6 +233,8 @@ public static class Builder { private String agentName; private String applicationName; private ApplicationId applicationId; + private String serviceName; + private ServiceId serviceId; private short serviceTypeCode; private int pid; private String vmVersion; @@ -265,6 +281,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; } @@ -323,7 +347,12 @@ public AgentInfoBo build() { 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..2425a7c587ab --- /dev/null +++ b/commons-server/src/main/java/com/navercorp/pinpoint/common/server/bo/ApplicationSelector.java @@ -0,0 +1,57 @@ +/* + * 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 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.putPrefixedString(name); + return buffer.getBuffer(); + } + + @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/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/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..d6630eccbb32 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 @@ -22,6 +22,7 @@ import com.navercorp.pinpoint.common.hbase.HbaseTableConstants; import com.navercorp.pinpoint.common.hbase.RowMapper; 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; @@ -91,6 +92,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..a015c091aa60 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.id.ServiceId; +import com.navercorp.pinpoint.common.server.bo.ApplicationInfo; 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,22 @@ 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()); + + UUID serviceIdValue = valueBuffer.readUUID(); + ServiceId serviceId = ServiceId.of(serviceIdValue); + + String applicationName = valueBuffer.readPrefixedString(); + + 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, serviceId, applicationName); } } 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/dao/hbase/mapper/ServiceIndexMapper.java b/commons-server/src/main/java/com/navercorp/pinpoint/common/server/dao/hbase/mapper/ServiceIndexMapper.java new file mode 100644 index 000000000000..f344b5492d8e --- /dev/null +++ b/commons-server/src/main/java/com/navercorp/pinpoint/common/server/dao/hbase/mapper/ServiceIndexMapper.java @@ -0,0 +1,59 @@ +/* + * 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.dao.hbase.mapper; + +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.UuidUtils; +import org.apache.hadoop.hbase.client.Result; +import org.springframework.stereotype.Component; + +import java.util.ArrayList; +import java.util.List; +import java.util.NavigableMap; +import java.util.Set; +import java.util.UUID; + +/** + * @author youngjin.kim2 + */ +@Component +public class ServiceIndexMapper implements RowMapper> { + + private static final HbaseColumnFamily.ServiceApplicationIndex DESCRIPTOR = HbaseColumnFamily.SERVICE_APPLICATION_INDEX; + + @Override + public List mapRow(Result result, int rowNum) throws Exception { + NavigableMap familyMap = result.getFamilyMap(DESCRIPTOR.getName()); + if (familyMap == null || familyMap.isEmpty()) { + return List.of(); + } + + Set qualifierSet = familyMap.keySet(); + List applicationIds = new ArrayList<>(qualifierSet.size()); + for (byte[] qualifier : qualifierSet) { + applicationIds.add(parseQualifier(qualifier)); + } + return applicationIds; + } + + private static ApplicationId parseQualifier(byte[] qualifier) { + UUID value = UuidUtils.fromBytes(qualifier); + return ApplicationId.of(value); + } + +} 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/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/grpc/src/main/java/com/navercorp/pinpoint/grpc/AgentHeaderFactory.java b/grpc/src/main/java/com/navercorp/pinpoint/grpc/AgentHeaderFactory.java index a68afbecd952..8f3bd6ecadc4 100644 --- a/grpc/src/main/java/com/navercorp/pinpoint/grpc/AgentHeaderFactory.java +++ b/grpc/src/main/java/com/navercorp/pinpoint/grpc/AgentHeaderFactory.java @@ -31,13 +31,16 @@ public class AgentHeaderFactory implements HeaderFactory { private final String 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(String 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; } @@ -46,6 +49,7 @@ public Metadata newHeader() { Metadata headers = new Metadata(); headers.put(Header.AGENT_ID_KEY, agentId); 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..1a1bd1de71a2 100644 --- a/grpc/src/main/java/com/navercorp/pinpoint/grpc/Header.java +++ b/grpc/src/main/java/com/navercorp/pinpoint/grpc/Header.java @@ -32,6 +32,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 @@ -54,22 +55,23 @@ private static Metadata.Key newStringKey(String s) { private final String 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, String 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, + String agentId, String agentName, String applicationName, String serviceName, int serviceType, long agentStartTime, long socketId, List supportCommandCodeList, @@ -77,6 +79,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; @@ -98,6 +101,10 @@ public String getApplicationName() { return applicationName; } + public String getServiceName() { + return serviceName; + } + public long getAgentStartTime() { return agentStartTime; } @@ -129,6 +136,7 @@ public String toString() { ", agentId='" + agentId + '\'' + ", agentName='" + agentName + '\'' + ", applicationName='" + applicationName + '\'' + + ", serviceName='" + serviceName + '\'' + ", agentStartTime=" + agentStartTime + ", socketId=" + socketId + ", serviceType=" + serviceType + @@ -151,6 +159,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 +171,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..2d9c5be176bd 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,7 @@ package com.navercorp.pinpoint.grpc.server; import com.navercorp.pinpoint.common.PinpointConstants; +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 +58,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, agentName, applicationName, serviceName, serviceType, startTime, socketId, supportCommandCodeList, properties); } public static Map emptyProperties(Metadata headers) { @@ -90,6 +92,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 228c8f5fa6c9..259b4f9ea8d9 100644 --- a/grpc/src/test/java/com/navercorp/pinpoint/grpc/ChannelFactoryTest.java +++ b/grpc/src/test/java/com/navercorp/pinpoint/grpc/ChannelFactoryTest.java @@ -33,7 +33,17 @@ import com.navercorp.pinpoint.grpc.trace.PSpan; import com.navercorp.pinpoint.grpc.trace.PSpanMessage; import com.navercorp.pinpoint.grpc.trace.SpanGrpc; -import io.grpc.*; +import io.grpc.CallOptions; +import io.grpc.Channel; +import io.grpc.ClientCall; +import io.grpc.ClientInterceptor; +import io.grpc.ManagedChannel; +import io.grpc.MethodDescriptor; +import io.grpc.NameResolverProvider; +import io.grpc.Server; +import io.grpc.ServerInterceptor; +import io.grpc.ServerTransportFilter; +import io.grpc.Status; import io.grpc.internal.PinpointDnsNameResolverProvider; import io.grpc.stub.StreamObserver; import org.apache.logging.log4j.LogManager; @@ -94,7 +104,7 @@ 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", "agentName", "appName", "serviceName", ServiceType.UNDEFINED.getCode(), System.currentTimeMillis()); CountRecordClientInterceptor countRecordClientInterceptor = new CountRecordClientInterceptor(); diff --git a/hbase/scripts/hbase-create.hbase b/hbase/scripts/hbase-create.hbase index 2c72d1664102..d2cd26aa5ac0 100644 --- a/hbase/scripts/hbase-create.hbase +++ b/hbase/scripts/hbase-create.hbase @@ -26,6 +26,9 @@ 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"]} +create 'ServiceApplicationIndex', { 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..89d81b126795 100644 --- a/hbase/scripts/hbase-drop.hbase +++ b/hbase/scripts/hbase-drop.hbase @@ -20,6 +20,13 @@ disable 'ApplicationMapStatisticsSelf_Ver2' disable 'HostApplicationMap_Ver2' +disable 'ApplicationIndex_Ver2' +disable 'ApplicationId' +disable 'ApplicationTraceIndex_Ver2' + +disable 'ServiceId' +disable 'ServiceApplicationIndex' + drop 'AgentInfo' drop 'AgentStatV2' @@ -43,4 +50,12 @@ drop 'ApplicationMapStatisticsSelf_Ver2' drop 'HostApplicationMap_Ver2' +drop 'ApplicationIndex_Ver2' +drop 'ApplicationId' +drop 'ApplicationTraceIndex_Ver2' + +drop 'ServiceId' +drop 'ServiceApplicationIndex' + + 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..7c5fb7a3fe0f 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 @@ -327,6 +327,7 @@ public ServerCall.Listener interceptCall(ServerCall> 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/component/ApplicationFactory.java b/web/src/main/java/com/navercorp/pinpoint/web/component/ApplicationFactory.java index d2def1697381..98206397753c 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,17 @@ package com.navercorp.pinpoint.web.component; +import com.navercorp.pinpoint.common.id.ApplicationId; +import com.navercorp.pinpoint.common.id.ServiceId; 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(ServiceId serviceId, 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..74b95b1accf4 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,14 @@ package com.navercorp.pinpoint.web.component; +import com.navercorp.pinpoint.common.id.ApplicationId; +import com.navercorp.pinpoint.common.id.ServiceId; 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,9 +39,9 @@ public DefaultApplicationFactory(ServiceTypeRegistryService registry) { } @Override - public Application createApplication(UUID applicationId, String applicationName, short serviceTypeCode) { + public Application createApplication(ServiceId serviceId, ApplicationId applicationId, String applicationName, short serviceTypeCode) { final ServiceType serviceType = registry.findServiceType(serviceTypeCode); - return new Application(applicationId, applicationName, serviceType); + return new Application(serviceId, applicationId, applicationName, serviceType); } @Override 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/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..ab03c4f57198 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,19 +15,23 @@ */ package com.navercorp.pinpoint.web.dao; +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.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(); 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..3c6e9f90b15b --- /dev/null +++ b/web/src/main/java/com/navercorp/pinpoint/web/dao/ServiceInfoDao.java @@ -0,0 +1,37 @@ +/* + * 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.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 ServiceInfoDao { + + ServiceId getServiceId(String serviceName); + + ServiceInfo getServiceInfo(ServiceId serviceId); + + List getServiceInfos(); + + List getApplicationIds(ServiceId serviceId); + +} 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..140e83f50ae7 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.id.ApplicationId; +import com.navercorp.pinpoint.common.server.bo.ApplicationInfo; +import com.navercorp.pinpoint.common.server.bo.ApplicationSelector; 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.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,69 @@ 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 = encodeSelectorRowKey(selector); + 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); + + return new Application(info.serviceId(), info.id(), info.name(), DEFAULT_SERVICE_TYPE); } @Override @@ -115,11 +124,71 @@ 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); } - private static byte[] encodeStringAsRowKey(String str) { - return HashUtils.hashBytes(BytesUtils.toBytes(str)).asBytes(); + @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 CheckAndMutateResult putInverse(ApplicationInfo application) { + ApplicationSelector selector = new ApplicationSelector(application.serviceId(), application.name()); + + TableName tableName = this.tableNameProvider.getTableName(DESCRIPTOR_INVERSE.getTable()); + byte[] rowKey = encodeSelectorRowKey(selector); + 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 static byte[] encodeSelectorRowKey(ApplicationSelector selector) { + return HashUtils.hashBytes(selector.toBytes()).asBytes(); + } + + private List mapApplicationInfos(List infos) { + List applications = new ArrayList<>(infos.size()); + for (ApplicationInfo info : infos) { + applications.add(new Application(info.serviceId(), 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..0a3b56f62ea4 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; /** @@ -109,7 +109,7 @@ public void setScanCacheSize(int 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 +125,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 +202,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 +237,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 +258,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 +285,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 +307,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 +318,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 +376,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/HbaseServiceInfoDao.java b/web/src/main/java/com/navercorp/pinpoint/web/dao/hbase/HbaseServiceInfoDao.java new file mode 100644 index 000000000000..2cd98c8c7f43 --- /dev/null +++ b/web/src/main/java/com/navercorp/pinpoint/web/dao/hbase/HbaseServiceInfoDao.java @@ -0,0 +1,144 @@ +/* + * 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.ApplicationId; +import com.navercorp.pinpoint.common.id.ServiceId; +import com.navercorp.pinpoint.common.server.bo.ServiceInfo; +import com.navercorp.pinpoint.common.server.util.HashUtils; +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 static final HbaseColumnFamily.ServiceApplicationIndex SERVICE_APPLICATION_INDEX = HbaseColumnFamily.SERVICE_APPLICATION_INDEX; + + private final HbaseOperations hbaseTemplate; + private final TableNameProvider tableNameProvider; + private final RowMapper forwardRowMapper; + private final RowMapper inverseRowMapper; + private final RowMapper> serviceIndexMapper; + + public HbaseServiceInfoDao( + HbaseOperations hbaseTemplate, + TableNameProvider tableNameProvider, + @Qualifier("serviceIdForwardMapper") RowMapper forwardRowMapper, + @Qualifier("serviceIdInverseMapper") RowMapper inverseRowMapper, + @Qualifier("serviceIndexMapper") RowMapper> serviceIndexMapper + ) { + 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.serviceIndexMapper = Objects.requireNonNull(serviceIndexMapper, "serviceIndexMapper"); + } + + @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); + } + + @Override + public List getApplicationIds(ServiceId serviceId) { + Objects.requireNonNull(serviceId, "serviceId"); + + if (logger.isDebugEnabled()) { + logger.debug("getApplicationIds() serviceId:{}", serviceId); + } + + TableName tableName = this.tableNameProvider.getTableName(SERVICE_APPLICATION_INDEX.getTable()); + byte[] rowKey = serviceId.toBytes(); + byte[] family = SERVICE_APPLICATION_INDEX.getName(); + + Get get = new Get(rowKey); + get.addFamily(family); + + return hbaseTemplate.get(tableName, get, this.serviceIndexMapper); + } + + private static byte[] encodeStringAsRowKey(String str) { + return HashUtils.hashBytes(BytesUtils.toBytes(str)).asBytes(); + } + +} 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..25e6b3f703d7 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) { @@ -60,7 +60,7 @@ public List mapRow(Result result, int rowNum) throws Exception { } List applicationList = new ArrayList<>(); for (short serviceTypeCode : uniqueTypeCodes) { - final Application application = applicationFactory.createApplication(applicationId, null, serviceTypeCode); + final Application application = applicationFactory.createApplication(null, applicationId, null, serviceTypeCode); applicationList.add(application); } return applicationList; 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..6a3609fe1f50 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,7 @@ package com.navercorp.pinpoint.web.service; +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 +30,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 +42,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,32 +70,31 @@ 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; @@ -158,13 +152,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(); 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..20067cf6ed54 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,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.common.server.bo.stat.JvmGcBo; import com.navercorp.pinpoint.common.server.util.AgentEventType; import com.navercorp.pinpoint.common.server.util.time.Range; @@ -62,7 +65,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 +211,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(); @@ -254,7 +256,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 +276,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 +319,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); 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..06ee1fbd4a21 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,7 +15,11 @@ */ 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.web.dao.ApplicationInfoDao; +import com.navercorp.pinpoint.web.vo.Application; import org.springframework.cache.annotation.Cacheable; import org.springframework.stereotype.Component; @@ -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(UUID.randomUUID()); + 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..a89c21a9fc5d 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,27 +39,25 @@ 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); - return applicationsV2.size() > 0 || applications.size() > 0; } @Override @@ -78,10 +78,26 @@ 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)) { + applications.addAll(this.applicationIndexDao.selectAllApplicationNames()); + } + List applicationIds = this.serviceInfoService.getApplicationIds(serviceId); + for (ApplicationId applicationId : applicationIds) { + Application application = this.applicationInfoService.getApplication(applicationId); + if (application != null) { + applications.add(application); + } + } + return applications; + } + + @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 +110,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 +130,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.serviceId(), helper.id(), helper.name(), helper.serviceType())); + } } return result; } @@ -133,8 +151,10 @@ 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()); - result.add(new Application(applicationId, application.name(), application.serviceType())); + ApplicationId applicationId = this.applicationInfoService.getApplicationId(new ApplicationSelector(ServiceId.DEFAULT_ID, application.name())); + if (applicationId != null) { + result.add(new Application(ServiceId.DEFAULT_ID, 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/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..770eb84306e6 --- /dev/null +++ b/web/src/main/java/com/navercorp/pinpoint/web/service/ServiceInfoServiceImpl.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.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.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; + + + public ServiceInfoServiceImpl(ServiceInfoDao serviceInfoDao) { + this.serviceInfoDao = Objects.requireNonNull(serviceInfoDao, "serviceInfoDao"); + } + + @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.serviceInfoDao.getApplicationIds(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..6d539e41b64a 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 @@ -31,10 +31,15 @@ public class ApplicationSerializer extends JsonSerializer { @Override public void serialize(Application application, JsonGenerator jgen, SerializerProvider provider) throws IOException { jgen.writeStartObject(); + if (application.serviceId() != null) { + jgen.writeStringField("serviceId", application.serviceId().toString()); + } else { + jgen.writeNullField("serviceId"); + } 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/vo/Application.java b/web/src/main/java/com/navercorp/pinpoint/web/vo/Application.java index 5819b33a5372..a27cc872f92d 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,12 @@ 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.id.ServiceId; 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,16 +30,17 @@ * @author jaehong.kim */ @JsonSerialize(using = ApplicationSerializer.class) -public record Application(UUID id, String name, ServiceType serviceType) { +public record Application(ServiceId serviceId, ApplicationId id, String name, ServiceType serviceType) { - public Application(UUID id, String name, ServiceType serviceType) { + public Application(ServiceId serviceId, ApplicationId id, String name, ServiceType serviceType) { + this.serviceId = serviceId; this.id = id; this.name = name; this.serviceType = Objects.requireNonNull(serviceType, "serviceType"); } public Application(String name, ServiceType serviceType) { - this(null, name, serviceType); + this(null, null, name, serviceType); } public short getServiceTypeCode() { 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..ae50b0428366 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,7 @@ 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.trace.ServiceType; import com.navercorp.pinpoint.web.vo.Application; import org.junit.jupiter.api.BeforeEach; @@ -30,14 +32,15 @@ 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 ServiceId SERVICE_UUID1 = ServiceId.of(new UUID(101, 101)); + final ServiceId SERVICE_UUID2 = ServiceId.of(new UUID(101, 102)); + final ServiceId SERVICE_UUID3 = ServiceId.of(new UUID(101, 103)); - AdminService adminService; + 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)); - @Mock - ApplicationInfoService applicationInfoService; + AdminService adminService; @Mock ApplicationService applicationService; @@ -47,17 +50,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 +68,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); @@ -94,9 +95,9 @@ public void testDuplicateAgentIdMap() { // given when(applicationService.getApplications()) .thenReturn(List.of( - new Application(APPLICATION_UUID1, APPLICATION_NAME1, ServiceType.UNDEFINED), - new Application(APPLICATION_UUID2, APPLICATION_NAME2, ServiceType.UNDEFINED), - new Application(APPLICATION_UUID3, APPLICATION_NAME3, ServiceType.UNDEFINED))); + new Application(SERVICE_UUID1, APPLICATION_UUID1, APPLICATION_NAME1, ServiceType.UNDEFINED), + new Application(SERVICE_UUID2, APPLICATION_UUID2, APPLICATION_NAME2, ServiceType.UNDEFINED), + new Application(SERVICE_UUID3, APPLICATION_UUID3, APPLICATION_NAME3, ServiceType.UNDEFINED))); when(applicationService.getAgents(eq(APPLICATION_UUID1))) .thenReturn(List.of(AGENT_ID1, AGENT_ID2, AGENT_ID3));