galovics commented on code in PR #2389:
URL: https://github.com/apache/fineract/pull/2389#discussion_r909533394


##########
fineract-provider/src/main/java/org/apache/fineract/infrastructure/core/filters/CorrelationHeaderFilter.java:
##########
@@ -0,0 +1,78 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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 org.apache.fineract.infrastructure.core.filters;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import org.slf4j.MDC;
+
+import lombok.RequiredArgsConstructor;
+
+import javax.servlet.Filter;
+import javax.servlet.FilterChain;
+import javax.servlet.FilterConfig;
+import javax.servlet.ServletException;
+import javax.servlet.ServletRequest;
+import javax.servlet.ServletResponse;
+import javax.servlet.http.HttpServletRequest;
+import java.io.IOException;
+import java.util.UUID;
+
+@RequiredArgsConstructor
+public class CorrelationHeaderFilter implements Filter {
+       
+    private static final Logger LOGGER = 
LoggerFactory.getLogger(CorrelationHeaderFilter.class);

Review Comment:
   Let's switch this with Lombok's `@Slf4j` annotation.



##########
fineract-provider/src/main/java/org/apache/fineract/infrastructure/core/filters/CorrelationHeaderFilter.java:
##########
@@ -0,0 +1,78 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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 org.apache.fineract.infrastructure.core.filters;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import org.slf4j.MDC;
+
+import lombok.RequiredArgsConstructor;
+
+import javax.servlet.Filter;
+import javax.servlet.FilterChain;
+import javax.servlet.FilterConfig;
+import javax.servlet.ServletException;
+import javax.servlet.ServletRequest;
+import javax.servlet.ServletResponse;
+import javax.servlet.http.HttpServletRequest;
+import java.io.IOException;
+import java.util.UUID;
+
+@RequiredArgsConstructor
+public class CorrelationHeaderFilter implements Filter {

Review Comment:
   We could turn this into a simple OncePerRequestFilter and attach the 
conditional bean creation here. Thoughts?



##########
fineract-provider/src/test/resources/application-test.properties:
##########
@@ -37,6 +37,9 @@ fineract.mode.read-enabled=true
 fineract.mode.write-enabled=true
 fineract.mode.batch-enabled=true
 
+fineract.logging.http.correlation-id.enabled=true

Review Comment:
   False here too please.



##########
fineract-war/setenv.sh:
##########
@@ -53,3 +53,5 @@ export FINERACT_DEFAULT_TENANTDB_TIMEZONE="Asia/Kolkata"
 export FINERACT_DEFAULT_TENANTDB_IDENTIFIER="default"
 export FINERACT_DEFAULT_TENANTDB_NAME="fineract_default"
 export FINERACT_DEFAULT_TENANTDB_DESCRIPTION="Default Demo Tenant"
+export FINERACT_LOGGING_HTTP_CORRELATION_ID_ENABLED="true"

Review Comment:
   False here too please.



##########
fineract-provider/src/main/resources/application.properties:
##########
@@ -40,6 +40,9 @@ 
fineract.mode.write-enabled=${FINERACT_MODE_WRITE_ENABLED:true}
 fineract.mode.batch-worker-enabled=${FINERACT_MODE_BATCH_WORKER_ENABLED:true}
 fineract.mode.batch-manager-enabled=${FINERACT_MODE_BATCH_MANAGER_ENABLED:true}
 
+fineract.logging.http.correlation-id.enabled=${FINERACT_LOGGING_HTTP_CORRELATION_ID_ENABLED:true}

Review Comment:
   Let's keep the default as ˙false`



##########
fineract-provider/src/main/java/org/apache/fineract/infrastructure/core/filters/CorrelationHeaderFilter.java:
##########
@@ -0,0 +1,78 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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 org.apache.fineract.infrastructure.core.filters;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import org.slf4j.MDC;
+
+import lombok.RequiredArgsConstructor;
+
+import javax.servlet.Filter;
+import javax.servlet.FilterChain;
+import javax.servlet.FilterConfig;
+import javax.servlet.ServletException;
+import javax.servlet.ServletRequest;
+import javax.servlet.ServletResponse;
+import javax.servlet.http.HttpServletRequest;
+import java.io.IOException;
+import java.util.UUID;
+
+@RequiredArgsConstructor
+public class CorrelationHeaderFilter implements Filter {
+       
+    private static final Logger LOGGER = 
LoggerFactory.getLogger(CorrelationHeaderFilter.class);
+    
+   
+    @Override
+    public void init(FilterConfig filterConfig) throws ServletException {
+        //TODO        
+    }
+
+    @Override
+    public void doFilter(ServletRequest servletRequest, ServletResponse 
servletResponse, FilterChain filterChain)
+            throws IOException, ServletException {
+                
+        LOGGER.info("CORRELATION_ID_HEADER : " + 
RequestCorrelation.CORRELATION_ID_HEADER);
+
+        final HttpServletRequest httpServletRequest = (HttpServletRequest) 
servletRequest;
+        
+        String currentCorrId = httpServletRequest.getHeader( 
RequestCorrelation.CORRELATION_ID_HEADER);
+
+        if (currentCorrId == null) {
+            currentCorrId = UUID.randomUUID().toString();
+            LOGGER.info("No correlationId found in Header. Generated : " + 
currentCorrId);
+        } else {
+            LOGGER.info("Found correlationId in Header : " + 
currentCorrId.replaceAll("[\r\n]","") );

Review Comment:
   This is good but let's keep it on debug level and use log parameters instead 
of concatenating the string.



##########
fineract-provider/src/main/java/org/apache/fineract/infrastructure/core/filters/RequestCorrelation.java:
##########
@@ -0,0 +1,66 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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 org.apache.fineract.infrastructure.core.filters;
+
+import org.springframework.http.HttpHeaders;
+
+public class RequestCorrelation {

Review Comment:
   I don't think we'll need access to the correlation ID down the service 
level, so we don't really need this class.



##########
docker-compose.yml:
##########
@@ -21,22 +21,8 @@
 version: '3.7'
 services:
   # Backend service
-  fineractmysql:
-    image: mariadb:10.8
-    volumes:
-      - 
./fineract-db/server_collation.cnf:/etc/mysql/conf.d/server_collation.cnf
-      - ./fineract-db/docker:/docker-entrypoint-initdb.d:Z,ro
-    restart: always
-    environment:
-      MYSQL_ROOT_PASSWORD: skdcnwauicn2ucnaecasdsajdnizucawencascdca
-    healthcheck:
-      test: ["CMD", "mysqladmin" ,"ping", "-h", "localhost", 
"--password=skdcnwauicn2ucnaecasdsajdnizucawencascdca" ]
-      timeout: 10s
-      retries: 10
-    ports:
-      - "3306:3306"
   fineract-server:
-    image: fineract:latest
+    image: fineract:1.6.1-62689eb6

Review Comment:
   I assume most of these changes you're going to revert, right?



##########
fineract-provider/src/main/resources/logback-spring.xml:
##########
@@ -32,7 +32,7 @@
 
     <!-- See https://github.com/apache/fineract/#logging-guidelines for why by 
default we log only to INFO, only (WARN and) ERROR
          but it's still possible to override this using java 
-Dlogging.level.root=info -jar fineract-provider.jar, as per 
https://docs.spring.io/spring-boot/docs/current/reference/html/spring-boot-features.html#boot-features-custom-log-levels
 -->
-    <root level="info">
+    <root level="debug">

Review Comment:
   I guess this is just an accident.



##########
fineract-provider/src/main/java/org/apache/fineract/infrastructure/core/filters/CorrelationHeaderFilter.java:
##########
@@ -0,0 +1,78 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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 org.apache.fineract.infrastructure.core.filters;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import org.slf4j.MDC;
+
+import lombok.RequiredArgsConstructor;
+
+import javax.servlet.Filter;
+import javax.servlet.FilterChain;
+import javax.servlet.FilterConfig;
+import javax.servlet.ServletException;
+import javax.servlet.ServletRequest;
+import javax.servlet.ServletResponse;
+import javax.servlet.http.HttpServletRequest;
+import java.io.IOException;
+import java.util.UUID;
+
+@RequiredArgsConstructor
+public class CorrelationHeaderFilter implements Filter {
+       
+    private static final Logger LOGGER = 
LoggerFactory.getLogger(CorrelationHeaderFilter.class);
+    
+   
+    @Override
+    public void init(FilterConfig filterConfig) throws ServletException {
+        //TODO        
+    }
+
+    @Override
+    public void doFilter(ServletRequest servletRequest, ServletResponse 
servletResponse, FilterChain filterChain)
+            throws IOException, ServletException {
+                
+        LOGGER.info("CORRELATION_ID_HEADER : " + 
RequestCorrelation.CORRELATION_ID_HEADER);
+
+        final HttpServletRequest httpServletRequest = (HttpServletRequest) 
servletRequest;
+        
+        String currentCorrId = httpServletRequest.getHeader( 
RequestCorrelation.CORRELATION_ID_HEADER);
+
+        if (currentCorrId == null) {
+            currentCorrId = UUID.randomUUID().toString();

Review Comment:
   I don't think we need to generate new correlation IDs,  at least not now 
anyway. Simply skip putting it into the MDC context.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to