Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
6c40458
feat(FSADT1-992): adding caddy metrics
paulushcgcj Jan 8, 2024
307d478
feat(FSADT1-992): enabling metrics to frontend
paulushcgcj Jan 8, 2024
42d672f
chore: testing caddy changes
paulushcgcj Jan 9, 2024
37b3553
fix: fixing caddy
paulushcgcj Jan 9, 2024
747a667
feat(FSADT1-992): adding observability
paulushcgcj Jan 10, 2024
60db9a8
Merge branch 'main' into feat/FSADT1-992
paulushcgcj Jan 10, 2024
bd6ff46
Merge branch 'main' into feat/FSADT1-992
paulushcgcj Jan 12, 2024
dbc61e4
chore: fixing dependency issues
paulushcgcj Jan 12, 2024
1a6ce1a
chore: updating dependency due to CVE
paulushcgcj Jan 12, 2024
dd4c0f0
chore: updating dependency to fix cve
paulushcgcj Jan 12, 2024
c641b64
chore: fixing dependency issues
paulushcgcj Jan 12, 2024
baa0a16
chore: trying to allow micrometer to build
paulushcgcj Jan 12, 2024
05c34e7
chore: trying to allow micrometer to build
paulushcgcj Jan 12, 2024
7ba6081
chore: trying to allow micrometer to build
paulushcgcj Jan 12, 2024
5fe0351
chore: trying to allow micrometer to build
paulushcgcj Jan 12, 2024
86ca5c1
Merge branch 'main' into feat/FSADT1-992
paulushcgcj Jan 16, 2024
ce07bbe
Merge branch 'main' into feat/FSADT1-992
paulushcgcj Jan 16, 2024
fa13023
Merge branch 'main' into feat/FSADT1-992
paulushcgcj Jan 16, 2024
0a93388
Merge branch 'main' into feat/FSADT1-992
paulushcgcj Jan 16, 2024
e84240b
Merge branch 'main' into feat/FSADT1-992
paulushcgcj Jan 16, 2024
7d7375c
Merge branch 'main' into feat/FSADT1-992
paulushcgcj Jan 17, 2024
90d520b
Merge branch 'main' into feat/FSADT1-992
paulushcgcj Jan 17, 2024
a3b3b2b
Merge branch 'main' into feat/FSADT1-992
paulushcgcj Jan 17, 2024
8523cc2
Merge branch 'main' into feat/FSADT1-992
paulushcgcj Jan 18, 2024
2cbc3a6
Merge branch 'main' into feat/FSADT1-992
paulushcgcj Jan 18, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion backend/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,4 @@ EXPOSE ${PORT}
HEALTHCHECK CMD curl -f http://localhost:${PORT}/actuator/health | grep '"status":"UP"'

# Startup
ENTRYPOINT ["/app/nr-forest-client-backend"]
ENTRYPOINT ["/app/nr-forest-client-backend","--spring.profiles.active=container"]
37 changes: 34 additions & 3 deletions backend/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,25 @@
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-aop</artifactId>
</dependency>

<dependency>
<groupId>io.micrometer</groupId>
<artifactId>micrometer-registry-prometheus</artifactId>
</dependency>
<dependency>
<groupId>io.micrometer</groupId>
<artifactId>micrometer-tracing-bridge-otel</artifactId>
</dependency>
<dependency>
<groupId>io.opentelemetry</groupId>
<artifactId>opentelemetry-exporter-zipkin</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.experimental</groupId>
<artifactId>r2dbc-micrometer-spring-boot</artifactId>
<version>1.0.2</version>
</dependency>

<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-jdbc</artifactId>
Expand All @@ -96,6 +111,7 @@
<groupId>org.flywaydb</groupId>
<artifactId>flyway-core</artifactId>
</dependency>

