summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authormark.j.leonard <mark.j.leonard@gmail.com>2019-02-21 16:04:11 +0000
committermark.j.leonard <mark.j.leonard@gmail.com>2019-02-21 16:06:20 +0000
commit64b11e238224cd6bce9682f307948447df48eb4c (patch)
tree7c0cec4bfa0d9c26d2946303b047a4f6ea4f4222
parent8ad5aa365b9da241ea1ead2300078b2e39da78c8 (diff)
Add metrics logging for Babel requests
Change-Id: I67492a90b0faac1c60be118be4e25237bd3a780d Issue-ID: AAI-2183 Signed-off-by: mark.j.leonard <mark.j.leonard@gmail.com>
-rw-r--r--src/main/java/org/onap/aai/modelloader/restclient/HttpsBabelServiceClient.java28
-rw-r--r--src/main/java/org/onap/aai/modelloader/service/ModelLoaderMsgs.java7
-rw-r--r--src/main/resources/org/onap/aai/modelloader/service/ModelLoaderMsgs.properties10
3 files changed, 38 insertions, 7 deletions
diff --git a/src/main/java/org/onap/aai/modelloader/restclient/HttpsBabelServiceClient.java b/src/main/java/org/onap/aai/modelloader/restclient/HttpsBabelServiceClient.java
index f07d0d3..805fe34 100644
--- a/src/main/java/org/onap/aai/modelloader/restclient/HttpsBabelServiceClient.java
+++ b/src/main/java/org/onap/aai/modelloader/restclient/HttpsBabelServiceClient.java
@@ -2,8 +2,8 @@
* ============LICENSE_START=======================================================
* org.onap.aai
* ================================================================================
- * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved.
- * Copyright © 2017-2018 European Software Marketing Ltd.
+ * Copyright © 2017-2019 AT&T Intellectual Property. All rights reserved.
+ * Copyright © 2017-2019 European Software Marketing Ltd.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -18,6 +18,7 @@
* limitations under the License.
* ============LICENSE_END=========================================================
*/
+
package org.onap.aai.modelloader.restclient;
import com.google.gson.Gson;
@@ -38,6 +39,8 @@ import java.security.NoSuchAlgorithmException;
import java.security.UnrecoverableKeyException;
import java.security.cert.CertificateException;
import java.security.cert.X509Certificate;
+import java.time.ZonedDateTime;
+import java.time.format.DateTimeFormatter;
import java.util.Base64;
import java.util.Collections;
import java.util.List;
@@ -52,8 +55,12 @@ import javax.ws.rs.core.Response;
import org.json.JSONException;
import org.json.JSONObject;
import org.onap.aai.babel.service.data.BabelArtifact;
+import org.onap.aai.cl.api.LogFields;
+import org.onap.aai.cl.api.LogLine;
import org.onap.aai.cl.api.Logger;
import org.onap.aai.cl.eelf.LoggerFactory;
+import org.onap.aai.cl.mdc.MdcContext;
+import org.onap.aai.cl.mdc.MdcOverride;
import org.onap.aai.modelloader.config.ModelLoaderConfig;
import org.onap.aai.modelloader.service.ModelLoaderMsgs;
@@ -64,6 +71,9 @@ import org.onap.aai.modelloader.service.ModelLoaderMsgs;
public class HttpsBabelServiceClient implements BabelServiceClient {
private static final Logger logger = LoggerFactory.getInstance().getLogger(HttpsBabelServiceClient.class);
+ private static final Logger metricsLogger =
+ LoggerFactory.getInstance().getMetricsLogger(HttpsBabelServiceClient.class);
+ private static final DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss.SSSXXX");
private static final String SSL_PROTOCOL = "TLS";
private static final String KEYSTORE_ALGORITHM = "SunX509";
@@ -156,7 +166,7 @@ public class HttpsBabelServiceClient implements BabelServiceClient {
public void checkServerTrusted(X509Certificate[] chain, String authType) throws CertificateException {
try {
finalLocalTm.checkServerTrusted(chain, authType);
- } catch (CertificateException e) {
+ } catch (CertificateException e) { // NOSONAR
defaultTrustManager.checkServerTrusted(chain, authType);
}
}
@@ -209,6 +219,9 @@ public class HttpsBabelServiceClient implements BabelServiceClient {
+ " Artifact version: " + artifactVersion + " Artifact payload: " + encodedPayload);
}
+ MdcOverride override = new MdcOverride();
+ override.addAttribute(MdcContext.MDC_START_TIME, ZonedDateTime.now().format(formatter));
+
WebResource webResource = client.resource(config.getBabelBaseUrl() + config.getBabelGenerateArtifactsUrl());
ClientResponse response = webResource.type("application/json")
.header(AaiRestClient.HEADER_TRANS_ID, Collections.singletonList(transactionId))
@@ -221,6 +234,15 @@ public class HttpsBabelServiceClient implements BabelServiceClient {
"Babel response " + response.getStatus() + " " + sanitizedJson);
}
+ metricsLogger.info(ModelLoaderMsgs.BABEL_REST_REQUEST, new LogFields() //
+ .setField(LogLine.DefinedFields.TARGET_ENTITY, "Babel")
+ .setField(LogLine.DefinedFields.STATUS_CODE,
+ Response.Status.fromStatusCode(response.getStatus()).getFamily()
+ .equals(Response.Status.Family.SUCCESSFUL) ? "COMPLETE" : "ERROR")
+ .setField(LogLine.DefinedFields.RESPONSE_CODE, response.getStatus())
+ .setField(LogLine.DefinedFields.RESPONSE_DESCRIPTION, response.getStatusInfo().toString()), //
+ override, response.toString());
+
if (response.getStatus() != Response.Status.OK.getStatusCode()) {
throw new BabelServiceClientException(sanitizedJson);
}
diff --git a/src/main/java/org/onap/aai/modelloader/service/ModelLoaderMsgs.java b/src/main/java/org/onap/aai/modelloader/service/ModelLoaderMsgs.java
index 26a9efa..a73d053 100644
--- a/src/main/java/org/onap/aai/modelloader/service/ModelLoaderMsgs.java
+++ b/src/main/java/org/onap/aai/modelloader/service/ModelLoaderMsgs.java
@@ -86,7 +86,12 @@ public enum ModelLoaderMsgs implements LogMessageEnum {
ARTIFACT_PARSE_ERROR,
/**
- * Arguments: {0} = info request payload.
+ * Arguments: {0} = info request for metrics.
+ **/
+ BABEL_REST_REQUEST,
+
+ /**
+ * Arguments: {0} = info request details.
**/
BABEL_REST_REQUEST_PAYLOAD,
diff --git a/src/main/resources/org/onap/aai/modelloader/service/ModelLoaderMsgs.properties b/src/main/resources/org/onap/aai/modelloader/service/ModelLoaderMsgs.properties
index d337915..b4aadf5 100644
--- a/src/main/resources/org/onap/aai/modelloader/service/ModelLoaderMsgs.properties
+++ b/src/main/resources/org/onap/aai/modelloader/service/ModelLoaderMsgs.properties
@@ -2,8 +2,8 @@
# ============LICENSE_START==========================================
# org.onap.aai
# ===================================================================
-# Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved.
-# Copyright © 2017-2018 European Software Marketing Ltd.
+# Copyright (c) 2017-2019 AT&T Intellectual Property. All rights reserved.
+# Copyright (c) 2017-2019 European Software Marketing Ltd.
# ===================================================================
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
@@ -98,7 +98,11 @@ AAI_REST_REQUEST_PAYLOAD=\
UNSUPPORTED_ARTIFACT_TYPE=\
MDLSVC0011I|\
The downloaded artifact: {0} has an unsupported type of: {1}|\
-
+
+BABEL_REST_REQUEST=\
+ MDLSVC0012I|\
+ {0}|\
+
# ERROR Level Logs
ASDC_CONNECTION_ERROR=\
MDLSVC2001E|\