Add tracing for the sdc-workflow-designer 19/140619/2
authorFiete Ostkamp <Fiete.Ostkamp@telekom.de>
Fri, 28 Mar 2025 14:48:29 +0000 (15:48 +0100)
committerFiete Ostkamp <Fiete.Ostkamp@telekom.de>
Fri, 28 Mar 2025 15:29:25 +0000 (16:29 +0100)
Issue-ID: SDC-4726
Change-Id: I53aa1d081ac248b1153005f1e28f8113d1c3ed02
Signed-off-by: Fiete Ostkamp <Fiete.Ostkamp@telekom.de>
sdc-workflow-designer-be/pom.xml
sdc-workflow-designer-be/src/main/resources/application.properties
sdc-workflow-designer-be/src/test/java/org/onap/sdc/workflow/TracingTest.java [new file with mode: 0644]

index f5dce3d..20c821b 100644 (file)
@@ -15,6 +15,7 @@
 
     <properties>
         <spring.boot.version>2.2.13.RELEASE</spring.boot.version>
+        <spring-cloud.version>Hoxton.SR12</spring-cloud.version>
         <org.springframework.version>5.3.30</org.springframework.version>
         <mapstruct.version>1.5.3.Final</mapstruct.version>
         <lombok.version>1.18.26</lombok.version>
                 <type>pom</type>
                 <scope>import</scope>
             </dependency>
+            <dependency>
+                <groupId>org.springframework.cloud</groupId>
+                <artifactId>spring-cloud-dependencies</artifactId>
+                <version>${spring-cloud.version}</version>
+                <type>pom</type>
+                <scope>import</scope>
+            </dependency>
         </dependencies>
     </dependencyManagement>
 
                 </exclusion>
             </exclusions>
         </dependency>
+        <dependency>
+            <groupId>org.springframework.cloud</groupId>
+            <artifactId>spring-cloud-starter-sleuth</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.springframework.cloud</groupId>
+            <artifactId>spring-cloud-sleuth-zipkin</artifactId>
+        </dependency>
         <dependency>
             <groupId>org.eclipse.jetty</groupId>
             <artifactId>jetty-server</artifactId>
                     <groupId>junit</groupId>
                     <artifactId>junit</artifactId>
                 </exclusion>
-                <exclusion>
+                <!-- <exclusion>
                     <groupId>org.springframework</groupId>
                     <artifactId>spring-core</artifactId>
+                </exclusion> -->
+                <exclusion>
+                    <groupId>org.junit.vintage</groupId>
+                    <artifactId>junit-vintage-engine</artifactId>
                 </exclusion>
-        <exclusion>
-          <groupId>org.junit.vintage</groupId>
-          <artifactId>junit-vintage-engine</artifactId>
-        </exclusion>
             </exclusions>
         </dependency>
+        <dependency>
+            <groupId>org.springframework.cloud</groupId>
+            <artifactId>spring-cloud-contract-wiremock</artifactId>
+            <version>2.2.8.RELEASE</version>
+            <scope>test</scope>
+        </dependency>
         <dependency>
             <groupId>io.springfox</groupId>
             <artifactId>springfox-boot-starter</artifactId>
index 8a21a3d..924cc2a 100644 (file)
@@ -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 (file)
index 0000000..dd58a54
--- /dev/null
@@ -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")));
+  }
+
+}