use of org.apache.druid.audit.AuditInfo 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.AuditInfo 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.AuditInfo in project druid by druid-io.
the class KillCompactionConfig method run.
@Override
public DruidCoordinatorRuntimeParams run(DruidCoordinatorRuntimeParams params) {
long currentTimeMillis = System.currentTimeMillis();
if ((lastKillTime + period) < currentTimeMillis) {
lastKillTime = currentTimeMillis;
try {
RetryUtils.retry(() -> {
final byte[] currentBytes = CoordinatorCompactionConfig.getConfigInByteFromDb(connector, connectorConfig);
final CoordinatorCompactionConfig current = CoordinatorCompactionConfig.convertByteToConfig(jacksonConfigManager, currentBytes);
// If current compaction config is empty then there is nothing to do
if (CoordinatorCompactionConfig.empty().equals(current)) {
log.info("Finished running KillCompactionConfig duty. Nothing to do as compaction config is already empty.");
emitMetric(params.getEmitter(), 0);
return ConfigManager.SetResult.ok();
}
// Get all active datasources
// Note that we get all active datasources after getting compaction config to prevent race condition if new
// datasource and config are added.
Set<String> activeDatasources = sqlSegmentsMetadataManager.retrieveAllDataSourceNames();
final Map<String, DataSourceCompactionConfig> updated = current.getCompactionConfigs().stream().filter(dataSourceCompactionConfig -> activeDatasources.contains(dataSourceCompactionConfig.getDataSource())).collect(Collectors.toMap(DataSourceCompactionConfig::getDataSource, Function.identity()));
// Calculate number of compaction configs to remove for logging
int compactionConfigRemoved = current.getCompactionConfigs().size() - updated.size();
ConfigManager.SetResult result = jacksonConfigManager.set(CoordinatorCompactionConfig.CONFIG_KEY, currentBytes, CoordinatorCompactionConfig.from(current, ImmutableList.copyOf(updated.values())), new AuditInfo("KillCompactionConfig", "CoordinatorDuty for automatic deletion of compaction config", ""));
if (result.isOk()) {
log.info("Finished running KillCompactionConfig duty. Removed %,d compaction configs", compactionConfigRemoved);
emitMetric(params.getEmitter(), compactionConfigRemoved);
} else if (result.isRetryable()) {
// Failed but is retryable
log.debug("Retrying KillCompactionConfig duty");
throw new RetryableException(result.getException());
} else {
// Failed and not retryable
log.error(result.getException(), "Failed to kill compaction configurations");
emitMetric(params.getEmitter(), 0);
}
return result;
}, e -> e instanceof RetryableException, UPDATE_NUM_RETRY);
} catch (Exception e) {
log.error(e, "Failed to kill compaction configurations");
emitMetric(params.getEmitter(), 0);
}
}
return params;
}
use of org.apache.druid.audit.AuditInfo in project druid by druid-io.
the class JacksonConfigManagerTest method testSet.
@Test
public void testSet() {
String key = "key";
TestConfig val = new TestConfig("version", "string", 3);
AuditInfo auditInfo = new AuditInfo("testAuthor", "testComment", "127.0.0.1");
jacksonConfigManager.set(key, val, auditInfo);
ArgumentCaptor<ConfigSerde> configSerdeCapture = ArgumentCaptor.forClass(ConfigSerde.class);
Mockito.verify(mockAuditManager).doAudit(ArgumentMatchers.eq(key), ArgumentMatchers.eq(key), ArgumentMatchers.eq(auditInfo), ArgumentMatchers.eq(val), configSerdeCapture.capture());
Assert.assertNotNull(configSerdeCapture.getValue());
}
use of org.apache.druid.audit.AuditInfo in project druid by druid-io.
the class CoordinatorDynamicConfigsResource method setDynamicConfigs.
// default value is used for backwards compatibility
@POST
@Consumes(MediaType.APPLICATION_JSON)
public Response setDynamicConfigs(final CoordinatorDynamicConfig.Builder dynamicConfigBuilder, @HeaderParam(AuditManager.X_DRUID_AUTHOR) @DefaultValue("") final String author, @HeaderParam(AuditManager.X_DRUID_COMMENT) @DefaultValue("") final String comment, @Context HttpServletRequest req) {
try {
CoordinatorDynamicConfig current = CoordinatorDynamicConfig.current(manager);
final SetResult setResult = manager.set(CoordinatorDynamicConfig.CONFIG_KEY, dynamicConfigBuilder.build(current), new AuditInfo(author, comment, req.getRemoteAddr()));
if (setResult.isOk()) {
return Response.ok().build();
} else {
return Response.status(Response.Status.BAD_REQUEST).entity(ServletResourceUtils.sanitizeException(setResult.getException())).build();
}
} catch (IllegalArgumentException e) {
return Response.status(Response.Status.BAD_REQUEST).entity(ServletResourceUtils.sanitizeException(e)).build();
}
}
Aggregations