Skip to content

Commit d4e6e85

Browse files
smilu97ga-ram
authored andcommitted
[#10741] Added applicationId
1 parent 8f9667c commit d4e6e85

File tree

189 files changed

+2859
-700
lines changed

Some content is hidden

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

189 files changed

+2859
-700
lines changed

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

+5-2
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,10 @@
1616

1717
package com.navercorp.pinpoint.bootstrap;
1818

19+
import com.navercorp.pinpoint.common.PinpointConstants;
1920
import com.navercorp.pinpoint.common.util.AgentUuidUtils;
2021
import com.navercorp.pinpoint.common.util.StringUtils;
22+
import com.navercorp.pinpoint.common.util.UuidUtils;
2123

2224
import java.util.List;
2325
import java.util.Objects;
@@ -46,6 +48,7 @@ public class AgentIdResolver {
4648
private final List<AgentProperties> agentPropertyList;
4749

4850
private final IdValidator idValidator = new IdValidator();
51+
private final IdValidator applicationNameValidator = new IdValidator(PinpointConstants.APPLICATION_NAME_MAX_LEN);
4952

5053
public AgentIdResolver(List<AgentProperties> agentPropertyList) {
5154
this.agentPropertyList = Objects.requireNonNull(agentPropertyList, "agentPropertyList");
@@ -74,7 +77,7 @@ public AgentIds resolve() {
7477
}
7578

7679
private String newRandomAgentId() {
77-
UUID agentUUID = UUID.randomUUID();
80+
UUID agentUUID = UuidUtils.createV4();
7881
return AgentUuidUtils.encode(agentUUID);
7982
}
8083

@@ -112,7 +115,7 @@ private String getApplicationName() {
112115
if (StringUtils.isEmpty(applicationName)) {
113116
continue;
114117
}
115-
if (idValidator.validateApplicationName(agentProperty.getType(), applicationName)) {
118+
if (applicationNameValidator.validateApplicationName(agentProperty.getType(), applicationName)) {
116119
logger.info(agentProperty.getType() + " " + agentProperty.getApplicationNameKey() + "=" + applicationName);
117120
source = applicationName;
118121
}

agent-module/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/provider/AgentInformationProvider.java

+6-5
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import com.google.inject.Inject;
2020
import com.google.inject.Provider;
2121
import com.navercorp.pinpoint.bootstrap.util.NetworkUtils;
22+
import com.navercorp.pinpoint.common.PinpointConstants;
2223
import com.navercorp.pinpoint.common.Version;
2324
import com.navercorp.pinpoint.common.trace.ServiceType;
2425
import com.navercorp.pinpoint.common.util.IdValidateUtils;
@@ -54,8 +55,8 @@ public AgentInformationProvider(@AgentId String agentId, @AgentName String agent
5455
Objects.requireNonNull(agentId, "agentId");
5556
Objects.requireNonNull(applicationName, "applicationName");
5657

57-
this.agentId = checkId("agentId", agentId);
58-
this.applicationName = checkId("applicationName", applicationName);
58+
this.agentId = checkId("agentId", agentId, PinpointConstants.AGENT_ID_MAX_LEN);
59+
this.applicationName = checkId("applicationName", applicationName, PinpointConstants.APPLICATION_NAME_MAX_LEN);
5960
this.agentName = agentName;
6061
this.isContainer = isContainer;
6162
this.agentStartTime = agentStartTime;
@@ -68,7 +69,6 @@ public AgentInformation get() {
6869
}
6970

7071
public AgentInformation createAgentInformation() {
71-
7272
final String machineName = NetworkUtils.getHostName();
7373
final String hostIp = NetworkUtils.getRepresentationHostIp();
7474

@@ -77,10 +77,11 @@ public AgentInformation createAgentInformation() {
7777
return new DefaultAgentInformation(agentId, agentName, applicationName, isContainer, agentStartTime, pid, machineName, hostIp, serverType, jvmVersion, Version.VERSION);
7878
}
7979

80-
private String checkId(String keyName,String id) {
81-
if (!IdValidateUtils.validateId(id)) {
80+
private String checkId(String keyName, String id, int maxLen) {
81+
if (!IdValidateUtils.validateId(id, maxLen)) {
8282
throw new IllegalArgumentException("invalid " + keyName + "=" + id);
8383
}
8484
return id;
8585
}
86+
8687
}

batch-alarmsender/src/main/java/com/navercorp/pinpoint/batch/alarm/sender/AlarmMailTemplate.java

+11-14
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ public AlarmMailTemplate(AlarmCheckerInterface checker, String pinpointUrl, Stri
4848

4949
public String createSubject() {
5050
RuleInterface rule = checker.getRule();
51-
return String.format("[PINPOINT-%s] %s Alarm for %s Service. #%d", batchEnv, rule.getCheckerName(), rule.getApplicationId(), sequenceCount);
51+
return String.format("[PINPOINT-%s] %s Alarm for %s Service. #%d", batchEnv, rule.getCheckerName(), rule.getApplicationName(), sequenceCount);
5252
}
5353

5454
public String getTime() {
@@ -67,21 +67,18 @@ public String getTime() {
6767

6868
public String createBody() {
6969
RuleInterface rule = checker.getRule();
70-
return newBody(createSubject(), rule.getCheckerName(), rule.getApplicationId(), rule.getServiceType(), getTime());
70+
return newBody(createSubject(), rule.getCheckerName(), rule.getApplicationName(), rule.getServiceType(), getTime());
7171
}
7272

7373
private String newBody(String subject, String rule, String applicationId, String serviceType, String currentTime) {
74-
StringBuilder body = new StringBuilder();
75-
body.append("<strong>").append(subject).append("</strong>");
76-
body.append(LINE_FEED);
77-
body.append(LINE_FEED);
78-
body.append(String.format("Rule : %s", rule));
79-
body.append(LINE_FEED);
80-
body.append(checker.getEmailMessage(pinpointUrl, applicationId, serviceType, currentTime));
81-
body.append(String.format(LINK_FORMAT, pinpointUrl));
82-
body.append(LINE_FEED);
83-
body.append(String.format(SCATTER_CHART_LINK_FORMAT, pinpointUrl, applicationId, serviceType, currentTime, applicationId));
84-
85-
return body.toString();
74+
return "<strong>" + subject + "</strong>" +
75+
LINE_FEED +
76+
LINE_FEED +
77+
String.format("Rule : %s", rule) +
78+
LINE_FEED +
79+
checker.getEmailMessage(pinpointUrl, applicationId, serviceType, currentTime) +
80+
String.format(LINK_FORMAT, pinpointUrl) +
81+
LINE_FEED +
82+
String.format(SCATTER_CHART_LINK_FORMAT, pinpointUrl, applicationId, serviceType, currentTime, applicationId);
8683
}
8784
}

batch-alarmsender/src/main/java/com/navercorp/pinpoint/batch/alarm/vo/sender/payload/WebhookPayload.java

+5-6
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818

1919
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
2020
import com.navercorp.pinpoint.batch.alarm.checker.AlarmCheckerInterface;
21-
import com.navercorp.pinpoint.batch.alarm.checker.PinotAlarmCheckerInterface;
2221

2322
/**
2423
* @author Jongjin.Bae
@@ -28,7 +27,7 @@ public class WebhookPayload {
2827

2928
private final String pinpointUrl;
3029
private final String batchEnv;
31-
private final String applicationId;
30+
private final String applicationName;
3231
private final String serviceType;
3332
private final String checkerName;
3433
private final String checkerType;
@@ -43,7 +42,7 @@ public WebhookPayload(String pinpointUrl, String batchEnv, AlarmCheckerInterface
4342
this.pinpointUrl = pinpointUrl;
4443
this.batchEnv = batchEnv;
4544

46-
this.applicationId = checker.getRule().getApplicationId();
45+
this.applicationName = checker.getRule().getApplicationName();
4746
this.serviceType = checker.getRule().getServiceType();
4847
this.checkerName = checker.getRule().getCheckerName();
4948
this.checkerType = checker.getCheckerType();
@@ -63,8 +62,8 @@ public String getBatchEnv() {
6362
return batchEnv;
6463
}
6564

66-
public String getApplicationId() {
67-
return applicationId;
65+
public String getApplicationName() {
66+
return applicationName;
6867
}
6968

7069
public String getServiceType() {
@@ -108,7 +107,7 @@ public String toString() {
108107
return "WebhookPayload{" +
109108
"pinpointUrl='" + pinpointUrl + '\'' +
110109
", batchEnv='" + batchEnv + '\'' +
111-
", applicationId='" + applicationId + '\'' +
110+
", applicationId='" + applicationName + '\'' +
112111
", serviceType='" + serviceType + '\'' +
113112
", checkerName='" + checkerName + '\'' +
114113
", checkerType='" + checkerType + '\'' +

batch-alarmsender/src/main/java/com/navercorp/pinpoint/batch/alarm/vo/sender/payload/WebhookPayloadSerializer.java

+14-14
Original file line numberDiff line numberDiff line change
@@ -29,30 +29,30 @@
2929
public class WebhookPayloadSerializer extends JsonSerializer<WebhookPayload> {
3030

3131
@Override
32-
public void serialize(WebhookPayload webhookPayload, JsonGenerator jgen, SerializerProvider serializers) throws IOException {
33-
jgen.writeStartObject();
32+
public void serialize(WebhookPayload webhookPayload, JsonGenerator gen, SerializerProvider serializers) throws IOException {
33+
gen.writeStartObject();
3434

35-
jgen.writeStringField("pinpointUrl", webhookPayload.getPinpointUrl());
36-
jgen.writeStringField("batchEnv", webhookPayload.getBatchEnv());
37-
jgen.writeStringField("applicationId", webhookPayload.getApplicationId());
38-
jgen.writeStringField("serviceType", webhookPayload.getServiceType());
39-
jgen.writeObjectField("userGroup", webhookPayload.getUserGroup());
35+
gen.writeStringField("pinpointUrl", webhookPayload.getPinpointUrl());
36+
gen.writeStringField("batchEnv", webhookPayload.getBatchEnv());
37+
gen.writeStringField("applicationId", webhookPayload.getApplicationName());
38+
gen.writeStringField("serviceType", webhookPayload.getServiceType());
39+
gen.writeObjectField("userGroup", webhookPayload.getUserGroup());
4040

41-
writeChecker(webhookPayload, jgen);
41+
writeChecker(webhookPayload, gen);
4242

43-
jgen.writeStringField("unit", webhookPayload.getUnit());
43+
gen.writeStringField("unit", webhookPayload.getUnit());
4444
Number threshold = webhookPayload.getThreshold();
4545
if (threshold instanceof Integer integer) {
46-
jgen.writeNumberField("threshold", integer);
46+
gen.writeNumberField("threshold", integer);
4747
} else if (threshold instanceof BigDecimal bigDecimal){
48-
jgen.writeNumberField("threshold", bigDecimal);
48+
gen.writeNumberField("threshold", bigDecimal);
4949
} else {
5050
throw new IOException("threshold type should be either Integer or BigDecimal");
5151
}
52-
jgen.writeStringField("notes", webhookPayload.getNotes());
53-
jgen.writeNumberField("sequenceCount", webhookPayload.getSequenceCount());
52+
gen.writeStringField("notes", webhookPayload.getNotes());
53+
gen.writeNumberField("sequenceCount", webhookPayload.getSequenceCount());
5454

55-
jgen.writeEndObject();
55+
gen.writeEndObject();
5656
}
5757

5858
private void writeChecker(WebhookPayload webhookPayload, JsonGenerator jgen) throws IOException {

batch-alarmsender/src/main/java/com/navercorp/pinpoint/web/vo/RuleInterface.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
public interface RuleInterface {
44
String getCheckerName();
5-
String getApplicationId();
5+
String getApplicationName();
66
String getServiceType();
77
Number getThreshold();
88
String getNotes();

batch/src/main/java/com/navercorp/pinpoint/batch/alarm/AlarmProcessor.java

+9-8
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@
2525
import com.navercorp.pinpoint.web.alarm.CheckerCategory;
2626
import com.navercorp.pinpoint.web.alarm.DataCollectorCategory;
2727
import com.navercorp.pinpoint.web.alarm.vo.Rule;
28-
import com.navercorp.pinpoint.web.dao.ApplicationIndexDao;
2928
import com.navercorp.pinpoint.web.service.AgentInfoService;
3029
import com.navercorp.pinpoint.web.service.AlarmService;
30+
import com.navercorp.pinpoint.web.service.ApplicationService;
3131
import com.navercorp.pinpoint.web.vo.Application;
3232
import jakarta.annotation.Nonnull;
3333
import org.springframework.batch.item.ItemProcessor;
@@ -37,6 +37,7 @@
3737
import java.util.List;
3838
import java.util.Map;
3939
import java.util.Objects;
40+
import java.util.UUID;
4041
import java.util.concurrent.TimeUnit;
4142
import java.util.function.Supplier;
4243

@@ -51,7 +52,7 @@ public class AlarmProcessor implements ItemProcessor<Application, AppAlarmChecke
5152

5253
private final DataCollectorFactory dataCollectorFactory;
5354

54-
private final ApplicationIndexDao applicationIndexDao;
55+
private final ApplicationService applicationService;
5556

5657
private final AgentInfoService agentInfoService;
5758

@@ -60,13 +61,13 @@ public class AlarmProcessor implements ItemProcessor<Application, AppAlarmChecke
6061
public AlarmProcessor(
6162
DataCollectorFactory dataCollectorFactory,
6263
AlarmService alarmService,
63-
ApplicationIndexDao applicationIndexDao,
64+
ApplicationService applicationService,
6465
AgentInfoService agentInfoService,
6566
CheckerRegistry checkerRegistry
6667
) {
6768
this.dataCollectorFactory = Objects.requireNonNull(dataCollectorFactory, "dataCollectorFactory");
6869
this.alarmService = Objects.requireNonNull(alarmService, "alarmService");
69-
this.applicationIndexDao = Objects.requireNonNull(applicationIndexDao, "applicationIndexDao");
70+
this.applicationService = Objects.requireNonNull(applicationService, "applicationService");
7071
this.agentInfoService = Objects.requireNonNull(agentInfoService, "agentInfoService");
7172
this.checkerRegistry = Objects.requireNonNull(checkerRegistry, "checkerRegistry");
7273
}
@@ -85,7 +86,7 @@ public AppAlarmChecker process(@Nonnull Application application) {
8586
}
8687

8788
private List<AlarmChecker<?>> getAlarmCheckers(Application application) {
88-
List<Rule> rules = alarmService.selectRuleByApplicationId(application.getName());
89+
List<Rule> rules = alarmService.selectRuleByApplicationId(application.name());
8990

9091
long now = System.currentTimeMillis();
9192
Supplier<List<String>> agentIds = getAgentIdsSupplier(application, now);
@@ -102,11 +103,11 @@ private List<AlarmChecker<?>> getAlarmCheckers(Application application) {
102103

103104
private Supplier<List<String>> getAgentIdsSupplier(Application application, long now) {
104105
Range range = Range.between(now - activeDuration, now);
105-
return Suppliers.memoize(() -> fetchActiveAgents(application.getName(), range));
106+
return Suppliers.memoize(() -> fetchActiveAgents(application.id(), range));
106107
}
107108

108-
private List<String> fetchActiveAgents(String applicationId, Range activeRange) {
109-
return applicationIndexDao.selectAgentIds(applicationId)
109+
private List<String> fetchActiveAgents(UUID applicationId, Range activeRange) {
110+
return this.applicationService.getAgents(applicationId)
110111
.stream()
111112
.filter(id -> agentInfoService.isActiveAgent(id, activeRange))
112113
.toList();

batch/src/main/java/com/navercorp/pinpoint/batch/alarm/AlarmReader.java

+7-7
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,15 @@
1616

1717
package com.navercorp.pinpoint.batch.alarm;
1818

19-
import com.navercorp.pinpoint.web.dao.ApplicationIndexDao;
2019
import com.navercorp.pinpoint.web.service.AlarmService;
20+
import com.navercorp.pinpoint.web.service.ApplicationService;
2121
import com.navercorp.pinpoint.web.vo.Application;
22+
import jakarta.annotation.Nonnull;
2223
import org.springframework.batch.core.ExitStatus;
2324
import org.springframework.batch.core.StepExecution;
2425
import org.springframework.batch.core.StepExecutionListener;
2526
import org.springframework.batch.item.ItemReader;
2627

27-
import jakarta.annotation.Nonnull;
2828
import java.util.ArrayList;
2929
import java.util.List;
3030
import java.util.Objects;
@@ -36,13 +36,13 @@
3636
*/
3737
public class AlarmReader implements ItemReader<Application>, StepExecutionListener {
3838

39-
private final ApplicationIndexDao applicationIndexDao;
39+
private final ApplicationService applicationService;
4040
private final AlarmService alarmService;
4141

4242
private Queue<Application> applicationQueue;
4343

44-
public AlarmReader(ApplicationIndexDao applicationIndexDao, AlarmService alarmService) {
45-
this.applicationIndexDao = Objects.requireNonNull(applicationIndexDao, "applicationIndexDao");
44+
public AlarmReader(ApplicationService applicationService, AlarmService alarmService) {
45+
this.applicationService = Objects.requireNonNull(applicationService, "applicationService");
4646
this.alarmService = Objects.requireNonNull(alarmService, "alarmService");
4747
}
4848

@@ -56,12 +56,12 @@ public void beforeStep(@Nonnull StepExecution stepExecution) {
5656
}
5757

5858
private List<Application> fetchApplications() {
59-
List<Application> applications = applicationIndexDao.selectAllApplicationNames();
59+
List<Application> applications = this.applicationService.getApplications();
6060
List<String> validApplicationIds = alarmService.selectApplicationId();
6161

6262
List<Application> validApplications = new ArrayList<>(applications.size());
6363
for (Application application: applications) {
64-
if (validApplicationIds.contains(application.getName())) {
64+
if (validApplicationIds.contains(application.name())) {
6565
validApplications.add(application);
6666
}
6767
}

batch/src/main/java/com/navercorp/pinpoint/batch/alarm/checker/AlarmChecker.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -85,12 +85,12 @@ public String getUnit() {
8585
public void check() {
8686
dataCollector.collect();
8787
detected = decideResult(getDetectedValue());
88-
logger.info("{} result is {} for application ({}). value is {}. (threshold : {}).", this.getClass().getSimpleName(), detected, rule.getApplicationId(), getDetectedValue(), rule.getThreshold());
88+
logger.info("{} result is {} for application ({}). value is {}. (threshold : {}).", this.getClass().getSimpleName(), detected, rule.getApplicationName(), getDetectedValue(), rule.getThreshold());
8989
}
9090

9191
public List<String> getSmsMessage() {
9292
List<String> messages = new ArrayList<>();
93-
messages.add(String.format("[PINPOINT Alarm - %s] %s is %s%s (Threshold : %s%s)", rule.getApplicationId(), rule.getCheckerName(), getDetectedValue(), unit, rule.getThreshold(), unit));
93+
messages.add(String.format("[PINPOINT Alarm - %s] %s is %s%s (Threshold : %s%s)", rule.getApplicationName(), rule.getCheckerName(), getDetectedValue(), unit, rule.getThreshold(), unit));
9494
return messages;
9595
}
9696

batch/src/main/java/com/navercorp/pinpoint/batch/alarm/checker/ErrorCountToCalleeChecker.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@ protected Long getDetectedValue() {
3737

3838
@Override
3939
public String getEmailMessage(String pinpointUrl, String applicationId, String serviceType, String currentTime) {
40-
return String.format("%s value is %s%s during the past 5 mins.(Threshold : %s%s) %s For From '%s' To '%s'.<br>", rule.getCheckerName(), getDetectedValue(), unit, rule.getThreshold(), unit, rule.getCheckerName(), rule.getApplicationId(), rule.getNotes());
40+
return String.format("%s value is %s%s during the past 5 mins.(Threshold : %s%s) %s For From '%s' To '%s'.<br>",
41+
rule.getCheckerName(), getDetectedValue(), unit, rule.getThreshold(), unit, rule.getCheckerName(), rule.getApplicationName(), rule.getNotes());
4142
}
4243

4344
}

batch/src/main/java/com/navercorp/pinpoint/batch/alarm/checker/ErrorRateToCalleeChecker.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,8 @@ protected Long getDetectedValue() {
3838

3939
@Override
4040
public String getEmailMessage(String pinpointUrl, String applicationId, String serviceType, String currentTime) {
41-
return String.format("%s value is %s%s during the past 5 mins.(Threshold : %s%s) %s For From '%s' To '%s'.<br>", rule.getCheckerName(), getDetectedValue(), unit, rule.getThreshold(), unit, rule.getCheckerName(), rule.getApplicationId(), rule.getNotes());
41+
return String.format("%s value is %s%s during the past 5 mins.(Threshold : %s%s) %s For From '%s' To '%s'.<br>",
42+
rule.getCheckerName(), getDetectedValue(), unit, rule.getThreshold(), unit, rule.getCheckerName(), rule.getApplicationName(), rule.getNotes());
4243
}
4344

4445
}

batch/src/main/java/com/navercorp/pinpoint/batch/alarm/checker/SlowCountToCalleeChecker.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@ protected Long getDetectedValue() {
3737

3838
@Override
3939
public String getEmailMessage(String pinpointUrl, String applicationId, String serviceType, String currentTime) {
40-
return String.format("%s value is %s%s during the past 5 mins.(Threshold : %s%s) %s For From '%s' To '%s'.<br>", rule.getCheckerName(), getDetectedValue(), unit, rule.getThreshold(), unit, rule.getCheckerName(), rule.getApplicationId(), rule.getNotes());
40+
return String.format("%s value is %s%s during the past 5 mins.(Threshold : %s%s) %s For From '%s' To '%s'.<br>",
41+
rule.getCheckerName(), getDetectedValue(), unit, rule.getThreshold(), unit, rule.getCheckerName(), rule.getApplicationName(), rule.getNotes());
4142
}
4243

4344
}

0 commit comments

Comments
 (0)