Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: adding Prometheus support #1371

Merged
merged 8 commits into from
Jul 10, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
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
4 changes: 4 additions & 0 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
10 changes: 10 additions & 0 deletions backend/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,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
@@ -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<MeterRegistry> metricsCommonTags() {
return registry -> registry.config()
.commonTags(
"version", appVersion,
"app", appName,
"zone",appZone
)
.meterFilter(ignoreTag())
.meterFilter(distribution());
}

@Bean
public MeterRegistryCustomizer<PrometheusMeterRegistry> 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);
}
};
}

}
8 changes: 8 additions & 0 deletions backend/src/main/resources/application.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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
Loading