Search in sources :

Example 1 with WebClient

use of com.linecorp.armeria.client.WebClient in project zipkin by openzipkin.

the class ITElasticsearchStorage method testUsageOfDeprecatedFeatures.

@Test
void testUsageOfDeprecatedFeatures() {
    WebClient webClient = WebClient.builder(elasticsearch().baseUrl()).factory(ClientFactory.builder().useHttp2Preface(false).build()).build();
    final AggregatedHttpResponse response = webClient.execute(HttpRequest.of(RequestHeaders.of(HttpMethod.GET, "/_migration/deprecations"))).aggregate().join();
    if (!response.contentAscii().isEmpty()) {
        LOGGER.warn("The ElasticSearch instance used during IT's is using deprecated features or " + "configuration. This is likely nothing to be really worried about (for example 'xpack.monitoring.enabled' " + "setting), but nevertheless it should be looked at to see if our docker image used during " + "integration tests needs updating for the next version of ElasticSearch. " + "See https://www.elastic.co/guide/en/elasticsearch/reference/current/migration-api-deprecation.html" + "for more information. This is the deprecation warning we received:\n\n" + response.contentAscii());
    }
}
Also used : WebClient(com.linecorp.armeria.client.WebClient) AggregatedHttpResponse(com.linecorp.armeria.common.AggregatedHttpResponse) Test(org.junit.jupiter.api.Test)

Example 2 with WebClient

use of com.linecorp.armeria.client.WebClient in project zipkin by openzipkin.

the class ServerIntegratedBenchmark method runBenchmark.

