Skip to content

Commit

Permalink
Add options to metrics definitions
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaelSnowden committed May 8, 2023
1 parent 9be72e0 commit 6d89449
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 15 deletions.
25 changes: 15 additions & 10 deletions common/metrics/defs.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ type (
metricType MetricType // metric type
metricName MetricName // metric name
unit MetricUnit
opts []Option
}

// ServiceIdx is an index that uniquely identifies the service
Expand Down Expand Up @@ -84,22 +85,26 @@ func (md metricDefinition) GetMetricUnit() MetricUnit {
return md.unit
}

func NewTimerDef(name string) metricDefinition {
return metricDefinition{metricName: MetricName(name), metricType: Timer, unit: Milliseconds}
func (md metricDefinition) GetOptions() []Option {
return md.opts
}

func NewBytesHistogramDef(name string) metricDefinition {
return metricDefinition{metricName: MetricName(name), metricType: Histogram, unit: Bytes}
func NewTimerDef(name string, opts ...Option) metricDefinition {

Check failure on line 92 in common/metrics/defs.go

View workflow job for this annotation

GitHub Actions / lint

unexported-return: exported func NewTimerDef returns unexported type metrics.metricDefinition, which can be annoying to use (revive)
return metricDefinition{metricName: MetricName(name), metricType: Timer, unit: Milliseconds, opts: opts}
}

func NewDimensionlessHistogramDef(name string) metricDefinition {
return metricDefinition{metricName: MetricName(name), metricType: Histogram, unit: Dimensionless}
func NewBytesHistogramDef(name string, opts ...Option) metricDefinition {

Check failure on line 96 in common/metrics/defs.go

View workflow job for this annotation

GitHub Actions / lint

unexported-return: exported func NewBytesHistogramDef returns unexported type metrics.metricDefinition, which can be annoying to use (revive)
return metricDefinition{metricName: MetricName(name), metricType: Histogram, unit: Bytes, opts: opts}
}

func NewCounterDef(name string) metricDefinition {
return metricDefinition{metricName: MetricName(name), metricType: Counter}
func NewDimensionlessHistogramDef(name string, opts ...Option) metricDefinition {

Check failure on line 100 in common/metrics/defs.go

View workflow job for this annotation

GitHub Actions / lint

unexported-return: exported func NewDimensionlessHistogramDef returns unexported type metrics.metricDefinition, which can be annoying to use (revive)
return metricDefinition{metricName: MetricName(name), metricType: Histogram, unit: Dimensionless, opts: opts}
}

func NewGaugeDef(name string) metricDefinition {
return metricDefinition{metricName: MetricName(name), metricType: Gauge}
func NewCounterDef(name string, opts ...Option) metricDefinition {

Check failure on line 104 in common/metrics/defs.go

View workflow job for this annotation

GitHub Actions / lint

unexported-return: exported func NewCounterDef returns unexported type metrics.metricDefinition, which can be annoying to use (revive)
return metricDefinition{metricName: MetricName(name), metricType: Counter, opts: opts}
}

func NewGaugeDef(name string, opts ...Option) metricDefinition {

Check failure on line 108 in common/metrics/defs.go

View workflow job for this annotation

GitHub Actions / lint

unexported-return: exported func NewGaugeDef returns unexported type metrics.metricDefinition, which can be annoying to use (revive)
return metricDefinition{metricName: MetricName(name), metricType: Gauge, opts: opts}
}
8 changes: 3 additions & 5 deletions common/metrics/help_text.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,13 @@ package metrics
// WithHelpText returns a HelpTextOption that sets the help text of a metric.
// Metrics handlers are not required to use this option.
func WithHelpText(helpText string) HelpTextOption {
return HelpTextOption{helpText: helpText}
return HelpTextOption(helpText)
}

// HelpTextOption stores the help text provided to the option.
type HelpTextOption struct {
helpText string
}
type HelpTextOption string

// apply sets the params.optionalHelpText field.
func (h HelpTextOption) apply(p *params) {
p.optionalHelpText = &h.helpText
p.optionalHelpText = (*string)(&h)
}

0 comments on commit 6d89449

Please sign in to comment.