Skip to content

Commit

Permalink
feat: adding Prometheus support (#1371)
Browse files Browse the repository at this point in the history
  • Loading branch information
paulushcgcj authored Jul 10, 2024
1 parent 2b424af commit 02231e8
Show file tree
Hide file tree
Showing 7 changed files with 206 additions and 87 deletions.
8 changes: 6 additions & 2 deletions backend/openshift.deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down Expand Up @@ -144,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:
Expand Down
12 changes: 12 additions & 0 deletions backend/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@
<artifactId>spring-boot-docker-compose</artifactId>
<version>3.3.0</version>
<optional>true</optional>
<scope>test</scope>
</dependency>

<!-- Geospatial -->
Expand Down Expand Up @@ -202,6 +203,7 @@
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-test</artifactId>
<scope>test</scope>
</dependency>

<!-- Documentation -->
Expand All @@ -211,7 +213,17 @@
<version>2.5.0</version>
</dependency>

<!-- Prometheus and Metrics -->
<dependency>
<groupId>io.micrometer</groupId>
<artifactId>micrometer-registry-prometheus</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-aop</artifactId>
</dependency>
</dependencies>


<build>
<plugins>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
@@ -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 {

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
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.prometheusmetrics.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<MeterRegistry> metricsCommonTags() {
return registry -> registry.config()
.commonTags(
"version", appVersion,
"app", appName,
"zone",appZone
)
.meterFilter(ignoreTag());
}

@Bean
public MeterRegistryCustomizer<PrometheusMeterRegistry> prometheusConfiguration() {
return MeterRegistry::config;
}

public MeterFilter ignoreTag() {
return MeterFilter.ignoreTags("type");
}


}
11 changes: 11 additions & 0 deletions backend/src/main/resources/application.properties
Original file line number Diff line number Diff line change
Expand Up @@ -52,3 +52,14 @@ 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
info.app.name=${spring.application.name}
info.app.zone=${APP_ZONE:local}
info.app.version=${app.version}
72 changes: 0 additions & 72 deletions backend/src/main/resources/logback-spring.xml

This file was deleted.

0 comments on commit 02231e8

Please sign in to comment.