Search in sources :

Example 16 with AuditEntry

use of org.apache.druid.audit.AuditEntry in project druid by druid-io.

the class SQLAuditManagerTest method testFetchAuditHistory.

@Test(timeout = 60_000L)
public void testFetchAuditHistory() {
    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);
    auditManager.doAudit(entry1Key, entry1Type, entry1AuditInfo, entry1Payload, stringConfigSerde);
    List<AuditEntry> auditEntries = auditManager.fetchAuditHistory("testKey", "testType", Intervals.of("2000-01-01T00:00:00Z/2100-01-03T00:00:00Z"));
    Assert.assertEquals(2, auditEntries.size());
    Assert.assertEquals(entry1Key, auditEntries.get(0).getKey());
    Assert.assertEquals(entry1Payload, auditEntries.get(0).getPayload());
    Assert.assertEquals(entry1Type, auditEntries.get(0).getType());
    Assert.assertEquals(entry1AuditInfo, auditEntries.get(0).getAuditInfo());
    Assert.assertEquals(entry1Key, auditEntries.get(1).getKey());
    Assert.assertEquals(entry1Payload, auditEntries.get(1).getPayload());
    Assert.assertEquals(entry1Type, auditEntries.get(1).getType());
    Assert.assertEquals(entry1AuditInfo, auditEntries.get(1).getAuditInfo());
}
Also used : AuditInfo(org.apache.druid.audit.AuditInfo) AuditEntry(org.apache.druid.audit.AuditEntry) Test(org.junit.Test)

Example 17 with AuditEntry

use of org.apache.druid.audit.AuditEntry in project druid by druid-io.

the class SQLAuditManagerTest method testCreateAuditEntryWithPayloadOverSkipPayloadLimit.

@Test(timeout = 60_000L)
public void testCreateAuditEntryWithPayloadOverSkipPayloadLimit() throws IOException {
    int maxPayloadSize = 10;
    SQLAuditManager auditManagerWithMaxPayloadSizeBytes = new SQLAuditManager(connector, derbyConnectorRule.metadataTablesConfigSupplier(), new NoopServiceEmitter(), mapper, new SQLAuditManagerConfig() {

        @Override
        public long getMaxPayloadSizeBytes() {
            return maxPayloadSize;
        }
    });
    String entry1Key = "testKey";
    String entry1Type = "testType";
    AuditInfo entry1AuditInfo = new AuditInfo("testAuthor", "testComment", "127.0.0.1");
    String entry1Payload = "payload audit to store";
    auditManagerWithMaxPayloadSizeBytes.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.assertNotEquals(entry1Payload, dbEntry.getPayload());
    Assert.assertEquals(StringUtils.format(AuditManager.PAYLOAD_SKIP_MSG_FORMAT, maxPayloadSize), dbEntry.getPayload());
    Assert.assertEquals(entry1Type, dbEntry.getType());
    Assert.assertEquals(entry1AuditInfo, dbEntry.getAuditInfo());
}
Also used : AuditInfo(org.apache.druid.audit.AuditInfo) AuditEntry(org.apache.druid.audit.AuditEntry) NoopServiceEmitter(org.apache.druid.server.metrics.NoopServiceEmitter) Test(org.junit.Test)

Example 18 with AuditEntry

use of org.apache.druid.audit.AuditEntry in project druid by druid-io.

the class SQLAuditManagerTest method testFetchAuditHistoryByKeyAndTypeWithLimit.

@Test(timeout = 60_000L)
public void testFetchAuditHistoryByKeyAndTypeWithLimit() {
    String entry1Key = "testKey1";
    String entry1Type = "testType";
    AuditInfo entry1AuditInfo = new AuditInfo("testAuthor", "testComment", "127.0.0.1");
    String entry1Payload = "testPayload";
    String entry2Key = "testKey2";
    String entry2Type = "testType";
    AuditInfo entry2AuditInfo = new AuditInfo("testAuthor", "testComment", "127.0.0.1");
    String entry2Payload = "testPayload";
    auditManager.doAudit(entry1Key, entry1Type, entry1AuditInfo, entry1Payload, stringConfigSerde);
    auditManager.doAudit(entry2Key, entry2Type, entry2AuditInfo, entry2Payload, stringConfigSerde);
    List<AuditEntry> auditEntries = auditManager.fetchAuditHistory("testKey1", "testType", 1);
    Assert.assertEquals(1, auditEntries.size());
    Assert.assertEquals(entry1Key, auditEntries.get(0).getKey());
    Assert.assertEquals(entry1Payload, auditEntries.get(0).getPayload());
    Assert.assertEquals(entry1Type, auditEntries.get(0).getType());
    Assert.assertEquals(entry1AuditInfo, auditEntries.get(0).getAuditInfo());
}
Also used : AuditInfo(org.apache.druid.audit.AuditInfo) AuditEntry(org.apache.druid.audit.AuditEntry) Test(org.junit.Test)

