use of com.datastax.oss.dsbulk.workflow.commons.metrics.prometheus.PrometheusManager.PullConfig in project dsbulk by datastax.
the class PrometheusManagerTest method should_expose_http_server_for_scraping.
@Test
void should_expose_http_server_for_scraping() throws IOException {
// given
int port = NetworkUtils.findAvailablePort();
PullConfig pullConfig = new PullConfig("", port);
PrometheusManager manager = new PrometheusManager(registry, "execution1", "job1", ImmutableMap.of("name1", "value1"), pullConfig, null);
URL url = new URL("http", "localhost", port, "/metrics");
// when
manager.init();
try {
manager.start();
registry.counter("records/total").inc();
// then
List<String> data = Resources.readLines(url, StandardCharsets.UTF_8);
assertThat(data).anySatisfy(line -> assertThat(line).startsWith("dsbulk_records_total").contains("application_version=").contains("client_id=").contains("driver_version=").contains("application_name=\"DataStax Bulk Loader execution1\"").contains("operation_id=\"execution1\"").contains("job=\"job1\"").contains("name1=\"value1\"").endsWith("1.0"));
} finally {
manager.close();
await().atMost(Duration.ofSeconds(5)).untilAsserted(() -> assertThatThrownBy(() -> url.openConnection().connect()).isInstanceOf(IOException.class));
}
}
use of com.datastax.oss.dsbulk.workflow.commons.metrics.prometheus.PrometheusManager.PullConfig in project dsbulk by datastax.
the class PrometheusManagerTest method should_not_expose_http_server_when_wrong_config.
@Test
void should_not_expose_http_server_when_wrong_config() {
// given
PullConfig pullConfig = new PullConfig("192.0.2.0", 0);
PrometheusManager manager = new PrometheusManager(registry, "execution1", "job1", ImmutableMap.of(), pullConfig, null);
// when
manager.init();
assertThatThrownBy(manager::start).isInstanceOf(UncheckedIOException.class).hasMessageContaining("ailed to start Prometheus Metrics HTTP server");
}
use of com.datastax.oss.dsbulk.workflow.commons.metrics.prometheus.PrometheusManager.PullConfig in project dsbulk by datastax.
the class MonitoringSettings method configurePrometheus.
private PrometheusManager configurePrometheus(Config config) {
boolean pullEnabled = config.getBoolean("pull.enabled");
boolean pushEnabled = config.getBoolean("push.enabled");
if (!pullEnabled && !pushEnabled) {
return null;
}
PullConfig pullConfig = null;
if (pullEnabled) {
pullConfig = new PullConfig(config.getString("pull.hostname"), config.getInt("pull.port"));
}
PushConfig pushConfig = null;
if (pushEnabled) {
pushConfig = new PushConfig(ConfigUtils.getURL(config, "push.url"), config.getString("push.username"), config.getString("push.password"), config.getBoolean("push.groupBy.instance"), config.getBoolean("push.groupBy.operation"), ConfigUtils.getStringMap(config, "push.groupBy.keys"));
}
return new PrometheusManager(registry, executionId, config.getString("job"), ConfigUtils.getStringMap(config, "labels"), pullConfig, pushConfig);
}
Aggregations