diff --git a/processing/src/test/java/org/apache/druid/audit/AuditInfoTest.java b/processing/src/test/java/org/apache/druid/audit/AuditInfoTest.java index 390ef302274b..38860efa9f0d 100644 --- a/processing/src/test/java/org/apache/druid/audit/AuditInfoTest.java +++ b/processing/src/test/java/org/apache/druid/audit/AuditInfoTest.java @@ -71,4 +71,12 @@ public void testAuditEntrySerde() throws IOException Assert.assertEquals(entry, serde); } + @Test + public void testRequestInfoEquality() throws IOException + { + RequestInfo requestInfo = new RequestInfo("overlord", "GET", "/uri", "a=b"); + RequestInfo deserialized = mapper.readValue(mapper.writeValueAsString(requestInfo), RequestInfo.class); + Assert.assertEquals(requestInfo, deserialized); + } + } diff --git a/server/src/main/java/org/apache/druid/server/audit/LoggingAuditManagerConfig.java b/server/src/main/java/org/apache/druid/server/audit/LoggingAuditManagerConfig.java index 6d6ab6e18d6e..6140936675c0 100644 --- a/server/src/main/java/org/apache/druid/server/audit/LoggingAuditManagerConfig.java +++ b/server/src/main/java/org/apache/druid/server/audit/LoggingAuditManagerConfig.java @@ -25,7 +25,6 @@ public class LoggingAuditManagerConfig implements AuditManagerConfig { - @JsonProperty private final AuditLogger.Level logLevel = AuditLogger.Level.INFO; @@ -37,7 +36,7 @@ public class LoggingAuditManagerConfig implements AuditManagerConfig private final HumanReadableBytes maxPayloadSizeBytes = HumanReadableBytes.valueOf(-1); @JsonProperty - private final boolean skipNullField = false; + private final Boolean skipNullField = false; @Override public boolean isSkipNullField() diff --git a/server/src/main/java/org/apache/druid/server/audit/SQLAuditManagerConfig.java b/server/src/main/java/org/apache/druid/server/audit/SQLAuditManagerConfig.java index aa012bb29599..290072965732 100644 --- a/server/src/main/java/org/apache/druid/server/audit/SQLAuditManagerConfig.java +++ b/server/src/main/java/org/apache/druid/server/audit/SQLAuditManagerConfig.java @@ -28,10 +28,10 @@ public class SQLAuditManagerConfig implements AuditManagerConfig { @JsonProperty - private final long auditHistoryMillis = 7 * 24 * 60 * 60 * 1000L; // 1 WEEK + private final Long auditHistoryMillis = 7 * 24 * 60 * 60 * 1000L; // 1 WEEK @JsonProperty - private final boolean includePayloadAsDimensionInMetric = false; + private final Boolean includePayloadAsDimensionInMetric = false; @JsonProperty @HumanReadableBytesRange( @@ -41,7 +41,7 @@ public class SQLAuditManagerConfig implements AuditManagerConfig private final HumanReadableBytes maxPayloadSizeBytes = HumanReadableBytes.valueOf(-1); @JsonProperty - private final boolean skipNullField = false; + private final Boolean skipNullField = false; public long getAuditHistoryMillis() { diff --git a/server/src/test/java/org/apache/druid/metadata/SQLMetadataRuleManagerTest.java b/server/src/test/java/org/apache/druid/metadata/SQLMetadataRuleManagerTest.java index 5a9fc0f13b01..a08ed0e86d56 100644 --- a/server/src/test/java/org/apache/druid/metadata/SQLMetadataRuleManagerTest.java +++ b/server/src/test/java/org/apache/druid/metadata/SQLMetadataRuleManagerTest.java @@ -34,7 +34,7 @@ import org.apache.druid.java.util.common.IAE; import org.apache.druid.java.util.common.Intervals; import org.apache.druid.java.util.common.StringUtils; -import org.apache.druid.segment.TestHelper; +import org.apache.druid.server.audit.AuditSerdeHelper; import org.apache.druid.server.audit.SQLAuditManager; import org.apache.druid.server.audit.SQLAuditManagerConfig; import org.apache.druid.server.coordinator.rules.IntervalLoadRule; @@ -65,7 +65,6 @@ public class SQLMetadataRuleManagerTest private AuditManager auditManager; private SQLMetadataSegmentPublisher publisher; private final ObjectMapper mapper = new DefaultObjectMapper(); - private final ObjectMapper jsonMapper = TestHelper.makeJsonMapper(); @Before public void setUp() @@ -75,7 +74,7 @@ public void setUp() connector.createAuditTable(); auditManager = new SQLAuditManager( new SQLAuditManagerConfig(), - null, + new AuditSerdeHelper(new SQLAuditManagerConfig(), mapper, mapper), connector, Suppliers.ofInstance(tablesConfig), new NoopServiceEmitter(), @@ -87,7 +86,7 @@ public void setUp() ruleManager = new SQLMetadataRuleManager(mapper, managerConfig, tablesConfig, connector, auditManager); connector.createSegmentTable(); publisher = new SQLMetadataSegmentPublisher( - jsonMapper, + mapper, derbyConnectorRule.metadataTablesConfigSupplier().get(), connector ); diff --git a/server/src/test/java/org/apache/druid/server/audit/AuditManagerConfigTest.java b/server/src/test/java/org/apache/druid/server/audit/AuditManagerConfigTest.java index e599532b4fcd..e9f714273684 100644 --- a/server/src/test/java/org/apache/druid/server/audit/AuditManagerConfigTest.java +++ b/server/src/test/java/org/apache/druid/server/audit/AuditManagerConfigTest.java @@ -54,7 +54,7 @@ public void testDefaultAuditConfig() } @Test - public void testDefaultLogAuditConfig() + public void testLogAuditConfigWithDefaults() { final Injector injector = createInjector(); final JsonConfigProvider provider = JsonConfigProvider.of( @@ -76,7 +76,7 @@ public void testDefaultLogAuditConfig() } @Test - public void testLogAuditConfig() + public void testLogAuditConfigWithOverrides() { final Injector injector = createInjector(); final JsonConfigProvider provider = JsonConfigProvider.of( @@ -89,7 +89,7 @@ public void testLogAuditConfig() props.setProperty("druid.audit.manager.logLevel", "WARN"); provider.inject(props, injector.getInstance(JsonConfigurator.class)); - + final AuditManagerConfig config = provider.get(); Assert.assertTrue(config instanceof LoggingAuditManagerConfig); @@ -99,6 +99,34 @@ public void testLogAuditConfig() Assert.assertEquals(AuditLogger.Level.WARN, logAuditConfig.getLogLevel()); } + @Test + public void testSqlAuditConfigWithOverrides() + { + final Injector injector = createInjector(); + final JsonConfigProvider provider = JsonConfigProvider.of( + CONFIG_BASE, + AuditManagerConfig.class + ); + + final Properties props = new Properties(); + props.setProperty("druid.audit.manager.type", "sql"); + props.setProperty("druid.audit.manager.skipNullField", "true"); + props.setProperty("druid.audit.manager.maxPayloadSizeBytes", "100"); + props.setProperty("druid.audit.manager.auditHistoryMillis", "1000"); + props.setProperty("druid.audit.manager.includePayloadAsDimensionInMetric", "true"); + + provider.inject(props, injector.getInstance(JsonConfigurator.class)); + + final AuditManagerConfig config = provider.get(); + Assert.assertTrue(config instanceof SQLAuditManagerConfig); + + final SQLAuditManagerConfig sqlAuditConfig = (SQLAuditManagerConfig) config; + Assert.assertTrue(sqlAuditConfig.isSkipNullField()); + Assert.assertTrue(sqlAuditConfig.isIncludePayloadAsDimensionInMetric()); + Assert.assertEquals(100, sqlAuditConfig.getMaxPayloadSizeBytes()); + Assert.assertEquals(1000L, sqlAuditConfig.getAuditHistoryMillis()); + } + private Injector createInjector() { return GuiceInjectors.makeStartupInjectorWithModules(