void runBenchmark(@Nullable GenericContainer<?> storage, GenericContainer<?> zipkin) throws Exception {
    GenericContainer<?> backend = new GenericContainer<>(parse("ghcr.io/openzipkin/brave-example:armeria")).withNetwork(Network.SHARED).withNetworkAliases("backend").withCommand("backend").withExposedPorts(9000).waitingFor(Wait.forHealthcheck());
    GenericContainer<?> frontend = new GenericContainer<>(parse("ghcr.io/openzipkin/brave-example:armeria")).withNetwork(Network.SHARED).withNetworkAliases("frontend").withCommand("frontend").withExposedPorts(8081).waitingFor(Wait.forHealthcheck());
    containers.add(frontend);
    // Use a quay.io mirror to prevent build outages due to Docker Hub pull quotas
    // Use same version as in docker/examples/docker-compose-prometheus.yml
    GenericContainer<?> prometheus = new GenericContainer<>(parse("quay.io/prometheus/prometheus:v2.23.0")).withNetwork(Network.SHARED).withNetworkAliases("prometheus").withExposedPorts(9090).withCopyFileToContainer(MountableFile.forClasspathResource("prometheus.yml"), "/etc/prometheus/prometheus.yml");
    containers.add(prometheus);
    // Use a quay.io mirror to prevent build outages due to Docker Hub pull quotas
    // Use same version as in docker/examples/docker-compose-prometheus.yml
    GenericContainer<?> grafana = new GenericContainer<>(parse("quay.io/app-sre/grafana:7.3.4")).withNetwork(Network.SHARED).withNetworkAliases("grafana").withExposedPorts(3000).withEnv("GF_AUTH_ANONYMOUS_ENABLED", "true").withEnv("GF_AUTH_ANONYMOUS_ORG_ROLE", "Admin");
    containers.add(grafana);
    // This is an arbitrary small image that has curl installed
    // Use a quay.io mirror to prevent build outages due to Docker Hub pull quotas
    // Use same version as in docker/examples/docker-compose-prometheus.yml
    GenericContainer<?> grafanaDashboards = new GenericContainer<>(parse("quay.io/rackspace/curl:7.70.0")).withNetwork(Network.SHARED).withWorkingDirectory("/tmp").withLogConsumer(new Slf4jLogConsumer(LOG)).withCreateContainerCmdModifier(it -> it.withEntrypoint("/tmp/create.sh")).withCopyFileToContainer(MountableFile.forClasspathResource("create-datasource-and-dashboard.sh", 555), "/tmp/create.sh");
    containers.add(grafanaDashboards);
    // Use a quay.io mirror to prevent build outages due to Docker Hub pull quotas
    GenericContainer<?> wrk = new GenericContainer<>(parse("quay.io/dim/wrk:stable")).withNetwork(Network.SHARED).withCreateContainerCmdModifier(it -> it.withEntrypoint("wrk")).withCommand("-t4 -c128 -d100s http://frontend:8081 --latency");
    containers.add(wrk);
    grafanaDashboards.dependsOn(grafana);
    wrk.dependsOn(frontend, backend, prometheus, grafanaDashboards, zipkin);
    if (storage != null)
        wrk.dependsOn(storage);
    Startables.deepStart(Stream.of(wrk)).join();
    System.out.println("Benchmark started.");
    if (zipkin != null)
        printContainerMapping(zipkin);
    if (storage != null)
        printContainerMapping(storage);
    printContainerMapping(backend);
    printContainerMapping(frontend);
    printContainerMapping(prometheus);
    printContainerMapping(grafana);
    while (wrk.isRunning()) {
        Thread.sleep(1000);
    }
    // Wait for prometheus to do a final scrape.
    Thread.sleep(5000);
    System.out.println("Benchmark complete, wrk output:");
    System.out.println(wrk.getLogs().replace("\n\n", "\n"));
    WebClient prometheusClient = WebClient.of("h1c://" + prometheus.getContainerIpAddress() + ":" + prometheus.getFirstMappedPort());
    System.out.println(String.format("Messages received: %s", prometheusValue(prometheusClient, "sum(zipkin_collector_messages_total)")));
    System.out.println(String.format("Spans received: %s", prometheusValue(prometheusClient, "sum(zipkin_collector_spans_total)")));
    System.out.println(String.format("Spans dropped: %s", prometheusValue(prometheusClient, "sum(zipkin_collector_spans_dropped_total)")));
    System.out.println("Memory quantiles:");
    printQuartiles(prometheusClient, "jvm_memory_used_bytes{area=\"heap\"}");
    printQuartiles(prometheusClient, "jvm_memory_used_bytes{area=\"nonheap\"}");
    System.out.println(String.format("Total GC time (s): %s", prometheusValue(prometheusClient, "sum(jvm_gc_pause_seconds_sum)")));
    System.out.println(String.format("Number of GCs: %s", prometheusValue(prometheusClient, "sum(jvm_gc_pause_seconds_count)")));
    System.out.println("POST Spans latency (s)");
    printHistogram(prometheusClient, "http_server_requests_seconds_bucket{" + "method=\"POST\",status=\"202\",uri=\"/api/v2/spans\"}");
    if (WAIT_AFTER_BENCHMARK) {
        System.out.println("Keeping containers running until explicit termination. " + "Feel free to poke around in grafana.");
        Thread.sleep(Long.MAX_VALUE);
    }
}
Also used : BeforeEach(org.junit.jupiter.api.BeforeEach) Arrays(java.util.Arrays) LoggerFactory(org.slf4j.LoggerFactory) SimpleImmutableEntry(java.util.AbstractMap.SimpleImmutableEntry) Disabled(org.junit.jupiter.api.Disabled) Network(org.testcontainers.containers.Network) ArrayList(java.util.ArrayList) LinkedHashMap(java.util.LinkedHashMap) Slf4jLogConsumer(org.testcontainers.containers.output.Slf4jLogConsumer) WebClient(com.linecorp.armeria.client.WebClient) Map(java.util.Map) GenericContainer(org.testcontainers.containers.GenericContainer) Path(java.nio.file.Path) Nullable(javax.annotation.Nullable) DockerImageName.parse(org.testcontainers.utility.DockerImageName.parse) Wait(org.testcontainers.containers.wait.strategy.Wait) QueryStringEncoder(io.netty.handler.codec.http.QueryStringEncoder) Logger(org.slf4j.Logger) Files(java.nio.file.Files) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Startables(org.testcontainers.lifecycle.Startables) Collectors(java.util.stream.Collectors) File(java.io.File) Test(org.junit.jupiter.api.Test) List(java.util.List) AfterEach(org.junit.jupiter.api.AfterEach) Stream(java.util.stream.Stream) Paths(java.nio.file.Paths) MountableFile(org.testcontainers.utility.MountableFile) Slf4jLogConsumer(org.testcontainers.containers.output.Slf4jLogConsumer) GenericContainer(org.testcontainers.containers.GenericContainer) WebClient(com.linecorp.armeria.client.WebClient)

Example 3 with WebClient

use of com.linecorp.armeria.client.WebClient in project zipkin by openzipkin.

the class ZipkinElasticsearchStorageConfigurationTest method providesBasicAuthInterceptor_whenBasicAuthUserNameAndPasswordConfigured.

