-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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(server): job metrics #8255
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
8aaec72
metric repo
mertalev 0f54e8c
add metric repo
mertalev ef1a608
remove unused import
mertalev 5a6cfee
formatting
mertalev ea79267
fix
mertalev 840fef6
try disabling job metrics for e2e
mertalev 99ad5cc
import otel in test module
mertalev File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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(), | ||
}; | ||
}; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Requiring passing in whether metrics is enabled or not send like an odd choice. Also making it optional send really weird because it doesn't do anything otherwise. Can you just move that logic globally to the repo instead? If anything add a method to enable or disable metrics, instead of requiring it in every call.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The reason is because there are different kinds of metrics and it can be that only some are enabled. The
enabled
flag is just for ergonomics to avoid repeatingif (jobMetrics)
, etc.I could change it to accept the metric group and have the repo own the decision to track the metric based on the group that's passed. How does that sound?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Isn't it being enabled a static property set once via an environment variable? Why would you need to pass it into the repo over and over? Id be fine with using it directly in the repository instead of requiring it to be passed in every method.