Skip to content

Commit

Permalink
DATAGO-63031: Fix logging of traceId, actorId and orgId so it's consi…
Browse files Browse the repository at this point in the history
…stent between EMA and EP (#125)
  • Loading branch information
gregmeldrum authored Oct 18, 2023
1 parent 81a453b commit cff50bc
Show file tree
Hide file tree
Showing 35 changed files with 155 additions and 75 deletions.
30 changes: 24 additions & 6 deletions service/application/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
<properties>
<springdoc.version>1.6.11</springdoc.version>
<snakeyaml.version>2.0</snakeyaml.version>
<spring-cloud-starter-sleuth.version>3.1.5</spring-cloud-starter-sleuth.version>
<spring-security-rsa.version>1.1.1</spring-security-rsa.version>
<spring-kafka.version>3.0.10</spring-kafka.version>
<kafka-clients.version>3.5.0</kafka-clients.version>
Expand Down Expand Up @@ -63,11 +62,6 @@
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-sleuth</artifactId>
<version>${spring-cloud-starter-sleuth.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-rsa</artifactId>
Expand Down Expand Up @@ -283,6 +277,30 @@
<version>1.1.2-SNAPSHOT</version>
</dependency>

<dependency>
<groupId>io.micrometer</groupId>
<artifactId>micrometer-tracing-bridge-brave</artifactId>
<!--version>1.1.1</version-->
</dependency>
<dependency>
<groupId>io.micrometer</groupId>
<artifactId>context-propagation</artifactId>
<version>1.0.3</version>
</dependency>
<dependency>
<groupId>io.micrometer</groupId>
<artifactId>micrometer-observation</artifactId>
</dependency>
<dependency>
<groupId>io.micrometer</groupId>
<artifactId>micrometer-observation-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>

<!-- for testing -->
<dependency>
<groupId>org.hamcrest</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@ public class ScanDataImportMessage extends MOPMessage {

String scanId;

String traceId;

String messagingServiceId;

String runtimeAgentId;
Expand All @@ -37,10 +35,10 @@ public ScanDataImportMessage(String orgId, String scanId, String traceId, String

this.orgId = orgId;
this.scanId = scanId;
this.traceId = traceId;
this.messagingServiceId = messagingServiceId;
this.runtimeAgentId = runtimeAgentId;
this.scanTypes = scanTypes;
setTraceId(traceId);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,13 @@ public class ScanDataMessage extends MOPMessage {

String scanId;

String traceId;

String scanType;

String data;

private String timestamp;

public ScanDataMessage(String orgId, String scanId, String traceId, String scanType, String data, String timestamp) {
public ScanDataMessage(String orgId, String scanId, String traceId, String actorId, String scanType, String data, String timestamp) {
super();
withMessageType(MOPMessageType.generic)
.withProtocol(MOPProtocol.scanData)
Expand All @@ -29,10 +27,11 @@ public ScanDataMessage(String orgId, String scanId, String traceId, String scanT

this.orgId = orgId;
this.scanId = scanId;
this.traceId = traceId;
this.scanType = scanType;
this.data = data;
this.timestamp = timestamp;
setTraceId(traceId);
setActorId(actorId);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,13 @@ public class ScanDataStatusMessage extends MOPMessage {

String scanId;

String traceId;

String status;

String description;

String scanType;

public ScanDataStatusMessage(String orgId, String scanId, String traceId, String status, String description, String scanType) {
public ScanDataStatusMessage(String orgId, String scanId, String traceId, String actorId, String status, String description, String scanType) {
super();
withMessageType(MOPMessageType.generic)
.withProtocol(MOPProtocol.scanDataControl)
Expand All @@ -33,10 +31,11 @@ public ScanDataStatusMessage(String orgId, String scanId, String traceId, String

this.orgId = orgId;
this.scanId = scanId;
this.traceId = traceId;
this.status = status;
this.description = description;
this.scanType = scanType;
setTraceId(traceId);
setActorId(actorId);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,13 @@ public class ScanLogMessage extends MOPMessage {

String scanId;

String traceId;

String level;

String log;

Long timestamp;

public ScanLogMessage(String orgId, String scanId, String traceId, String level, String log, Long timestamp) {
public ScanLogMessage(String orgId, String scanId, String traceId, String actorId, String level, String log, Long timestamp) {
super();
withMessageType(MOPMessageType.generic)
.withProtocol(MOPProtocol.scanDataControl)
Expand All @@ -29,10 +27,11 @@ public ScanLogMessage(String orgId, String scanId, String traceId, String level,

this.orgId = orgId;
this.scanId = scanId;
this.traceId = traceId;
this.level = level;
this.log = log;
this.timestamp = timestamp;
setTraceId(traceId);
setActorId(actorId);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,13 @@ public class ScanStatusMessage extends MOPMessage {

String scanId;

String traceId;

String status;

String description;

private List<String> scanTypes;

public ScanStatusMessage(String orgId, String scanId, String traceId, String status, String description, List<String> scanTypes) {
public ScanStatusMessage(String orgId, String scanId, String traceId, String actorId, String status, String description, List<String> scanTypes) {
super();
withMessageType(MOPMessageType.generic)
.withProtocol(MOPProtocol.scanDataControl)
Expand All @@ -35,10 +33,11 @@ public ScanStatusMessage(String orgId, String scanId, String traceId, String sta

this.orgId = orgId;
this.scanId = scanId;
this.traceId = traceId;
this.status = status;
this.description = description;
this.scanTypes = scanTypes;
setTraceId(traceId);
setActorId(actorId);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@

import ch.qos.logback.classic.spi.ILoggingEvent;
import ch.qos.logback.core.AppenderBase;
import com.solace.maas.ep.event.management.agent.repository.model.route.RouteEntity;
import com.solace.maas.ep.event.management.agent.plugin.constants.RouteConstants;
import com.solace.maas.ep.event.management.agent.plugin.manager.loader.PluginLoader;
import com.solace.maas.ep.event.management.agent.plugin.route.RouteBundle;
import com.solace.maas.ep.event.management.agent.plugin.route.handler.base.MessagingServiceRouteDelegate;
import com.solace.maas.ep.event.management.agent.repository.model.route.RouteEntity;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.extern.slf4j.Slf4j;
Expand All @@ -30,20 +30,23 @@ protected void append(ILoggingEvent event) {
sendLogsAsync(event,
event.getMDCPropertyMap().get(RouteConstants.SCAN_ID),
event.getMDCPropertyMap().get(RouteConstants.TRACE_ID),
event.getMDCPropertyMap().get(RouteConstants.ACTOR_ID),
event.getMDCPropertyMap().get(RouteConstants.SCAN_TYPE),
event.getMDCPropertyMap().get(RouteConstants.SCHEDULE_ID),
event.getMDCPropertyMap().get(RouteConstants.MESSAGING_SERVICE_ID));
}
}
}

public void sendLogsAsync(ILoggingEvent event, String scanId, String traceId, String scanType, String groupId, String messagingServiceId) {
public void sendLogsAsync(ILoggingEvent event, String scanId, String traceId, String actorId,
String scanType, String groupId, String messagingServiceId) {
RouteEntity route = creatLoggingRoute(scanType, messagingServiceId);

producerTemplate.asyncSend(route.getId(), exchange -> {
// Need to set headers to let the Route have access to the Scan ID, Group ID, and Messaging Service ID.
exchange.getIn().setHeader(RouteConstants.SCAN_ID, scanId);
exchange.getIn().setHeader(RouteConstants.TRACE_ID, traceId);
exchange.getIn().setHeader(RouteConstants.ACTOR_ID, actorId);
exchange.getIn().setHeader(RouteConstants.SCAN_TYPE, scanType);
exchange.getIn().setHeader(RouteConstants.SCHEDULE_ID, groupId);
exchange.getIn().setHeader(RouteConstants.MESSAGING_SERVICE_ID, messagingServiceId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import lombok.extern.slf4j.Slf4j;
import org.apache.camel.Exchange;
import org.apache.camel.Processor;
import org.slf4j.MDC;
import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression;
import org.springframework.stereotype.Component;

Expand All @@ -23,6 +24,7 @@ public class ScanDataImportParseMetaInfFileProcessor implements Processor {
public void process(Exchange exchange) throws Exception {
MetaInfFileBO metaInfFileBO = exchange.getIn().getBody(MetaInfFileBO.class);
String traceId = (String) exchange.getProperty(TRACE_ID);
MDC.put(TRACE_ID, traceId);

exchange.getIn().setHeader(RouteConstants.SCAN_ID, metaInfFileBO.getScanId());
exchange.getIn().setHeader(RouteConstants.MESSAGING_SERVICE_ID, metaInfFileBO.getMessagingServiceId());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,11 @@ public void process(Exchange exchange) throws Exception {
String messagingServiceId = (String) properties.get(RouteConstants.MESSAGING_SERVICE_ID);
String scanId = (String) properties.get(RouteConstants.SCAN_ID);
String traceId = (String) properties.get(RouteConstants.TRACE_ID);
String actorId = (String) properties.get(RouteConstants.ACTOR_ID);
String scanType = (String) properties.get(RouteConstants.SCAN_TYPE);
Boolean isImportOp = (Boolean) properties.get(RouteConstants.IS_DATA_IMPORT);

ScanDataMessage scanDataMessage = new ScanDataMessage(orgId, scanId, traceId, scanType, body, Instant.now().toString());
ScanDataMessage scanDataMessage = new ScanDataMessage(orgId, scanId, traceId, actorId, scanType, body, Instant.now().toString());

topicDetails.put("orgId", orgId);
topicDetails.put("runtimeAgentId", runtimeAgentId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
import ch.qos.logback.classic.spi.ILoggingEvent;
import com.solace.maas.ep.common.messages.ScanLogMessage;
import com.solace.maas.ep.event.management.agent.config.eventPortal.EventPortalProperties;
import com.solace.maas.ep.event.management.agent.publisher.ScanLogsPublisher;
import com.solace.maas.ep.event.management.agent.plugin.constants.RouteConstants;
import com.solace.maas.ep.event.management.agent.publisher.ScanLogsPublisher;
import lombok.extern.slf4j.Slf4j;
import org.apache.camel.Exchange;
import org.apache.camel.Processor;
Expand Down Expand Up @@ -42,9 +42,10 @@ public void process(Exchange exchange) throws Exception {
ILoggingEvent event = (ILoggingEvent) exchange.getIn().getBody();
String scanId = (String) properties.get(RouteConstants.SCAN_ID);
String traceId = (String) properties.get(RouteConstants.TRACE_ID);
String actorId = (String) properties.get(RouteConstants.ACTOR_ID);
String messagingServiceId = (String) properties.get(RouteConstants.MESSAGING_SERVICE_ID);

ScanLogMessage logDataMessage = new ScanLogMessage(orgId, scanId, traceId, event.getLevel().toString(),
ScanLogMessage logDataMessage = new ScanLogMessage(orgId, scanId, traceId, actorId, event.getLevel().toString(),
String.format("%s%s", event.getFormattedMessage(), "\n"), event.getTimeStamp());

topicDetails.put("orgId", orgId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ public void process(Exchange exchange) throws Exception {
String messagingServiceId = (String) properties.get(RouteConstants.MESSAGING_SERVICE_ID);
String scanId = (String) properties.get(RouteConstants.SCAN_ID);
String traceId = (String) properties.get(RouteConstants.TRACE_ID);
String actorId = (String) properties.get(RouteConstants.ACTOR_ID);
ScanStatus status = (ScanStatus) properties.get(RouteConstants.SCAN_STATUS);
String description = (String) properties.get(RouteConstants.SCAN_STATUS_DESC);

Expand All @@ -54,7 +55,7 @@ public void process(Exchange exchange) throws Exception {
topicDetails.put("scanType", scanType);
topicDetails.put("status", status.name());

ScanStatusMessage generalStatusMessage = new ScanStatusMessage(orgId, scanId, traceId, status.name(), description, scanTypes);
ScanStatusMessage generalStatusMessage = new ScanStatusMessage(orgId, scanId, traceId, actorId, status.name(), description, scanTypes);

exchange.getIn().setHeader(RouteConstants.GENERAL_STATUS_MESSAGE, generalStatusMessage);
exchange.getIn().setHeader(RouteConstants.TOPIC_DETAILS, topicDetails);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ public void process(Exchange exchange) throws Exception {
String messagingServiceId = (String) properties.get(RouteConstants.MESSAGING_SERVICE_ID);
String scanId = (String) properties.get(RouteConstants.SCAN_ID);
String traceId = (String) properties.get(RouteConstants.TRACE_ID);
String actorId = (String) properties.get(RouteConstants.ACTOR_ID);
String scanType = (String) properties.get(RouteConstants.SCAN_TYPE);
ScanStatus status = (ScanStatus) properties.get(RouteConstants.SCAN_STATUS);
String description = (String) properties.get(RouteConstants.SCAN_STATUS_DESC);
Expand All @@ -49,7 +50,8 @@ public void process(Exchange exchange) throws Exception {
topicDetails.put("status", status.name());
topicDetails.put("scanDataType", scanType);

ScanDataStatusMessage scanDataStatusMessage = new ScanDataStatusMessage(orgId, scanId, traceId, status.name(), description, scanType);
ScanDataStatusMessage scanDataStatusMessage = new ScanDataStatusMessage(orgId, scanId, traceId, actorId,
status.name(), description, scanType);

exchange.getIn().setHeader(RouteConstants.SCAN_DATA_STATUS_MESSAGE, scanDataStatusMessage);
exchange.getIn().setHeader(RouteConstants.TOPIC_DETAILS, topicDetails);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@
import com.solace.maas.ep.event.management.agent.plugin.processor.ScanTypeDescendentsProcessor;
import com.solace.maas.ep.event.management.agent.repository.model.scan.ScanRecipientHierarchyEntity;
import com.solace.maas.ep.event.management.agent.repository.scan.ScanRecipientHierarchyRepository;
import jakarta.transaction.Transactional;
import lombok.extern.slf4j.Slf4j;
import org.apache.camel.Exchange;
import org.springframework.stereotype.Component;

import jakarta.transaction.Transactional;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
Expand All @@ -33,6 +33,7 @@ public void process(Exchange exchange) throws Exception {

String scanId = (String) properties.get(RouteConstants.SCAN_ID);
String traceId = (String) properties.get(RouteConstants.TRACE_ID);
String actorId = (String) properties.get(RouteConstants.ACTOR_ID);
String scanType = (String) properties.get(RouteConstants.SCAN_TYPE);
boolean isEmptyScanTypes = (boolean) properties.get(RouteConstants.IS_EMPTY_SCAN_TYPES);

Expand All @@ -43,7 +44,8 @@ public void process(Exchange exchange) throws Exception {

if (isEmptyScanTypes) {
allDescendentScanTypes.forEach(type ->
log.info("Scan request [{}], trace ID [{}]: Encountered an empty scan type [{}].", scanId, traceId, type));
log.info("Scan request [{}], trace ID [{}], actor ID [{}]: Encountered an empty scan type [{}].",
scanId, traceId, actorId, type));
}

exchange.getIn().setHeader(RouteConstants.SCAN_TYPE, allDescendentScanTypes);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,6 @@
import com.solace.maas.ep.event.management.agent.repository.model.file.DataCollectionFileEntity;
import com.solace.maas.ep.event.management.agent.repository.model.mesagingservice.MessagingServiceEntity;
import com.solace.maas.ep.event.management.agent.repository.model.route.RouteEntity;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.hibernate.annotations.CreationTimestamp;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;

import jakarta.persistence.CascadeType;
import jakarta.persistence.Column;
import jakarta.persistence.Entity;
Expand All @@ -22,6 +15,13 @@
import jakarta.persistence.ManyToOne;
import jakarta.persistence.OneToMany;
import jakarta.persistence.Table;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.hibernate.annotations.CreationTimestamp;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;

import java.io.Serializable;
import java.time.Instant;
import java.util.List;
Expand All @@ -45,6 +45,9 @@ public class ScanEntity implements Serializable {
@Column(name = "TRACE_ID")
private String traceId;

@Column(name = "ACTOR_ID")
private String actorId;

@OneToMany(mappedBy = "scan", fetch = FetchType.LAZY, cascade = CascadeType.MERGE)
private List<ScanTypeEntity> scanTypes;

Expand Down
Loading

0 comments on commit cff50bc

Please sign in to comment.