From b8acdf0ac4b9ccb05e4dd273b81693b439e9c422 Mon Sep 17 00:00:00 2001 From: Raja Kolli Date: Fri, 8 Dec 2023 11:48:24 +0000 Subject: [PATCH] feat : adds observation --- order-service/pom.xml | 10 +++++++++ .../config/ObservedAspectConfiguration.java | 21 +++++++++++++++++++ .../orderservice/services/OrderService.java | 2 ++ .../common/AbstractIntegrationTest.java | 19 +++++++++++++++++ .../TestPaymentApplication.java | 3 ++- test-em-all.sh | 2 +- 6 files changed, 55 insertions(+), 2 deletions(-) create mode 100644 order-service/src/main/java/com/example/orderservice/config/ObservedAspectConfiguration.java diff --git a/order-service/pom.xml b/order-service/pom.xml index 70b429b8..e5325731 100644 --- a/order-service/pom.xml +++ b/order-service/pom.xml @@ -180,6 +180,16 @@ spring-boot-testcontainers test + + io.micrometer + micrometer-observation-test + test + + + io.micrometer + micrometer-tracing-test + test + org.springframework.kafka spring-kafka-test diff --git a/order-service/src/main/java/com/example/orderservice/config/ObservedAspectConfiguration.java b/order-service/src/main/java/com/example/orderservice/config/ObservedAspectConfiguration.java new file mode 100644 index 00000000..191e9703 --- /dev/null +++ b/order-service/src/main/java/com/example/orderservice/config/ObservedAspectConfiguration.java @@ -0,0 +1,21 @@ +/*** +

+ Licensed under MIT License Copyright (c) 2023 Raja Kolli. +

+***/ + +package com.example.orderservice.config; + +import io.micrometer.observation.ObservationRegistry; +import io.micrometer.observation.aop.ObservedAspect; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +@Configuration +public class ObservedAspectConfiguration { + + @Bean + public ObservedAspect observedAspect(ObservationRegistry observationRegistry) { + return new ObservedAspect(observationRegistry); + } +} diff --git a/order-service/src/main/java/com/example/orderservice/services/OrderService.java b/order-service/src/main/java/com/example/orderservice/services/OrderService.java index 8ac97c62..9813ab91 100644 --- a/order-service/src/main/java/com/example/orderservice/services/OrderService.java +++ b/order-service/src/main/java/com/example/orderservice/services/OrderService.java @@ -16,6 +16,7 @@ Licensed under MIT License Copyright (c) 2021-2023 Raja Kolli. import com.example.orderservice.model.response.OrderResponse; import com.example.orderservice.model.response.PagedResult; import com.example.orderservice.repositories.OrderRepository; +import io.micrometer.observation.annotation.Observed; import java.util.List; import java.util.Optional; import java.util.concurrent.CompletableFuture; @@ -33,6 +34,7 @@ Licensed under MIT License Copyright (c) 2021-2023 Raja Kolli. @RequiredArgsConstructor @Loggable @Slf4j +@Observed(name = "orderService") public class OrderService { private final OrderRepository orderRepository; diff --git a/order-service/src/test/java/com/example/orderservice/common/AbstractIntegrationTest.java b/order-service/src/test/java/com/example/orderservice/common/AbstractIntegrationTest.java index 642df9cc..0a1e8f07 100644 --- a/order-service/src/test/java/com/example/orderservice/common/AbstractIntegrationTest.java +++ b/order-service/src/test/java/com/example/orderservice/common/AbstractIntegrationTest.java @@ -9,9 +9,14 @@ Licensed under MIT License Copyright (c) 2021-2023 Raja Kolli. import com.example.orderservice.TestOrderServiceApplication; import com.example.orderservice.utils.AppConstants; import com.fasterxml.jackson.databind.ObjectMapper; +import io.micrometer.observation.tck.TestObservationRegistry; +import io.micrometer.tracing.test.simple.SimpleTracer; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.autoconfigure.actuate.observability.AutoConfigureObservability; import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.boot.test.context.TestConfiguration; +import org.springframework.context.annotation.Bean; import org.springframework.test.context.ActiveProfiles; import org.springframework.test.web.servlet.MockMvc; @@ -21,9 +26,23 @@ Licensed under MIT License Copyright (c) 2021-2023 Raja Kolli. properties = {"spring.cloud.config.enabled=false"}, classes = TestOrderServiceApplication.class) @AutoConfigureMockMvc +@AutoConfigureObservability public abstract class AbstractIntegrationTest extends ContainerInitializer { @Autowired protected MockMvc mockMvc; @Autowired protected ObjectMapper objectMapper; + + @TestConfiguration + static class ObservationTestConfiguration { + @Bean + TestObservationRegistry observationRegistry() { + return TestObservationRegistry.create(); + } + + @Bean + SimpleTracer simpleTracer() { + return new SimpleTracer(); + } + } } diff --git a/payment-service/src/test/java/com/example/paymentservice/TestPaymentApplication.java b/payment-service/src/test/java/com/example/paymentservice/TestPaymentApplication.java index ee83a702..a2d314af 100644 --- a/payment-service/src/test/java/com/example/paymentservice/TestPaymentApplication.java +++ b/payment-service/src/test/java/com/example/paymentservice/TestPaymentApplication.java @@ -32,7 +32,8 @@ GenericContainer zipkContainer() { @ServiceConnection KafkaContainer kafkaContainer() { return new KafkaContainer(DockerImageName.parse("confluentinc/cp-kafka").withTag("7.5.2")) - .withKraft(); + .withKraft() + .withReuse(true); } public static void main(String[] args) { diff --git a/test-em-all.sh b/test-em-all.sh index 871f64d4..27aa6850 100755 --- a/test-em-all.sh +++ b/test-em-all.sh @@ -143,7 +143,7 @@ function setupTestData() { # Verify that communication between catalog-service and inventory service is established assertCurl 200 "curl -k http://$HOST:$PORT/catalog-service/api/catalog/productCode/$PROD_CODE_1?fetchInStock=true" assertEqual \"${PROD_CODE_1}\" $(echo ${RESPONSE} | jq .code) - assertEqual \"true\" $(echo ${RESPONSE} | jq .inStock) + assertEqual true $(echo ${RESPONSE} | jq .inStock) body="{\"name\": \"$CUSTOMER_NAME" body+=\