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

option to provide metrics registry #27

Merged
merged 1 commit into from
Jun 28, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 18 additions & 4 deletions options.go
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,15 @@ func WithLogger(log logger.Logger) ProcessorOption {
}
}

// WithRegistry sets the metrics registry the processor should use. The registry
// should not be prefixed, otherwise the monitor web view won't work as it
// expects metrics of certain name.
func WithRegistry(r metrics.Registry) ProcessorOption {
return func(o *poptions) {
o.registry = r
}
}

func (opt *poptions) applyOptions(group string, opts ...ProcessorOption) error {
opt.clientID = defaultClientID

Expand All @@ -207,8 +216,6 @@ func (opt *poptions) applyOptions(group string, opts ...ProcessorOption) error {
opt.storageSnapshotInterval = storage.DefaultStorageSnapshotInterval
}

opt.registry = metrics.NewRegistry()

// prefix registry
opt.gokaRegistry = metrics.NewPrefixedChildRegistry(opt.registry, fmt.Sprintf("goka.processor-%s.", group))

Expand Down Expand Up @@ -253,6 +260,15 @@ type voptions struct {
kafkaRegistry metrics.Registry
}

// WithViewRegistry sets the metrics registry the processor should use. The
// registry should not be prefixed, otherwise the monitor web view won't work as
// it expects metrics of certain name.
func WithViewRegistry(r metrics.Registry) ViewOption {
return func(o *voptions) {
o.registry = r
}
}

// WithViewLogger sets the logger the view should use. By default, views
// use the standard library logger.
func WithViewLogger(log logger.Logger) ViewOption {
Expand Down Expand Up @@ -350,8 +366,6 @@ func (opt *voptions) applyOptions(topic Table, opts ...ViewOption) error {
opt.builders.topicmgr = defaultTopicManagerBuilder
}

opt.registry = metrics.NewRegistry()

// Set a default registry to pass it to the kafka consumer builders.
if opt.kafkaRegistry == nil {
opt.kafkaRegistry = metrics.NewPrefixedChildRegistry(opt.registry, fmt.Sprintf("kafka.view-%s.", topic))
Expand Down
1 change: 1 addition & 0 deletions processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ func NewProcessor(brokers []string, gg *GroupGraph, options ...ProcessorOption)
options = append(
// default options comes first
[]ProcessorOption{
WithRegistry(metrics.NewRegistry()),
WithLogger(logger.Default()),
WithUpdateCallback(DefaultUpdate),
WithStoragePath("/tmp/goka"),
Expand Down
1 change: 1 addition & 0 deletions view.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ func NewView(brokers []string, topic Table, codec Codec, options ...ViewOption)
options = append(
// default options comes first
[]ViewOption{
WithViewRegistry(metrics.NewRegistry()),
WithViewLogger(logger.Default()),
WithViewCallback(DefaultUpdate),
WithViewStoragePath(defaultReaderStoragePath),
Expand Down