Search in sources :

Example 1 with OK

use of zipkin2.CheckResult.OK in project zipkin by openzipkin.

the class ITEnsureIndexTemplate method createZipkinIndexTemplate_getTraces_returnsSuccess.

@Test
void createZipkinIndexTemplate_getTraces_returnsSuccess(TestInfo testInfo) throws Exception {
    String testSuffix = testSuffix(testInfo);
    storage = newStorageBuilder(testInfo).templatePriority(10).build();
    try {
        // Delete all templates in order to create the "catch-all" index template, because
        // ES does not allow multiple index templates of the same index_patterns and priority
        http(DELETE, "/_template/*");
        setUpCatchAllTemplate();
        // Implicitly creates an index template
        checkStorage();
        // Get all templates. We don't assert on this at the moment. This is for logging on ES_DEBUG.
        http(GET, "/_template");
        // Now, add a span, which should be indexed differently than default.
        Span span = spanBuilder(testSuffix).putTag("queryTest", "ok").build();
        accept(asList(span));
        // Assert that Zipkin's templates work and source is returned
        assertGetTracesReturns(requestBuilder().parseAnnotationQuery("queryTest=" + span.tags().get("queryTest")).build(), asList(span));
    } finally {
        // Delete "catch-all" index template so it does not interfere with any other test
        http(DELETE, catchAllIndexPath());
    }
}
Also used : Span(zipkin2.Span) Test(org.junit.jupiter.api.Test)

Example 2 with OK

use of zipkin2.CheckResult.OK in project zipkin by openzipkin.

the class ITElasticsearchClientInitialization method doesntHangWhenAllDown.

/**
 * blocking a little is ok, but blocking forever is not.
 */
@Test(timeout = 3000L)
public void doesntHangWhenAllDown() throws IOException {
    TestPropertyValues.of("spring.config.name=zipkin-server", "zipkin.storage.type:elasticsearch", "zipkin.storage.elasticsearch.timeout:1000", "zipkin.storage.elasticsearch.hosts:127.0.0.1:1234,127.0.0.1:5678").applyTo(context);
    Access.registerElasticsearch(context);
    context.refresh();
    try (ElasticsearchStorage storage = context.getBean(ElasticsearchStorage.class)) {
        CheckResult result = storage.check();
        assertThat(result.ok()).isFalse();
    }
}
Also used : ElasticsearchStorage(zipkin2.elasticsearch.ElasticsearchStorage) CheckResult(zipkin2.CheckResult) Test(org.junit.Test)

Example 3 with OK

use of zipkin2.CheckResult.OK in project zipkin by openzipkin.

the class ITElasticsearchHealthCheck method notHealthyThenHealthyThenNotHealthy.

@Test
public void notHealthyThenHealthyThenNotHealthy() {
    server1Health.setHealthy(false);
    server2Health.setHealthy(false);
    try (ElasticsearchStorage storage = context.getBean(ElasticsearchStorage.class)) {
        CheckResult result = storage.check();
        assertThat(result.ok()).isFalse();
        server2Health.setHealthy(true);
        awaitTimeout.untilAsserted(() -> assertThat(storage.check().ok()).isTrue());
        server2Health.setHealthy(false);
        awaitTimeout.untilAsserted(() -> assertThat(storage.check().ok()).isFalse());
    }
}
Also used : ElasticsearchStorage(zipkin2.elasticsearch.ElasticsearchStorage) CheckResult(zipkin2.CheckResult) Test(org.junit.Test)

Example 4 with OK

use of zipkin2.CheckResult.OK in project spring-cloud-sleuth by spring-cloud.

the class FeignRetriesTests method testRetriedWhenRequestEventuallyIsSent.

