use of org.apache.druid.audit.AuditEntry in project druid by druid-io.
the class SQLAuditManagerTest method testAuditEntrySerde.
@Test(timeout = 60_000L)
public void testAuditEntrySerde() throws IOException {
AuditEntry entry = new AuditEntry("testKey", "testType", new AuditInfo("testAuthor", "testComment", "127.0.0.1"), "testPayload", DateTimes.of("2013-01-01T00:00:00Z"));
ObjectMapper mapper = new DefaultObjectMapper();
AuditEntry serde = mapper.readValue(mapper.writeValueAsString(entry), AuditEntry.class);
Assert.assertEquals(entry, serde);
}
use of org.apache.druid.audit.AuditEntry in project druid by druid-io.
the class SQLAuditManagerTest method testAuditMetricEventBuilderConfig.
@Test
public void testAuditMetricEventBuilderConfig() {
AuditEntry entry = new AuditEntry("testKey", "testType", new AuditInfo("testAuthor", "testComment", "127.0.0.1"), "testPayload", DateTimes.of("2013-01-01T00:00:00Z"));
SQLAuditManager auditManagerWithPayloadAsDimension = new SQLAuditManager(connector, derbyConnectorRule.metadataTablesConfigSupplier(), new NoopServiceEmitter(), mapper, new SQLAuditManagerConfig() {
@Override
public boolean getIncludePayloadAsDimensionInMetric() {
return true;
}
});
ServiceMetricEvent.Builder auditEntryBuilder = ((SQLAuditManager) auditManager).getAuditMetricEventBuilder(entry);
Assert.assertEquals(null, auditEntryBuilder.getDimension(PAYLOAD_DIMENSION_KEY));
ServiceMetricEvent.Builder auditEntryBuilderWithPayload = auditManagerWithPayloadAsDimension.getAuditMetricEventBuilder(entry);
Assert.assertEquals("testPayload", auditEntryBuilderWithPayload.getDimension(PAYLOAD_DIMENSION_KEY));
}
use of org.apache.druid.audit.AuditEntry in project druid by druid-io.
the class SQLAuditManagerTest method testRemoveAuditLogsOlderThanWithEntryOlderThanTime.
@Test(timeout = 60_000L)
public void testRemoveAuditLogsOlderThanWithEntryOlderThanTime() throws IOException {
String entry1Key = "testKey";
String entry1Type = "testType";
AuditInfo entry1AuditInfo = new AuditInfo("testAuthor", "testComment", "127.0.0.1");
String entry1Payload = "testPayload";
auditManager.doAudit(entry1Key, entry1Type, entry1AuditInfo, entry1Payload, stringConfigSerde);
byte[] payload = connector.lookup(derbyConnectorRule.metadataTablesConfigSupplier().get().getAuditTable(), "audit_key", "payload", "testKey");
AuditEntry dbEntry = mapper.readValue(payload, AuditEntry.class);
Assert.assertEquals(entry1Key, dbEntry.getKey());
Assert.assertEquals(entry1Payload, dbEntry.getPayload());
Assert.assertEquals(entry1Type, dbEntry.getType());
Assert.assertEquals(entry1AuditInfo, dbEntry.getAuditInfo());
// Do delete
auditManager.removeAuditLogsOlderThan(System.currentTimeMillis());
// Verify the delete
payload = connector.lookup(derbyConnectorRule.metadataTablesConfigSupplier().get().getAuditTable(), "audit_key", "payload", "testKey");
Assert.assertNull(payload);
}
use of org.apache.druid.audit.AuditEntry in project druid by druid-io.
the class SQLAuditManager method doAudit.
@Override
public void doAudit(AuditEntry auditEntry, Handle handle) throws IOException {
emitter.emit(getAuditMetricEventBuilder(auditEntry).build("config/audit", 1));
AuditEntry auditEntryToStore = auditEntry;
if (config.getMaxPayloadSizeBytes() >= 0) {
int payloadSize = jsonMapper.writeValueAsBytes(auditEntry.getPayload()).length;
if (payloadSize > config.getMaxPayloadSizeBytes()) {
auditEntryToStore = AuditEntry.builder().key(auditEntry.getKey()).type(auditEntry.getType()).auditInfo(auditEntry.getAuditInfo()).payload(StringUtils.format(PAYLOAD_SKIP_MSG_FORMAT, config.getMaxPayloadSizeBytes())).auditTime(auditEntry.getAuditTime()).build();
}
}
handle.createStatement(StringUtils.format("INSERT INTO %s ( audit_key, type, author, comment, created_date, payload) VALUES (:audit_key, :type, :author, :comment, :created_date, :payload)", getAuditTable())).bind("audit_key", auditEntry.getKey()).bind("type", auditEntry.getType()).bind("author", auditEntry.getAuditInfo().getAuthor()).bind("comment", auditEntry.getAuditInfo().getComment()).bind("created_date", auditEntry.getAuditTime().toString()).bind("payload", jsonMapper.writeValueAsBytes(auditEntryToStore)).execute();
}
use of org.apache.druid.audit.AuditEntry in project druid by druid-io.
the class SQLAuditManager method doAudit.
@Override
public <T> void doAudit(String key, String type, AuditInfo auditInfo, T payload, ConfigSerde<T> configSerde) {
AuditEntry auditEntry = AuditEntry.builder().key(key).type(type).auditInfo(auditInfo).payload(configSerde.serializeToString(payload, config.isSkipNullField())).build();
dbi.withHandle(new HandleCallback<Void>() {
@Override
public Void withHandle(Handle handle) throws Exception {
doAudit(auditEntry, handle);
return null;
}
});
}
Aggregations