Skip to content

Commit

Permalink
Fix tests and coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
kfaraz committed Dec 8, 2023
1 parent 71ae175 commit 737b796
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@

public class LoggingAuditManagerConfig implements AuditManagerConfig
{

@JsonProperty
private final AuditLogger.Level logLevel = AuditLogger.Level.INFO;

Expand All @@ -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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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()
Expand All @@ -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(),
Expand All @@ -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
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public void testDefaultAuditConfig()
}

@Test
public void testDefaultLogAuditConfig()
public void testLogAuditConfigWithDefaults()
{
final Injector injector = createInjector();
final JsonConfigProvider<AuditManagerConfig> provider = JsonConfigProvider.of(
Expand All @@ -76,7 +76,7 @@ public void testDefaultLogAuditConfig()
}

@Test
public void testLogAuditConfig()
public void testLogAuditConfigWithOverrides()
{
final Injector injector = createInjector();
final JsonConfigProvider<AuditManagerConfig> provider = JsonConfigProvider.of(
Expand All @@ -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);

Expand All @@ -99,6 +99,34 @@ public void testLogAuditConfig()
Assert.assertEquals(AuditLogger.Level.WARN, logAuditConfig.getLogLevel());
}

@Test
public void testSqlAuditConfigWithOverrides()
{
final Injector injector = createInjector();
final JsonConfigProvider<AuditManagerConfig> 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(
Expand Down

0 comments on commit 737b796

Please sign in to comment.