Skip to content

Commit

Permalink
feat : adds observation
Browse files Browse the repository at this point in the history
  • Loading branch information
rajadilipkolli committed Dec 8, 2023
1 parent 284a7ac commit b8acdf0
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 2 deletions.
10 changes: 10 additions & 0 deletions order-service/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,16 @@
<artifactId>spring-boot-testcontainers</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.micrometer</groupId>
<artifactId>micrometer-observation-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.micrometer</groupId>
<artifactId>micrometer-tracing-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.kafka</groupId>
<artifactId>spring-kafka-test</artifactId>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/***
<p>
Licensed under MIT License Copyright (c) 2023 Raja Kolli.
</p>
***/

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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion test-em-all.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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+=\
Expand Down

0 comments on commit b8acdf0

Please sign in to comment.