From c45071de9c6986960d9a093f116687edeebf2b77 Mon Sep 17 00:00:00 2001 From: Fiete Ostkamp Date: Mon, 23 Jun 2025 10:54:31 +0200 Subject: [PATCH] Add tracing to cnf-adapter - add dependencyManagement for spring-cloud - add tracing dependencies and properties - define TracingTest that is not yet working due to context issues Issue-ID: SO-4177 Change-Id: I744da93c5d63f7b9d0dd049d72ae00c6b0ec1c3b Signed-off-by: Fiete Ostkamp --- so-cnf-adapter-application/pom.xml | 120 ++++++++++++--------- .../src/main/resources/application.yaml | 16 ++- .../org/onap/so/adapters/cnf/rest/TracingTest.java | 91 ++++++++++++++++ .../src/test/resources/application.properties | 5 - so-cnfm/so-cnfm-lcm/so-cnfm-lcm-bpmn-flows/pom.xml | 5 + 5 files changed, 179 insertions(+), 58 deletions(-) create mode 100644 so-cnf-adapter-application/src/test/java/org/onap/so/adapters/cnf/rest/TracingTest.java delete mode 100644 so-cnf-adapter-application/src/test/resources/application.properties diff --git a/so-cnf-adapter-application/pom.xml b/so-cnf-adapter-application/pom.xml index b82a62f..5783ecb 100755 --- a/so-cnf-adapter-application/pom.xml +++ b/so-cnf-adapter-application/pom.xml @@ -48,66 +48,81 @@ - - org.apache.maven.plugins - maven-jar-plugin - - - original - - - - - org.jacoco - jacoco-maven-plugin - - - org.apache.maven.plugins - maven-surefire-plugin - - - DEBUG - - 2 - suites - false - 1 - - - - - - src/main/resources - true - - **/*.p12 - **/*.jks - - - - src/main/resources - false - - **/*.p12 - **/*.jks - - - + + org.apache.maven.plugins + maven-jar-plugin + + + original + + + + + org.jacoco + jacoco-maven-plugin + + + org.apache.maven.plugins + maven-surefire-plugin + + + DEBUG + + 2 + suites + false + 1 + + + + + + src/main/resources + true + + **/*.p12 + **/*.jks + + + + src/main/resources + false + + **/*.p12 + **/*.jks + + + - - - org.onap.aai.schema-service - aai-schema - 1.9.2 - - + + + org.onap.aai.schema-service + aai-schema + 1.9.2 + + + org.springframework.cloud + spring-cloud-dependencies + Hoxton.SR12 + pom + import + + org.springframework.boot spring-boot-starter-actuator + + org.springframework.cloud + spring-cloud-starter-sleuth + + + org.springframework.cloud + spring-cloud-sleuth-zipkin + org.springframework.boot spring-boot-starter-web @@ -159,6 +174,7 @@ org.springframework.cloud spring-cloud-contract-wiremock + 2.2.8.RELEASE test diff --git a/so-cnf-adapter-application/src/main/resources/application.yaml b/so-cnf-adapter-application/src/main/resources/application.yaml index 098ca64..dd36cb7 100644 --- a/so-cnf-adapter-application/src/main/resources/application.yaml +++ b/so-cnf-adapter-application/src/main/resources/application.yaml @@ -27,11 +27,25 @@ aai: enabled: false spring: + application: + name: so-cnf-adapter + main: + allow-bean-definition-overriding: true security: usercredentials: - username: ${ACTUATOR_USERNAME} password: ${ACTUATOR_PASSWORD} role: ACTUATOR + sleuth: + enabled: ${TRACING_ENABLED:false} + trace-id128: true + sampler: + probability: ${TRACING_SAMPLING_PROBABILITY:1.0} + supports-join: false + propagation: + type: w3c,bc + web: + skip-pattern: ${TRACING_SKIP_PATTERN} # jpa: # show-sql: false @@ -63,4 +77,4 @@ multicloud: #management: # security: # enabled: false - # basic: \ No newline at end of file + # basic: diff --git a/so-cnf-adapter-application/src/test/java/org/onap/so/adapters/cnf/rest/TracingTest.java b/so-cnf-adapter-application/src/test/java/org/onap/so/adapters/cnf/rest/TracingTest.java new file mode 100644 index 0000000..fbdfe5d --- /dev/null +++ b/so-cnf-adapter-application/src/test/java/org/onap/so/adapters/cnf/rest/TracingTest.java @@ -0,0 +1,91 @@ +/* + * 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. + */ +package org.onap.so.adapters.cnf.rest; + +import org.junit.Before; +import org.junit.Ignore; +import org.junit.Rule; +import org.junit.Test; +import org.springframework.boot.autoconfigure.EnableAutoConfiguration; +import org.springframework.boot.autoconfigure.ImportAutoConfiguration; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; +import org.springframework.boot.web.server.LocalServerPort; +import org.springframework.cloud.sleuth.autoconfig.TraceAutoConfiguration; +import org.springframework.cloud.sleuth.zipkin2.ZipkinAutoConfiguration; +import org.springframework.http.HttpStatus; +import org.springframework.test.context.DynamicPropertyRegistry; +import org.springframework.test.context.DynamicPropertySource; +import org.springframework.util.SocketUtils; +import org.springframework.web.client.RestClientException; +import org.springframework.web.client.RestTemplate; +import org.springframework.web.util.DefaultUriBuilderFactory; + +import com.github.tomakehurst.wiremock.client.WireMock; +import com.github.tomakehurst.wiremock.junit.WireMockRule; + +import static com.github.tomakehurst.wiremock.core.WireMockConfiguration.wireMockConfig; + +import lombok.SneakyThrows; + +@Ignore +@EnableAutoConfiguration +@ImportAutoConfiguration(classes = { TraceAutoConfiguration.class, ZipkinAutoConfiguration.class }) +@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT, properties = { + "spring.sleuth.enabled=true", + "spring.sleuth.sampler.probability=1.0" +}) +public class TracingTest { + + private static int wireMockPort = SocketUtils.findAvailableTcpPort(); + + @Rule + public WireMockRule wireMockRule = new WireMockRule(wireMockConfig().port(wireMockPort)); + + @LocalServerPort + private int port; + + RestTemplate restTemplate; + + @Before + public void setup() { + this.restTemplate = new RestTemplate(); + restTemplate.setUriTemplateHandler(new DefaultUriBuilderFactory("http://localhost:" + port)); + } + + @DynamicPropertySource + static void configureProperties(DynamicPropertyRegistry registry) { + registry.add("spring.sleuth.enabled", () -> "true"); + registry.add("spring.zipkin.baseUrl", () -> "http://localhost:" + wireMockPort); + registry.add("spring.sleuth.sampler.probability", () -> "1.0"); + } + + @Test + @SneakyThrows + public void thatTracesAreExported() throws InterruptedException { + WireMock.stubFor(WireMock.post(WireMock.urlEqualTo("/api/v2/spans")) + .willReturn(WireMock.aResponse().withStatus(HttpStatus.OK.value()))); + + try { + restTemplate.getForObject("http://localhost:" + port + "/foo", String.class); + } catch (RestClientException e) { + // this provokes a 404. For the test it's not important what is returned here + } + + Thread.sleep(1000); + WireMock.verify(WireMock.postRequestedFor(WireMock.urlEqualTo("/api/v2/spans"))); + } +} diff --git a/so-cnf-adapter-application/src/test/resources/application.properties b/so-cnf-adapter-application/src/test/resources/application.properties deleted file mode 100644 index cbbfef1..0000000 --- a/so-cnf-adapter-application/src/test/resources/application.properties +++ /dev/null @@ -1,5 +0,0 @@ -aai.enabled=true -aai.endpoint=http://localhost:8443 -aai.auth=5E12ACACBD552A415E081E29F2C4772F9835792A51C766CCFDD7433DB5220B59969CB2798C -mso.msoKey=07a7159d3bf51a0e53be7a8f89699be7 -spring.main.allow-bean-definition-overriding=true \ No newline at end of file diff --git a/so-cnfm/so-cnfm-lcm/so-cnfm-lcm-bpmn-flows/pom.xml b/so-cnfm/so-cnfm-lcm/so-cnfm-lcm-bpmn-flows/pom.xml index 447577e..8e58cfe 100644 --- a/so-cnfm/so-cnfm-lcm/so-cnfm-lcm-bpmn-flows/pom.xml +++ b/so-cnfm/so-cnfm-lcm/so-cnfm-lcm-bpmn-flows/pom.xml @@ -109,6 +109,7 @@ org.springframework.cloud spring-cloud-contract-wiremock + 2.2.8.RELEASE test @@ -129,6 +130,10 @@ org.apache.tomcat tomcat-catalina + + org.springframework.cloud + spring-cloud-starter-sleuth + -- 2.16.6