Example 19 with AuditEntry

use of org.apache.druid.audit.AuditEntry in project druid by druid-io.

the class SQLAuditManagerTest method testFetchAuditHistoryByTypeWithLimit.

@Test(timeout = 60_000L)
public void testFetchAuditHistoryByTypeWithLimit() {
    String entry1Key = "testKey";
    String entry1Type = "testType";
    AuditInfo entry1AuditInfo = new AuditInfo("testAuthor", "testComment", "127.0.0.1");
    String entry1Payload = "testPayload1";
    String entry2Key = "testKey";
    String entry2Type = "testType";
    AuditInfo entry2AuditInfo = new AuditInfo("testAuthor", "testComment", "127.0.0.1");
    String entry2Payload = "testPayload2";
    String entry3Key = "testKey";
    String entry3Type = "testType";
    AuditInfo entry3AuditInfo = new AuditInfo("testAuthor", "testComment", "127.0.0.1");
    String entry3Payload = "testPayload3";
    auditManager.doAudit(entry1Key, entry1Type, entry1AuditInfo, entry1Payload, stringConfigSerde);
    auditManager.doAudit(entry2Key, entry2Type, entry2AuditInfo, entry2Payload, stringConfigSerde);
    auditManager.doAudit(entry3Key, entry3Type, entry3AuditInfo, entry3Payload, stringConfigSerde);
    List<AuditEntry> auditEntries = auditManager.fetchAuditHistory("testType", 2);
    Assert.assertEquals(2, auditEntries.size());
    Assert.assertEquals(entry3Key, auditEntries.get(0).getKey());
    Assert.assertEquals(entry3Payload, auditEntries.get(0).getPayload());
    Assert.assertEquals(entry3Type, auditEntries.get(0).getType());
    Assert.assertEquals(entry3AuditInfo, auditEntries.get(0).getAuditInfo());
    Assert.assertEquals(entry2Key, auditEntries.get(1).getKey());
    Assert.assertEquals(entry2Payload, auditEntries.get(1).getPayload());
    Assert.assertEquals(entry2Type, auditEntries.get(1).getType());
    Assert.assertEquals(entry2AuditInfo, auditEntries.get(1).getAuditInfo());
}
Also used : AuditInfo(org.apache.druid.audit.AuditInfo) AuditEntry(org.apache.druid.audit.AuditEntry) Test(org.junit.Test)

Aggregations

AuditEntry (org.apache.druid.audit.AuditEntry)19 AuditInfo (org.apache.druid.audit.AuditInfo)16 Test (org.junit.Test)16 ImmutableList (com.google.common.collect.ImmutableList)4 List (java.util.List)4 Response (javax.ws.rs.core.Response)4 NoopServiceEmitter (org.apache.druid.server.metrics.NoopServiceEmitter)3 Interval (org.joda.time.Interval)3 TypeReference (com.fasterxml.jackson.core.type.TypeReference)2 IntervalLoadRule (org.apache.druid.server.coordinator.rules.IntervalLoadRule)2 Rule (org.apache.druid.server.coordinator.rules.Rule)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 ResourceFilters (com.sun.jersey.spi.container.ResourceFilters)1 IOException (java.io.IOException)1 GET (javax.ws.rs.GET)1 Path (javax.ws.rs.Path)1 Produces (javax.ws.rs.Produces)1 DefaultObjectMapper (org.apache.druid.jackson.DefaultObjectMapper)1 ServiceMetricEvent (org.apache.druid.java.util.emitter.service.ServiceMetricEvent)1 Handle (org.skife.jdbi.v2.Handle)1