-
Notifications
You must be signed in to change notification settings - Fork 5k
[Metricbeat autodiscover][Provider Kubernetes] Add condition to node/namespace watchers #37181
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
Changes from 3 commits
510a67a
0a75329
a7b5824
0e3091a
fd9a2a4
f06aebe
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -59,7 +59,7 @@ type pod struct { | |||||
| func NewPodEventer(uuid uuid.UUID, cfg *conf.C, client k8s.Interface, publish func(event []bus.Event)) (Eventer, error) { | ||||||
| logger := logp.NewLogger("autodiscover.pod") | ||||||
|
|
||||||
| var replicaSetWatcher, jobWatcher kubernetes.Watcher | ||||||
| var replicaSetWatcher, jobWatcher, nodeWatcher, namespaceWatcher kubernetes.Watcher | ||||||
|
|
||||||
| config := defaultConfig() | ||||||
| err := cfg.Unpack(&config) | ||||||
|
|
@@ -96,40 +96,50 @@ func NewPodEventer(uuid uuid.UUID, cfg *conf.C, client k8s.Interface, publish fu | |||||
| return nil, fmt.Errorf("couldn't create watcher for %T due to error %w", &kubernetes.Pod{}, err) | ||||||
| } | ||||||
|
|
||||||
| options := kubernetes.WatchOptions{ | ||||||
| SyncTimeout: config.SyncPeriod, | ||||||
| Node: config.Node, | ||||||
| Namespace: config.Namespace, | ||||||
| } | ||||||
|
|
||||||
| metaConf := config.AddResourceMetadata | ||||||
| nodeWatcher, err := kubernetes.NewNamedWatcher("node", client, &kubernetes.Node{}, options, nil) | ||||||
| if err != nil { | ||||||
| logger.Errorf("couldn't create watcher for %T due to error %+v", &kubernetes.Node{}, err) | ||||||
|
|
||||||
| var options kubernetes.WatchOptions | ||||||
| if metaConf.Node.Enabled() { | ||||||
| options = kubernetes.WatchOptions{ | ||||||
| SyncTimeout: config.SyncPeriod, | ||||||
| Node: config.Node, | ||||||
| Namespace: config.Namespace, | ||||||
| } | ||||||
| nodeWatcher, err = kubernetes.NewNamedWatcher("node", client, &kubernetes.Node{}, options, nil) | ||||||
| if err != nil { | ||||||
| logger.Errorf("couldn't create watcher for %T due to error %+v", &kubernetes.Node{}, err) | ||||||
| } | ||||||
| } | ||||||
| namespaceWatcher, err := kubernetes.NewNamedWatcher("namespace", client, &kubernetes.Namespace{}, kubernetes.WatchOptions{ | ||||||
| SyncTimeout: config.SyncPeriod, | ||||||
| }, nil) | ||||||
| if err != nil { | ||||||
| logger.Errorf("couldn't create watcher for %T due to error %+v", &kubernetes.Namespace{}, err) | ||||||
| if metaConf.Namespace.Enabled() { | ||||||
| options = kubernetes.WatchOptions{ | ||||||
| SyncTimeout: config.SyncPeriod, | ||||||
| } | ||||||
| namespaceWatcher, err = kubernetes.NewNamedWatcher("namespace", client, &kubernetes.Namespace{}, options, nil) | ||||||
| if err != nil { | ||||||
| logger.Errorf("couldn't create watcher for %T due to error %+v", &kubernetes.Namespace{}, err) | ||||||
| } | ||||||
| } | ||||||
|
|
||||||
| // Resource is Pod so we need to create watchers for Replicasets and Jobs that it might belongs to | ||||||
| // Resource is Pod, so we need to create watchers for Replicasets and Jobs that it might belong to | ||||||
| // in order to be able to retrieve 2nd layer Owner metadata like in case of: | ||||||
| // Deployment -> Replicaset -> Pod | ||||||
| // CronJob -> job -> Pod | ||||||
| if metaConf.Deployment { | ||||||
| replicaSetWatcher, err = kubernetes.NewNamedWatcher("resource_metadata_enricher_rs", client, &kubernetes.ReplicaSet{}, kubernetes.WatchOptions{ | ||||||
| options = kubernetes.WatchOptions{ | ||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Minor suggestion since we touch this codebase: Would it make sense to use the same If we watch for Pods on specific Namespace then their parent Deployments and CronJobs will be on the same Namespace as well. |
||||||
| SyncTimeout: config.SyncPeriod, | ||||||
| }, nil) | ||||||
| } | ||||||
| replicaSetWatcher, err = kubernetes.NewNamedWatcher("resource_metadata_enricher_rs", client, | ||||||
| &kubernetes.ReplicaSet{}, options, nil) | ||||||
| if err != nil { | ||||||
| logger.Errorf("Error creating watcher for %T due to error %+v", &kubernetes.ReplicaSet{}, err) | ||||||
| } | ||||||
| } | ||||||
| if metaConf.CronJob { | ||||||
| jobWatcher, err = kubernetes.NewNamedWatcher("resource_metadata_enricher_job", client, &kubernetes.Job{}, kubernetes.WatchOptions{ | ||||||
| options = kubernetes.WatchOptions{ | ||||||
| SyncTimeout: config.SyncPeriod, | ||||||
| }, nil) | ||||||
| } | ||||||
| jobWatcher, err = kubernetes.NewNamedWatcher("resource_metadata_enricher_job", client, &kubernetes.Job{}, | ||||||
| options, nil) | ||||||
| if err != nil { | ||||||
| logger.Errorf("Error creating watcher for %T due to error %+v", &kubernetes.Job{}, err) | ||||||
| } | ||||||
|
|
@@ -152,12 +162,12 @@ func NewPodEventer(uuid uuid.UUID, cfg *conf.C, client k8s.Interface, publish fu | |||||
|
|
||||||
| watcher.AddEventHandler(p) | ||||||
|
|
||||||
| if nodeWatcher != nil && (config.Hints.Enabled() || metaConf.Node.Enabled()) { | ||||||
| if nodeWatcher != nil && config.Hints.Enabled() { | ||||||
| updater := kubernetes.NewNodePodUpdater(p.unlockedUpdate, watcher.Store(), &p.crossUpdate) | ||||||
| nodeWatcher.AddEventHandler(updater) | ||||||
| } | ||||||
|
|
||||||
| if namespaceWatcher != nil && (config.Hints.Enabled() || metaConf.Namespace.Enabled()) { | ||||||
| if namespaceWatcher != nil && config.Hints.Enabled() { | ||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Now that I see this line again I realize that Let's take for example the So I believe we need to rethink of this patch more carefully. I see 2 options here:
The point is that we cannot couple Hint's based autodiscovery functionality with the Most probably that's why we fetch the namespace Annotations at
A real use case would be the following:a) the users have disabled the namespace metadata enrichment with The hints' events won't be complete because we won't have Namespace annotations at
I might miss sth here but my point is that we need to revisit this seeing the big picture and then decide accordingly. As we can see there are lot's of different pieces affected here.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
I like this option, because this way we can still stop the watchers with
Maybe the user would have way too many options when we can already use the ones available.
Thanks, it is clear 👍
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
I commited new changes so now it works like this.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also somehow related: #34717 |
||||||
| updater := kubernetes.NewNamespacePodUpdater(p.unlockedUpdate, watcher.Store(), &p.crossUpdate) | ||||||
| namespaceWatcher.AddEventHandler(updater) | ||||||
| } | ||||||
|
|
||||||
Uh oh!
There was an error while loading. Please reload this page.