Search in sources :

Example 26 with SuppressLogger

use of io.opentelemetry.internal.testing.slf4j.SuppressLogger in project opentelemetry-java by open-telemetry.

the class BeanstalkResourceTest method testBadConfigFile.

@Test
@SuppressLogger(BeanstalkResource.class)
void testBadConfigFile(@TempDir File tempFolder) throws IOException {
    File file = new File(tempFolder, "beanstalk.config");
    String content = "\"deployment_id\":4,\"version_label\":\"2\",\"" + "environment_name\":\"HttpSubscriber-env\"}";
    Files.write(content.getBytes(Charsets.UTF_8), file);
    Attributes attributes = BeanstalkResource.buildResource(file.getPath()).getAttributes();
    assertThat(attributes).isEmpty();
}
Also used : Attributes(io.opentelemetry.api.common.Attributes) ResourceAttributes(io.opentelemetry.semconv.resource.attributes.ResourceAttributes) File(java.io.File) SuppressLogger(io.opentelemetry.internal.testing.slf4j.SuppressLogger) Test(org.junit.jupiter.api.Test)

Example 27 with SuppressLogger

use of io.opentelemetry.internal.testing.slf4j.SuppressLogger in project opentelemetry-java by open-telemetry.

the class Ec2ResourceTest method badJson.

@Test
@SuppressLogger(Ec2Resource.class)
void badJson() {
    server.enqueue(HttpResponse.of(HttpStatus.NOT_FOUND));
    server.enqueue(HttpResponse.of(MediaType.JSON_UTF_8, "I'm not JSON"));
    Attributes attributes = Ec2Resource.buildResource("localhost:" + server.httpPort()).getAttributes();
    assertThat(attributes).isEmpty();
    AggregatedHttpRequest request1 = server.takeRequest().request();
    assertThat(request1.path()).isEqualTo("/latest/api/token");
    assertThat(request1.headers().get("X-aws-ec2-metadata-token-ttl-seconds")).isEqualTo("60");
    AggregatedHttpRequest request2 = server.takeRequest().request();
    assertThat(request2.path()).isEqualTo("/latest/dynamic/instance-identity/document");
    assertThat(request2.headers().get("X-aws-ec2-metadata-token")).isNull();
}
Also used : Attributes(io.opentelemetry.api.common.Attributes) ResourceAttributes(io.opentelemetry.semconv.resource.attributes.ResourceAttributes) AggregatedHttpRequest(com.linecorp.armeria.common.AggregatedHttpRequest) SuppressLogger(io.opentelemetry.internal.testing.slf4j.SuppressLogger) Test(org.junit.jupiter.api.Test)

Example 28 with SuppressLogger

use of io.opentelemetry.internal.testing.slf4j.SuppressLogger in project opentelemetry-java by open-telemetry.

the class EksResourceTest method testEks.

@Test
@SuppressLogger(EksResource.class)
void testEks(@TempDir File tempFolder) throws IOException {
    File mockK8sTokenFile = new File(tempFolder, "k8sToken");
    String token = "token123";
    Files.write(token.getBytes(Charsets.UTF_8), mockK8sTokenFile);
    File mockK8sKeystoreFile = new File(tempFolder, "k8sCert");
    String truststore = "truststore123";
    Files.write(truststore.getBytes(Charsets.UTF_8), mockK8sKeystoreFile);
    when(httpClient.fetchString(any(), Mockito.eq(K8S_SVC_URL + AUTH_CONFIGMAP_PATH), any(), any())).thenReturn("not empty");
    when(httpClient.fetchString(any(), Mockito.eq(K8S_SVC_URL + CW_CONFIGMAP_PATH), any(), any())).thenReturn("{\"data\":{\"cluster.name\":\"my-cluster\"}}");
    when(mockDockerHelper.getContainerId()).thenReturn("0123456789A");
    Resource eksResource = EksResource.buildResource(httpClient, mockDockerHelper, mockK8sTokenFile.getPath(), mockK8sKeystoreFile.getPath());
    Attributes attributes = eksResource.getAttributes();
    assertThat(eksResource.getSchemaUrl()).isEqualTo(ResourceAttributes.SCHEMA_URL);
    assertThat(attributes).containsOnly(entry(ResourceAttributes.CLOUD_PROVIDER, "aws"), entry(ResourceAttributes.CLOUD_PLATFORM, "aws_eks"), entry(ResourceAttributes.K8S_CLUSTER_NAME, "my-cluster"), entry(ResourceAttributes.CONTAINER_ID, "0123456789A"));
}
Also used : Resource(io.opentelemetry.sdk.resources.Resource) Attributes(io.opentelemetry.api.common.Attributes) ResourceAttributes(io.opentelemetry.semconv.resource.attributes.ResourceAttributes) File(java.io.File) SuppressLogger(io.opentelemetry.internal.testing.slf4j.SuppressLogger) Test(org.junit.jupiter.api.Test)

