-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* metric repo * add metric repo * remove unused import * formatting * fix * try disabling job metrics for e2e * import otel in test module
- Loading branch information
Showing
7 changed files
with
83 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import { MetricOptions } from '@opentelemetry/api'; | ||
|
||
export interface CustomMetricOptions extends MetricOptions { | ||
enabled?: boolean; | ||
} | ||
|
||
export const IMetricRepository = 'IMetricRepository'; | ||
|
||
export interface IMetricRepository { | ||
addToCounter(name: string, value: number, options?: CustomMetricOptions): void; | ||
updateGauge(name: string, value: number, options?: CustomMetricOptions): void; | ||
updateHistogram(name: string, value: number, options?: CustomMetricOptions): void; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import { Inject } from '@nestjs/common'; | ||
import { MetricService } from 'nestjs-otel'; | ||
import { CustomMetricOptions, IMetricRepository } from 'src/interfaces/metric.interface'; | ||
|
||
export class MetricRepository implements IMetricRepository { | ||
constructor(@Inject(MetricService) private readonly metricService: MetricService) {} | ||
|
||
addToCounter(name: string, value: number, options?: CustomMetricOptions): void { | ||
if (options?.enabled === false) { | ||
return; | ||
} | ||
|
||
this.metricService.getCounter(name, options).add(value); | ||
} | ||
|
||
updateGauge(name: string, value: number, options?: CustomMetricOptions): void { | ||
if (options?.enabled === false) { | ||
return; | ||
} | ||
|
||
this.metricService.getUpDownCounter(name, options).add(value); | ||
} | ||
|
||
updateHistogram(name: string, value: number, options?: CustomMetricOptions): void { | ||
if (options?.enabled === false) { | ||
return; | ||
} | ||
|
||
this.metricService.getHistogram(name, options).record(value); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import { IMetricRepository } from 'src/interfaces/metric.interface'; | ||
|
||
export const newMetricRepositoryMock = (): jest.Mocked<IMetricRepository> => { | ||
return { | ||
addToCounter: jest.fn(), | ||
updateGauge: jest.fn(), | ||
updateHistogram: jest.fn(), | ||
}; | ||
}; |