MokuLakshithReddy commented on code in PR #149:
URL:
https://github.com/apache/fineract-consumer-facing/pull/149#discussion_r4178962802
##########
consumer/src/main/java/org/apache/fineract/consumer/infrastructure/audit/data/NonTransactionalAuditEvent.java:
##########
@@ -39,10 +40,19 @@ public final class NonTransactionalAuditEvent {
private final boolean unknownPrincipal;
private final String deviceFingerprint;
private final Map<String, Object> details;
+ private final String correlationId;
public static NonTransactionalAuditEvent of(AuditEventType eventType, Long
userId,
boolean unknownPrincipal, String deviceFingerprint, Map<String,
Object> details) {
+ return of(eventType, userId, unknownPrincipal, deviceFingerprint,
details,
+ CorrelationIdHolder.getCurrentCorrelationId());
Review Comment:
Resolved! Captured CorrelationIdHolder.getCurrentCorrelationId() on the
request thread before delegating to pplicationTaskExecutor.execute, and passed
it directly to NonTransactionalAuditEvent.of(..., correlationId) so the event
retains the originating request's correlation context.
##########
consumer/src/test/java/org/apache/fineract/consumer/infrastructure/correlation/service/CorrelationIdHolderTest.java:
##########
@@ -0,0 +1,62 @@
+/*
+ * 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.consumer.infrastructure.correlation.service;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+import org.junit.jupiter.api.Test;
+
+class CorrelationIdHolderTest {
+
+ private final CorrelationIdHolder holder = new CorrelationIdHolder();
Review Comment:
Resolved! Added @BeforeEach and @AfterEach teardown hooks calling
holder.clear() in CorrelationIdHolderTest to prevent any test state pollution.
##########
consumer/src/test/java/org/apache/fineract/consumer/infrastructure/fineractclient/interceptors/FineractCorrelationIdInterceptorTest.java:
##########
@@ -0,0 +1,82 @@
+/*
+ * 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.consumer.infrastructure.fineractclient.interceptors;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+import feign.Request;
+import feign.RequestTemplate;
+import
org.apache.fineract.consumer.infrastructure.correlation.service.CorrelationIdHolder;
+import
org.apache.fineract.consumer.infrastructure.fineractclient.data.FineractHeaders;
+import org.junit.jupiter.api.Test;
+
+class FineractCorrelationIdInterceptorTest {
+
+ private static final String TEST_CORRELATION_ID =
"c6b8c9d1-0000-4000-8000-000000000001";
+
+ private final CorrelationIdHolder holder = new CorrelationIdHolder();
+ private final FineractCorrelationIdInterceptor interceptor = new
FineractCorrelationIdInterceptor(holder);
Review Comment:
Resolved! Added @BeforeEach and @AfterEach teardown hooks calling
holder.clear() in FineractCorrelationIdInterceptorTest to eliminate cross-test
state leakage.
##########
frontend/src/app/core/interceptors/correlation-id.interceptor.ts:
##########
@@ -0,0 +1,47 @@
+/*
+ * 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.
+ */
+
+import { HttpInterceptorFn } from '@angular/common/http';
+
+export function generateCorrelationId(): string {
+ if (typeof crypto !== 'undefined' && typeof crypto.randomUUID ===
'function') {
+ return crypto.randomUUID();
+ }
+ return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, (c) => {
+ const r = (Math.random() * 16) | 0;
+ const v = c === 'x' ? r : (r & 0x3) | 0x8;
+ return v.toString(16);
+ });
+}
+
+export const correlationIdInterceptor: HttpInterceptorFn = (req, next) => {
+ if (!req.url.startsWith('/api')) {
+ return next(req);
Review Comment:
Resolved! Updated AuditService.flush() in
rontend/src/app/core/audit/audit.service.ts to include 'X-Correlation-ID':
generateCorrelationId() in the native etch headers, ensuring client audit
batches carry correlation headers.
--
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]