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

Improved diagnostic logs for httpGet and httpPost adaptive functions #161

Merged
Merged
Show file tree
Hide file tree
Changes from 4 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 @@ -23,6 +23,8 @@ public class Constants {
public static final String OUTCOME_SUCCESS = "onSuccess";
public static final String OUTCOME_FAIL = "onFail";
public static final String OUTCOME_TIMEOUT = "onTimeout";
public static final String GET = "GET";
public static final String POST = "POST";

public static final String RECEIVER_URL = "AdaptiveAuth.EventPublisher.ReceiverURL";
public static final String HTTP_CONNECTION_TIMEOUT = "AdaptiveAuth.HTTPConnectionTimeout";
Expand Down Expand Up @@ -61,8 +63,10 @@ public static class LogConstants {
*/
public static class ActionIDs {

public static final String RECEIVE_TOKEN = "receive-token";
public static final String RECEIVE_API_RESPONSE = "receive-api-response";
public static final String REQUEST_TOKEN_HTTP_GET = "request-token-http-get";
public static final String REQUEST_TOKEN_HTTP_POST = "request-token-http-post";
public static final String INVOKE_API_HTTP_GET = "invoke-api-http-get";
public static final String INVOKE_API_HTTP_POST = "invoke-api-http-post";
}
Sachin-Mamoru marked this conversation as resolved.
Show resolved Hide resolved

/**
Expand All @@ -72,15 +76,15 @@ public static class InputKeys {

public static final String TOKEN_ENDPOINT = "token endpoint";
public static final String API = "external api";
public static final String GRANT_TYPE = "grant type";
}

/**
* Define common and reusable Configuration keys for diagnostic logs.
*/
public static class ConfigKeys {

public static final String SUPPORTED_GRANT_TYPES = "supported grant types";

public static final String MAX_REQUEST_ATTEMPTS = "max request attempts";
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ public abstract class AbstractHTTPFunction {
protected static final String TYPE_TEXT_PLAIN = "text/plain";
private static final char DOMAIN_SEPARATOR = '.';
private static final String RESPONSE = "response";
private String INVOKE_API = "invoke-api";
private final int requestRetryCount;
private final List<String> allowedDomains;

Expand Down Expand Up @@ -98,6 +99,12 @@ protected void executeHttpMethod(HttpUriRequest clientRequest, Map<String, Objec
String outcome;
String endpointURL = null;

if (clientRequest.getMethod().equals(Constants.GET)) {
INVOKE_API = Constants.LogConstants.ActionIDs.INVOKE_API_HTTP_GET;
} else if (clientRequest.getMethod().equals(Constants.POST)) {
INVOKE_API = Constants.LogConstants.ActionIDs.INVOKE_API_HTTP_POST;
}

Sachin-Mamoru marked this conversation as resolved.
Show resolved Hide resolved
HttpUriRequest request;
try {
if (authConfigModel != null) {
Expand Down Expand Up @@ -155,8 +162,9 @@ protected void executeHttpMethod(HttpUriRequest clientRequest, Map<String, Objec
if (LoggerUtils.isDiagnosticLogsEnabled()) {
DiagnosticLog.DiagnosticLogBuilder diagnosticLogBuilder = new
DiagnosticLog.DiagnosticLogBuilder(Constants.LogConstants.ADAPTIVE_AUTH_SERVICE,
Constants.LogConstants.ActionIDs.RECEIVE_API_RESPONSE);
INVOKE_API);
diagnosticLogBuilder.inputParam(Constants.LogConstants.InputKeys.API, endpointURL)
.configParam(Constants.LogConstants.ConfigKeys.MAX_REQUEST_ATTEMPTS, maxRetries)
.resultMessage("Retrying the request for external api. Attempt: " + attempts)
.logDetailLevel(DiagnosticLog.LogDetailLevel.APPLICATION)
.resultStatus(DiagnosticLog.ResultStatus.FAILED);
Expand Down Expand Up @@ -200,8 +208,7 @@ private Pair<RetryDecision, Pair<String, JSONObject>> executeRequest(HttpUriRequ
}
if (LoggerUtils.isDiagnosticLogsEnabled()) {
DiagnosticLog.DiagnosticLogBuilder diagnosticLogBuilder = new
DiagnosticLog.DiagnosticLogBuilder(Constants.LogConstants.ADAPTIVE_AUTH_SERVICE,
Constants.LogConstants.ActionIDs.RECEIVE_API_RESPONSE);
DiagnosticLog.DiagnosticLogBuilder(Constants.LogConstants.ADAPTIVE_AUTH_SERVICE, INVOKE_API);
diagnosticLogBuilder.inputParam(Constants.LogConstants.InputKeys.API, endpointURL)
.resultMessage("Successfully called the external api. Status code: " + responseCode)
.logDetailLevel(DiagnosticLog.LogDetailLevel.APPLICATION)
Expand All @@ -215,8 +222,7 @@ private Pair<RetryDecision, Pair<String, JSONObject>> executeRequest(HttpUriRequ
} else if (responseCode >= 300 && responseCode < 400) {
if (LoggerUtils.isDiagnosticLogsEnabled()) {
DiagnosticLog.DiagnosticLogBuilder diagnosticLogBuilder = new
DiagnosticLog.DiagnosticLogBuilder(Constants.LogConstants.ADAPTIVE_AUTH_SERVICE,
Constants.LogConstants.ActionIDs.RECEIVE_API_RESPONSE);
DiagnosticLog.DiagnosticLogBuilder(Constants.LogConstants.ADAPTIVE_AUTH_SERVICE, INVOKE_API);
diagnosticLogBuilder.inputParam(Constants.LogConstants.InputKeys.API, endpointURL)
.resultMessage("External api invocation returned a redirection. Status code: " +
responseCode)
Expand All @@ -231,8 +237,7 @@ private Pair<RetryDecision, Pair<String, JSONObject>> executeRequest(HttpUriRequ
} else if (responseCode >= 400 && responseCode < 500) {
if (LoggerUtils.isDiagnosticLogsEnabled()) {
DiagnosticLog.DiagnosticLogBuilder diagnosticLogBuilder = new
DiagnosticLog.DiagnosticLogBuilder(Constants.LogConstants.ADAPTIVE_AUTH_SERVICE,
Constants.LogConstants.ActionIDs.RECEIVE_API_RESPONSE);
DiagnosticLog.DiagnosticLogBuilder(Constants.LogConstants.ADAPTIVE_AUTH_SERVICE, INVOKE_API);
diagnosticLogBuilder.inputParam(Constants.LogConstants.InputKeys.API, endpointURL)
.resultMessage("External api invocation returned a client error. Status code: " +
responseCode)
Expand All @@ -247,8 +252,7 @@ private Pair<RetryDecision, Pair<String, JSONObject>> executeRequest(HttpUriRequ
} else {
if (LoggerUtils.isDiagnosticLogsEnabled()) {
DiagnosticLog.DiagnosticLogBuilder diagnosticLogBuilder = new
DiagnosticLog.DiagnosticLogBuilder(Constants.LogConstants.ADAPTIVE_AUTH_SERVICE,
Constants.LogConstants.ActionIDs.RECEIVE_API_RESPONSE);
DiagnosticLog.DiagnosticLogBuilder(Constants.LogConstants.ADAPTIVE_AUTH_SERVICE, INVOKE_API);
diagnosticLogBuilder.inputParam(Constants.LogConstants.InputKeys.API, endpointURL)
.resultMessage("Received unknown response from external API call. Status code: " +
responseCode)
Expand All @@ -266,8 +270,7 @@ private Pair<RetryDecision, Pair<String, JSONObject>> executeRequest(HttpUriRequ
if (e instanceof IllegalArgumentException) {
if (LoggerUtils.isDiagnosticLogsEnabled()) {
DiagnosticLog.DiagnosticLogBuilder diagnosticLogBuilder = new
DiagnosticLog.DiagnosticLogBuilder(Constants.LogConstants.ADAPTIVE_AUTH_SERVICE,
Constants.LogConstants.ActionIDs.RECEIVE_API_RESPONSE);
DiagnosticLog.DiagnosticLogBuilder(Constants.LogConstants.ADAPTIVE_AUTH_SERVICE, INVOKE_API);
diagnosticLogBuilder.inputParam(Constants.LogConstants.InputKeys.API, endpointURL)
.resultMessage("Invalid Url for external API call.")
.logDetailLevel(DiagnosticLog.LogDetailLevel.APPLICATION)
Expand All @@ -279,8 +282,7 @@ private Pair<RetryDecision, Pair<String, JSONObject>> executeRequest(HttpUriRequ
} else if (e instanceof ConnectTimeoutException || e instanceof SocketTimeoutException) {
if (LoggerUtils.isDiagnosticLogsEnabled()) {
DiagnosticLog.DiagnosticLogBuilder diagnosticLogBuilder = new
DiagnosticLog.DiagnosticLogBuilder(Constants.LogConstants.ADAPTIVE_AUTH_SERVICE,
Constants.LogConstants.ActionIDs.RECEIVE_API_RESPONSE);
DiagnosticLog.DiagnosticLogBuilder(Constants.LogConstants.ADAPTIVE_AUTH_SERVICE, INVOKE_API);
diagnosticLogBuilder.inputParam(Constants.LogConstants.InputKeys.API, endpointURL)
.resultMessage("Request for the external API timed out.")
.logDetailLevel(DiagnosticLog.LogDetailLevel.APPLICATION)
Expand All @@ -296,8 +298,7 @@ private Pair<RetryDecision, Pair<String, JSONObject>> executeRequest(HttpUriRequ
} else if (e instanceof ParseException) {
if (LoggerUtils.isDiagnosticLogsEnabled()) {
DiagnosticLog.DiagnosticLogBuilder diagnosticLogBuilder = new
DiagnosticLog.DiagnosticLogBuilder(Constants.LogConstants.ADAPTIVE_AUTH_SERVICE,
Constants.LogConstants.ActionIDs.RECEIVE_API_RESPONSE);
DiagnosticLog.DiagnosticLogBuilder(Constants.LogConstants.ADAPTIVE_AUTH_SERVICE, INVOKE_API);
diagnosticLogBuilder.inputParam(Constants.LogConstants.InputKeys.API, endpointURL)
.resultMessage("Failed to parse the response from the external API.")
.logDetailLevel(DiagnosticLog.LogDetailLevel.APPLICATION)
Expand All @@ -309,8 +310,7 @@ private Pair<RetryDecision, Pair<String, JSONObject>> executeRequest(HttpUriRequ
} else {
if (LoggerUtils.isDiagnosticLogsEnabled()) {
DiagnosticLog.DiagnosticLogBuilder diagnosticLogBuilder = new
DiagnosticLog.DiagnosticLogBuilder(Constants.LogConstants.ADAPTIVE_AUTH_SERVICE,
Constants.LogConstants.ActionIDs.RECEIVE_API_RESPONSE);
DiagnosticLog.DiagnosticLogBuilder(Constants.LogConstants.ADAPTIVE_AUTH_SERVICE, INVOKE_API);
diagnosticLogBuilder.inputParam(Constants.LogConstants.InputKeys.API, endpointURL)
.resultMessage("Received an error while invoking the external API.")
.logDetailLevel(DiagnosticLog.LogDetailLevel.APPLICATION)
Expand Down
Loading
Loading