Skip to content

Commit

Permalink
[pinpoint-apm#10741] Added applicationId
Browse files Browse the repository at this point in the history
  • Loading branch information
smilu97 committed Mar 15, 2024
1 parent 87913a1 commit 4ab676a
Show file tree
Hide file tree
Showing 188 changed files with 2,665 additions and 717 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public AlarmMailTemplate(AlarmCheckerInterface checker, String pinpointUrl, Stri

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

public String getCurrentTime() {
Expand All @@ -58,21 +58,18 @@ public String getCurrentTime() {

public String createBody() {
RuleInterface rule = checker.getRule();
return newBody(createSubject(), rule.getCheckerName(), rule.getApplicationId(), rule.getServiceType(), getCurrentTime());
return newBody(createSubject(), rule.getCheckerName(), rule.getApplicationName(), rule.getServiceType(), getCurrentTime());
}

private String newBody(String subject, String rule, String applicationId, String serviceType, String currentTime) {
StringBuilder body = new StringBuilder();
body.append("<strong>").append(subject).append("</strong>");
body.append(LINE_FEED);
body.append(LINE_FEED);
body.append(String.format("Rule : %s", rule));
body.append(LINE_FEED);
body.append(checker.getEmailMessage(pinpointUrl, applicationId, serviceType, currentTime));
body.append(String.format(LINK_FORMAT, pinpointUrl));
body.append(LINE_FEED);
body.append(String.format(SCATTER_CHART_LINK_FORMAT, pinpointUrl, applicationId, serviceType, currentTime, applicationId));

return body.toString();
return "<strong>" + subject + "</strong>" +
LINE_FEED +
LINE_FEED +
String.format("Rule : %s", rule) +
LINE_FEED +
checker.getEmailMessage(pinpointUrl, applicationId, serviceType, currentTime) +
String.format(LINK_FORMAT, pinpointUrl) +
LINE_FEED +
String.format(SCATTER_CHART_LINK_FORMAT, pinpointUrl, applicationId, serviceType, currentTime, applicationId);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@

import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.navercorp.pinpoint.batch.alarm.checker.AlarmCheckerInterface;
import com.navercorp.pinpoint.batch.alarm.checker.PinotAlarmCheckerInterface;

/**
* @author Jongjin.Bae
Expand All @@ -28,7 +27,7 @@ public class WebhookPayload {

private final String pinpointUrl;
private final String batchEnv;
private final String applicationId;
private final String applicationName;
private final String serviceType;
private final String checkerName;
private final String checkerType;
Expand All @@ -43,7 +42,7 @@ public WebhookPayload(String pinpointUrl, String batchEnv, AlarmCheckerInterface
this.pinpointUrl = pinpointUrl;
this.batchEnv = batchEnv;

this.applicationId = checker.getRule().getApplicationId();
this.applicationName = checker.getRule().getApplicationName();
this.serviceType = checker.getRule().getServiceType();
this.checkerName = checker.getRule().getCheckerName();
this.checkerType = checker.getCheckerType();
Expand All @@ -63,8 +62,8 @@ public String getBatchEnv() {
return batchEnv;
}

public String getApplicationId() {
return applicationId;
public String getApplicationName() {
return applicationName;
}

public String getServiceType() {
Expand Down Expand Up @@ -108,7 +107,7 @@ public String toString() {
return "WebhookPayload{" +
"pinpointUrl='" + pinpointUrl + '\'' +
", batchEnv='" + batchEnv + '\'' +
", applicationId='" + applicationId + '\'' +
", applicationId='" + applicationName + '\'' +
", serviceType='" + serviceType + '\'' +
", checkerName='" + checkerName + '\'' +
", checkerType='" + checkerType + '\'' +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,30 +29,30 @@
public class WebhookPayloadSerializer extends JsonSerializer<WebhookPayload> {

@Override
public void serialize(WebhookPayload webhookPayload, JsonGenerator jgen, SerializerProvider serializers) throws IOException {
jgen.writeStartObject();
public void serialize(WebhookPayload webhookPayload, JsonGenerator gen, SerializerProvider serializers) throws IOException {
gen.writeStartObject();

jgen.writeStringField("pinpointUrl", webhookPayload.getPinpointUrl());
jgen.writeStringField("batchEnv", webhookPayload.getBatchEnv());
jgen.writeStringField("applicationId", webhookPayload.getApplicationId());
jgen.writeStringField("serviceType", webhookPayload.getServiceType());
jgen.writeObjectField("userGroup", webhookPayload.getUserGroup());
gen.writeStringField("pinpointUrl", webhookPayload.getPinpointUrl());
gen.writeStringField("batchEnv", webhookPayload.getBatchEnv());
gen.writeStringField("applicationId", webhookPayload.getApplicationName());
gen.writeStringField("serviceType", webhookPayload.getServiceType());
gen.writeObjectField("userGroup", webhookPayload.getUserGroup());

writeChecker(webhookPayload, jgen);
writeChecker(webhookPayload, gen);

jgen.writeStringField("unit", webhookPayload.getUnit());
gen.writeStringField("unit", webhookPayload.getUnit());
Number threshold = webhookPayload.getThreshold();
if (threshold instanceof Integer integer) {
jgen.writeNumberField("threshold", integer);
gen.writeNumberField("threshold", integer);
} else if (threshold instanceof BigDecimal bigDecimal){
jgen.writeNumberField("threshold", bigDecimal);
gen.writeNumberField("threshold", bigDecimal);
} else {
throw new IOException("threshold type should be either Integer or BigDecimal");
}
jgen.writeStringField("notes", webhookPayload.getNotes());
jgen.writeNumberField("sequenceCount", webhookPayload.getSequenceCount());
gen.writeStringField("notes", webhookPayload.getNotes());
gen.writeNumberField("sequenceCount", webhookPayload.getSequenceCount());

jgen.writeEndObject();
gen.writeEndObject();
}

private void writeChecker(WebhookPayload webhookPayload, JsonGenerator jgen) throws IOException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

public interface RuleInterface {
String getCheckerName();
String getApplicationId();
String getApplicationName();
String getServiceType();
Number getThreshold();
String getNotes();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@
import com.navercorp.pinpoint.web.alarm.CheckerCategory;
import com.navercorp.pinpoint.web.alarm.DataCollectorCategory;
import com.navercorp.pinpoint.web.alarm.vo.Rule;
import com.navercorp.pinpoint.web.dao.ApplicationIndexDao;
import com.navercorp.pinpoint.web.service.AgentInfoService;
import com.navercorp.pinpoint.web.service.AlarmService;
import com.navercorp.pinpoint.web.service.ApplicationService;
import com.navercorp.pinpoint.web.vo.Application;
import jakarta.annotation.Nonnull;
import org.springframework.batch.item.ItemProcessor;
Expand All @@ -37,6 +37,7 @@
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;

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

private final DataCollectorFactory dataCollectorFactory;

private final ApplicationIndexDao applicationIndexDao;
private final ApplicationService applicationService;

private final AgentInfoService agentInfoService;

Expand All @@ -60,13 +61,13 @@ public class AlarmProcessor implements ItemProcessor<Application, AppAlarmChecke
public AlarmProcessor(
DataCollectorFactory dataCollectorFactory,
AlarmService alarmService,
ApplicationIndexDao applicationIndexDao,
ApplicationService applicationService,
AgentInfoService agentInfoService,
CheckerRegistry checkerRegistry
) {
this.dataCollectorFactory = Objects.requireNonNull(dataCollectorFactory, "dataCollectorFactory");
this.alarmService = Objects.requireNonNull(alarmService, "alarmService");
this.applicationIndexDao = Objects.requireNonNull(applicationIndexDao, "applicationIndexDao");
this.applicationService = Objects.requireNonNull(applicationService, "applicationService");
this.agentInfoService = Objects.requireNonNull(agentInfoService, "agentInfoService");
this.checkerRegistry = Objects.requireNonNull(checkerRegistry, "checkerRegistry");
}
Expand All @@ -85,7 +86,7 @@ public AppAlarmChecker process(@Nonnull Application application) {
}

private List<AlarmChecker<?>> getAlarmCheckers(Application application) {
List<Rule> rules = alarmService.selectRuleByApplicationId(application.getName());
List<Rule> rules = alarmService.selectRuleByApplicationId(application.name());

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

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

private List<String> fetchActiveAgents(String applicationId, Range activeRange) {
return applicationIndexDao.selectAgentIds(applicationId)
private List<String> fetchActiveAgents(UUID applicationId, Range activeRange) {
return this.applicationService.getAgents(applicationId)
.stream()
.filter(id -> agentInfoService.isActiveAgent(id, activeRange))
.toList();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,15 @@

package com.navercorp.pinpoint.batch.alarm;

import com.navercorp.pinpoint.web.dao.ApplicationIndexDao;
import com.navercorp.pinpoint.web.service.AlarmService;
import com.navercorp.pinpoint.web.service.ApplicationService;
import com.navercorp.pinpoint.web.vo.Application;
import jakarta.annotation.Nonnull;
import org.springframework.batch.core.ExitStatus;
import org.springframework.batch.core.StepExecution;
import org.springframework.batch.core.StepExecutionListener;
import org.springframework.batch.item.ItemReader;

import jakarta.annotation.Nonnull;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
Expand All @@ -36,13 +36,13 @@
*/
public class AlarmReader implements ItemReader<Application>, StepExecutionListener {

private final ApplicationIndexDao applicationIndexDao;
private final ApplicationService applicationService;
private final AlarmService alarmService;

private Queue<Application> applicationQueue;

public AlarmReader(ApplicationIndexDao applicationIndexDao, AlarmService alarmService) {
this.applicationIndexDao = Objects.requireNonNull(applicationIndexDao, "applicationIndexDao");
public AlarmReader(ApplicationService applicationService, AlarmService alarmService) {
this.applicationService = Objects.requireNonNull(applicationService, "applicationService");
this.alarmService = Objects.requireNonNull(alarmService, "alarmService");
}

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

private List<Application> fetchApplications() {
List<Application> applications = applicationIndexDao.selectAllApplicationNames();
List<Application> applications = this.applicationService.getApplications();
List<String> validApplicationIds = alarmService.selectApplicationId();

List<Application> validApplications = new ArrayList<>(applications.size());
for (Application application: applications) {
if (validApplicationIds.contains(application.getName())) {
if (validApplicationIds.contains(application.name())) {
validApplications.add(application);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,12 +85,12 @@ public String getUnit() {
public void check() {
dataCollector.collect();
detected = decideResult(getDetectedValue());
logger.info("{} result is {} for application ({}). value is {}. (threshold : {}).", this.getClass().getSimpleName(), detected, rule.getApplicationId(), getDetectedValue(), rule.getThreshold());
logger.info("{} result is {} for application ({}). value is {}. (threshold : {}).", this.getClass().getSimpleName(), detected, rule.getApplicationName(), getDetectedValue(), rule.getThreshold());
}

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ protected Long getDetectedValue() {

@Override
public String getEmailMessage(String pinpointUrl, String applicationId, String serviceType, String currentTime) {
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());
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.getApplicationName(), rule.getNotes());
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ protected Long getDetectedValue() {

@Override
public String getEmailMessage(String pinpointUrl, String applicationId, String serviceType, String currentTime) {
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());
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.getApplicationName(), rule.getNotes());
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ protected Long getDetectedValue() {

@Override
public String getEmailMessage(String pinpointUrl, String applicationId, String serviceType, String currentTime) {
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());
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.getApplicationName(), rule.getNotes());
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,14 @@ public SlowRateToCalleeChecker(DataCollector dataCollector, Rule rule) {

@Override
protected Long getDetectedValue() {
String calleName = rule.getNotes();
return ((MapStatisticsCallerDataCollector)dataCollector).getCountRate(calleName, DataCategory.SLOW_RATE);
String calleeName = rule.getNotes();
return ((MapStatisticsCallerDataCollector)dataCollector).getCountRate(calleeName, DataCategory.SLOW_RATE);
}

@Override
public String getEmailMessage(String pinpointUrl, String applicationId, String serviceType, String currentTime) {
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());
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.getApplicationName(), rule.getNotes());
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -62,15 +62,15 @@ public void collect() {
LinkCallDataMap linkCallDataMap = linkData.getLinkCallDataMap();

for (LinkCallData linkCallData : linkCallDataMap.getLinkDataList()) {
calleeStatMap.put(linkCallData.getTarget().getName(), linkCallData);
calleeStatMap.put(linkCallData.getTarget().name(), linkCallData);
}
}

init.set(true);
}

public long getCount(String calleName, DataCategory dataCategory) {
final LinkCallData linkCallData = calleeStatMap.get(calleName);
public long getCount(String calleeName, DataCategory dataCategory) {
final LinkCallData linkCallData = calleeStatMap.get(calleeName);
if (linkCallData == null) {
return 0;
}
Expand Down Expand Up @@ -102,8 +102,8 @@ public long getCount(String calleName, DataCategory dataCategory) {

}

public long getCountRate(String calleName, DataCategory dataCategory) {
final LinkCallData linkCallData = calleeStatMap.get(calleName);
public long getCountRate(String calleeName, DataCategory dataCategory) {
final LinkCallData linkCallData = calleeStatMap.get(calleeName);
if (linkCallData == null) {
return 0;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public class ResponseTimeDataCollector extends DataCollector {
private final MapResponseDao responseDao;
private final long timeSlotEndTime;
private final long slotInterval;
private final AtomicBoolean init =new AtomicBoolean(false); // need to consider a race condition when checkers start simultaneously.
private final AtomicBoolean init = new AtomicBoolean(false); // need to consider a race condition when checkers start simultaneously.

private long fastCount = 0;
private long normalCount = 0;
Expand Down
Loading

0 comments on commit 4ab676a

Please sign in to comment.