From 536094296fe1fe5adaa85bfdb03de06ab5ae7ab9 Mon Sep 17 00:00:00 2001 From: Sky Ao Date: Sat, 16 Dec 2023 16:21:52 +0000 Subject: [PATCH] remove testcase for http tracing Signed-off-by: Sky Ao --- .../io/dapr/it/tracing/http/Controller.java | 25 ------- .../it/tracing/http/OpenTelemetryConfig.java | 43 ----------- .../http/OpenTelemetryInterceptor.java | 70 ------------------ .../http/OpenTelemetryInterceptorConfig.java | 31 -------- .../java/io/dapr/it/tracing/http/Service.java | 51 ------------- .../io/dapr/it/tracing/http/TracingIT.java | 72 ------------------- 6 files changed, 292 deletions(-) delete mode 100644 sdk-tests/src/test/java/io/dapr/it/tracing/http/Controller.java delete mode 100644 sdk-tests/src/test/java/io/dapr/it/tracing/http/OpenTelemetryConfig.java delete mode 100644 sdk-tests/src/test/java/io/dapr/it/tracing/http/OpenTelemetryInterceptor.java delete mode 100644 sdk-tests/src/test/java/io/dapr/it/tracing/http/OpenTelemetryInterceptorConfig.java delete mode 100644 sdk-tests/src/test/java/io/dapr/it/tracing/http/Service.java delete mode 100644 sdk-tests/src/test/java/io/dapr/it/tracing/http/TracingIT.java diff --git a/sdk-tests/src/test/java/io/dapr/it/tracing/http/Controller.java b/sdk-tests/src/test/java/io/dapr/it/tracing/http/Controller.java deleted file mode 100644 index 54df1f9fa9..0000000000 --- a/sdk-tests/src/test/java/io/dapr/it/tracing/http/Controller.java +++ /dev/null @@ -1,25 +0,0 @@ -package io.dapr.it.tracing.http; - -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.PostMapping; -import org.springframework.web.bind.annotation.RequestBody; -import org.springframework.web.bind.annotation.RestController; - -/** - * SpringBoot Controller to handle input binding. - */ -@RestController -public class Controller { - - @PostMapping(path = "/sleep") - public void sleep(@RequestBody int seconds) throws InterruptedException { - if (seconds < 0) { - throw new IllegalArgumentException("Sleep time cannot be negative."); - } - Thread.sleep(seconds * 1000); - } - - @GetMapping(path = "/health") - public void health() { - } -} diff --git a/sdk-tests/src/test/java/io/dapr/it/tracing/http/OpenTelemetryConfig.java b/sdk-tests/src/test/java/io/dapr/it/tracing/http/OpenTelemetryConfig.java deleted file mode 100644 index 8a976f93dc..0000000000 --- a/sdk-tests/src/test/java/io/dapr/it/tracing/http/OpenTelemetryConfig.java +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Copyright 2021 The Dapr Authors - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * http://www.apache.org/licenses/LICENSE-2.0 - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and -limitations under the License. -*/ - -package io.dapr.it.tracing.http; - -import io.opentelemetry.api.OpenTelemetry; -import io.opentelemetry.api.trace.Tracer; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.autoconfigure.EnableAutoConfiguration; -import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration; -import org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; - -@Configuration -@EnableAutoConfiguration(exclude = {DataSourceAutoConfiguration.class, HibernateJpaAutoConfiguration.class}) -public class OpenTelemetryConfig { - - public static final String TRACER_NAME = "integration testing tracer"; - - public static final String SERVICE_NAME = "integration testing service over http"; - - @Bean - public OpenTelemetry initOpenTelemetry() throws InterruptedException { - return io.dapr.it.tracing.OpenTelemetry.createOpenTelemetry(SERVICE_NAME); - } - - @Bean - public Tracer initTracer(@Autowired OpenTelemetry openTelemetry) { - return openTelemetry.getTracer(TRACER_NAME); - } - -} diff --git a/sdk-tests/src/test/java/io/dapr/it/tracing/http/OpenTelemetryInterceptor.java b/sdk-tests/src/test/java/io/dapr/it/tracing/http/OpenTelemetryInterceptor.java deleted file mode 100644 index 0be4baee8c..0000000000 --- a/sdk-tests/src/test/java/io/dapr/it/tracing/http/OpenTelemetryInterceptor.java +++ /dev/null @@ -1,70 +0,0 @@ -/* - * Copyright 2021 The Dapr Authors - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * http://www.apache.org/licenses/LICENSE-2.0 - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and -limitations under the License. -*/ - -package io.dapr.it.tracing.http; - -import io.opentelemetry.api.OpenTelemetry; -import io.opentelemetry.context.Context; -import io.opentelemetry.context.propagation.TextMapPropagator; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Component; -import org.springframework.web.servlet.HandlerInterceptor; -import org.springframework.web.servlet.ModelAndView; - -import jakarta.servlet.DispatcherType; -import jakarta.servlet.http.HttpServletRequest; -import jakarta.servlet.http.HttpServletResponse; -import java.util.Collections; - -@Component -public class OpenTelemetryInterceptor implements HandlerInterceptor { - - @Autowired - private OpenTelemetry openTelemetry; - - private static final TextMapPropagator.Getter HTTP_SERVLET_REQUEST_GETTER = - new TextMapPropagator.Getter<>() { - @Override - public Iterable keys(HttpServletRequest carrier) { - return Collections.list(carrier.getHeaderNames()); - } - - @Override - public String get(HttpServletRequest carrier, String key) { - return carrier.getHeader(key); - } - }; - - @Override - public boolean preHandle( - HttpServletRequest request, HttpServletResponse response, Object handler) { - final TextMapPropagator textFormat = openTelemetry.getPropagators().getTextMapPropagator(); - // preHandle is called twice for asynchronous request. For more information, read: - // https://docs.spring.io/spring-framework/docs/current/javadoc-api/org/springframework/web/servlet/AsyncHandlerInterceptor.html - if (request.getDispatcherType() == DispatcherType.ASYNC) { - return true; - } - - Context context = textFormat.extract(Context.current(), request, HTTP_SERVLET_REQUEST_GETTER); - request.setAttribute("opentelemetry-context", context); - return true; - } - - @Override - public void postHandle( - HttpServletRequest request, HttpServletResponse response, Object handler, - ModelAndView modelAndView) { - // There is no global context to be changed in post handle since it is done in preHandle on a new call. - } - -} diff --git a/sdk-tests/src/test/java/io/dapr/it/tracing/http/OpenTelemetryInterceptorConfig.java b/sdk-tests/src/test/java/io/dapr/it/tracing/http/OpenTelemetryInterceptorConfig.java deleted file mode 100644 index ce23430139..0000000000 --- a/sdk-tests/src/test/java/io/dapr/it/tracing/http/OpenTelemetryInterceptorConfig.java +++ /dev/null @@ -1,31 +0,0 @@ -/* - * Copyright 2021 The Dapr Authors - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * http://www.apache.org/licenses/LICENSE-2.0 - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and -limitations under the License. -*/ - -package io.dapr.it.tracing.http; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Component; -import org.springframework.web.servlet.config.annotation.InterceptorRegistry; -import org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport; - -@Component -public class OpenTelemetryInterceptorConfig extends WebMvcConfigurationSupport { - - @Autowired - OpenTelemetryInterceptor interceptor; - - @Override - public void addInterceptors(InterceptorRegistry registry) { - registry.addInterceptor(interceptor); - } -} \ No newline at end of file diff --git a/sdk-tests/src/test/java/io/dapr/it/tracing/http/Service.java b/sdk-tests/src/test/java/io/dapr/it/tracing/http/Service.java deleted file mode 100644 index ba43173058..0000000000 --- a/sdk-tests/src/test/java/io/dapr/it/tracing/http/Service.java +++ /dev/null @@ -1,51 +0,0 @@ -/* - * Copyright 2021 The Dapr Authors - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * http://www.apache.org/licenses/LICENSE-2.0 - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and -limitations under the License. -*/ - -package io.dapr.it.tracing.http; - -import io.dapr.it.DaprRunConfig; -import org.springframework.boot.SpringApplication; -import org.springframework.boot.autoconfigure.SpringBootApplication; - - -/** - * Service for subscriber. - */ -@DaprRunConfig( - enableAppHealthCheck = true -) -@SpringBootApplication -public class Service { - - public static final String SUCCESS_MESSAGE = "Completed initialization in"; - - public static void main(String[] args) { - int port = Integer.parseInt(args[0]); - - System.out.printf("Service starting on port %d ...\n", port); - - // Start Dapr's callback endpoint. - start(port); - } - - /** - * Starts Dapr's callback in a given port. - * - * @param port Port to listen to. - */ - private static void start(int port) { - SpringApplication app = new SpringApplication(Service.class); - app.run(String.format("--server.port=%d", port)); - } - -} \ No newline at end of file diff --git a/sdk-tests/src/test/java/io/dapr/it/tracing/http/TracingIT.java b/sdk-tests/src/test/java/io/dapr/it/tracing/http/TracingIT.java deleted file mode 100644 index 96b669ef78..0000000000 --- a/sdk-tests/src/test/java/io/dapr/it/tracing/http/TracingIT.java +++ /dev/null @@ -1,72 +0,0 @@ -package io.dapr.it.tracing.http; - -import io.dapr.client.DaprClient; -import io.dapr.client.DaprClientBuilder; -import io.dapr.client.domain.HttpExtension; -import io.dapr.it.BaseIT; -import io.dapr.it.DaprRun; -import io.dapr.it.tracing.Validation; -import io.opentelemetry.api.OpenTelemetry; -import io.opentelemetry.api.trace.Span; -import io.opentelemetry.api.trace.Tracer; -import io.opentelemetry.context.Scope; -import io.opentelemetry.sdk.OpenTelemetrySdk; -import org.junit.jupiter.params.ParameterizedTest; -import org.junit.jupiter.params.provider.ValueSource; - -import java.util.UUID; - -import static io.dapr.it.tracing.OpenTelemetry.createOpenTelemetry; -import static io.dapr.it.tracing.OpenTelemetry.getReactorContext; - -public class TracingIT extends BaseIT { - - /** - * Run of a Dapr application. - */ - private DaprRun daprRun = null; - - public void setup(boolean useGrpc) throws Exception { - daprRun = startDaprApp( - TracingIT.class.getSimpleName() + "http", - Service.SUCCESS_MESSAGE, - Service.class, - true, - 30000); - - if (useGrpc) { - daprRun.switchToGRPC(); - } else { - daprRun.switchToHTTP(); - } - - // Wait since service might be ready even after port is available. - Thread.sleep(2000); - } - - @ParameterizedTest - @ValueSource(booleans = {true, false}) - public void testInvoke(boolean useGrpc) throws Exception { - setup(useGrpc); - - final OpenTelemetry openTelemetry = createOpenTelemetry(OpenTelemetryConfig.SERVICE_NAME); - final Tracer tracer = openTelemetry.getTracer(OpenTelemetryConfig.TRACER_NAME); - - final String spanName = UUID.randomUUID().toString(); - Span span = tracer.spanBuilder(spanName).setSpanKind(Span.Kind.CLIENT).startSpan(); - - try (DaprClient client = new DaprClientBuilder().build()) { - client.waitForSidecar(10000).block(); - try (Scope scope = span.makeCurrent()) { - client.invokeMethod(daprRun.getAppName(), "sleep", 1, HttpExtension.POST) - .contextWrite(getReactorContext()) - .block(); - } - } - span.end(); - OpenTelemetrySdk.getGlobalTracerManagement().shutdown(); - - Validation.validate(spanName, "calllocal/tracingithttp-service/sleep"); - } - -}