Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[#11126] modify the pinpoint link in the body of the email alarm. #11127

Merged
merged 1 commit into from
Jun 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public class AlarmMailTemplate {

private static final String LINE_FEED = "<br>";
private static final String LINK_FORMAT = "<a href=\"%s\" >pinpoint site</a>";
private static final String SCATTER_CHART_LINK_FORMAT = "<a href=\"%s/main/%s@%s/5m/%s\" >scatter chart of %s</a>";
private static final String SCATTER_CHART_LINK_FORMAT = "<a href=\"%s/serverMap/%s@%s?%s\" >scatter chart of %s</a>";

private static final DateTimeFormatter FORMATTER = DateTimeFormatter.ofPattern("yyyy-MM-dd-HH:mm:ss");

Expand All @@ -51,14 +51,23 @@ public String createSubject() {
return String.format("[PINPOINT-%s] %s Alarm for %s Service. #%d", batchEnv, rule.getCheckerName(), rule.getApplicationId(), sequenceCount);
}

public String getCurrentTime() {
LocalDateTime now = LocalDateTime.now();
return FORMATTER.format(now);
public String getTime() {
LocalDateTime to = LocalDateTime.now();
String toTime = FORMATTER.format(to);
LocalDateTime from = to.minusMinutes(5);
String fromTime = FORMATTER.format(from);

StringBuilder sb = new StringBuilder();
sb.append("from=");
sb.append(fromTime);
sb.append("&to=");
sb.append(toTime);
return sb.toString();
}

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

private String newBody(String subject, String rule, String applicationId, String serviceType, String currentTime) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/*
* 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.batch.alarm.sender;

import com.navercorp.pinpoint.batch.alarm.checker.AlarmCheckerInterface;
import com.navercorp.pinpoint.web.vo.RuleInterface;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.Mock;
import org.mockito.junit.jupiter.MockitoExtension;

import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.Mockito.when;

/**
* @author minwoo-jung
*/
//@Disabled
@ExtendWith({MockitoExtension.class})
class AlarmMailTemplateTest {

@Mock
AlarmCheckerInterface checker;

@Mock
RuleInterface rule;

@Test
public void newBodyTest() {
when(rule.getCheckerName()).thenReturn("checkerName");
when(rule.getApplicationId()).thenReturn("applicaitonId");
when(rule.getServiceType()).thenReturn("TOMCAT");
when(checker.getRule()).thenReturn(rule);
when(checker.getEmailMessage(anyString(), anyString(), anyString(), anyString())).thenReturn("ERROR RATE is 25 % (Threshold: 10 %)<br>");

AlarmMailTemplate alarmMailTemplate = new AlarmMailTemplate(checker, "http://pinpoint.com", "batchEnv", 1);
alarmMailTemplate.createBody();
}
}