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

DTS-38567: Log Management | As a user I can access the data fetch errors #1361

Merged
merged 5 commits into from
Aug 21, 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 @@ -70,6 +70,7 @@
<ng-template pTemplate="header">
<tr>
<th id="processorName">Processor Name</th>
<th id="connectionName">Connection Name</th>
<th id="executionTime">Last Executed On</th>
<th></th>
<th id="state">Status</th>
Expand All @@ -82,11 +83,16 @@
{{ processor.toolName === 'Azure' ? 'Azure Board' : processor.toolName }}
</td>

<td class='custom-table-cell'>
{{ processor.connectionName }}
</td>
<td class='custom-table-cell'>
<span
*ngIf="(!findTraceLogForTool(processor.toolName)?.executionOngoing && processor.toolName === 'Jira') || processor.toolName !== 'Jira'">{{
showExecutionDate(processor.toolName) }}</span>
</td>


<td class="custom-table-cell">
<p-progressBar mode="indeterminate"
*ngIf="processor.toolName === 'Jira' && findTraceLogForTool(processor.toolName)?.executionOngoing === true "
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
package com.publicissapient.kpidashboard.jira.listener;

import static com.publicissapient.kpidashboard.jira.helper.JiraHelper.convertDateToCustomFormat;
import static com.publicissapient.kpidashboard.jira.util.JiraProcessorUtil.generateLogMessage;

import java.io.IOException;
import java.net.UnknownHostException;
Expand Down Expand Up @@ -146,15 +147,15 @@ public void afterJob(JobExecution jobExecution) {
log.info("removing project with basicProjectConfigId {}", projectId);
// Mark the execution as completed
ongoingExecutionsService.markExecutionAsCompleted(projectId);
if (jiraClientService.isContainRestClient(projectId)){
try {
jiraClientService.getRestClientMap(projectId).close();
} catch (IOException e) {
throw new RuntimeException("Failed to close rest client",e);// NOSONAR
}
jiraClientService.removeRestClientMapClientForKey(projectId);
jiraClientService.removeKerberosClientMapClientForKey(projectId);
}
if (jiraClientService.isContainRestClient(projectId)) {
try {
jiraClientService.getRestClientMap(projectId).close();
} catch (IOException e) {
throw new RuntimeException("Failed to close rest client", e);// NOSONAR
}
jiraClientService.removeRestClientMapClientForKey(projectId);
jiraClientService.removeKerberosClientMapClientForKey(projectId);
}
}
}

