Skip to content
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: add histogram and summary metric types #2705

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

wemeetagain
Copy link
Member

Description

  • Add Histogram, HistogramGroup, Summary, SummaryGroup metric types
  • Add registerHistogram, registerHistogramGroup, registerSummary, registerSummaryGroup methods to Metrics interface
  • Add corresponding implementations to prometheus and simple metrics packages

Change checklist

  • I have performed a self-review of my own code
  • I have made corresponding changes to the documentation if necessary (this includes comments as well)
  • I have added tests that prove my fix is effective or that my feature works

@wemeetagain wemeetagain requested a review from a team as a code owner September 17, 2024 16:43
@SgtPooki SgtPooki linked an issue Sep 18, 2024 that may be closed by this pull request
Copy link
Member

@achingbrain achingbrain left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, just some minor nits for error types and logging.

registerHistogram (name: string, opts?: HistogramOptions): Histogram
registerHistogram (name: string, opts: any = {}): any {
if (name == null || name.trim() === '') {
throw new Error('Metric name is required')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use InvalidParametersError for invalid parameters

registerHistogramGroup (name: string, opts?: HistogramOptions): HistogramGroup
registerHistogramGroup (name: string, opts: any = {}): any {
if (name == null || name.trim() === '') {
throw new Error('Metric name is required')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use InvalidParametersError for invalid parameters

registerSummary (name: string, opts?: SummaryOptions): Summary
registerSummary (name: string, opts: any = {}): any {
if (name == null || name.trim() === '') {
throw new Error('Metric name is required')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use InvalidParametersError for invalid parameters

registerSummaryGroup (name: string, opts?: SummaryOptions): SummaryGroup
registerSummaryGroup (name: string, opts: any = {}): any {
if (name == null || name.trim() === '') {
throw new Error('Metric name is required')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use InvalidParametersError for invalid parameters

registerHistogram (name: string, opts?: HistogramOptions): Histogram
registerHistogram (name: string, opts: any = {}): any {
if (name == null ?? name.trim() === '') {
throw new Error('Histogram name is required')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use InvalidParametersError for invalid parameters

registerHistogramGroup (name: string, opts?: HistogramOptions): HistogramGroup
registerHistogramGroup (name: string, opts: any = {}): any {
if (name == null || name.trim() === '') {
throw new Error('Metric name is required')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use InvalidParametersError for invalid parameters

registerSummary (name: string, opts?: SummaryOptions): Summary
registerSummary (name: string, opts: any = {}): any {
if (name == null || name.trim() === '') {
throw new Error('Metric name is required')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use InvalidParametersError for invalid parameters

registerSummaryGroup (name: string, opts?: SummaryOptions): SummaryGroup
registerSummaryGroup (name: string, opts: any = {}): any {
if (name == null || name.trim() === '') {
throw new Error('Metric name is required')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use InvalidParametersError for invalid parameters

return metrics.get(name)
}

this.log('Register histogram', name)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
this.log('Register histogram', name)
this.log('register histogram', name)

let metric = metrics.get(name)

if (metrics.has(name)) {
this.log('Reuse existing histogram', name)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
this.log('Reuse existing histogram', name)
this.log('reuse existing histogram', name)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Expose histogram metric type
2 participants