From 06211481e374257927cc043d1e969cac5cc2db5c Mon Sep 17 00:00:00 2001 From: Paulo Gomes da Cruz Junior Date: Tue, 9 Jul 2024 15:58:20 -0700 Subject: [PATCH 1/8] feat: adding Prometheus support --- backend/openshift.deploy.yml | 4 ++ backend/pom.xml | 10 +++ .../BackendStartApiApplication.java | 2 + .../config/SparMetricsConfig.java | 69 +++++++++++++++++++ .../src/main/resources/application.properties | 8 +++ 5 files changed, 93 insertions(+) create mode 100644 backend/src/main/java/ca/bc/gov/backendstartapi/config/SparMetricsConfig.java diff --git a/backend/openshift.deploy.yml b/backend/openshift.deploy.yml index 89c9db9a8..345aaab97 100644 --- a/backend/openshift.deploy.yml +++ b/backend/openshift.deploy.yml @@ -80,6 +80,10 @@ objects: type: RollingUpdate template: metadata: + annotations: + prometheus.io/scrape: "true" + prometheus.io/port: "8090" + prometheus.io/path: "/metrics" labels: app: ${NAME}-${ZONE} deployment: ${NAME}-${ZONE}-${COMPONENT} diff --git a/backend/pom.xml b/backend/pom.xml index 2ce920677..8331e060d 100644 --- a/backend/pom.xml +++ b/backend/pom.xml @@ -211,7 +211,17 @@ 2.5.0 + + + io.micrometer + micrometer-registry-prometheus + + + org.springframework.boot + spring-boot-starter-aop + + diff --git a/backend/src/main/java/ca/bc/gov/backendstartapi/BackendStartApiApplication.java b/backend/src/main/java/ca/bc/gov/backendstartapi/BackendStartApiApplication.java index 45da57076..a82ca65f2 100644 --- a/backend/src/main/java/ca/bc/gov/backendstartapi/BackendStartApiApplication.java +++ b/backend/src/main/java/ca/bc/gov/backendstartapi/BackendStartApiApplication.java @@ -2,9 +2,11 @@ import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.context.annotation.EnableAspectJAutoProxy; /** Starting point of the service app. */ @SpringBootApplication +@EnableAspectJAutoProxy(proxyTargetClass = true) public class BackendStartApiApplication { public static void main(String[] args) { diff --git a/backend/src/main/java/ca/bc/gov/backendstartapi/config/SparMetricsConfig.java b/backend/src/main/java/ca/bc/gov/backendstartapi/config/SparMetricsConfig.java new file mode 100644 index 000000000..156d555b4 --- /dev/null +++ b/backend/src/main/java/ca/bc/gov/backendstartapi/config/SparMetricsConfig.java @@ -0,0 +1,69 @@ +package ca.bc.gov.backendstartapi.config; + +import io.micrometer.core.aop.TimedAspect; +import io.micrometer.core.instrument.Meter; +import io.micrometer.core.instrument.MeterRegistry; +import io.micrometer.core.instrument.config.MeterFilter; +import io.micrometer.core.instrument.distribution.DistributionStatisticConfig; +import io.micrometer.prometheus.PrometheusMeterRegistry; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.boot.actuate.autoconfigure.metrics.MeterRegistryCustomizer; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + + +@Configuration +public class SparMetricsConfig { + + @Value("${info.app.version}") + private String appVersion; + + @Value("${info.app.name}") + private String appName; + + @Value("${info.app.zone}") + private String appZone; + + @Bean + public TimedAspect timedAspect(MeterRegistry registry) { + return new TimedAspect(registry); + } + + @Bean + public MeterRegistryCustomizer metricsCommonTags() { + return registry -> registry.config() + .commonTags( + "version", appVersion, + "app", appName, + "zone",appZone + ) + .meterFilter(ignoreTag()) + .meterFilter(distribution()); + } + + @Bean + public MeterRegistryCustomizer prometheusConfiguration() { + return MeterRegistry::config; + } + + public MeterFilter ignoreTag() { + return MeterFilter.ignoreTags("type"); + } + + public MeterFilter distribution() { + return new MeterFilter() { + + @Override + public DistributionStatisticConfig configure(Meter.Id id, + DistributionStatisticConfig config) { + return DistributionStatisticConfig + .builder() + .percentiles(0.5, 0.95, 0.99) + .percentilesHistogram(true) + .build() + .merge(config); + } + }; + } + +} \ No newline at end of file diff --git a/backend/src/main/resources/application.properties b/backend/src/main/resources/application.properties index 1f2e1b872..6d32dd471 100644 --- a/backend/src/main/resources/application.properties +++ b/backend/src/main/resources/application.properties @@ -52,3 +52,11 @@ oracle-api.base-url = ${ORACLE_SERVER_URL:https://nr-spar-test-oracle-api.apps.s # ForestClient API forest-client-api.address = ${FORESTCLIENTAPI_ADDRESS:https://nr-forest-client-api-prod.api.gov.bc.ca/api} forest-client-api.key = ${FORESTCLIENTAPI_KEY:placeholder-api-key} + +# Metrics +management.endpoint.metrics.enabled=false +management.endpoint.prometheus.enabled=true +management.endpoints.web.path-mapping.prometheus=metrics +management.endpoints.web.base-path=/ +management.endpoints.web.exposure.include=health,info,metrics,otlp,tracing,httptrace,prometheus +management.metrics.export.prometheus.enabled=true \ No newline at end of file From 91e0f34547acfb8bc0cf234a38772ac3506861bc Mon Sep 17 00:00:00 2001 From: Paulo Gomes da Cruz Junior Date: Tue, 9 Jul 2024 16:05:24 -0700 Subject: [PATCH 2/8] fix: fixing dependency import --- .../ca/bc/gov/backendstartapi/config/SparMetricsConfig.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/backend/src/main/java/ca/bc/gov/backendstartapi/config/SparMetricsConfig.java b/backend/src/main/java/ca/bc/gov/backendstartapi/config/SparMetricsConfig.java index 156d555b4..26831bfe6 100644 --- a/backend/src/main/java/ca/bc/gov/backendstartapi/config/SparMetricsConfig.java +++ b/backend/src/main/java/ca/bc/gov/backendstartapi/config/SparMetricsConfig.java @@ -5,7 +5,7 @@ import io.micrometer.core.instrument.MeterRegistry; import io.micrometer.core.instrument.config.MeterFilter; import io.micrometer.core.instrument.distribution.DistributionStatisticConfig; -import io.micrometer.prometheus.PrometheusMeterRegistry; +import io.micrometer.prometheusmetrics.PrometheusMeterRegistry; import org.springframework.beans.factory.annotation.Value; import org.springframework.boot.actuate.autoconfigure.metrics.MeterRegistryCustomizer; import org.springframework.context.annotation.Bean; From 2b2cdd54f8d5a9a7a5abbc6a2057f585cb821108 Mon Sep 17 00:00:00 2001 From: Paulo Gomes da Cruz Junior Date: Tue, 9 Jul 2024 16:21:12 -0700 Subject: [PATCH 3/8] fix: adding info --- backend/src/main/resources/application.properties | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/backend/src/main/resources/application.properties b/backend/src/main/resources/application.properties index 6d32dd471..5f519895b 100644 --- a/backend/src/main/resources/application.properties +++ b/backend/src/main/resources/application.properties @@ -59,4 +59,6 @@ management.endpoint.prometheus.enabled=true management.endpoints.web.path-mapping.prometheus=metrics management.endpoints.web.base-path=/ management.endpoints.web.exposure.include=health,info,metrics,otlp,tracing,httptrace,prometheus -management.metrics.export.prometheus.enabled=true \ No newline at end of file +management.metrics.export.prometheus.enabled=true +info.app.name: ${spring.application.name} +info.app.zone: ${APP_ZONE:local} From 8f2cf20ea94c9bd5524205a3d85485b96920a64c Mon Sep 17 00:00:00 2001 From: Paulo Gomes da Cruz Junior Date: Tue, 9 Jul 2024 16:32:32 -0700 Subject: [PATCH 4/8] fix: removing histogram --- .../config/SparMetricsConfig.java | 18 +----------------- 1 file changed, 1 insertion(+), 17 deletions(-) diff --git a/backend/src/main/java/ca/bc/gov/backendstartapi/config/SparMetricsConfig.java b/backend/src/main/java/ca/bc/gov/backendstartapi/config/SparMetricsConfig.java index 26831bfe6..6b413fe7c 100644 --- a/backend/src/main/java/ca/bc/gov/backendstartapi/config/SparMetricsConfig.java +++ b/backend/src/main/java/ca/bc/gov/backendstartapi/config/SparMetricsConfig.java @@ -37,8 +37,7 @@ public MeterRegistryCustomizer metricsCommonTags() { "app", appName, "zone",appZone ) - .meterFilter(ignoreTag()) - .meterFilter(distribution()); + .meterFilter(ignoreTag()); } @Bean @@ -50,20 +49,5 @@ public MeterFilter ignoreTag() { return MeterFilter.ignoreTags("type"); } - public MeterFilter distribution() { - return new MeterFilter() { - - @Override - public DistributionStatisticConfig configure(Meter.Id id, - DistributionStatisticConfig config) { - return DistributionStatisticConfig - .builder() - .percentiles(0.5, 0.95, 0.99) - .percentilesHistogram(true) - .build() - .merge(config); - } - }; - } } \ No newline at end of file From ebd75402631f8392fefce4143de249227276ac47 Mon Sep 17 00:00:00 2001 From: Paulo Gomes da Cruz Junior Date: Tue, 9 Jul 2024 16:38:19 -0700 Subject: [PATCH 5/8] fix: fixing params --- backend/src/main/resources/application.properties | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/backend/src/main/resources/application.properties b/backend/src/main/resources/application.properties index 5f519895b..bab15dbc4 100644 --- a/backend/src/main/resources/application.properties +++ b/backend/src/main/resources/application.properties @@ -54,11 +54,12 @@ forest-client-api.address = ${FORESTCLIENTAPI_ADDRESS:https://nr-forest-client-a forest-client-api.key = ${FORESTCLIENTAPI_KEY:placeholder-api-key} # Metrics -management.endpoint.metrics.enabled=false +management.endpoint.metrics.enabled=false management.endpoint.prometheus.enabled=true management.endpoints.web.path-mapping.prometheus=metrics management.endpoints.web.base-path=/ management.endpoints.web.exposure.include=health,info,metrics,otlp,tracing,httptrace,prometheus management.metrics.export.prometheus.enabled=true -info.app.name: ${spring.application.name} -info.app.zone: ${APP_ZONE:local} +info.app.name=${spring.application.name} +info.app.zone=${APP_ZONE:local} +info.app.version= @project.version@ From 57540d03d50f007c35fbb8c4d257e8d0a1e2925b Mon Sep 17 00:00:00 2001 From: Paulo Gomes da Cruz Junior Date: Tue, 9 Jul 2024 16:46:43 -0700 Subject: [PATCH 6/8] fix: removing logback --- .../src/main/resources/application.properties | 2 +- backend/src/main/resources/logback-spring.xml | 72 ------------------- 2 files changed, 1 insertion(+), 73 deletions(-) delete mode 100644 backend/src/main/resources/logback-spring.xml diff --git a/backend/src/main/resources/application.properties b/backend/src/main/resources/application.properties index bab15dbc4..eeeb04a64 100644 --- a/backend/src/main/resources/application.properties +++ b/backend/src/main/resources/application.properties @@ -62,4 +62,4 @@ management.endpoints.web.exposure.include=health,info,metrics,otlp,tracing,httpt management.metrics.export.prometheus.enabled=true info.app.name=${spring.application.name} info.app.zone=${APP_ZONE:local} -info.app.version= @project.version@ +info.app.version=${app.version} diff --git a/backend/src/main/resources/logback-spring.xml b/backend/src/main/resources/logback-spring.xml deleted file mode 100644 index 8b7532c33..000000000 --- a/backend/src/main/resources/logback-spring.xml +++ /dev/null @@ -1,72 +0,0 @@ - - - - - - - - - - - - - - - - - - - - %date{yyyy-MM-dd HH:mm:ss.SSS} %highlight(%-5level) [%blue(%t)] %yellow(%c): %msg%n%throwable - - - - - - ${LOGS}/postgres-api.log - - {%nopex"labels.project":"${applicationName}","service.version":"${appVersion}","service.environment":"${serviceEnv}","@timestamp":"%date{yyyy-MM-dd HH:mm:ss.SSS}","log.level":"%p","log.logger":"%logger{36}","message":"%replace(%msg){'\"','\\"'}","ecs.version":"${ecsVersion}","event.category":"web","event.dataset":"application.log.utc","event.ingested":"diagnostic","event.kind":"event","organization.id":"${sparTeamEmail}","organization.name":"TeamSPAR"}%n - - - - ${LOGS}/archived/postgres-api-%d{yyyy-MM-dd}.%i.log - - 7 - - 30MB - - 10MB - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file From 7eb1818321af1202d251658c0011e20ff3868fc2 Mon Sep 17 00:00:00 2001 From: Paulo Gomes da Cruz Junior Date: Tue, 9 Jul 2024 17:02:25 -0700 Subject: [PATCH 7/8] chore: removing dependency --- backend/pom.xml | 2 + .../config/NativeImageConfig.java | 135 ++++++++++++++++-- 2 files changed, 124 insertions(+), 13 deletions(-) diff --git a/backend/pom.xml b/backend/pom.xml index 8331e060d..996cabb51 100644 --- a/backend/pom.xml +++ b/backend/pom.xml @@ -157,6 +157,7 @@ spring-boot-docker-compose 3.3.0 true + test @@ -202,6 +203,7 @@ org.springframework.security spring-security-test + test diff --git a/backend/src/main/java/ca/bc/gov/backendstartapi/config/NativeImageConfig.java b/backend/src/main/java/ca/bc/gov/backendstartapi/config/NativeImageConfig.java index 84bbd849a..86225a457 100644 --- a/backend/src/main/java/ca/bc/gov/backendstartapi/config/NativeImageConfig.java +++ b/backend/src/main/java/ca/bc/gov/backendstartapi/config/NativeImageConfig.java @@ -1,34 +1,143 @@ package ca.bc.gov.backendstartapi.config; +import ca.bc.gov.backendstartapi.dto.CaculatedParentTreeValsDto; +import ca.bc.gov.backendstartapi.dto.CodeDescriptionDto; import ca.bc.gov.backendstartapi.dto.DescribedEnumDto; import ca.bc.gov.backendstartapi.dto.FavouriteActivityCreateDto; import ca.bc.gov.backendstartapi.dto.FavouriteActivityUpdateDto; import ca.bc.gov.backendstartapi.dto.ForestClientDto; +import ca.bc.gov.backendstartapi.dto.ForestClientLocationDto; +import ca.bc.gov.backendstartapi.dto.ForestClientSearchDto; +import ca.bc.gov.backendstartapi.dto.GameticMethodologyDto; +import ca.bc.gov.backendstartapi.dto.GeneticWorthTraitsDto; import ca.bc.gov.backendstartapi.dto.GeospatialOracleResDto; +import ca.bc.gov.backendstartapi.dto.GeospatialRequestDto; +import ca.bc.gov.backendstartapi.dto.GeospatialRespondDto; +import ca.bc.gov.backendstartapi.dto.ListItemDto; +import ca.bc.gov.backendstartapi.dto.MethodOfPaymentDto; +import ca.bc.gov.backendstartapi.dto.OrchardDto; +import ca.bc.gov.backendstartapi.dto.OrchardParentTreeValsDto; +import ca.bc.gov.backendstartapi.dto.OrchardSpuDto; +import ca.bc.gov.backendstartapi.dto.ParentTreeDto; +import ca.bc.gov.backendstartapi.dto.ParentTreeGeneticInfoDto; +import ca.bc.gov.backendstartapi.dto.ParentTreeGeneticQualityDto; +import ca.bc.gov.backendstartapi.dto.PtCalculationResDto; +import ca.bc.gov.backendstartapi.dto.PtValsCalReqDto; +import ca.bc.gov.backendstartapi.dto.RevisionCountDto; +import ca.bc.gov.backendstartapi.dto.SameSpeciesTreeDto; +import ca.bc.gov.backendstartapi.dto.SaveSeedlotFormDtoClassA; import ca.bc.gov.backendstartapi.dto.SeedPlanZoneDto; +import ca.bc.gov.backendstartapi.dto.SeedlotAclassFormDto; +import ca.bc.gov.backendstartapi.dto.SeedlotApplicationPatchDto; +import ca.bc.gov.backendstartapi.dto.SeedlotCreateDto; +import ca.bc.gov.backendstartapi.dto.SeedlotDto; +import ca.bc.gov.backendstartapi.dto.SeedlotFormCollectionDto; +import ca.bc.gov.backendstartapi.dto.SeedlotFormExtractionDto; +import ca.bc.gov.backendstartapi.dto.SeedlotFormInterimDto; +import ca.bc.gov.backendstartapi.dto.SeedlotFormOrchardDto; +import ca.bc.gov.backendstartapi.dto.SeedlotFormOwnershipDto; +import ca.bc.gov.backendstartapi.dto.SeedlotFormParentTreeSmpDto; +import ca.bc.gov.backendstartapi.dto.SeedlotFormSubmissionDto; +import ca.bc.gov.backendstartapi.dto.SeedlotReviewElevationLatLongDto; +import ca.bc.gov.backendstartapi.dto.SeedlotReviewGeoInformationDto; +import ca.bc.gov.backendstartapi.dto.SeedlotReviewSeedPlanZoneDto; +import ca.bc.gov.backendstartapi.dto.SeedlotSourceDto; +import ca.bc.gov.backendstartapi.dto.SeedlotStatusResponseDto; +import ca.bc.gov.backendstartapi.dto.UserDto; import ca.bc.gov.backendstartapi.dto.oracle.AreaOfUseDto; import ca.bc.gov.backendstartapi.dto.oracle.AreaOfUseSpuGeoDto; +import ca.bc.gov.backendstartapi.dto.oracle.SpuDto; import ca.bc.gov.backendstartapi.dto.oracle.SpzDto; +import ca.bc.gov.backendstartapi.enums.DescribedEnum; +import ca.bc.gov.backendstartapi.enums.ForestClientExpiredEnum; +import ca.bc.gov.backendstartapi.enums.ForestClientStatusEnum; +import ca.bc.gov.backendstartapi.enums.ForestClientTypeEnum; +import ca.bc.gov.backendstartapi.enums.LatitudeCodeEnum; +import ca.bc.gov.backendstartapi.enums.LongitudeCodeEnum; +import ca.bc.gov.backendstartapi.enums.parser.ConeAndPollenCountHeader; +import ca.bc.gov.backendstartapi.enums.parser.CsvParsingHeader; +import ca.bc.gov.backendstartapi.enums.parser.SmpMixHeader; import ca.bc.gov.backendstartapi.vo.parser.ConeAndPollenCount; import ca.bc.gov.backendstartapi.vo.parser.SmpMixVolume; import org.springframework.aot.hint.annotation.RegisterReflectionForBinding; import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.ImportRuntimeHints; -/** This class holds configurations for building Cloud Native images. */ +/** + * This class holds configurations for building Cloud Native images. + */ @Configuration @RegisterReflectionForBinding({ - DescribedEnumDto.class, - FavouriteActivityCreateDto.class, - FavouriteActivityUpdateDto.class, - ForestClientDto.class, - ConeAndPollenCount.class, - SeedPlanZoneDto.class, - SmpMixVolume.class, - GeospatialOracleResDto.class, - AreaOfUseDto.class, - AreaOfUseSpuGeoDto.class, - SpzDto.class + DescribedEnumDto.class, + FavouriteActivityCreateDto.class, + FavouriteActivityUpdateDto.class, + ForestClientDto.class, + ConeAndPollenCount.class, + SeedPlanZoneDto.class, + SmpMixVolume.class, + GeospatialOracleResDto.class, + AreaOfUseDto.class, + AreaOfUseSpuGeoDto.class, + SpzDto.class, + CaculatedParentTreeValsDto.class, + CodeDescriptionDto.class, + DescribedEnumDto.class, + FavouriteActivityCreateDto.class, + FavouriteActivityUpdateDto.class, + ForestClientDto.class, + ForestClientLocationDto.class, + ForestClientSearchDto.class, + GameticMethodologyDto.class, + GeneticWorthTraitsDto.class, + GeospatialOracleResDto.class, + GeospatialRequestDto.class, + GeospatialRespondDto.class, + ListItemDto.class, + MethodOfPaymentDto.class, + OrchardDto.class, + OrchardParentTreeValsDto.class, + OrchardSpuDto.class, + ParentTreeDto.class, + ParentTreeGeneticInfoDto.class, + ParentTreeGeneticQualityDto.class, + PtCalculationResDto.class, + PtValsCalReqDto.class, + RevisionCountDto.class, + SameSpeciesTreeDto.class, + SaveSeedlotFormDtoClassA.class, + SeedPlanZoneDto.class, + SeedlotAclassFormDto.class, + SeedlotApplicationPatchDto.class, + SeedlotCreateDto.class, + SeedlotDto.class, + SeedlotFormCollectionDto.class, + SeedlotFormExtractionDto.class, + SeedlotFormInterimDto.class, + SeedlotFormOrchardDto.class, + SeedlotFormOwnershipDto.class, + SeedlotFormParentTreeSmpDto.class, + SeedlotFormSubmissionDto.class, + SeedlotReviewElevationLatLongDto.class, + SeedlotReviewGeoInformationDto.class, + SeedlotReviewSeedPlanZoneDto.class, + SeedlotSourceDto.class, + SeedlotStatusResponseDto.class, + UserDto.class, + AreaOfUseDto.class, + AreaOfUseSpuGeoDto.class, + SpuDto.class, + SpzDto.class, + DescribedEnum.class, + ForestClientExpiredEnum.class, + ForestClientStatusEnum.class, + ForestClientTypeEnum.class, + LatitudeCodeEnum.class, + LongitudeCodeEnum.class, + ConeAndPollenCountHeader.class, + CsvParsingHeader.class, + SmpMixHeader.class }) @ImportRuntimeHints(value = {HttpServletRequestRuntimeHint.class}) -public class NativeImageConfig {} +public class NativeImageConfig { + +} From ee46a115d8bca96a37221d65510404e198aea399 Mon Sep 17 00:00:00 2001 From: Paulo Gomes da Cruz Junior Date: Tue, 9 Jul 2024 17:23:18 -0700 Subject: [PATCH 8/8] fix: fixing health check --- backend/openshift.deploy.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/backend/openshift.deploy.yml b/backend/openshift.deploy.yml index 345aaab97..711917b0f 100644 --- a/backend/openshift.deploy.yml +++ b/backend/openshift.deploy.yml @@ -148,11 +148,11 @@ objects: containerPort: 8090 readinessProbe: httpGet: - path: /actuator/health + path: /health port: container-port livenessProbe: httpGet: - path: /actuator/health + path: /health port: container-port startupProbe: tcpSocket: