Search in sources :

Example 1 with PullConfig

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));
    }
}
Also used : PullConfig(com.datastax.oss.dsbulk.workflow.commons.metrics.prometheus.PrometheusManager.PullConfig) IOException(java.io.IOException) UncheckedIOException(java.io.UncheckedIOException) URL(java.net.URL) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 2 with PullConfig

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");
}
Also used : PullConfig(com.datastax.oss.dsbulk.workflow.commons.metrics.prometheus.PrometheusManager.PullConfig) UncheckedIOException(java.io.UncheckedIOException) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 3 with PullConfig

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);
}
Also used : PushConfig(com.datastax.oss.dsbulk.workflow.commons.metrics.prometheus.PrometheusManager.PushConfig) PullConfig(com.datastax.oss.dsbulk.workflow.commons.metrics.prometheus.PrometheusManager.PullConfig) PrometheusManager(com.datastax.oss.dsbulk.workflow.commons.metrics.prometheus.PrometheusManager)

Aggregations

PullConfig (com.datastax.oss.dsbulk.workflow.commons.metrics.prometheus.PrometheusManager.PullConfig)3 UncheckedIOException (java.io.UncheckedIOException)2 Test (org.junit.jupiter.api.Test)2 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)2 PrometheusManager (com.datastax.oss.dsbulk.workflow.commons.metrics.prometheus.PrometheusManager)1 PushConfig (com.datastax.oss.dsbulk.workflow.commons.metrics.prometheus.PrometheusManager.PushConfig)1 IOException (java.io.IOException)1 URL (java.net.URL)1