Skip to content
This repository has been archived by the owner on Mar 2, 2025. It is now read-only.

Commit

Permalink
Merge pull request #240 from IKatsuba/metrics-path
Browse files Browse the repository at this point in the history
feat: adds metrics path env variable
  • Loading branch information
IKatsuba authored Sep 27, 2023
2 parents 6f400a2 + 9a20baf commit a1d9e8b
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 7 deletions.
10 changes: 4 additions & 6 deletions apps/api/src/main.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
/**
* This is not a production server yet!
* This is only a minimal backend to get started.
*/

import { Logger } from 'nestjs-pino';
import { NestFactory } from '@nestjs/core';

Expand All @@ -16,12 +11,15 @@ async function bootstrap() {
bufferLogs: true,
});

const config = app.get(ConfigService<Environment>);
const logger = app.get(Logger);

app.useLogger(logger);

const globalPrefix = 'nx-cloud';
app.setGlobalPrefix(globalPrefix, { exclude: ['ping'] });
app.setGlobalPrefix(globalPrefix, {
exclude: ['ping', config.get('METRICS_PATH', '/metrics')],
});

const configService = app.get<ConfigService<Environment>>(ConfigService);

Expand Down
2 changes: 2 additions & 0 deletions libs/api/models/src/lib/environment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,6 @@ export interface Environment {
// LOG ends here

ENV: 'development' | string;

METRICS_PATH: string;
}
11 changes: 10 additions & 1 deletion libs/api/stats/src/lib/prometheus-stats.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,19 @@ import {
makeHistogramProvider,
PrometheusModule,
} from '@willsoto/nestjs-prometheus';
import { ConfigService } from '@nestjs/config';
import { Environment } from '@nx-turbo/api-models';

@Global()
@Module({
imports: [PrometheusModule.register()],
imports: [
PrometheusModule.registerAsync({
useFactory: (config: ConfigService<Environment>) => ({
path: config.get('METRICS_PATH', '/metrics'),
}),
inject: [ConfigService],
}),
],
providers: [
{
provide: Stats,
Expand Down

0 comments on commit a1d9e8b

Please sign in to comment.