Skip to content

Commit

Permalink
webhook: add StatsReporterOptions in webhook.Options
Browse files Browse the repository at this point in the history
There are two ways to customize StatsReporter:

1. Use a whole new StatsReporter implementation.
1. Or pass Option funcs to customize the default StatsReporter.

Option 1 is less practical at this time due to the metrics registration
conflict. `webhook.RegisterMetrics()` is called regardless which
StatsReporter implementation is used (which is a problem by itself). The
second option is more practical since it works well without dealing with
metrics conflicts.

The `webhook.Option` in particular allows people to discard certain
metrics tags.
  • Loading branch information
zhouhaibing089 committed Mar 31, 2024
1 parent 3f88da6 commit b7ac4a9
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion webhook/webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,9 @@ type Options struct {
// only a single port for the service.
Port int

// StatsReporterOptions are the options used to initialize the default StatsReporter
StatsReporterOptions []Option

// StatsReporter reports metrics about the webhook.
// This will be automatically initialized by the constructor if left uninitialized.
StatsReporter StatsReporter
Expand Down Expand Up @@ -144,7 +147,7 @@ func New(
logger := logging.FromContext(ctx)

if opts.StatsReporter == nil {
reporter, err := NewStatsReporter()
reporter, err := NewStatsReporter(opts.StatsReporterOptions...)
if err != nil {
return nil, err
}
Expand Down

0 comments on commit b7ac4a9

Please sign in to comment.