<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
Expand All @@ -110,6 +126,7 @@
<artifactId>lombok</artifactId>
<optional>true</optional>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
Expand Down Expand Up @@ -172,6 +189,20 @@
<artifactId>reactor-netty-http</artifactId>
<version>1.1.13</version>
</dependency>
<dependency>
<groupId>io.micrometer</groupId>
<artifactId>micrometer-bom</artifactId>
<version>${micrometer.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
<dependency>
<groupId>io.micrometer</groupId>
<artifactId>micrometer-tracing-bom</artifactId>
<version>${micrometer-tracing.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>

Expand Down Expand Up @@ -203,10 +234,10 @@
<buildArgs>
<buildArg>-H:+ReportExceptionStackTraces</buildArg>
<buildArg>
--trace-class-initialization=org.apache.commons.logging.LogFactoryService</buildArg>
<buildArg>--trace-class-initialization=org.apache.commons.logging.LogFactory</buildArg>
--trace-class-initialization=org.apache.commons.logging.LogFactoryService,io.micrometer.common.util.internal.logging.LocationAwareSlf4JLogger,ch.qos.logback.classic.Logger</buildArg>
<buildArg>--trace-class-initialization=org.apache.commons.logging.LogFactory,io.micrometer.common.util.internal.logging.LocationAwareSlf4JLogger,ch.qos.logback.classic.Logger</buildArg>
<buildArg>
--initialize-at-build-time=org.apache.commons.logging.LogFactoryService</buildArg>
--initialize-at-build-time=org.apache.commons.logging.LogFactoryService,io.micrometer.common.util.internal.logging.LocationAwareSlf4JLogger,ch.qos.logback.classic.Logger</buildArg>
</buildArgs>
</configuration>
</plugin>
Expand Down
5 changes: 5 additions & 0 deletions backend/src/main/java/ca/bc/gov/app/BootApplication.java
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
package ca.bc.gov.app;

import org.slf4j.bridge.SLF4JBridgeHandler;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.scheduling.annotation.EnableScheduling;
import reactor.core.publisher.Hooks;

@SpringBootApplication
@EnableScheduling
public class BootApplication {

public static void main(String[] args) {
SLF4JBridgeHandler.removeHandlersForRootLogger();
SLF4JBridgeHandler.install();
Hooks.enableAutomaticContextPropagation();
SpringApplication.run(BootApplication.class, args);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package ca.bc.gov.app.configuration;

import io.micrometer.observation.ObservationRegistry;
import io.micrometer.observation.aop.ObservedAspect;
import io.micrometer.observation.contextpropagation.ObservationThreadLocalAccessor;
import io.micrometer.tracing.annotation.MethodInvocationProcessor;
import io.micrometer.tracing.annotation.SpanAspect;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration(proxyBeanMethods = false)
@Slf4j
public class TracingConfiguration {

@Bean
ObservedAspect observedAspect(
ObservationRegistry observationRegistry
) {
ObservationThreadLocalAccessor.getInstance().setObservationRegistry(observationRegistry);
return new ObservedAspect(observationRegistry);
}

@Bean
SpanAspect spanAspect(MethodInvocationProcessor methodInvocationProcessor) {
return new SpanAspect(methodInvocationProcessor);
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package ca.bc.gov.app.controller;

import ca.bc.gov.app.exception.ValidationException;
import io.micrometer.observation.annotation.Observed;
import java.util.Arrays;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.BooleanUtils;
Expand Down Expand Up @@ -31,6 +32,7 @@
@Slf4j
@Component
@Order(-2)
@Observed
public class GlobalErrorController extends AbstractErrorWebExceptionHandler {

public GlobalErrorController(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import ca.bc.gov.app.dto.client.EmailRequestDto;
import ca.bc.gov.app.service.client.ClientService;
import io.micrometer.observation.annotation.Observed;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.HttpStatus;
Expand All @@ -21,6 +22,7 @@
@Slf4j
@RequestMapping(value = "/api/ches", produces = MediaType.APPLICATION_JSON_VALUE)
@RequiredArgsConstructor
@Observed
public class ChesController {

private final ClientService clientService;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import ca.bc.gov.app.dto.client.ClientAddressDto;
import ca.bc.gov.app.dto.client.CodeNameDto;
import ca.bc.gov.app.service.client.ClientAddressService;
import io.micrometer.observation.annotation.Observed;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.MediaType;
Expand All @@ -18,6 +19,7 @@
@Slf4j
@RequestMapping(value = "/api/clients", produces = MediaType.APPLICATION_JSON_VALUE)
@RequiredArgsConstructor
@Observed
public class ClientAddressController {

private final ClientAddressService clientAddressService;
Expand All @@ -30,13 +32,16 @@ public Flux<CodeNameDto> findPossibleAddresses(
Integer maxSuggestions,
@RequestParam(value = "searchTerm", required = true)
String searchTerm) {
log.info("Requesting possible addresses for country: {}, maxSuggestions: {}, searchTerm: {}",
country, maxSuggestions, searchTerm);
return clientAddressService
.findPossibleAddresses(country, maxSuggestions, searchTerm);
}

@GetMapping("/addresses/{addressId}")
public Mono<ClientAddressDto> getAddress(
@PathVariable String addressId) {
log.info("Requesting address for addressId: {}", addressId);
return clientAddressService
.getAddress(addressId);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import ca.bc.gov.app.dto.client.EmailRequestDto;
import ca.bc.gov.app.exception.NoClientDataFound;
import ca.bc.gov.app.service.client.ClientService;
import io.micrometer.observation.annotation.Observed;
import java.time.LocalDate;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
Expand All @@ -30,6 +31,7 @@
@RequestMapping(value = "/api/clients", produces = MediaType.APPLICATION_JSON_VALUE)
@RequiredArgsConstructor
@Slf4j
@Observed
public class ClientController {

private final ClientService clientService;
Expand All @@ -40,6 +42,7 @@ public Mono<ClientDetailsDto> getClientDetails(
@RequestHeader(ApplicationConstant.USERID_HEADER) String userId,
@RequestHeader(name = ApplicationConstant.BUSINESSID_HEADER, defaultValue = StringUtils.EMPTY) String businessId
) {
log.info("Requesting client details for client number {} from the client service.", clientNumber);
return clientService.getClientDetails(clientNumber,userId,businessId);
}

Expand All @@ -48,14 +51,17 @@ public Flux<CodeNameDto> listCountries(
@RequestParam(value = "page", required = false, defaultValue = "0")
Integer page,
@RequestParam(value = "size", required = false, defaultValue = "10")
Integer size) {
Integer size
) {
log.info("Requesting a list of countries from the client service.");
return clientService
.listCountries(page, size);
}

@GetMapping("/getCountryByCode/{countryCode}")
public Mono<CodeNameDto> getCountryByCode(
@PathVariable String countryCode) {
log.info("Requesting a country by code {} from the client service.", countryCode);
return clientService.getCountryByCode(countryCode);
}

Expand All @@ -66,18 +72,21 @@ public Flux<CodeNameDto> listProvinces(
Integer page,
@RequestParam(value = "size", required = false, defaultValue = "10")
Integer size) {
log.info("Requesting a list of provinces for country code {} from the client service.", countryCode);
return clientService
.listProvinces(countryCode, page, size);
}

@GetMapping("/getClientTypeByCode/{code}")
public Mono<CodeNameDto> getClientTypeByCode(
@PathVariable String code) {
log.info("Requesting a client type by code {} from the client service.", code);
return clientService.getClientTypeByCode(code);
}

@GetMapping("/activeClientTypeCodes")
public Flux<CodeNameDto> findActiveClientTypeCodes() {
log.info("Requesting a list of active client type codes from the client service.");
return clientService
.findActiveClientTypeCodes(LocalDate.now());
}
Expand All @@ -89,6 +98,7 @@ public Flux<CodeNameDto> listClientContactTypeCodes(
@RequestParam(value = "size", required = false, defaultValue = "10")
Integer size
) {
log.info("Requesting a list of active client contact type codes from the client service.");
return clientService
.listClientContactTypeCodes(LocalDate.now(),page, size);
}
Expand All @@ -103,6 +113,7 @@ public Flux<CodeNameDto> listClientContactTypeCodes(
public Flux<ClientLookUpDto> findByClientName(
@PathVariable String name
) {
log.info("Requesting a list of clients with name {} from the client service.", name);
return clientService
.findByClientNameOrIncorporation(name)
.map(client -> client.withName(WordUtils.capitalize(client.name())));
Expand All @@ -111,6 +122,7 @@ public Flux<ClientLookUpDto> findByClientName(
@GetMapping(value = "/incorporation/{incorporationId}")
public Mono<ClientLookUpDto> findByIncorporationNumber(
@PathVariable String incorporationId) {
log.info("Requesting a client with incorporation number {} from the client service.", incorporationId);
return clientService
.findByClientNameOrIncorporation(incorporationId)
.next()
Expand All @@ -133,6 +145,7 @@ public Mono<Void> sendEmail(
@RequestHeader(ApplicationConstant.USERID_HEADER) String userId,
@RequestHeader(name = ApplicationConstant.BUSINESSID_HEADER, defaultValue = StringUtils.EMPTY) String businessId
) {
log.info("Sending email to {} from the client service.", emailRequestDto.email());
return clientService.triggerEmailDuplicatedClient(emailRequestDto, userId, businessId);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,10 @@
import ca.bc.gov.app.models.client.SubmissionStatusEnum;
import ca.bc.gov.app.service.client.ClientSubmissionService;
import ca.bc.gov.app.validator.client.ClientSubmitRequestValidator;
import io.micrometer.observation.annotation.Observed;
import java.util.List;
import java.util.Map;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
Expand All @@ -32,6 +34,8 @@

@RestController
@RequestMapping(value = "/api/clients/submissions", produces = MediaType.APPLICATION_JSON_VALUE)
@Observed
@Slf4j
public class ClientSubmissionController extends
AbstractController<ClientSubmissionDto, ClientSubmitRequestValidator> {

Expand Down Expand Up @@ -61,6 +65,8 @@ public Flux<ClientListSubmissionDto> listSubmissions(
@RequestParam(required = false)
String[] updatedAt
) {
log.info("Listing submissions: page={}, size={}, requestType={}, requestStatus={}, clientType={}, name={}, updatedAt={}",
page, size, requestType, requestStatus, clientType, name, updatedAt);
return clientService
.listSubmissions(
page,
Expand All @@ -82,17 +88,23 @@ public Mono<Void> submit(
@RequestHeader(ApplicationConstant.USERMAIL_HEADER) String userEmail,
@RequestHeader(ApplicationConstant.USERNAME_HEADER) String userName,
ServerHttpResponse serverResponse) {
return Mono.just(request)

return Mono
.just(request)
.switchIfEmpty(
Mono.error(new InvalidRequestObjectException("no request body was provided"))
)
.doOnNext(sub -> log.info("Submitting request: {}", sub))
.doOnNext(this::validate)
.doOnNext(sub -> log.info("Request is valid: {}", sub))
.doOnError(e -> log.error("Request is invalid: {}", e.getMessage()))
.flatMap(submissionDto -> clientService.submit(
submissionDto,
userId,
userEmail,
userName,
businessId))
.doOnNext(submissionId -> log.info("Submission persisted: {}", submissionId))
.doOnNext(submissionId ->
serverResponse
.getHeaders()
Expand Down
Loading