use of org.apache.druid.java.util.emitter.service.ServiceEventBuilder in project druid by druid-io.
the class InfluxdbEmitterTest method setUp.
@Before
public void setUp() {
DateTime date = new DateTime(2017, 10, 30, 10, 00, // 10:00am on 30/10/2017 = 1509357600000000000 in epoch nanoseconds
DateTimeZone.UTC);
String metric = "metric/te/st/value";
Number value = 1234;
ImmutableMap<String, String> serviceDims = ImmutableMap.of("service", "druid/historical", "host", "localhost", "version", "0.10.0");
ServiceMetricEvent.Builder builder = ServiceMetricEvent.builder();
builder.setDimension("nonWhiteListedDim", "test");
builder.setDimension("dataSource", "test_datasource");
ServiceEventBuilder eventBuilder = builder.build(date, metric, value);
event = (ServiceMetricEvent) eventBuilder.build(serviceDims);
}
use of org.apache.druid.java.util.emitter.service.ServiceEventBuilder in project druid by druid-io.
the class InfluxdbEmitterTest method testMetricIsInDimensionWhitelist.
@Test
public void testMetricIsInDimensionWhitelist() {
DateTime date = new DateTime(2017, 10, 30, 10, 00, // 10:00am on 30/10/2017 = 1509357600000000000 in epoch nanoseconds
DateTimeZone.UTC);
String metric = "metric/time";
Number value = 1234;
ImmutableMap<String, String> serviceDims = ImmutableMap.of("service", "druid/historical", "host", "localhost", "version", "0.10.0");
ServiceMetricEvent.Builder builder = ServiceMetricEvent.builder();
ServiceEventBuilder eventBuilder = builder.build(date, metric, value);
builder.setDimension("dataSource", "wikipedia");
builder.setDimension("taskType", "index");
ServiceMetricEvent event = (ServiceMetricEvent) eventBuilder.build(serviceDims);
InfluxdbEmitterConfig config = new InfluxdbEmitterConfig("localhost", 8086, null, null, null, null, "dbname", 10000, 15000, 30000, "adam", "password", ImmutableSet.of("dataSource"));
InfluxdbEmitter influxdbEmitter = new InfluxdbEmitter(config);
String expected = "druid_metric,service=druid/historical,hostname=localhost,dataSource=wikipedia druid_time=1234 1509357600000000000" + "\n";
String actual = influxdbEmitter.transformForInfluxSystems(event);
Assert.assertEquals(expected, actual);
}
use of org.apache.druid.java.util.emitter.service.ServiceEventBuilder in project druid by druid-io.
the class InfluxdbEmitterTest method testMetricIsInDefaultDimensionWhitelist.
@Test
public void testMetricIsInDefaultDimensionWhitelist() {
DateTime date = new DateTime(2017, 10, 30, 10, 00, // 10:00am on 30/10/2017 = 1509357600000000000 in epoch nanoseconds
DateTimeZone.UTC);
String metric = "metric/time";
Number value = 1234;
ImmutableMap<String, String> serviceDims = ImmutableMap.of("service", "druid/historical", "host", "localhost", "version", "0.10.0");
ServiceMetricEvent.Builder builder = ServiceMetricEvent.builder();
ServiceEventBuilder eventBuilder = builder.build(date, metric, value);
builder.setDimension("dataSource", "wikipedia");
builder.setDimension("taskType", "index");
ServiceMetricEvent event = (ServiceMetricEvent) eventBuilder.build(serviceDims);
InfluxdbEmitterConfig config = new InfluxdbEmitterConfig("localhost", 8086, null, null, null, null, "dbname", 10000, 15000, 30000, "adam", "password", null);
InfluxdbEmitter influxdbEmitter = new InfluxdbEmitter(config);
String expected = "druid_metric,service=druid/historical,hostname=localhost,dataSource=wikipedia,taskType=index druid_time=1234 1509357600000000000" + "\n";
String actual = influxdbEmitter.transformForInfluxSystems(event);
Assert.assertEquals(expected, actual);
}
use of org.apache.druid.java.util.emitter.service.ServiceEventBuilder in project druid by druid-io.
the class KillCompactionConfigTest method testRunRetryForRetryableException.
@Test
public void testRunRetryForRetryableException() {
String inactiveDatasourceName = "inactive_datasource";
DataSourceCompactionConfig inactiveDatasourceConfig = new DataSourceCompactionConfig(inactiveDatasourceName, null, 500L, null, new Period(3600), null, new UserCompactionTaskGranularityConfig(Granularities.HOUR, null, null), null, null, null, null, ImmutableMap.of("key", "val"));
CoordinatorCompactionConfig originalCurrentConfig = CoordinatorCompactionConfig.from(ImmutableList.of(inactiveDatasourceConfig));
byte[] originalCurrentConfigBytes = { 1, 2, 3 };
Mockito.when(mockConnector.lookup(ArgumentMatchers.anyString(), ArgumentMatchers.eq("name"), ArgumentMatchers.eq("payload"), ArgumentMatchers.eq(CoordinatorCompactionConfig.CONFIG_KEY))).thenReturn(originalCurrentConfigBytes);
Mockito.when(mockJacksonConfigManager.convertByteToConfig(ArgumentMatchers.eq(originalCurrentConfigBytes), ArgumentMatchers.eq(CoordinatorCompactionConfig.class), ArgumentMatchers.eq(CoordinatorCompactionConfig.empty()))).thenReturn(originalCurrentConfig);
Mockito.when(mockDruidCoordinatorRuntimeParams.getEmitter()).thenReturn(mockServiceEmitter);
Mockito.when(mockSqlSegmentsMetadataManager.retrieveAllDataSourceNames()).thenReturn(ImmutableSet.of());
Mockito.when(mockJacksonConfigManager.set(ArgumentMatchers.eq(CoordinatorCompactionConfig.CONFIG_KEY), ArgumentMatchers.any(byte[].class), ArgumentMatchers.any(CoordinatorCompactionConfig.class), ArgumentMatchers.any())).thenAnswer(new Answer() {
private int count = 0;
@Override
public Object answer(InvocationOnMock invocation) {
if (count++ < 3) {
// Return fail result with RetryableException the first three call to updated set
return ConfigManager.SetResult.fail(new Exception(), true);
} else {
// Return success ok on the fourth call to set updated config
return ConfigManager.SetResult.ok();
}
}
});
TestDruidCoordinatorConfig druidCoordinatorConfig = new TestDruidCoordinatorConfig(null, null, null, new Duration("PT5S"), null, null, null, null, null, null, null, new Duration("PT6S"), null, null, null, null, 10, null);
killCompactionConfig = new KillCompactionConfig(druidCoordinatorConfig, mockSqlSegmentsMetadataManager, mockJacksonConfigManager, mockConnector, mockConnectorConfig);
killCompactionConfig.run(mockDruidCoordinatorRuntimeParams);
// Verify and Assert
final ArgumentCaptor<ServiceEventBuilder> emittedEventCaptor = ArgumentCaptor.forClass(ServiceEventBuilder.class);
Mockito.verify(mockServiceEmitter).emit(emittedEventCaptor.capture());
Assert.assertEquals(KillCompactionConfig.COUNT_METRIC, emittedEventCaptor.getValue().build(ImmutableMap.of()).toMap().get("metric"));
// Should delete 1 config
Assert.assertEquals(1, emittedEventCaptor.getValue().build(ImmutableMap.of()).toMap().get("value"));
// Should call convertByteToConfig and lookup (to refresh current compaction config) four times due to RetryableException when failed
Mockito.verify(mockJacksonConfigManager, Mockito.times(4)).convertByteToConfig(ArgumentMatchers.eq(originalCurrentConfigBytes), ArgumentMatchers.eq(CoordinatorCompactionConfig.class), ArgumentMatchers.eq(CoordinatorCompactionConfig.empty()));
Mockito.verify(mockConnector, Mockito.times(4)).lookup(ArgumentMatchers.anyString(), ArgumentMatchers.eq("name"), ArgumentMatchers.eq("payload"), ArgumentMatchers.eq(CoordinatorCompactionConfig.CONFIG_KEY));
// Should call set (to try set new updated compaction config) four times due to RetryableException when failed
Mockito.verify(mockJacksonConfigManager, Mockito.times(4)).set(ArgumentMatchers.eq(CoordinatorCompactionConfig.CONFIG_KEY), ArgumentMatchers.any(byte[].class), ArgumentMatchers.any(CoordinatorCompactionConfig.class), ArgumentMatchers.any());
Mockito.verifyNoMoreInteractions(mockJacksonConfigManager);
// Should call retrieveAllDataSourceNames four times due to RetryableException when failed
Mockito.verify(mockSqlSegmentsMetadataManager, Mockito.times(4)).retrieveAllDataSourceNames();
Mockito.verifyNoMoreInteractions(mockSqlSegmentsMetadataManager);
}
Aggregations