@Test
public void testRetriedWhenRequestEventuallyIsSent() throws Exception {
    String url = "http://localhost:" + server.getPort();
    final AtomicInteger atomicInteger = new AtomicInteger();
    // Client to simulate a retry scenario
    final Client client = (request, options) -> {
        // we simulate an exception only for the first request
        if (atomicInteger.get() == 1) {
            throw new IOException();
        } else {
            // with the second retry (first retry) we send back good result
            return Response.builder().status(200).reason("OK").headers(new HashMap<>()).body("OK", Charset.defaultCharset()).build();
        }
    };
    TestInterface api = Feign.builder().client(new TracingFeignClient(this.httpTracing, new Client() {

        @Override
        public Response execute(Request request, Request.Options options) throws IOException {
            atomicInteger.incrementAndGet();
            return client.execute(request, options);
        }
    })).target(TestInterface.class, url);
    then(api.decodedPost()).isEqualTo("OK");
    // request interception should take place only twice (1st request & 2nd retry)
    then(atomicInteger.get()).isEqualTo(2);
    then(this.reporter.getSpans().get(0).tags()).containsEntry("error", "IOException");
    then(this.reporter.getSpans().get(1).kind().ordinal()).isEqualTo(Span.Kind.CLIENT.ordinal());
}
Also used : Mock(org.mockito.Mock) RunWith(org.junit.runner.RunWith) Span(zipkin2.Span) HashMap(java.util.HashMap) Client(feign.Client) ErrorParser(org.springframework.cloud.sleuth.ErrorParser) CurrentTraceContext(brave.propagation.CurrentTraceContext) ExceptionMessageErrorParser(org.springframework.cloud.sleuth.ExceptionMessageErrorParser) Charset(java.nio.charset.Charset) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) After(org.junit.After) ArrayListSpanReporter(org.springframework.cloud.sleuth.util.ArrayListSpanReporter) MockWebServer(okhttp3.mockwebserver.MockWebServer) FeignException(feign.FeignException) Before(org.junit.Before) Tracing(brave.Tracing) HttpTracing(brave.http.HttpTracing) Response(feign.Response) SleuthHttpParserAccessor(org.springframework.cloud.sleuth.instrument.web.SleuthHttpParserAccessor) RequestLine(feign.RequestLine) IOException(java.io.IOException) Test(org.junit.Test) BDDAssertions.then(org.assertj.core.api.BDDAssertions.then) Feign(feign.Feign) BDDMockito(org.mockito.BDDMockito) Rule(org.junit.Rule) BeanFactory(org.springframework.beans.factory.BeanFactory) Request(feign.Request) MockitoJUnitRunner(org.mockito.junit.MockitoJUnitRunner) Assertions.failBecauseExceptionWasNotThrown(org.assertj.core.api.Assertions.failBecauseExceptionWasNotThrown) Response(feign.Response) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) HashMap(java.util.HashMap) Request(feign.Request) IOException(java.io.IOException) Client(feign.Client) Test(org.junit.Test)

Example 5 with OK

use of zipkin2.CheckResult.OK in project crnk-framework by crnk-project.

the class AbstractBraveModuleTest method testFindTargets.

@Test
public void testFindTargets() {
    RelationshipRepository<Project, Serializable, Task, Serializable> relRepo = client.getRepositoryForType(Project.class, Task.class);
    relRepo.findManyTargets(123L, "tasks", new QuerySpec(Task.class));
    // check client call and link span
    ArgumentCaptor<Span> clientSpanCaptor = ArgumentCaptor.forClass(Span.class);
    Mockito.verify(clientReporter, Mockito.times(1)).report(clientSpanCaptor.capture());
    List<Span> clientSpans = clientSpanCaptor.getAllValues();
    Span callSpan = clientSpans.get(0);
    Assert.assertEquals("get", callSpan.name());
    Assert.assertEquals(Span.Kind.CLIENT, callSpan.kind());
    // check server local span
    ArgumentCaptor<Span> serverSpanCaptor = ArgumentCaptor.forClass(Span.class);
    Mockito.verify(serverReporter, Mockito.times(2)).report(serverSpanCaptor.capture());
    List<Span> serverSpans = serverSpanCaptor.getAllValues();
    Span repositorySpan0 = serverSpans.get(0);
    Assert.assertEquals("crnk:get:/tasks/", repositorySpan0.name());
    Assert.assertTrue(repositorySpan0.toString().contains("\"lc\""));
    assertTag(repositorySpan0, "lc", "crnk");
    assertTag(repositorySpan0, "crnk.results", "0");
    assertTag(repositorySpan0, "crnk.status", "OK");
    Span repositorySpan1 = serverSpans.get(1);
    Assert.assertEquals("crnk:get:/projects/123/tasks/", repositorySpan1.name());
    Assert.assertTrue(repositorySpan1.toString().contains("\"lc\""));
    assertTag(repositorySpan1, "lc", "crnk");
    assertTag(repositorySpan1, "crnk.query", "?");
    assertTag(repositorySpan1, "crnk.results", "0");
    assertTag(repositorySpan1, "crnk.status", "OK");
}
Also used : Project(io.crnk.monitor.brave.mock.models.Project) Serializable(java.io.Serializable) Task(io.crnk.monitor.brave.mock.models.Task) QuerySpec(io.crnk.core.queryspec.QuerySpec) Span(zipkin2.Span) Test(org.junit.Test)

Aggregations

Span (zipkin2.Span)8 Test (org.junit.Test)7 Test (org.junit.jupiter.api.Test)5 Task (io.crnk.monitor.brave.mock.models.Task)3 TestSpanData (io.opentelemetry.sdk.testing.trace.TestSpanData)3 SpanData (io.opentelemetry.sdk.trace.data.SpanData)3 CheckResult (zipkin2.CheckResult)3 Endpoint (zipkin2.Endpoint)3 ElasticsearchStorage (zipkin2.elasticsearch.ElasticsearchStorage)3 QuerySpec (io.crnk.core.queryspec.QuerySpec)2 Tracing (brave.Tracing)1 HttpTracing (brave.http.HttpTracing)1 CurrentTraceContext (brave.propagation.CurrentTraceContext)1 Client (feign.Client)1 Feign (feign.Feign)1 FeignException (feign.FeignException)1 Request (feign.Request)1 RequestLine (feign.RequestLine)1 Response (feign.Response)1 FilterSpec (io.crnk.core.queryspec.FilterSpec)1