-
Notifications
You must be signed in to change notification settings - Fork 14
US65644: Map ACS-specific audit events to Predix-specific ones #90
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
| auditPayload.put("httpMethod", auditEvent.getMethod()); | ||
| auditPayload.put("requestBody", auditEvent.getRequestBody()); | ||
| auditPayload.put("responseBody", auditEvent.getResponseBody()); | ||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we create a json string out of auditPayload and then store it in payload field.
anubhavi25
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As discussed, I checked in the CheckStyle fixes to service/src/test/java/com/ge/predix/acs/audit/PredixEventMapperTest.java so please pull those changes.
|
|
||
| public class PredixEventMapper { | ||
|
|
||
| public AuditEventV2 map(final com.ge.predix.audit.AuditEvent auditEvent) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No need to specify the full package name since now there's no name clash between AuditEvent and AuditEventV2
| public class PredixEventMapper { | ||
|
|
||
| public AuditEventV2 map(final com.ge.predix.audit.AuditEvent auditEvent) { | ||
| Map<String, String> auditPayload = new HashMap<String, String>(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can just use the diamond operator <> since you already gave the type specification via the Map declaration: Map<String, String> auditPayload = new HashMap<>();
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed
|
|
||
| } | ||
|
|
||
| private boolean isSuccessful(final com.ge.predix.audit.AuditEvent auditEvent) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See comment re. not needing the full package name
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed
| AuditEventV2Builder auditEventBuilder = AuditEventV2.builder().timestamp(auditEvent.getTime().toEpochMilli()) | ||
| .correlationId(auditEvent.getCorrelationId()).tenantUuid(auditEvent.getZoneId()) | ||
| .publisherType(PublisherType.APP_SERVICE).categoryType(CategoryType.API_CALLS) | ||
| .payload(auditPayload.toString()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
auditPayload.toString() will invoke AbstractMap#toString() which looks like JSON but isn't. Echoing @anurag-gujral, shouldn't we be serializing this as JSON instead?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Am now serializing
| @Autowired | ||
| private AuditClient auditClient; | ||
|
|
||
| @Autowired |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This coincidentally works since PredixEventProcessor and PredixEventMapper are part of the same package, but it might break if trying to wire an instance of PredixEventMapper elsewhere. Perhaps add an @Component annotation to the PredixEventMapper class above?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This has not been addressed, frank can you please comment?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@anurag-gujral, @FrankGasparovic has addressed this above.
| CategoryType.API_CALLS, EventType.FAILURE_API_REQUEST, Classifier.FAILURE }, | ||
| { "request body", "PUT", 200, "response body", "9101112", "13141516", PublisherType.APP_SERVICE, | ||
| CategoryType.API_CALLS, EventType.SUCCESS_API_REQUEST, Classifier.SUCCESS } }; | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should probably add at least one test for auditing input validation failures: { ... , PublisherType.APP_SERVICE, CategoryType.MALICIOUS, EventType.INVALID_INPUTS, Classifier.FAILURE }
If it's outside the scope of the current release, we should at least create a story to track this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added story for this in audit feature
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The story for CategoryType.MALICIOUS /input validation has been added to the backlog.
service/pom.xml
Outdated
| </dependencyManagement> | ||
| <dependencies> | ||
|
|
||
| <dependency> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This isn't necessary since the audit-sdk dependencies have already been added to the POMs. All that's necessary is to change the version in the <audit-sdk.version>0.0.x-SNAPSHOT</audit-sdk.version> line in the top-level POM.
That said, we should add something like the following to the public Maven profile in this POM to exclude compilation of all src and test classes in the com.ge.predix.acs.audit package:
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.3</version>
<configuration>
<excludes>
<exclude>com/ge/predix/acs/audit/*</exclude>
</excludes>
<testExcludes>
<testExclude>com/ge/predix/acs/audit/*</testExclude>
</testExcludes>
</configuration>
</plugin>
</plugins>
</build>
| import com.ge.predix.audit.sdk.AuditClient; | ||
| import com.ge.predix.audit.sdk.exception.AuditException; | ||
| import com.ge.predix.audit.sdk.message.AuditEventV2; | ||
| import com.ge.predix.eventhub.EventHubClientException; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To allow this import to be resolved, we probably want to explicitly add the EventHub SDK dependency to the predix Maven profile of acs/service/pom.xml:
<dependency>
<groupId>com.ge.predix.eventhub</groupId>
<artifactId>predix-event-hub-sdk</artifactId>
<version>${predix-event-hub-sdk.version}</version>
</dependency>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
added
|
|
||
| @BeforeMethod | ||
| public void setup() throws AuditException, EventHubClientException { | ||
| this.eventProcessor = new PredixEventProcessor(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Contrary to what we thought, this line to instantiate this.eventProcessor doesn't seem necessary (runs without a NullPointerException for me)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed
|
|
||
| @Test | ||
| public void testPredixEventProcess() throws AuditException, EventHubClientException { | ||
| AuditEventV2 mockPredixEvent = Mockito.mock(AuditEventV2.class); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Slightly better since it passes a mock object to process(...) instead of null:
@Test
public void testPredixEventProcess() throws AuditException, EventHubClientException {
AuditEvent mockAuditEvent = Mockito.mock(AuditEvent.class);
AuditEventV2 mockPredixEvent = Mockito.mock(AuditEventV2.class);
Mockito.when(mockedMapper.map(mockAuditEvent)).thenReturn(mockPredixEvent);
Assert.assertTrue(this.eventProcessor.process(mockAuditEvent));
Mockito.verify(mockedClient).audit(mockPredixEvent);
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added
18e7a5b to
26bddfe
Compare
26bddfe to
d78ad53
Compare
Signed-off-by: Anubhav <[email protected]>
|
|
||
| public AuditEventV2 map(final AuditEvent auditEvent) { | ||
| Map<String, String> auditPayload = new HashMap<>(); | ||
| auditPayload.put("httpMethod", auditEvent.getMethod()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
May next time when we commit we can make hardcoded string to private final String members
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Only used in one place at the moment.
| String payload = ""; | ||
| try { | ||
| payload = this.objectMapper.writeValueAsString(auditPayload); | ||
| } catch (JsonProcessingException e) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This does not look correct, the map function should throw an exception instead of just logging.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We are only constructing well formed JSON in this map method with potentially "garbage" as values in the JSON. I don't see a reason that we should throw this exception.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also the values in the auditPayload cannot be null, so we shouldn't have problems.
| @Override | ||
| public boolean process(final AuditEvent auditEvent) { | ||
| AuditEventV2 predixEvent = eventMapper.map(auditEvent); | ||
| try { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Need proper exception handling rather than catching the exception and returning boolean
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Boolean is required because of the way we created the tests for the AuditEventProcessor. Also we shouldn't add the throws at the interface level because different implementations of AuditEventProcessor may not use the Predix-Audit SDK.
d78ad53 to
5bb3b3b
Compare
No description provided.