Skip to content

Commit d37a0fb

Browse files
smilu97ga-ram
authored andcommitted
[#10741] Added service id
1 parent d4e6e85 commit d37a0fb

File tree

242 files changed

+2827
-1028
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

242 files changed

+2827
-1028
lines changed

agent-module/bootstraps/bootstrap-core/src/main/java/com/navercorp/pinpoint/bootstrap/context/TraceContext.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import com.navercorp.pinpoint.bootstrap.plugin.jdbc.JdbcContext;
2121
import com.navercorp.pinpoint.common.annotations.InterfaceAudience;
2222
import com.navercorp.pinpoint.common.annotations.InterfaceStability;
23+
import com.navercorp.pinpoint.common.id.AgentId;
2324

2425
/**
2526
* @author emeroad
@@ -73,7 +74,7 @@ public interface TraceContext {
7374

7475
// ActiveThreadCounter getActiveThreadCounter();
7576

76-
String getAgentId();
77+
AgentId getAgentId();
7778

7879
String getApplicationName();
7980

agent-module/bootstraps/bootstrap-core/src/main/java/com/navercorp/pinpoint/bootstrap/context/TraceId.java

+3-1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616

1717
package com.navercorp.pinpoint.bootstrap.context;
1818

19+
import com.navercorp.pinpoint.common.id.AgentId;
20+
1921
/**
2022
* @author emeroad
2123
*/
@@ -27,7 +29,7 @@ public interface TraceId {
2729

2830
String getTransactionId();
2931

30-
String getAgentId();
32+
AgentId getAgentId();
3133

3234
long getAgentStartTime();
3335

agent-module/bootstraps/bootstrap-core/src/main/java/com/navercorp/pinpoint/bootstrap/resolver/condition/MainClassCondition.java

+3-2
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import com.navercorp.pinpoint.common.util.SystemPropertyKey;
2424

2525
import java.io.IOException;
26+
import java.util.Objects;
2627
import java.util.jar.JarFile;
2728

2829
/**
@@ -49,7 +50,7 @@ public MainClassCondition(SimpleProperty property) {
4950
throw new IllegalArgumentException("properties should not be null");
5051
}
5152
this.applicationMainClassName = getMainClassName(property);
52-
if (this.applicationMainClassName == NOT_FOUND) {
53+
if (Objects.equals(this.applicationMainClassName, NOT_FOUND)) {
5354
logger.info("Main class could not be deduced, please set 'profiler.applicationservertype' in pinpoint.config.");
5455
logger.info("If you're running on 1.6.0_24 or prior version of Java, consider upgrading to 1.6.0_25+.");
5556
}
@@ -84,7 +85,7 @@ public boolean check(String condition) {
8485
*/
8586
@Override
8687
public String getValue() {
87-
if (this.applicationMainClassName == NOT_FOUND) {
88+
if (Objects.equals(this.applicationMainClassName, NOT_FOUND)) {
8889
return "";
8990
}
9091
return this.applicationMainClassName;

agent-module/bootstraps/bootstrap/src/main/java/com/navercorp/pinpoint/bootstrap/AgentIdResolver.java

+28-34
Original file line numberDiff line numberDiff line change
@@ -17,30 +17,28 @@
1717
package com.navercorp.pinpoint.bootstrap;
1818

1919
import com.navercorp.pinpoint.common.PinpointConstants;
20-
import com.navercorp.pinpoint.common.util.AgentUuidUtils;
20+
import com.navercorp.pinpoint.common.id.ServiceId;
2121
import com.navercorp.pinpoint.common.util.StringUtils;
22-
import com.navercorp.pinpoint.common.util.UuidUtils;
2322

2423
import java.util.List;
2524
import java.util.Objects;
26-
import java.util.UUID;
2725

2826
/**
2927
* @author Woonduk Kang(emeroad)
3028
*/
3129
public class AgentIdResolver {
3230
public static final String APPLICATION_NAME = "applicationName";
33-
public static final String AGENT_ID = "agentId";
31+
public static final String SERVICE_NAME = "serviceName";
3432
public static final String AGENT_NAME = "agentName";
3533

3634
public static final String SYSTEM_PROPERTY_PREFIX = "pinpoint.";
3735
public static final String APPLICATION_NAME_SYSTEM_PROPERTY = SYSTEM_PROPERTY_PREFIX + "applicationName";
38-
public static final String AGENT_ID_SYSTEM_PROPERTY = SYSTEM_PROPERTY_PREFIX + "agentId";
36+
public static final String SERVICE_NAME_SYSTEM_PROPERTY = SYSTEM_PROPERTY_PREFIX + "serviceName";
3937
public static final String AGENT_NAME_SYSTEM_PROPERTY = SYSTEM_PROPERTY_PREFIX + "agentName";
4038

4139
public static final String ENV_PROPERTY_PREFIX = "PINPOINT_";
4240
public static final String APPLICATION_NAME_ENV_PROPERTY = ENV_PROPERTY_PREFIX + "APPLICATION_NAME";
43-
public static final String AGENT_ID_ENV_PROPERTY = ENV_PROPERTY_PREFIX + "AGENT_ID";
41+
public static final String SERVICE_NAME_ENV_PROPERTY = ENV_PROPERTY_PREFIX + "SERVICE_NAME";
4442
public static final String AGENT_NAME_ENV_PROPERTY = ENV_PROPERTY_PREFIX + "AGENT_NAME";
4543

4644
private final BootLogger logger = BootLogger.getLogger(this.getClass());
@@ -49,51 +47,32 @@ public class AgentIdResolver {
4947

5048
private final IdValidator idValidator = new IdValidator();
5149
private final IdValidator applicationNameValidator = new IdValidator(PinpointConstants.APPLICATION_NAME_MAX_LEN);
50+
private final IdValidator serviceNameValidator = new IdValidator(PinpointConstants.SERVICE_NAME_MAX_LEN);
5251

5352
public AgentIdResolver(List<AgentProperties> agentPropertyList) {
5453
this.agentPropertyList = Objects.requireNonNull(agentPropertyList, "agentPropertyList");
5554
}
5655

5756
public AgentIds resolve() {
58-
String agentId = getAgentId();
59-
if (StringUtils.isEmpty(agentId)) {
60-
logger.info("Failed to resolve AgentId(-Dpinpoint.agentId)");
61-
agentId = newRandomAgentId();
62-
logger.info("Auto generate AgentId='" + agentId + "'");
63-
}
64-
6557
final String applicationName = getApplicationName();
6658
if (StringUtils.isEmpty(applicationName)) {
6759
logger.warn("Failed to resolve ApplicationName(-Dpinpoint.applicationName)");
6860
return null;
6961
}
7062

63+
String serviceName = getServiceName();
64+
if (StringUtils.isEmpty(serviceName)) {
65+
logger.info("Failed to resolve ServiceName(-Dpinpoint.serviceName)");
66+
serviceName = ServiceId.DEFAULT_SERVICE_NAME;
67+
logger.info("Using default serviceName='" + serviceName + "'");
68+
}
69+
7170
final String agentName = getAgentName();
7271
if (StringUtils.isEmpty(agentName)) {
7372
logger.info("No AgentName(-Dpinpoint.agentName) provided, it's optional!");
7473
}
7574

76-
return new AgentIds(agentId, agentName, applicationName);
77-
}
78-
79-
private String newRandomAgentId() {
80-
UUID agentUUID = UuidUtils.createV4();
81-
return AgentUuidUtils.encode(agentUUID);
82-
}
83-
84-
private String getAgentId() {
85-
String source = null;
86-
for (AgentProperties agentProperty : agentPropertyList) {
87-
final String agentId = agentProperty.getAgentId();
88-
if (StringUtils.isEmpty(agentId)) {
89-
continue;
90-
}
91-
if (idValidator.validateAgentId(agentProperty.getType(), agentId)) {
92-
logger.info(agentProperty.getType() + " " + agentProperty.getAgentIdKey() + "=" + agentId);
93-
source = agentId;
94-
}
95-
}
96-
return source;
75+
return new AgentIds(agentName, applicationName, serviceName);
9776
}
9877

9978
private String getAgentName() {
@@ -123,4 +102,19 @@ private String getApplicationName() {
123102
return source;
124103
}
125104

105+
private String getServiceName() {
106+
String source = null;
107+
for (AgentProperties agentProperty : agentPropertyList) {
108+
final String serviceName = agentProperty.getServiceName();
109+
if (StringUtils.isEmpty(serviceName)) {
110+
continue;
111+
}
112+
if (serviceNameValidator.validateServiceName(agentProperty.getType(), serviceName)) {
113+
logger.info(agentProperty.getType() + " " + agentProperty.getServiceNameKey() + "=" + serviceName);
114+
source = serviceName;
115+
}
116+
}
117+
return source;
118+
}
119+
126120
}

agent-module/bootstraps/bootstrap/src/main/java/com/navercorp/pinpoint/bootstrap/AgentIdResolverBuilder.java

+6-6
Original file line numberDiff line numberDiff line change
@@ -32,29 +32,29 @@ public void addSystemProperties(Properties system) {
3232
Objects.requireNonNull(system, "system");
3333

3434
AgentProperties systemProperties = new AgentProperties(AgentIdSourceType.SYSTEM, system,
35-
AgentIdResolver.AGENT_ID_SYSTEM_PROPERTY,
3635
AgentIdResolver.AGENT_NAME_SYSTEM_PROPERTY,
37-
AgentIdResolver.APPLICATION_NAME_SYSTEM_PROPERTY);
36+
AgentIdResolver.APPLICATION_NAME_SYSTEM_PROPERTY,
37+
AgentIdResolver.SERVICE_NAME_SYSTEM_PROPERTY);
3838
this.agentProperties.add(systemProperties);
3939
}
4040

4141
public void addEnvProperties(Map<String, String> env) {
4242
Objects.requireNonNull(env, "env");
4343

4444
AgentProperties envProperties = new AgentProperties(AgentIdSourceType.SYSTEM_ENV, env,
45-
AgentIdResolver.AGENT_ID_ENV_PROPERTY,
4645
AgentIdResolver.AGENT_NAME_ENV_PROPERTY,
47-
AgentIdResolver.APPLICATION_NAME_ENV_PROPERTY);
46+
AgentIdResolver.APPLICATION_NAME_ENV_PROPERTY,
47+
AgentIdResolver.SERVICE_NAME_ENV_PROPERTY);
4848
this.agentProperties.add(envProperties);
4949
}
5050

5151
public void addAgentArgument(Map<String, String> agentArguments) {
5252
Objects.requireNonNull(agentArguments, "agentArguments");
5353

5454
AgentProperties agentArgument = new AgentProperties(AgentIdSourceType.AGENT_ARGUMENT, agentArguments,
55-
AgentIdResolver.AGENT_ID,
5655
AgentIdResolver.AGENT_NAME,
57-
AgentIdResolver.APPLICATION_NAME);
56+
AgentIdResolver.APPLICATION_NAME,
57+
AgentIdResolver.SERVICE_NAME);
5858
this.agentProperties.add(agentArgument);
5959
}
6060

agent-module/bootstraps/bootstrap/src/main/java/com/navercorp/pinpoint/bootstrap/AgentIds.java

+8-8
Original file line numberDiff line numberDiff line change
@@ -22,19 +22,14 @@
2222
* @author Woonduk Kang(emeroad)
2323
*/
2424
public class AgentIds {
25-
private final String agentId;
2625
private final String agentName;
2726
private final String applicationName;
27+
private final String serviceName;
2828

29-
public AgentIds(String agentId, String agentName, String applicationName) {
30-
this.agentId = Objects.requireNonNull(agentId, "agentId");
29+
public AgentIds(String agentName, String applicationName, String serviceName) {
3130
this.agentName = agentName;
3231
this.applicationName = Objects.requireNonNull(applicationName, "applicationName");
33-
}
34-
35-
36-
public String getAgentId() {
37-
return agentId;
32+
this.serviceName = Objects.requireNonNull(serviceName, "serviceName");
3833
}
3934

4035
public String getAgentName() {
@@ -44,4 +39,9 @@ public String getAgentName() {
4439
public String getApplicationName() {
4540
return applicationName;
4641
}
42+
43+
public String getServiceName() {
44+
return serviceName;
45+
}
46+
4747
}

agent-module/bootstraps/bootstrap/src/main/java/com/navercorp/pinpoint/bootstrap/AgentOption.java

+4-1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
package com.navercorp.pinpoint.bootstrap;
1818

1919
import com.navercorp.pinpoint.bootstrap.config.ProfilerConfig;
20+
import com.navercorp.pinpoint.common.id.AgentId;
2021

2122
import java.lang.instrument.Instrumentation;
2223
import java.util.List;
@@ -28,12 +29,14 @@ public interface AgentOption {
2829

2930
Instrumentation getInstrumentation();
3031

31-
String getAgentId();
32+
AgentId getAgentId();
3233

3334
String getAgentName();
3435

3536
String getApplicationName();
3637

38+
String getServiceName();
39+
3740
boolean isContainer();
3841

3942
ProfilerConfig getProfilerConfig();

agent-module/bootstraps/bootstrap/src/main/java/com/navercorp/pinpoint/bootstrap/AgentProperties.java

+19-21
Original file line numberDiff line numberDiff line change
@@ -26,20 +26,20 @@
2626
public class AgentProperties {
2727
private final AgentIdSourceType type;
2828
private final Properties properties;
29-
private final String agentIdKey;
3029
private final String agentNameKey;
3130
private final String applicationNameKey;
31+
private final String serviceNameKey;
3232

33-
public AgentProperties(AgentIdSourceType type, Properties properties, String agentIdKey, String agentNameKey, String applicationNameKey) {
33+
public AgentProperties(AgentIdSourceType type, Properties properties, String agentNameKey, String applicationNameKey, String serviceNameKey) {
3434
this.type = Objects.requireNonNull(type, "type");
3535
this.properties = Objects.requireNonNull(properties, "properties");
36-
this.agentIdKey = Objects.requireNonNull(agentIdKey, "agentIdKey");
3736
this.agentNameKey = Objects.requireNonNull(agentNameKey, "agentNameKey");
3837
this.applicationNameKey = Objects.requireNonNull(applicationNameKey, "applicationNameKey");
38+
this.serviceNameKey = Objects.requireNonNull(serviceNameKey, "serviceNameKey");
3939
}
4040

41-
public AgentProperties(AgentIdSourceType type, Map<String, String> properties, String agentIdKey, String agentNameKey, String applicationNameKey) {
42-
this(type, toProperties(properties), agentIdKey, agentNameKey, applicationNameKey);
41+
public AgentProperties(AgentIdSourceType type, Map<String, String> properties, String agentNameKey, String applicationNameKey, String serviceNameKey) {
42+
this(type, toProperties(properties), agentNameKey, applicationNameKey, serviceNameKey);
4343
}
4444

4545
private static Properties toProperties(Map<String, String> properties) {
@@ -54,18 +54,10 @@ public AgentIdSourceType getType() {
5454
return type;
5555
}
5656

57-
public String getAgentId() {
58-
return trim(this.properties.getProperty(agentIdKey));
59-
}
60-
6157
public String getAgentName() {
6258
return trim(this.properties.getProperty(agentNameKey));
6359
}
6460

65-
public String getAgentIdKey() {
66-
return agentIdKey;
67-
}
68-
6961
public String getAgentNameKey() {
7062
return agentNameKey;
7163
}
@@ -78,6 +70,14 @@ public String getApplicationNameKey() {
7870
return applicationNameKey;
7971
}
8072

73+
public String getServiceName() {
74+
return trim(this.properties.getProperty(serviceNameKey));
75+
}
76+
77+
public String getServiceNameKey() {
78+
return serviceNameKey;
79+
}
80+
8181
private String trim(String string) {
8282
if (string == null) {
8383
return null;
@@ -87,13 +87,11 @@ private String trim(String string) {
8787

8888
@Override
8989
public String toString() {
90-
final StringBuilder sb = new StringBuilder("AgentProperties{");
91-
sb.append("type=").append(type);
92-
sb.append(", properties=").append(properties);
93-
sb.append(", agentIdKey='").append(agentIdKey).append('\'');
94-
sb.append(", agentNameKey='").append(agentNameKey).append('\'');
95-
sb.append(", applicationNameKey='").append(applicationNameKey).append('\'');
96-
sb.append('}');
97-
return sb.toString();
90+
return "AgentProperties{" + "type=" + type +
91+
", properties=" + properties +
92+
", agentNameKey='" + agentNameKey + '\'' +
93+
", applicationNameKey='" + applicationNameKey + '\'' +
94+
", serviceNameKey='" + serviceNameKey + '\'' +
95+
'}';
9896
}
9997
}

0 commit comments

Comments
 (0)