Skip to content

Commit

Permalink
Merge pull request #2884 from alphagov/pp-11548/update-prometheus-init
Browse files Browse the repository at this point in the history
PP-11548: Initialise prom metrics without default sample builder
  • Loading branch information
jfharden authored Sep 19, 2023
2 parents c45299a + 3bfac74 commit 0c25c45
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 11 deletions.
6 changes: 5 additions & 1 deletion build-local.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,8 @@ set -e
cd "$(dirname "$0")"

mvn -DskipITs clean verify
docker build -t govukpay/ledger:local .
if [ "$(uname -m)" == "arm64" ]; then
docker build -t governmentdigitalservice/pay-ledger:local -f m1/arm64.Dockerfile .
else
docker build -t governmentdigitalservice/pay-ledger:local .
fi
14 changes: 4 additions & 10 deletions src/main/java/uk/gov/pay/ledger/app/LedgerApp.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
import uk.gov.pay.ledger.report.resource.PerformanceReportResource;
import uk.gov.pay.ledger.report.resource.ReportResource;
import uk.gov.pay.ledger.transaction.resource.TransactionResource;
import uk.gov.service.payments.commons.utils.prometheus.PrometheusDefaultLabelSampleBuilder;
import uk.gov.service.payments.logging.GovUkPayDropwizardRequestJsonLogLayoutFactory;
import uk.gov.service.payments.logging.LoggingFilter;
import uk.gov.service.payments.logging.LogstashConsoleAppenderFactory;
Expand Down Expand Up @@ -71,8 +70,10 @@ public DataSourceFactory getDataSourceFactory(LedgerConfig configuration) {

@Override
public void run(LedgerConfig config, Environment environment) {
config.getEcsContainerMetadataUriV4().ifPresent(uri -> initialisePrometheusMetrics(environment, uri));

CollectorRegistry collectorRegistry = CollectorRegistry.defaultRegistry;
collectorRegistry.register(new DropwizardExports(environment.metrics()));
environment.admin().addServlet("prometheusMetrics", new MetricsServlet(collectorRegistry)).addMapping("/metrics");

JdbiFactory jdbiFactory = new JdbiFactory();
final Jdbi jdbi = jdbiFactory.build(environment, config.getDataSourceFactory(), "postgresql");

Expand Down Expand Up @@ -100,11 +101,4 @@ public void run(LedgerConfig config, Environment environment) {

environment.jersey().register(injector.getInstance(PayoutResource.class));
}

private void initialisePrometheusMetrics(Environment environment, URI ecsContainerMetadataUri) {
LOGGER.info("Initialising prometheus metrics.");
CollectorRegistry collectorRegistry = new CollectorRegistry();
collectorRegistry.register(new DropwizardExports(environment.metrics(), new PrometheusDefaultLabelSampleBuilder(ecsContainerMetadataUri)));
environment.admin().addServlet("prometheusMetrics", new MetricsServlet(collectorRegistry)).addMapping("/metrics");
}
}

0 comments on commit 0c25c45

Please sign in to comment.