@Test
public void providesBasicAuthInterceptor_whenBasicAuthUserNameAndPasswordConfigured() {
    TestPropertyValues.of("zipkin.storage.type:elasticsearch", "zipkin.storage.elasticsearch.hosts:127.0.0.1:1234", "zipkin.storage.elasticsearch.username:somename", "zipkin.storage.elasticsearch.password:pass").applyTo(context);
    Access.registerElasticsearch(context);
    context.refresh();
    HttpClientFactory factory = context.getBean(HttpClientFactory.class);
    WebClient client = WebClient.builder("http://127.0.0.1:1234").option(ClientOptions.DECORATION, factory.options.decoration()).build();
    assertThat(client.as(BasicAuthInterceptor.class)).isNotNull();
}
Also used : WebClient(com.linecorp.armeria.client.WebClient) Test(org.junit.Test)

Example 4 with WebClient

use of com.linecorp.armeria.client.WebClient in project zipkin by openzipkin.

the class ZipkinElasticsearchStorageConfigurationTest method doesntProvideBasicAuthInterceptor_whenBasicAuthUserNameandPasswordNotConfigured.

@Test
public void doesntProvideBasicAuthInterceptor_whenBasicAuthUserNameandPasswordNotConfigured() {
    TestPropertyValues.of("zipkin.storage.type:elasticsearch", "zipkin.storage.elasticsearch.hosts:127.0.0.1:1234").applyTo(context);
    Access.registerElasticsearch(context);
    context.refresh();
    HttpClientFactory factory = context.getBean(HttpClientFactory.class);
    WebClient client = WebClient.builder("http://127.0.0.1:1234").option(ClientOptions.DECORATION, factory.options.decoration()).build();
    assertThat(client.as(BasicAuthInterceptor.class)).isNull();
}
Also used : WebClient(com.linecorp.armeria.client.WebClient) Test(org.junit.Test)

Example 5 with WebClient

use of com.linecorp.armeria.client.WebClient in project zipkin by openzipkin.

the class ZipkinElasticsearchStorageConfigurationTest method providesBasicAuthInterceptor_whenDynamicCredentialsConfigured.

@Test
public void providesBasicAuthInterceptor_whenDynamicCredentialsConfigured() {
    String credentialsFile = pathOfResource("es-credentials");
    TestPropertyValues.of("zipkin.storage.type:elasticsearch", "zipkin.storage.elasticsearch.hosts:127.0.0.1:1234", "zipkin.storage.elasticsearch.credentials-file:" + credentialsFile, "zipkin.storage.elasticsearch.credentials-refresh-interval:2").applyTo(context);
    Access.registerElasticsearch(context);
    context.refresh();
    HttpClientFactory factory = context.getBean(HttpClientFactory.class);
    WebClient client = WebClient.builder("http://127.0.0.1:1234").option(ClientOptions.DECORATION, factory.options.decoration()).build();
    assertThat(client.as(BasicAuthInterceptor.class)).isNotNull();
    BasicCredentials basicCredentials = Objects.requireNonNull(client.as(BasicAuthInterceptor.class)).basicCredentials;
    String credentials = basicCredentials.getCredentials();
    assertThat(credentials).isEqualTo("Basic Zm9vOmJhcg==");
}
Also used : WebClient(com.linecorp.armeria.client.WebClient) Test(org.junit.Test)

Aggregations

WebClient (com.linecorp.armeria.client.WebClient)6 Test (org.junit.Test)3 Test (org.junit.jupiter.api.Test)2 Logger (org.slf4j.Logger)2 LoggerFactory (org.slf4j.LoggerFactory)2 GenericContainer (org.testcontainers.containers.GenericContainer)2 Slf4jLogConsumer (org.testcontainers.containers.output.Slf4jLogConsumer)2 Wait (org.testcontainers.containers.wait.strategy.Wait)2 DockerImageName.parse (org.testcontainers.utility.DockerImageName.parse)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 ClientFactory (com.linecorp.armeria.client.ClientFactory)1 ClientOptions (com.linecorp.armeria.client.ClientOptions)1 ClientOptionsBuilder (com.linecorp.armeria.client.ClientOptionsBuilder)1 WebClientBuilder (com.linecorp.armeria.client.WebClientBuilder)1 ContentPreviewingClient (com.linecorp.armeria.client.logging.ContentPreviewingClient)1 LoggingClient (com.linecorp.armeria.client.logging.LoggingClient)1 LoggingClientBuilder (com.linecorp.armeria.client.logging.LoggingClientBuilder)1 AggregatedHttpResponse (com.linecorp.armeria.common.AggregatedHttpResponse)1 HttpResponse (com.linecorp.armeria.common.HttpResponse)1 LogLevel (com.linecorp.armeria.common.logging.LogLevel)1