From efba1a0fb886343f4b22d49f339d129253829dec Mon Sep 17 00:00:00 2001 From: Fiete Ostkamp Date: Fri, 28 Mar 2025 15:48:29 +0100 Subject: [PATCH] Add tracing for the sdc-workflow-designer Issue-ID: SDC-4726 Change-Id: I53aa1d081ac248b1153005f1e28f8113d1c3ed02 Signed-off-by: Fiete Ostkamp --- sdc-workflow-designer-be/pom.xml | 32 ++++++-- .../src/main/resources/application.properties | 11 ++- .../java/org/onap/sdc/workflow/TracingTest.java | 86 ++++++++++++++++++++++ 3 files changed, 122 insertions(+), 7 deletions(-) create mode 100644 sdc-workflow-designer-be/src/test/java/org/onap/sdc/workflow/TracingTest.java diff --git a/sdc-workflow-designer-be/pom.xml b/sdc-workflow-designer-be/pom.xml index f5dce3d7..20c821b9 100644 --- a/sdc-workflow-designer-be/pom.xml +++ b/sdc-workflow-designer-be/pom.xml @@ -15,6 +15,7 @@ 2.2.13.RELEASE + Hoxton.SR12 5.3.30 1.5.3.Final 1.18.26 @@ -44,6 +45,13 @@ pom import + + org.springframework.cloud + spring-cloud-dependencies + ${spring-cloud.version} + pom + import + @@ -173,6 +181,14 @@ + + org.springframework.cloud + spring-cloud-starter-sleuth + + + org.springframework.cloud + spring-cloud-sleuth-zipkin + org.eclipse.jetty jetty-server @@ -372,16 +388,22 @@ junit junit - + + + org.junit.vintage + junit-vintage-engine - - org.junit.vintage - junit-vintage-engine - + + org.springframework.cloud + spring-cloud-contract-wiremock + 2.2.8.RELEASE + test + io.springfox springfox-boot-starter diff --git a/sdc-workflow-designer-be/src/main/resources/application.properties b/sdc-workflow-designer-be/src/main/resources/application.properties index 8a21a3d9..924cc2a3 100644 --- a/sdc-workflow-designer-be/src/main/resources/application.properties +++ b/sdc-workflow-designer-be/src/main/resources/application.properties @@ -25,8 +25,6 @@ server.ssl.key-store-type=${SERVER_SSL_KEYSTORE_TYPE:} server.ssl.trust-store-password=${SERVER_SSL_TRUST_PASSWORD:} server.ssl.trust-store=${SERVER_SSL_TRUSTSTORE_PATH:} server.ssl.trust-store-type=${SERVER_SSL_TRUSTSTORE_TYPE:} -#server.ssl.protocol=${SERVER_SSL_PROTOCOL:TLS} -#server.ssl.enabled-protocols=${SERVER_SSL_ENABLED_PROTOCOL:TLSv1.2} sdc.be.protocol=${SDC_PROTOCOL:} @@ -71,3 +69,12 @@ logging.pattern.file= %d{yyyy-MM-dd HH:mm:ss} [%thread] %-5level %logger{36} - % debug=true trace=true + +spring.application.name=${APP_NAME:sdc-wfd-be} +spring.sleuth.enabled=${TRACING_ENABLED:false} +spring.zipkin.baseUrl=${TRACING_COLLECTOR_BASEURL} +spring.sleuth.trace-id128=true +spring.sleuth.sampler.probability=${TRACING_SAMPLING_PROBABILITY} +spring.sleuth.propagation.type=w3c,b3 +spring.sleuth.supports-join=false +spring.sleuth.web.skip-pattern=${TRACING_SKIP_PATTERN} diff --git a/sdc-workflow-designer-be/src/test/java/org/onap/sdc/workflow/TracingTest.java b/sdc-workflow-designer-be/src/test/java/org/onap/sdc/workflow/TracingTest.java new file mode 100644 index 00000000..dd58a540 --- /dev/null +++ b/sdc-workflow-designer-be/src/test/java/org/onap/sdc/workflow/TracingTest.java @@ -0,0 +1,86 @@ +package org.onap.sdc.workflow; +/* + * Copyright © 2025 Deutsche Telekom + * + * 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. + */ + +import static com.github.tomakehurst.wiremock.client.WireMock.postRequestedFor; +import static com.github.tomakehurst.wiremock.client.WireMock.urlEqualTo; +import static com.github.tomakehurst.wiremock.client.WireMock.verify; +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; + +import org.junit.jupiter.api.Test; +import org.onap.sdc.workflow.api.WorkflowController; +import org.onap.sdc.workflow.services.WorkflowManager; +import org.onap.sdc.workflow.services.WorkflowVersionManager; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Qualifier; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.boot.autoconfigure.ImportAutoConfiguration; +import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.boot.test.mock.mockito.MockBean; +import org.springframework.cloud.contract.wiremock.AutoConfigureWireMock; +import org.springframework.cloud.sleuth.autoconfig.TraceAutoConfiguration; +import org.springframework.cloud.sleuth.zipkin2.ZipkinAutoConfiguration; +import org.springframework.http.HttpStatus; +import org.springframework.http.MediaType; +import org.springframework.test.web.servlet.MockMvc; +import org.springframework.test.web.servlet.result.MockMvcResultMatchers; + +import com.github.tomakehurst.wiremock.client.WireMock; + +import lombok.SneakyThrows; + +@AutoConfigureMockMvc +@AutoConfigureWireMock(port = 0) +@ImportAutoConfiguration(classes = {TraceAutoConfiguration.class, ZipkinAutoConfiguration.class}) +@SpringBootTest(properties = { + "spring.sleuth.enabled=true", + "spring.zipkin.baseUrl=http://localhost:${wiremock.server.port}", + "spring.sleuth.sampler.probability=1.0" +}, classes = WorkflowController.class) +public class TracingTest { + + @MockBean + @Qualifier("workflowManager") + WorkflowManager workflowManager; + + @MockBean + @Qualifier("workflowVersionManager") + WorkflowVersionManager workflowVersionManager; + + @Autowired + private MockMvc mockMvc; + + @Value("${wiremock.server.port}") + private int wiremockPort; + + @Test + @SneakyThrows + public void thatArtifactsCanBePushed() { + WireMock.stubFor( + WireMock.post(WireMock.urlEqualTo("/api/v2/spans")) + .willReturn( + WireMock.aResponse() + .withStatus(HttpStatus.OK.value()))); + + mockMvc.perform(get("/wf/workflows") + .accept(MediaType.APPLICATION_JSON)) + .andExpect(MockMvcResultMatchers.status().isOk()); + + verify(postRequestedFor(urlEqualTo("/api/v2/spans"))); + } + +} -- 2.16.6