Search in sources :

Example 1 with AuditEntry

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

the class RulesResourceTest method testGetDatasourceRuleHistoryWithCount.

@Test
public void testGetDatasourceRuleHistoryWithCount() {
    AuditEntry entry1 = new AuditEntry("testKey", "testType", new AuditInfo("testAuthor", "testComment", "127.0.0.1"), "testPayload", DateTimes.of("2013-01-02T00:00:00Z"));
    AuditEntry entry2 = new AuditEntry("testKey", "testType", new AuditInfo("testAuthor", "testComment", "127.0.0.1"), "testPayload", DateTimes.of("2013-01-01T00:00:00Z"));
    EasyMock.expect(auditManager.fetchAuditHistory(EasyMock.eq("datasource1"), EasyMock.eq("rules"), EasyMock.eq(2))).andReturn(ImmutableList.of(entry1, entry2)).once();
    EasyMock.replay(auditManager);
    RulesResource rulesResource = new RulesResource(databaseRuleManager, auditManager);
    Response response = rulesResource.getDatasourceRuleHistory("datasource1", null, 2);
    List<AuditEntry> rulesHistory = (List) response.getEntity();
    Assert.assertEquals(2, rulesHistory.size());
    Assert.assertEquals(entry1, rulesHistory.get(0));
    Assert.assertEquals(entry2, rulesHistory.get(1));
    EasyMock.verify(auditManager);
}
Also used : Response(javax.ws.rs.core.Response) AuditInfo(org.apache.druid.audit.AuditInfo) AuditEntry(org.apache.druid.audit.AuditEntry) List(java.util.List) ImmutableList(com.google.common.collect.ImmutableList) Test(org.junit.Test)

Example 2 with AuditEntry

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

the class SQLMetadataRuleManagerTest method testFetchAuditEntriesForAllDataSources.

@Test
public void testFetchAuditEntriesForAllDataSources() throws Exception {
    List<Rule> rules = Collections.singletonList(new IntervalLoadRule(Intervals.of("2015-01-01/2015-02-01"), ImmutableMap.of(DruidServer.DEFAULT_TIER, DruidServer.DEFAULT_NUM_REPLICANTS)));
    AuditInfo auditInfo = new AuditInfo("test_author", "test_comment", "127.0.0.1");
    ruleManager.overrideRule("test_dataSource", rules, auditInfo);
    ruleManager.overrideRule("test_dataSource2", rules, auditInfo);
    // fetch rules from metadata storage
    ruleManager.poll();
    Assert.assertEquals(rules, ruleManager.getRules("test_dataSource"));
    Assert.assertEquals(rules, ruleManager.getRules("test_dataSource2"));
    // test fetch audit entries
    List<AuditEntry> auditEntries = auditManager.fetchAuditHistory("rules", null);
    Assert.assertEquals(2, auditEntries.size());
    for (AuditEntry entry : auditEntries) {
        Assert.assertEquals(rules, mapper.readValue(entry.getPayload(), new TypeReference<List<Rule>>() {
        }));
        Assert.assertEquals(auditInfo, entry.getAuditInfo());
    }
}
Also used : AuditInfo(org.apache.druid.audit.AuditInfo) IntervalLoadRule(org.apache.druid.server.coordinator.rules.IntervalLoadRule) AuditEntry(org.apache.druid.audit.AuditEntry) IntervalLoadRule(org.apache.druid.server.coordinator.rules.IntervalLoadRule) Rule(org.apache.druid.server.coordinator.rules.Rule) TypeReference(com.fasterxml.jackson.core.type.TypeReference) Test(org.junit.Test)

Example 3 with AuditEntry

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

the class SQLAuditManagerTest method testCreateAuditEntry.

@Test(timeout = 60_000L)
public void testCreateAuditEntry() 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());
}
Also used : AuditInfo(org.apache.druid.audit.AuditInfo) AuditEntry(org.apache.druid.audit.AuditEntry) Test(org.junit.Test)

Example 4 with AuditEntry

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

the class SQLAuditManagerTest method testRemoveAuditLogsOlderThanWithEntryNotOlderThanTime.

@Test(timeout = 60_000L)
public void testRemoveAuditLogsOlderThanWithEntryNotOlderThanTime() 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(DateTimes.of("2012-01-01T00:00:00Z").getMillis());
    // Verify that entry was not delete
    payload = connector.lookup(derbyConnectorRule.metadataTablesConfigSupplier().get().getAuditTable(), "audit_key", "payload", "testKey");
    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());
}
Also used : AuditInfo(org.apache.druid.audit.AuditInfo) AuditEntry(org.apache.druid.audit.AuditEntry) Test(org.junit.Test)

Example 5 with AuditEntry

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

the class SQLAuditManagerTest method testCreateAuditEntryWithPayloadUnderSkipPayloadLimit.

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

        @Override
        public long getMaxPayloadSizeBytes() {
            return 500;
        }
    });
    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.assertEquals(entry1Payload, 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)

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