Skip to content

Commit be8d649

Browse files
authored
Merge pull request #196 from jeevanjoseph/feature/orders-metrics
Feature/orders metrics
2 parents 8a49c22 + d6c72a4 commit be8d649

File tree

6 files changed

+35
-5
lines changed

6 files changed

+35
-5
lines changed

deploy/complete/docker-compose/docker-compose.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ services:
132132

133133
# OCI Orders service
134134
orders:
135-
image: iad.ocir.io/oracle/ateam/mushop-orders:2.2.1
135+
image: iad.ocir.io/oracle/ateam/mushop-orders:2.2.2
136136
ports:
137137
- 8085:80
138138
hostname: orders

deploy/complete/helm-chart/mushop/charts/orders/values.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ replicaCount: 1
22

33
image:
44
repository: iad.ocir.io/oracle/ateam/mushop-orders
5-
tag: 2.2.1
5+
tag: 2.2.2
66
pullPolicy: IfNotPresent
77

88
dbtools:

src/orders/VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
2.2.1
1+
2.2.2

src/orders/src/main/java/mushop/orders/services/MessagingService.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
import com.fasterxml.jackson.core.JsonProcessingException;
88
import com.fasterxml.jackson.databind.ObjectMapper;
9+
import io.micrometer.core.instrument.MeterRegistry;
910
import io.nats.client.Connection;
1011
import io.nats.client.Dispatcher;
1112
import io.nats.client.Message;
@@ -30,6 +31,8 @@
3031
public class MessagingService {
3132
@Autowired
3233
private CustomerOrderRepository customerOrderRepository;
34+
@Autowired
35+
private MeterRegistry meterRegistry;
3336
private final Logger log = LoggerFactory.getLogger(getClass());
3437
private final ObjectMapper objectMapper = new ObjectMapper();
3538
private Connection nc;
@@ -82,6 +85,7 @@ public void dispatchToFulfillment(OrderUpdate order) throws JsonProcessingExcept
8285
String msg = objectMapper.writeValueAsString(order);
8386
log.debug("Sending order over to fulfillment {}", order);
8487
this.nc.publish(this.mushopOrdersSubject, msg.getBytes(StandardCharsets.UTF_8));
88+
meterRegistry.counter("orders.fulfillment_sent").increment();
8589
}
8690

8791
private void handleMessage(Message message) {
@@ -94,6 +98,8 @@ private void handleMessage(Message message) {
9498
order.setShipment(update.getShipment());
9599
customerOrderRepository.save(order);
96100
log.info("order {} is now {}", order.getId(), update.getShipment().getName());
101+
meterRegistry.counter("orders.fulfillment_ack").increment();
102+
97103
}
98104
);
99105

src/orders/src/main/java/mushop/orders/services/OrdersService.java

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package mushop.orders.services;
22

3+
import io.micrometer.core.instrument.DistributionSummary;
4+
import io.micrometer.core.instrument.MeterRegistry;
35
import mushop.orders.config.OrdersConfigurationProperties;
46
import mushop.orders.entities.*;
57
import mushop.orders.repositories.CustomerOrderRepository;
@@ -38,6 +40,9 @@ public class OrdersService {
3840
@Autowired
3941
private CustomerOrderRepository customerOrderRepository;
4042

43+
@Autowired
44+
private MeterRegistry meterRegistry;
45+
4146
@Value(value = "${http.timeout:5}")
4247
private long timeout;
4348

@@ -47,6 +52,7 @@ public class OrdersService {
4752
public CustomerOrder createNewOrder(NewOrderResource orderPayload) {
4853
LOG.info("Creating order {}", orderPayload);
4954
LOG.debug("Starting calls");
55+
meterRegistry.counter("orders.placed").increment();
5056
try {
5157
Future<Address> addressFuture = asyncGetService.getObject(orderPayload.address,
5258
new ParameterizedTypeReference<Address>() {
@@ -82,9 +88,11 @@ public CustomerOrder createNewOrder(NewOrderResource orderPayload) {
8288

8389
LOG.info("Received payment response: " + paymentResponse);
8490
if (paymentResponse == null) {
91+
meterRegistry.counter("orders.rejected","cause","payment_response_invalid").increment();
8592
throw new PaymentDeclinedException("Unable to parse authorisation packet");
8693
}
8794
if (!paymentResponse.isAuthorised()) {
95+
meterRegistry.counter("orders.rejected","cause","payment_declined").increment();
8896
throw new PaymentDeclinedException(paymentResponse.getMessage());
8997
}
9098

@@ -102,12 +110,28 @@ public CustomerOrder createNewOrder(NewOrderResource orderPayload) {
102110

103111
CustomerOrder savedOrder = customerOrderRepository.save(order);
104112
LOG.debug("Saved order: " + savedOrder);
113+
meterRegistry.summary("orders.amount").record(amount);
114+
DistributionSummary.builder("order.stats")
115+
.serviceLevelObjectives(10d,20d,30d,40d,50d,60d,70d,80d,90d,100d,110d)
116+
//.publishPercentileHistogram()
117+
.maximumExpectedValue(120d)
118+
.minimumExpectedValue(5d)
119+
.register(meterRegistry)
120+
.record(amount);
105121
OrderUpdate update = new OrderUpdate(savedOrder.getId(), null);
106122
messagingService.dispatchToFulfillment(update);
107123
return savedOrder;
108124
} catch (TimeoutException e) {
125+
meterRegistry.counter("orders.rejected","cause","timeout").increment();
109126
throw new OrderFailedException("Unable to create order due to timeout from one of the services.", e);
110-
} catch (InterruptedException | IOException | ExecutionException e) {
127+
} catch (InterruptedException e) {
128+
meterRegistry.counter("orders.rejected","cause","interrupted").increment();
129+
throw new OrderFailedException("Unable to create order due to unspecified IO error.", e);
130+
}catch ( IOException e) {
131+
meterRegistry.counter("orders.rejected","cause","connectivity").increment();
132+
throw new OrderFailedException("Unable to create order due to unspecified IO error.", e);
133+
}catch (ExecutionException e) {
134+
meterRegistry.counter("orders.rejected","cause","task_failed").increment();
111135
throw new OrderFailedException("Unable to create order due to unspecified IO error.", e);
112136
}
113137

src/orders/src/main/resources/application.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ spring.application.name=orders
22
server.port=${port:8082}
33
server.tomcat.max-threads=2
44

5-
spring.main.lazy-initialization=false
5+
spring.main.lazy-initialization=true
66

77
management.endpoints.web.exposure.include=*
88
management.endpoint.health.show-details=always

0 commit comments

Comments
 (0)