Skip to content

Commit

Permalink
feat: network for build info
Browse files Browse the repository at this point in the history
  • Loading branch information
avsetsin committed Apr 16, 2022
1 parent a0f746e commit d53d72d
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 3 deletions.
7 changes: 5 additions & 2 deletions src/app.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,21 @@ import { APP_NAME, APP_VERSION } from 'app.constants';
import { METRIC_BUILD_INFO } from 'common/prometheus';
import { WINSTON_MODULE_NEST_PROVIDER } from 'nest-winston';
import { Gauge } from 'prom-client';
import { ProviderService } from 'provider';

export class AppService implements OnModuleInit {
constructor(
private providerService: ProviderService,
@Inject(WINSTON_MODULE_NEST_PROVIDER) private logger: LoggerService,
@InjectMetric(METRIC_BUILD_INFO) private buildInfo: Gauge<string>,
) {}

onModuleInit() {
async onModuleInit(): Promise<void> {
const network = await this.providerService.getNetworkName();
const version = APP_VERSION;
const name = APP_NAME;

this.buildInfo.labels({ version, name }).inc();
this.buildInfo.labels({ version, name, network }).inc();
this.logger.log('Init app', { name, version });
}
}
2 changes: 1 addition & 1 deletion src/common/prometheus/prometheus.provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ export const PrometheusBlockDataErrorsCounterProvider = makeCounterProvider({
export const PrometheusBuildInfoGaugeProvider = makeCounterProvider({
name: METRIC_BUILD_INFO,
help: 'Build information',
labelNames: ['version', 'name'] as const,
labelNames: ['version', 'name', 'network'] as const,
});

export const PrometheusDepositedKeysProvider = makeGaugeProvider({
Expand Down
10 changes: 10 additions & 0 deletions src/provider/provider.service.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Block } from '@ethersproject/abstract-provider';
import { CHAINS } from '@lido-sdk/constants';
import { Injectable } from '@nestjs/common';
import { RpcBatchProvider, RpcProvider } from './interfaces';

Expand Down Expand Up @@ -48,4 +49,13 @@ export class ProviderService {
public async getBlock(): Promise<Block> {
return await this.provider.getBlock('latest');
}

/**
* Returns network name
*/
public async getNetworkName(): Promise<string> {
const network = await this.provider.getNetwork();
const name = CHAINS[network.chainId]?.toLocaleLowerCase();
return name || network.name;
}
}

0 comments on commit d53d72d

Please sign in to comment.