Search in sources :

Example 1 with PushConfig

use of com.datastax.oss.dsbulk.workflow.commons.metrics.prometheus.PrometheusManager.PushConfig in project dsbulk by datastax.

the class PrometheusManagerTest method should_report_failed_gateway_push.

@Test
@ExtendWith(WiremockResolver.class)
@ExtendWith(LogInterceptingExtension.class)
void should_report_failed_gateway_push(@Wiremock WireMockServer server, @LogCapture(value = PrometheusManager.class, level = ERROR) LogInterceptor logs) throws MalformedURLException {
    // given
    PushConfig pushConfig = new PushConfig(new URL(server.baseUrl()), "", "", false, false, ImmutableMap.of());
    PrometheusManager manager = new PrometheusManager(registry, "execution1", "job1", ImmutableMap.of(), null, pushConfig);
    server.givenThat(post(urlPathEqualTo("/metrics/job/job1")).willReturn(aResponse().withStatus(503)));
    // when
    manager.init();
    manager.pushMetrics(Duration.ofSeconds(123), true);
    // then
    assertThat(logs).hasMessageContaining(String.format("Push to Prometheus PushGateway %s failed. Response code from %s/metrics/job/job1 was 503", server.baseUrl(), server.baseUrl()));
}
Also used : PushConfig(com.datastax.oss.dsbulk.workflow.commons.metrics.prometheus.PrometheusManager.PushConfig) URL(java.net.URL) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) ExtendWith(org.junit.jupiter.api.extension.ExtendWith)

Example 2 with PushConfig

use of com.datastax.oss.dsbulk.workflow.commons.metrics.prometheus.PrometheusManager.PushConfig in project dsbulk by datastax.

the class PrometheusManagerTest method should_push_metrics_to_gateway.

@ParameterizedTest
@MethodSource
@ExtendWith(WiremockResolver.class)
void should_push_metrics_to_gateway(boolean success, boolean groupByInstance, boolean groupByOperationId, ImmutableMap<String, String> groupingKeys, String pathRegex, @Wiremock WireMockServer server) throws MalformedURLException {
    // given
    PushConfig pushConfig = new PushConfig(new URL(server.baseUrl()), "user1", "password1", groupByInstance, groupByOperationId, groupingKeys);
    PrometheusManager manager = new PrometheusManager(registry, "execution1", "job1", ImmutableMap.of("name1", "value1"), null, pushConfig);
    server.givenThat(post(urlPathEqualTo(pathRegex)).willReturn(aResponse().withStatus(201)));
    // when
    manager.init();
    registry.counter("records/total").inc(123456);
    manager.pushMetrics(Duration.ofSeconds(123), success);
    // then
    String version = WorkflowUtils.getBulkLoaderVersion();
    String driverVersion = Session.OSS_DRIVER_COORDINATES.getVersion().toString();
    String expectedLabelsAsString = "{name1=\"value1\",application_version=\"" + version + "\",application_name=\"DataStax Bulk Loader execution1\",client_id=\"de13b396-eb09-31d1-9876-cba56b790be0\",driver_version=\"" + driverVersion + "\",operation_id=\"execution1\",job=\"job1\",}";
    RequestPatternBuilder builder = postRequestedFor(urlPathMatching(pathRegex)).withHeader("Content-Type", containing("text/plain")).withHeader("Authorization", equalTo("Basic dXNlcjE6cGFzc3dvcmQx")).withRequestBody(containing("dsbulk_elapsed_time_seconds" + expectedLabelsAsString + " 123.0")).withRequestBody(containing("dsbulk_records_total" + expectedLabelsAsString + " 123456.0"));
    if (success) {
        builder = builder.withRequestBody(containing("dsbulk_success" + expectedLabelsAsString + " 1.0")).withRequestBody(containing("dsbulk_last_success" + expectedLabelsAsString));
    } else {
        builder = builder.withRequestBody(containing("dsbulk_success" + expectedLabelsAsString + " 0.0")).withRequestBody(notMatching(".*dsbulk_last_success.*"));
    }
    server.verify(builder);
}
Also used : PushConfig(com.datastax.oss.dsbulk.workflow.commons.metrics.prometheus.PrometheusManager.PushConfig) RequestPatternBuilder(com.github.tomakehurst.wiremock.matching.RequestPatternBuilder) URL(java.net.URL) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource) ExtendWith(org.junit.jupiter.api.extension.ExtendWith)

Example 3 with PushConfig

use of com.datastax.oss.dsbulk.workflow.commons.metrics.prometheus.PrometheusManager.PushConfig 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

PushConfig (com.datastax.oss.dsbulk.workflow.commons.metrics.prometheus.PrometheusManager.PushConfig)3 URL (java.net.URL)2 ExtendWith (org.junit.jupiter.api.extension.ExtendWith)2 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)2 PrometheusManager (com.datastax.oss.dsbulk.workflow.commons.metrics.prometheus.PrometheusManager)1 PullConfig (com.datastax.oss.dsbulk.workflow.commons.metrics.prometheus.PrometheusManager.PullConfig)1 RequestPatternBuilder (com.github.tomakehurst.wiremock.matching.RequestPatternBuilder)1 Test (org.junit.jupiter.api.Test)1 MethodSource (org.junit.jupiter.params.provider.MethodSource)1