Example 29 with SuppressLogger

use of io.opentelemetry.internal.testing.slf4j.SuppressLogger in project opentelemetry-java by open-telemetry.

the class JaegerRemoteSamplerTest method unimplemented_error_server_response.

@Test
@SuppressLogger(OkHttpGrpcService.class)
void unimplemented_error_server_response() {
    addGrpcError(12, null);
    try (JaegerRemoteSampler sampler = JaegerRemoteSampler.builder().setEndpoint(server.httpUri().toString()).setServiceName(SERVICE_NAME).setPollingInterval(50, TimeUnit.MILLISECONDS).build()) {
        assertThat(sampler.getDescription()).startsWith("JaegerRemoteSampler{ParentBased{root:TraceIdRatioBased{0.001000}");
        await().untilAsserted(() -> {
            LoggingEvent log = logs.assertContains("Server responded with UNIMPLEMENTED.");
            assertThat(log.getLevel()).isEqualTo(Level.ERROR);
        });
    }
}
Also used : LoggingEvent(org.slf4j.event.LoggingEvent) SuppressLogger(io.opentelemetry.internal.testing.slf4j.SuppressLogger) Test(org.junit.jupiter.api.Test)

Example 30 with SuppressLogger

use of io.opentelemetry.internal.testing.slf4j.SuppressLogger in project opentelemetry-java by open-telemetry.

the class JaegerRemoteSamplerTest method unavailable_error_server_response.

@Test
@SuppressLogger(OkHttpGrpcService.class)
void unavailable_error_server_response() {
    addGrpcError(14, "クマ🐻 resource exhausted");
    try (JaegerRemoteSampler sampler = JaegerRemoteSampler.builder().setEndpoint(server.httpUri().toString()).setServiceName(SERVICE_NAME).setPollingInterval(50, TimeUnit.MILLISECONDS).build()) {
        assertThat(sampler.getDescription()).startsWith("JaegerRemoteSampler{ParentBased{root:TraceIdRatioBased{0.001000}");
        await().untilAsserted(() -> {
            LoggingEvent log = logs.assertContains("Server is UNAVAILABLE");
            assertThat(log.getLevel()).isEqualTo(Level.ERROR);
        });
    }
}
Also used : LoggingEvent(org.slf4j.event.LoggingEvent) SuppressLogger(io.opentelemetry.internal.testing.slf4j.SuppressLogger) Test(org.junit.jupiter.api.Test)

Aggregations

SuppressLogger (io.opentelemetry.internal.testing.slf4j.SuppressLogger)32 Test (org.junit.jupiter.api.Test)32 LoggingEvent (org.slf4j.event.LoggingEvent)11 HashMap (java.util.HashMap)6 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)6 Attributes (io.opentelemetry.api.common.Attributes)3 ResourceAttributes (io.opentelemetry.semconv.resource.attributes.ResourceAttributes)3 DoubleHistogram (io.opentelemetry.api.metrics.DoubleHistogram)2 LongCounter (io.opentelemetry.api.metrics.LongCounter)2 LongHistogram (io.opentelemetry.api.metrics.LongHistogram)2 CompletableResultCode (io.opentelemetry.sdk.common.CompletableResultCode)2 LogData (io.opentelemetry.sdk.logs.data.LogData)2 LogExporter (io.opentelemetry.sdk.logs.export.LogExporter)2 MetricExporter (io.opentelemetry.sdk.metrics.export.MetricExporter)2 BoundDoubleHistogram (io.opentelemetry.sdk.metrics.internal.instrument.BoundDoubleHistogram)2 BoundLongCounter (io.opentelemetry.sdk.metrics.internal.instrument.BoundLongCounter)2 BoundLongHistogram (io.opentelemetry.sdk.metrics.internal.instrument.BoundLongHistogram)2 SpanExporter (io.opentelemetry.sdk.trace.export.SpanExporter)2 File (java.io.File)2 AggregatedHttpRequest (com.linecorp.armeria.common.AggregatedHttpRequest)1