From 9eee6ac9daa5b82946b4f7c7eaa817ae3e1f4cab Mon Sep 17 00:00:00 2001 From: Michael O'Brien Date: Mon, 25 Jun 2018 13:59:31 -0400 Subject: logging library use and k8s Change-Id: I264f6dd5270543a216612c50fd5806458e0e806a Issue-ID: LOG-135 Signed-off-by: Michael O'Brien --- reference/logging-demo/.classpath | 2 + reference/logging-demo/pom.xml | 21 ++++++-- .../org/onap/demo/logging/ApplicationService.java | 11 ++++- .../onap/demo/logging/ApplicationServiceLocal.java | 4 +- .../java/org/onap/demo/logging/LoggingAspect.java | 55 +++++++++++++++++++++ .../onap/demo/logging/RestHealthServiceImpl.java | 8 ++- .../org/onap/demo/logging/RestServiceImpl.java | 25 +++++----- .../logging-demo/src/main/resources/logback.xml | 32 ++++++++++++ .../src/main/webapp/WEB-INF/spring.xml | 5 ++ .../onap/logging/demo/ApplicationServiceTest.java | 45 +++++++++++++++++ .../logging-docker-demo-service/DockerFile | 2 + .../logging-docker-demo-service/build.sh | 31 ++++++++++++ .../logging-docker-demo/DockerFile | 2 +- .../logging-docker-demo/build.sh | 27 +++++++++- reference/logging-docker-root/pom.xml | 2 +- .../logdemo/templates/all-services.yaml | 10 ++-- .../templates/log-mock-demo-deployment.yaml | 43 ---------------- .../templates/log-mock-service-deployment.yaml | 43 ++++++++++++++++ reference/logging-kubernetes/logdemo/values.yaml | 2 +- .../logging-kubernetes/logdemoservice/Chart.yaml | 4 ++ .../logdemoservice/templates/all-services.yaml | 14 ++++++ .../log-mock-demo-service-deployment.yaml | 57 ++++++++++++++++++++++ .../logging-kubernetes/logdemoservice/values.yaml | 7 +++ reference/logging-kubernetes/pom.xml | 2 +- reference/logging-library/pom.xml | 7 ++- reference/logging-mock-service/pom.xml | 10 ++-- reference/logging-slf4j-demo/pom.xml | 4 +- reference/logging-slf4j/pom.xml | 4 +- .../org/onap/logging/ref/slf4j/ONAPLogAdapter.java | 3 +- .../onap/logging/ref/slf4j/ONAPLogAdapterTest.java | 41 ++++++++++++++++ reference/pom.xml | 2 +- 31 files changed, 439 insertions(+), 86 deletions(-) create mode 100644 reference/logging-demo/src/main/java/org/onap/demo/logging/LoggingAspect.java create mode 100644 reference/logging-demo/src/main/resources/logback.xml create mode 100644 reference/logging-demo/src/test/java/org/onap/logging/demo/ApplicationServiceTest.java create mode 100644 reference/logging-docker-root/logging-docker-demo-service/DockerFile create mode 100755 reference/logging-docker-root/logging-docker-demo-service/build.sh delete mode 100644 reference/logging-kubernetes/logdemo/templates/log-mock-demo-deployment.yaml create mode 100644 reference/logging-kubernetes/logdemo/templates/log-mock-service-deployment.yaml create mode 100644 reference/logging-kubernetes/logdemoservice/Chart.yaml create mode 100644 reference/logging-kubernetes/logdemoservice/templates/all-services.yaml create mode 100644 reference/logging-kubernetes/logdemoservice/templates/log-mock-demo-service-deployment.yaml create mode 100644 reference/logging-kubernetes/logdemoservice/values.yaml (limited to 'reference') diff --git a/reference/logging-demo/.classpath b/reference/logging-demo/.classpath index 159bf9a..9a77030 100644 --- a/reference/logging-demo/.classpath +++ b/reference/logging-demo/.classpath @@ -1,6 +1,8 @@ + + diff --git a/reference/logging-demo/pom.xml b/reference/logging-demo/pom.xml index a695970..60fbe98 100644 --- a/reference/logging-demo/pom.xml +++ b/reference/logging-demo/pom.xml @@ -3,14 +3,15 @@ org.onap.logging-analytics logging-reference - 1.2.0-SNAPSHOT + 1.2.2-SNAPSHOT logging-demo war logging-demo 2.5.1 - 4.3.6.RELEASE + 4.3.6.RELEASE + 1.2.3 @@ -71,12 +72,12 @@ org.onap.logging-analytics logging-library - 1.2.0-SNAPSHOT + 1.2.2-SNAPSHOT org.onap.logging-analytics logging-mock-service - 1.2.0-SNAPSHOT + 1.2.2-SNAPSHOT @@ -252,6 +253,16 @@ org.springframework spring-webmvc ${spring.version} - + + + ch.qos.logback + logback-core + ${logback.version} + + + ch.qos.logback + logback-classic + ${logback.version} + diff --git a/reference/logging-demo/src/main/java/org/onap/demo/logging/ApplicationService.java b/reference/logging-demo/src/main/java/org/onap/demo/logging/ApplicationService.java index d0355df..d6329e2 100644 --- a/reference/logging-demo/src/main/java/org/onap/demo/logging/ApplicationService.java +++ b/reference/logging-demo/src/main/java/org/onap/demo/logging/ApplicationService.java @@ -20,14 +20,23 @@ */ package org.onap.demo.logging; +import javax.servlet.http.HttpServletRequest; + +import org.slf4j.LoggerFactory; import org.springframework.stereotype.Service; @Service("daoFacade") +/** + * Run with http://localhost:8080/logging-demo/rest/health/health + * + */ public class ApplicationService implements ApplicationServiceLocal { @Override - public Boolean health() { + public Boolean health(HttpServletRequest servletRequest) { Boolean health = true; // TODO: check database + // Log outside the AOP framework - to simulate existing component logs between the ENTRY/EXIT markers + LoggerFactory.getLogger(this.getClass()).info("Running /health"); return health; } diff --git a/reference/logging-demo/src/main/java/org/onap/demo/logging/ApplicationServiceLocal.java b/reference/logging-demo/src/main/java/org/onap/demo/logging/ApplicationServiceLocal.java index ac585fb..e2cd5b7 100644 --- a/reference/logging-demo/src/main/java/org/onap/demo/logging/ApplicationServiceLocal.java +++ b/reference/logging-demo/src/main/java/org/onap/demo/logging/ApplicationServiceLocal.java @@ -20,6 +20,8 @@ */ package org.onap.demo.logging; +import javax.servlet.http.HttpServletRequest; + public interface ApplicationServiceLocal { - Boolean health(); + Boolean health(HttpServletRequest request); } diff --git a/reference/logging-demo/src/main/java/org/onap/demo/logging/LoggingAspect.java b/reference/logging-demo/src/main/java/org/onap/demo/logging/LoggingAspect.java new file mode 100644 index 0000000..2901ce1 --- /dev/null +++ b/reference/logging-demo/src/main/java/org/onap/demo/logging/LoggingAspect.java @@ -0,0 +1,55 @@ +/** + * ============LICENSE_START======================================================= + * org.onap.logging + * ================================================================================ + * Copyright © 2018 Amdocs + * All rights reserved. + * ================================================================================ + * 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. + * ============LICENSE_END========================================================= + */ +package org.onap.demo.logging; + +import javax.servlet.http.HttpServletRequest; + +import org.aspectj.lang.JoinPoint; +import org.aspectj.lang.annotation.After; +import org.aspectj.lang.annotation.Aspect; +import org.aspectj.lang.annotation.Before; +import org.onap.logging.ref.slf4j.ONAPLogAdapter; +import org.slf4j.LoggerFactory; + +@Aspect +public class LoggingAspect { + + @Before("execution(* org.onap.demo.logging.*.*(..))") + public void logBefore(JoinPoint joinPoint) { + Object[] args = joinPoint.getArgs(); + Object servletRequest = args[0]; + ONAPLogAdapter.HttpServletRequestAdapter requestAdapter = + new ONAPLogAdapter.HttpServletRequestAdapter((HttpServletRequest)servletRequest); + final ONAPLogAdapter adapter = new ONAPLogAdapter( + LoggerFactory.getLogger(joinPoint.getTarget().getClass())); + try { + adapter.entering(requestAdapter); + } finally { + } + } + + @After("execution(* org.onap.demo.logging.*.*(..))") + public void logAfter(JoinPoint joinPoint) { + final ONAPLogAdapter adapter = new ONAPLogAdapter( + LoggerFactory.getLogger(joinPoint.getTarget().getClass())); + adapter.exiting(); + } +} diff --git a/reference/logging-demo/src/main/java/org/onap/demo/logging/RestHealthServiceImpl.java b/reference/logging-demo/src/main/java/org/onap/demo/logging/RestHealthServiceImpl.java index 33e3874..bcc4efb 100644 --- a/reference/logging-demo/src/main/java/org/onap/demo/logging/RestHealthServiceImpl.java +++ b/reference/logging-demo/src/main/java/org/onap/demo/logging/RestHealthServiceImpl.java @@ -21,16 +21,21 @@ package org.onap.demo.logging; import javax.inject.Inject; +import javax.servlet.http.HttpServletRequest; import javax.ws.rs.GET; import javax.ws.rs.Path; import javax.ws.rs.Produces; import javax.ws.rs.core.Application; +import javax.ws.rs.core.Context; import javax.ws.rs.core.MediaType; import org.springframework.beans.factory.annotation.Qualifier; @Path("/health") public class RestHealthServiceImpl extends Application { + + @Context private HttpServletRequest servletRequest; + @Inject @Qualifier("daoFacade") private ApplicationServiceLocal applicationServiceLocal; @@ -39,7 +44,8 @@ public class RestHealthServiceImpl extends Application { @Path("/health") @Produces(MediaType.TEXT_HTML) public String getHealth() { - return applicationServiceLocal.health().toString(); + + return applicationServiceLocal.health(servletRequest).toString(); } } diff --git a/reference/logging-demo/src/main/java/org/onap/demo/logging/RestServiceImpl.java b/reference/logging-demo/src/main/java/org/onap/demo/logging/RestServiceImpl.java index 9dfe884..fe13f0c 100644 --- a/reference/logging-demo/src/main/java/org/onap/demo/logging/RestServiceImpl.java +++ b/reference/logging-demo/src/main/java/org/onap/demo/logging/RestServiceImpl.java @@ -31,19 +31,20 @@ import org.springframework.beans.factory.annotation.Qualifier; @Path("/read") public class RestServiceImpl extends Application { - @Inject - @Qualifier("daoFacade") + @Inject + @Qualifier("daoFacade") private ApplicationServiceLocal applicationServiceLocal; - - @GET - @Path("/test") - @Produces(MediaType.TEXT_HTML) - public String getTest() { - return "testing: " + applicationServiceLocal; - } - private ApplicationServiceLocal getApplicationService() { - return applicationServiceLocal; - } + @GET + @Path("/test") + @Produces(MediaType.TEXT_HTML) + public String getTest() { + return "testing: " + applicationServiceLocal; + + } + + private ApplicationServiceLocal getApplicationService() { + return applicationServiceLocal; + } } diff --git a/reference/logging-demo/src/main/resources/logback.xml b/reference/logging-demo/src/main/resources/logback.xml new file mode 100644 index 0000000..71d41e4 --- /dev/null +++ b/reference/logging-demo/src/main/resources/logback.xml @@ -0,0 +1,32 @@ + + + + + + + + + + + + + ${pattern} + + + + + output.log + + ${pattern} + + + + + + + + + + + + diff --git a/reference/logging-demo/src/main/webapp/WEB-INF/spring.xml b/reference/logging-demo/src/main/webapp/WEB-INF/spring.xml index 32d1235..2b4d585 100644 --- a/reference/logging-demo/src/main/webapp/WEB-INF/spring.xml +++ b/reference/logging-demo/src/main/webapp/WEB-INF/spring.xml @@ -34,6 +34,11 @@ + + + + + diff --git a/reference/logging-demo/src/test/java/org/onap/logging/demo/ApplicationServiceTest.java b/reference/logging-demo/src/test/java/org/onap/logging/demo/ApplicationServiceTest.java new file mode 100644 index 0000000..aab2ba7 --- /dev/null +++ b/reference/logging-demo/src/test/java/org/onap/logging/demo/ApplicationServiceTest.java @@ -0,0 +1,45 @@ +/** + * ============LICENSE_START======================================================= + * org.onap.logging + * ================================================================================ + * Copyright © 2018 Amdocs + * All rights reserved. + * ================================================================================ + * 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. + * ============LICENSE_END========================================================= + */ +package org.onap.logging.demo; + +import static org.junit.Assert.*; + +import javax.servlet.http.HttpServletRequest; + +import org.junit.Test; +import org.onap.demo.logging.ApplicationService; +import org.springframework.mock.web.MockHttpServletRequest; +import org.springframework.util.Assert; + +public class ApplicationServiceTest { + + @Test + public final void testHealth() { + ApplicationService service = new ApplicationService(); + Assert.notNull(service); + HttpServletRequest servletRequest = new MockHttpServletRequest(); + Assert.notNull(servletRequest); + boolean health = service.health(servletRequest); + Assert.isTrue(health); + System.out.println("health : " + health); + } + +} diff --git a/reference/logging-docker-root/logging-docker-demo-service/DockerFile b/reference/logging-docker-root/logging-docker-demo-service/DockerFile new file mode 100644 index 0000000..bb9a7cf --- /dev/null +++ b/reference/logging-docker-root/logging-docker-demo-service/DockerFile @@ -0,0 +1,2 @@ +FROM tomcat:8.0.48-jre8 +COPY target/logging-demo-*-SNAPSHOT.war /usr/local/tomcat/webapps/logging-demo.war diff --git a/reference/logging-docker-root/logging-docker-demo-service/build.sh b/reference/logging-docker-root/logging-docker-demo-service/build.sh new file mode 100755 index 0000000..247b1ee --- /dev/null +++ b/reference/logging-docker-root/logging-docker-demo-service/build.sh @@ -0,0 +1,31 @@ +#!/bin/bash +############################################################################# +# +# Copyright © 2018 Amdocs. +# +# 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. +# +############################################################################# +# v20180625 +# https://wiki.onap.org/display/DW/Cloud+Native+Deployment +# source from https://jira.onap.org/browse/LOG-135 +# Michael O'Brien + +mkdir target +# reuse the same war for the service pods +cp ../../logging-demo/target/*.war target +docker build -t oomk8s/logging-demo-service -f DockerFile . +docker images | grep logging-demo-service +docker tag oomk8s/logging-demo-service oomk8s/logging-demo-service:0.0.3 +docker login +docker push oomk8s/logging-demo-service:0.0.3 +#docker run -d -it --rm -p 8888:8080 oomk8s/logging-demo-service:latest diff --git a/reference/logging-docker-root/logging-docker-demo/DockerFile b/reference/logging-docker-root/logging-docker-demo/DockerFile index b3d68f0..bb9a7cf 100644 --- a/reference/logging-docker-root/logging-docker-demo/DockerFile +++ b/reference/logging-docker-root/logging-docker-demo/DockerFile @@ -1,2 +1,2 @@ FROM tomcat:8.0.48-jre8 -COPY target/logging-demo-1.2.0-SNAPSHOT.war /usr/local/tomcat/webapps/logging-demo.war +COPY target/logging-demo-*-SNAPSHOT.war /usr/local/tomcat/webapps/logging-demo.war diff --git a/reference/logging-docker-root/logging-docker-demo/build.sh b/reference/logging-docker-root/logging-docker-demo/build.sh index d2e0ea2..491c64c 100755 --- a/reference/logging-docker-root/logging-docker-demo/build.sh +++ b/reference/logging-docker-root/logging-docker-demo/build.sh @@ -1,8 +1,31 @@ +#!/bin/bash +############################################################################# +# +# Copyright © 2018 Amdocs. +# +# 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. +# +############################################################################# +# v20180625 +# https://wiki.onap.org/display/DW/Cloud+Native+Deployment +# source from https://jira.onap.org/browse/LOG-135 +# Michael O'Brien + + mkdir target cp ../../logging-demo/target/*.war target docker build -t oomk8s/logging-demo-nbi -f DockerFile . docker images | grep logging-demo-nbi -docker tag oomk8s/logging-demo-nbi oomk8s/logging-demo-nbi:0.0.1 +docker tag oomk8s/logging-demo-nbi oomk8s/logging-demo-nbi:0.0.3 docker login -docker push oomk8s/logging-demo-nbi:0.0.1 +docker push oomk8s/logging-demo-nbi:0.0.3 #docker run -d -it --rm -p 8888:8080 oomk8s/logging-demo-nbi:latest diff --git a/reference/logging-docker-root/pom.xml b/reference/logging-docker-root/pom.xml index 771856e..42239a6 100644 --- a/reference/logging-docker-root/pom.xml +++ b/reference/logging-docker-root/pom.xml @@ -4,7 +4,7 @@ org.onap.logging-analytics logging-reference - 1.2.0-SNAPSHOT + 1.2.2-SNAPSHOT logging-docker-root pom diff --git a/reference/logging-kubernetes/logdemo/templates/all-services.yaml b/reference/logging-kubernetes/logdemo/templates/all-services.yaml index 9e4f694..dc57183 100644 --- a/reference/logging-kubernetes/logdemo/templates/all-services.yaml +++ b/reference/logging-kubernetes/logdemo/templates/all-services.yaml @@ -2,13 +2,13 @@ apiVersion: v1 kind: Service metadata: labels: - app: logdemo - name: logdemo - namespace: "{{ .Values.nsPrefix }}-logdemo" + app: logservice + name: logservice + namespace: "{{ .Values.nsPrefix }}-logservice" spec: ports: - port: 8080 - nodePort: {{ .Values.nodePortPrefix }}99 + nodePort: {{ .Values.nodePortPrefix }}98 selector: - app: logdemo + app: logservice type: NodePort diff --git a/reference/logging-kubernetes/logdemo/templates/log-mock-demo-deployment.yaml b/reference/logging-kubernetes/logdemo/templates/log-mock-demo-deployment.yaml deleted file mode 100644 index afd513e..0000000 --- a/reference/logging-kubernetes/logdemo/templates/log-mock-demo-deployment.yaml +++ /dev/null @@ -1,43 +0,0 @@ -#{{ if not .Values.disableLogdemoLogdemo }} -apiVersion: extensions/v1beta1 -kind: Deployment -metadata: - name: logdemo - namespace: "{{ .Values.nsPrefix }}-logdemo" -spec: - selector: - matchLabels: - app: logdemo - template: - metadata: - labels: - app: logdemo - name: logdemo - spec: - containers: - - image: {{ .Values.image.logdemo }} - imagePullPolicy: {{ .Values.pullPolicy }} - name: logdemo - volumeMounts: - - name: localtime - mountPath: /etc/localtime - readOnly: true - - name: logdemo-eteshare - mountPath: /share - ports: - - containerPort: 8080 - readinessProbe: - tcpSocket: - port: 8080 - initialDelaySeconds: 5 - periodSeconds: 10 - volumes: - - name: localtime - hostPath: - path: /etc/localtime - - name: logdemo-eteshare - hostPath: - path: /dockerdata-nfs/{{ .Values.nsPrefix }}/logdemo/eteshare - imagePullSecrets: - - name: "{{ .Values.nsPrefix }}-docker-registry-key" -#{{ end }} diff --git a/reference/logging-kubernetes/logdemo/templates/log-mock-service-deployment.yaml b/reference/logging-kubernetes/logdemo/templates/log-mock-service-deployment.yaml new file mode 100644 index 0000000..92bcbe8 --- /dev/null +++ b/reference/logging-kubernetes/logdemo/templates/log-mock-service-deployment.yaml @@ -0,0 +1,43 @@ +#{{ if not .Values.disableLogserviceLogservice }} +apiVersion: extensions/v1beta1 +kind: Deployment +metadata: + name: logservice + namespace: "{{ .Values.nsPrefix }}-logservice" +spec: + selector: + matchLabels: + app: logservice + template: + metadata: + labels: + app: logservice + name: logservice + spec: + containers: + - image: {{ .Values.image.logservice }} + imagePullPolicy: {{ .Values.pullPolicy }} + name: logservice + volumeMounts: + - name: localtime + mountPath: /etc/localtime + readOnly: true + - name: logservice-eteshare + mountPath: /share + ports: + - containerPort: 8080 + readinessProbe: + tcpSocket: + port: 8080 + initialDelaySeconds: 5 + periodSeconds: 10 + volumes: + - name: localtime + hostPath: + path: /etc/localtime + - name: logservice-eteshare + hostPath: + path: /dockerdata-nfs/{{ .Values.nsPrefix }}/logservice/eteshare + imagePullSecrets: + - name: "{{ .Values.nsPrefix }}-docker-registry-key" +#{{ end }} diff --git a/reference/logging-kubernetes/logdemo/values.yaml b/reference/logging-kubernetes/logdemo/values.yaml index 53e3fc6..a13dbe3 100644 --- a/reference/logging-kubernetes/logdemo/values.yaml +++ b/reference/logging-kubernetes/logdemo/values.yaml @@ -3,5 +3,5 @@ pullPolicy: Always nodePortPrefix: 302 image: readiness: oomk8s/readiness-check:1.0.0 - logdemo: oomk8s/logging-demo-nbi:0.0.1 + logdemo: oomk8s/logging-demo-nbi:0.0.2 filebeat: docker.elastic.co/beats/filebeat:5.5.0 diff --git a/reference/logging-kubernetes/logdemoservice/Chart.yaml b/reference/logging-kubernetes/logdemoservice/Chart.yaml new file mode 100644 index 0000000..b9eed13 --- /dev/null +++ b/reference/logging-kubernetes/logdemoservice/Chart.yaml @@ -0,0 +1,4 @@ +apiVersion: v1 +description: A Helm chart for Kubernetes +name: logdemoservice +version: 0.1.0 diff --git a/reference/logging-kubernetes/logdemoservice/templates/all-services.yaml b/reference/logging-kubernetes/logdemoservice/templates/all-services.yaml new file mode 100644 index 0000000..10b7109 --- /dev/null +++ b/reference/logging-kubernetes/logdemoservice/templates/all-services.yaml @@ -0,0 +1,14 @@ +apiVersion: v1 +kind: Service +metadata: + labels: + app: logdemoservice + name: logdemoservice + namespace: "{{ .Values.nsPrefix }}-logdemoservice" +spec: + ports: + - port: 8080 + nodePort: {{ .Values.nodePortPrefix }}98 + selector: + app: logdemoservice + type: NodePort diff --git a/reference/logging-kubernetes/logdemoservice/templates/log-mock-demo-service-deployment.yaml b/reference/logging-kubernetes/logdemoservice/templates/log-mock-demo-service-deployment.yaml new file mode 100644 index 0000000..f40da2f --- /dev/null +++ b/reference/logging-kubernetes/logdemoservice/templates/log-mock-demo-service-deployment.yaml @@ -0,0 +1,57 @@ +#{{ if not .Values.disableLogdemoserviceLogdemoservice }} +apiVersion: extensions/v1beta1 +kind: Deployment +metadata: + name: logdemoservice + namespace: "{{ .Values.nsPrefix }}-logdemoservice" +spec: + selector: + matchLabels: + app: logdemoservice + template: + metadata: + labels: + app: logdemoservice + name: logdemoservice + spec: + containers: + - image: {{ .Values.image.logdemoservice }} + imagePullPolicy: {{ .Values.pullPolicy }} + name: logdemoservice + volumeMounts: + - mountPath: /var/log/onap + name: log-mock-demo-service-logs + ports: + - containerPort: 8080 + readinessProbe: + tcpSocket: + port: 8080 + initialDelaySeconds: 5 + periodSeconds: 10 + - image: {{ .Values.image.filebeat }} + imagePullPolicy: {{ .Values.pullPolicy }} + name: filebeat-onap + volumeMounts: + - mountPath: /usr/share/filebeat/filebeat.yml + name: filebeat-conf + - mountPath: /var/log/onap + name: log-mock-demo-service-logs + - mountPath: /usr/share/filebeat/data + name: log-mock-demo-service-data-filebeat + volumes: + - name: filebeat-conf + hostPath: + path: /dockerdata-nfs/{{ .Values.nsPrefix }}/log/filebeat/logback/filebeat.yml + - name: log-mock-demo-service-logs + emptyDir: {} + - name: log-mock-demo-service-data-filebeat + emptyDir: {} + - name: localtime + hostPath: + path: /etc/localtime + - name: logdemoservice-eteshare + hostPath: + path: /dockerdata-nfs/{{ .Values.nsPrefix }}/logdemoservice/eteshare + imagePullSecrets: + - name: "{{ .Values.nsPrefix }}-docker-registry-key" +#{{ end }} diff --git a/reference/logging-kubernetes/logdemoservice/values.yaml b/reference/logging-kubernetes/logdemoservice/values.yaml new file mode 100644 index 0000000..3b89a4b --- /dev/null +++ b/reference/logging-kubernetes/logdemoservice/values.yaml @@ -0,0 +1,7 @@ +nsPrefix: onap +pullPolicy: Always +nodePortPrefix: 302 +image: + readiness: oomk8s/readiness-check:1.0.0 + logdemoservice: oomk8s/logging-demo-service:0.0.1 + filebeat: docker.elastic.co/beats/filebeat:5.5.0 diff --git a/reference/logging-kubernetes/pom.xml b/reference/logging-kubernetes/pom.xml index 6f32c54..1042811 100644 --- a/reference/logging-kubernetes/pom.xml +++ b/reference/logging-kubernetes/pom.xml @@ -4,7 +4,7 @@ org.onap.logging-analytics logging-reference - 1.2.0-SNAPSHOT + 1.2.2-SNAPSHOT logging-kubernetes pom diff --git a/reference/logging-library/pom.xml b/reference/logging-library/pom.xml index 74e3a7c..ed07037 100644 --- a/reference/logging-library/pom.xml +++ b/reference/logging-library/pom.xml @@ -3,7 +3,7 @@ org.onap.logging-analytics logging-reference - 1.2.0-SNAPSHOT + 1.2.2-SNAPSHOT logging-library @@ -60,5 +60,10 @@ + + org.onap.logging-analytics + logging-slf4j + 1.2.2-SNAPSHOT + diff --git a/reference/logging-mock-service/pom.xml b/reference/logging-mock-service/pom.xml index 7777b5a..f6264b1 100644 --- a/reference/logging-mock-service/pom.xml +++ b/reference/logging-mock-service/pom.xml @@ -3,7 +3,7 @@ org.onap.logging-analytics logging-reference - 1.2.0-SNAPSHOT + 1.2.2-SNAPSHOT logging-mock-service jar @@ -62,8 +62,12 @@ org.onap.logging-analytics logging-library - 1.2.0-SNAPSHOT + 1.2.2-SNAPSHOT + + + org.onap.logging-analytics + logging-slf4j + 1.2.2-SNAPSHOT - diff --git a/reference/logging-slf4j-demo/pom.xml b/reference/logging-slf4j-demo/pom.xml index c4542b3..8565948 100644 --- a/reference/logging-slf4j-demo/pom.xml +++ b/reference/logging-slf4j-demo/pom.xml @@ -3,14 +3,12 @@ org.onap.logging-analytics logging-reference - 1.2.0-SNAPSHOT + 1.2.2-SNAPSHOT .. logging-slf4j-demo logging-slf4j-demo war - 1.2.0-SNAPSHOT - 1.5.10.RELEASE diff --git a/reference/logging-slf4j/pom.xml b/reference/logging-slf4j/pom.xml index 9cc9d4b..138f7de 100644 --- a/reference/logging-slf4j/pom.xml +++ b/reference/logging-slf4j/pom.xml @@ -3,14 +3,12 @@ org.onap.logging-analytics logging-reference - 1.2.0-SNAPSHOT + 1.2.2-SNAPSHOT .. logging-slf4j logging-slf4j jar - 1.2.0-SNAPSHOT - diff --git a/reference/logging-slf4j/src/main/java/org/onap/logging/ref/slf4j/ONAPLogAdapter.java b/reference/logging-slf4j/src/main/java/org/onap/logging/ref/slf4j/ONAPLogAdapter.java index d26cd13..aafc74d 100644 --- a/reference/logging-slf4j/src/main/java/org/onap/logging/ref/slf4j/ONAPLogAdapter.java +++ b/reference/logging-slf4j/src/main/java/org/onap/logging/ref/slf4j/ONAPLogAdapter.java @@ -333,7 +333,8 @@ public class ONAPLogAdapter { // Default the service name to the requestURI, in the event that // no value has been provided. - if (MDC.get(ONAPLogConstants.MDCs.SERVICE_NAME) == null) { + if (MDC.get(ONAPLogConstants.MDCs.SERVICE_NAME) == null || + MDC.get(ONAPLogConstants.MDCs.SERVICE_NAME).equalsIgnoreCase(EMPTY_MESSAGE)) { MDC.put(ONAPLogConstants.MDCs.SERVICE_NAME, request.getRequestURI()); } diff --git a/reference/logging-slf4j/src/test/java/org/onap/logging/ref/slf4j/ONAPLogAdapterTest.java b/reference/logging-slf4j/src/test/java/org/onap/logging/ref/slf4j/ONAPLogAdapterTest.java index b14df9f..1d11bd3 100644 --- a/reference/logging-slf4j/src/test/java/org/onap/logging/ref/slf4j/ONAPLogAdapterTest.java +++ b/reference/logging-slf4j/src/test/java/org/onap/logging/ref/slf4j/ONAPLogAdapterTest.java @@ -166,6 +166,47 @@ public class ONAPLogAdapterTest { MDC.clear(); } } + + /** + * Test ENTERING with an EMPTY_STRING serviceName. + */ + @Test + public void testEnteringWithEMPTY_STRING_serviceName() { + + final Logger logger = LoggerFactory.getLogger(this.getClass()); + final ONAPLogAdapter adapter = new ONAPLogAdapter(logger); + final MockHttpServletRequest http = new MockHttpServletRequest(); + http.setRequestURI("uri123"); + http.setServerName("local123"); + http.setRemoteAddr("remote123"); + http.addHeader("X-ONAP-RequestID", "request123"); + http.addHeader("X-ONAP-InvocationID", "invocation123"); + http.addHeader("X-ONAP-PartnerName", "partner123"); + + try { + // an empty string should kick in setting the actual service name (treated same as null) + adapter.getServiceDescriptor().setServiceName(""); + adapter.entering(http); + final Map mdcs = MDC.getCopyOfContextMap(); + assertThat(mdcs.get("RequestID"), is("request123")); + assertThat(mdcs.get("InvocationID"), is("invocation123")); + assertThat(mdcs.get("PartnerName"), is("partner123")); + assertThat(mdcs.get("ServiceName"), is("uri123")); + assertThat(mdcs.get("ServerFQDN"), is("local123")); + assertThat(mdcs.get("ClientIPAddress"), is("remote123")); + + // Timestamp format and value: + + final String invokeTimestampString = mdcs.get("InvokeTimestamp"); + assertThat(invokeTimestampString, notNullValue()); + assertThat(invokeTimestampString, endsWith("Z")); + final long invokeTimestamp = DatatypeConverter.parseDateTime(invokeTimestampString).getTimeInMillis(); + assertThat(Math.abs(System.currentTimeMillis() - invokeTimestamp), lessThan(5000L)); + } + finally { + MDC.clear(); + } + } @Test public void testSetServiceDescriptor() { diff --git a/reference/pom.xml b/reference/pom.xml index 7bb5f64..0844c9a 100644 --- a/reference/pom.xml +++ b/reference/pom.xml @@ -4,7 +4,7 @@ org.onap.logging-analytics logging-analytics - 1.2.0-SNAPSHOT + 1.2.2-SNAPSHOT logging-reference pom -- cgit 1.2.3-korg