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

Start autodiscover consumers before producers #7926

Merged
merged 2 commits into from
Nov 8, 2018
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
1 change: 1 addition & 0 deletions CHANGELOG.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ https://github.com/elastic/beats/compare/v6.4.0...master[Check the HEAD diff]
- The export config subcommand should not display real value for field reference. {pull}xxx[xxx]
- The export config subcommand should not display real value for field reference. {pull}8769[8769]
- Do not panic when no tokenizer string is configured for a dissect processor. {issue}8895[8895]
- Start autodiscover consumers before producers. {pull}7926[7926]
- The setup command will not fail if no dashboard is available to import. {pull}8977[8977]

*Auditbeat*
Expand Down
9 changes: 7 additions & 2 deletions libbeat/autodiscover/autodiscover.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,11 +104,16 @@ func (a *Autodiscover) Start() {
logp.Info("Starting autodiscover manager")
a.listener = a.bus.Subscribe(a.adapter.EventFilter()...)

// It is important to start the worker first before starting the producer.
// In hosts that have large number of workloads, it is easy to have an initial
// sync of workloads to have a count that is greater than 100 (which is the size
// of the bounded Go channel. Starting the providers before the consumer would
// result in the channel filling up and never allowing the worker to start up.
go a.worker()
Copy link

Choose a reason for hiding this comment

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

Let's add a more detailed comment explaining that worker reads events generated by providers. Moving go a.worker() after the loop leads to a deadlock in the providers, due to a missing consumer on the channels. It's too easy to not see this kind of issue and accidentily break the code again.


for _, provider := range a.providers {
provider.Start()
}

go a.worker()
}

func (a *Autodiscover) worker() {
Expand Down
4 changes: 4 additions & 0 deletions libbeat/common/kubernetes/watcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ type watcher struct {
k8sResourceFactory func() k8s.Resource
items func() []k8s.Resource
handler ResourceEventHandler
logger *logp.Logger
}

// NewWatcher initializes the watcher client to provide a events handler for
Expand All @@ -82,6 +83,7 @@ func NewWatcher(client *k8s.Client, resource Resource, options WatchOptions) (Wa
lastResourceVersion: "0",
ctx: ctx,
stop: cancel,
logger: logp.NewLogger("kubernetes"),
}
switch resource.(type) {
// add resource type which you want to support watching here
Expand Down Expand Up @@ -184,10 +186,12 @@ func (w *watcher) sync() error {
return err
}

w.logger.Debugf("Got %v items from the resource sync", len(w.items()))
for _, item := range w.items() {
w.onAdd(item)
}

w.logger.Debugf("Done syncing %v items from the resource sync", len(w.items()))
// Store last version
w.lastResourceVersion = w.resourceList.GetMetadata().GetResourceVersion()

Expand Down