Expand All @@ -180,12 +181,11 @@ private void setExecutionInfoInTraceLog(boolean status, Throwable stepFailureExc
.findByProcessorNameAndBasicProjectConfigIdIn(JiraConstants.JIRA, Collections.singletonList(projectId));
if (CollectionUtils.isNotEmpty(procExecTraceLogs)) {
for (ProcessorExecutionTraceLog processorExecutionTraceLog : procExecTraceLogs) {
checkDeltaIssues(processorExecutionTraceLog,status);
checkDeltaIssues(processorExecutionTraceLog, status);
processorExecutionTraceLog.setExecutionEndedAt(System.currentTimeMillis());
processorExecutionTraceLog.setExecutionSuccess(status);
if (stepFailureException != null && processorExecutionTraceLog.isProgressStats()) {
String failureMessage = "An error occurred. Please check logs.";
processorExecutionTraceLog.setErrorMessage(failureMessage);
processorExecutionTraceLog.setErrorMessage(generateLogMessage(stepFailureException));
processorExecutionTraceLog.setFailureLog(stepFailureException.getMessage());
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
package com.publicissapient.kpidashboard.jira.listener;

import static com.publicissapient.kpidashboard.jira.helper.JiraHelper.convertDateToCustomFormat;
import static com.publicissapient.kpidashboard.jira.util.JiraProcessorUtil.generateLogMessage;

import java.io.IOException;
import java.net.UnknownHostException;
Expand Down Expand Up @@ -137,7 +138,7 @@ public void afterJob(JobExecution jobExecution) {
break;
}
}
setExecutionInfoInTraceLog(false, stepFaliureException);
setExecutionInfoInTraceLog(false, stepFaliureException);
sendNotification(stepFaliureException);
} else {
setExecutionInfoInTraceLog(true, null);
Expand All @@ -150,15 +151,15 @@ public void afterJob(JobExecution jobExecution) {
ongoingExecutionsService.markExecutionAsCompleted(projectId);

log.info("removing client for basicProjectConfigId {}", projectId);
if (jiraClientService.isContainRestClient(projectId)){
try {
jiraClientService.getRestClientMap(projectId).close();
} catch (IOException e) {
throw new RuntimeException("Failed to close rest client",e);// NOSONAR
}
jiraClientService.removeRestClientMapClientForKey(projectId);
jiraClientService.removeKerberosClientMapClientForKey(projectId);
}
if (jiraClientService.isContainRestClient(projectId)) {
try {
jiraClientService.getRestClientMap(projectId).close();
} catch (IOException e) {
throw new RuntimeException("Failed to close rest client", e);// NOSONAR
}
jiraClientService.removeRestClientMapClientForKey(projectId);
jiraClientService.removeKerberosClientMapClientForKey(projectId);
}
}
}

Expand All @@ -179,18 +180,16 @@ private static String getProjectName(ProjectBasicConfig projectBasicConfig) {
return projectBasicConfig == null ? "" : projectBasicConfig.getProjectName();
}


private void setExecutionInfoInTraceLog(boolean status, Throwable stepFailureException) {
List<ProcessorExecutionTraceLog> procExecTraceLogs = processorExecutionTraceLogRepo
.findByProcessorNameAndBasicProjectConfigIdIn(JiraConstants.JIRA, Collections.singletonList(projectId));
if (CollectionUtils.isNotEmpty(procExecTraceLogs)) {
for (ProcessorExecutionTraceLog processorExecutionTraceLog : procExecTraceLogs) {
checkDeltaIssues(processorExecutionTraceLog,status);
checkDeltaIssues(processorExecutionTraceLog, status);
processorExecutionTraceLog.setExecutionEndedAt(System.currentTimeMillis());
processorExecutionTraceLog.setExecutionSuccess(status);
if (stepFailureException != null && processorExecutionTraceLog.isProgressStats()) {
String failureMessage = "An error occurred. Please check logs.";
processorExecutionTraceLog.setErrorMessage(failureMessage);
processorExecutionTraceLog.setErrorMessage(generateLogMessage(stepFailureException));
processorExecutionTraceLog.setFailureLog(stepFailureException.getMessage());
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,10 @@
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import com.publicissapient.kpidashboard.common.exceptions.ClientErrorMessageEnum;
import org.apache.commons.lang3.StringUtils;
import org.codehaus.jettison.json.JSONException;
import org.joda.time.DateTime;
Expand All @@ -53,7 +56,8 @@
@Slf4j
public class JiraProcessorUtil {

private JiraProcessorUtil(){}
private JiraProcessorUtil() {
}

// not static because not thread safe
private static final String SPRINT_SPLIT = "(?=,\\w+=)";
Expand All @@ -68,6 +72,21 @@ private JiraProcessorUtil(){}
private static final String ACTIVATEDDATE = "activatedDate";
private static final String GOAL = "goal";
private static final String BOARDID = "boardId";
private static final Pattern EXCEPTION_WITH_MESSAGE_PATTERN = Pattern
.compile("^(\\w+(?:\\.\\w+)*Exception):\\s*(.+)$");

private static final Pattern EXCEPTION_WITH_STATUS_CODE_PATTERN = Pattern
.compile("(\\w+(?:\\.\\w+)*Exception)\\{[^}]*statusCode=Optional\\.of\\((\\d+)\\)");

private static final Pattern ERROR_COLLECTION_PATTERN = Pattern
.compile("\\[ErrorCollection\\{status=(\\d+), errors=\\{.*\\}, errorMessages=\\[.*\\]\\}\\]");

private static final Pattern ERROR_WITH_STATUS_CODE_PATTERN = Pattern.compile("Error:\\s*(\\d+)\\s*-\\s*(.*)");

private static final String UNAUTHORIZED = "Sorry, you are not authorized to access the requested resource.";
private static final String TO_MANY_REQUEST = "Too many request try after sometime.";
private static final String OTHER_CLIENT_ERRORS = "An unexpected error has occurred. Please contact the KnowHow Support for assistance.";
private static final String FORBIDDEN="Forbidden, check your credentials.";

/**
* This method return UTF-8 decoded string response
Expand Down Expand Up @@ -354,4 +373,47 @@ public static ProcessorExecutionTraceLog saveChunkProgressInTrace(
return processorExecutionTraceLog;
}

public static String generateLogMessage(Throwable exception) {
shunaray marked this conversation as resolved.
Show resolved Hide resolved
String exceptionMessage = exception.getMessage();

String logMessage = matchPattern(exceptionMessage, EXCEPTION_WITH_STATUS_CODE_PATTERN, true);
if (logMessage != null)
return logMessage;

logMessage = matchPattern(exceptionMessage, EXCEPTION_WITH_MESSAGE_PATTERN, false);
if (logMessage != null)
return logMessage;

logMessage = matchPattern(exceptionMessage, ERROR_COLLECTION_PATTERN, true);
if (logMessage != null)
return logMessage;

logMessage = matchPattern(exceptionMessage, ERROR_WITH_STATUS_CODE_PATTERN, true);
if (logMessage != null)
return logMessage;

return "No matching exception pattern found";
}

private static String matchPattern(String exceptionMessage, Pattern pattern, boolean hasStatusCode) {
Matcher matcher = pattern.matcher(exceptionMessage);
if (matcher.find()) {
if (hasStatusCode) {
int statusCode = Integer.parseInt(matcher.group(1));
switch (statusCode) {
case 401:
return UNAUTHORIZED;
case 429:
return TO_MANY_REQUEST;
case 403:
return FORBIDDEN;
default:
return OTHER_CLIENT_ERRORS;
}
}
return OTHER_CLIENT_ERRORS;
}
return null;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -234,4 +234,46 @@ public void testSaveChunkProgressInTrace_BothNotNull() {
assertEquals("Process Issues 0 to 0 out of 0", progressStatusList.get(0).getStepName());
assertEquals(BatchStatus.COMPLETED.toString(), progressStatusList.get(0).getStatus());
}
@Test
public void testGenerateLogMessage_withExceptionMessage() {
Throwable exception = new Throwable("java.lang.NullPointerException: null");
String expectedMessage = "An unexpected error has occurred. Please contact the KnowHow Support for assistance.";
String actualMessage = JiraProcessorUtil.generateLogMessage(exception);
assertEquals(expectedMessage, actualMessage);
}
@Test
public void testGenerateLogMessage_withErrorCollection() {
Throwable exception = new Throwable("org.codehaus.jettison.json.JSONException: A JSONObject text must begin with '{'");
String expectedMessage = "An unexpected error has occurred. Please contact the KnowHow Support for assistance.";
String actualMessage = JiraProcessorUtil.generateLogMessage(exception);
assertEquals(expectedMessage, actualMessage);
}
@Test
public void testGenerateLogMessage_withErrorStatusCode401() {
Throwable exception = new Throwable("[ErrorCollection{status=401, errors={}, errorMessages=[]}]");
String expectedMessage = "Sorry, you are not authorized to access the requested resource.";
String actualMessage = JiraProcessorUtil.generateLogMessage(exception);
assertEquals(expectedMessage, actualMessage);
}
@Test
public void testGenerateLogMessage_withErrorStatusCode403() {
Throwable exception = new Throwable("[ErrorCollection{status=403, errors={}, errorMessages=[]}]");
String expectedMessage = "Forbidden, check your credentials.";
String actualMessage = JiraProcessorUtil.generateLogMessage(exception);
assertEquals(expectedMessage, actualMessage);
}
@Test
public void testGenerateLogMessage_withErrorStatusCode429() {
Throwable exception = new Throwable("[ErrorCollection{status=429, errors={}, errorMessages=[]}]");
String expectedMessage = "Too many request try after sometime.";
String actualMessage = JiraProcessorUtil.generateLogMessage(exception);
assertEquals(expectedMessage, actualMessage);
}
@Test
public void testGenerateLogMessage_noMatchingPattern() {
Throwable exception = new Throwable("Some random exception message");
String expectedMessage = "No matching exception pattern found";
String actualMessage = JiraProcessorUtil.generateLogMessage(exception);
assertEquals(expectedMessage, actualMessage);
}
}
Loading