-
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
Closed
Closed
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
510a67a
Add condition to node/namespace watchers.
constanca-m 0a75329
Add CHANGELOG-developer.next.asciidoc entry
constanca-m a7b5824
Update CHANGELOG-developer.next.asciidoc
constanca-m 0e3091a
Update options for namespace and node watchers.
constanca-m fd9a2a4
Fix service metagen.
constanca-m f06aebe
Add test on conditions for namespace/node watchers.
constanca-m File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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() || config.Hints.Enabled() { | ||
| options = kubernetes.WatchOptions{ | ||
| SyncTimeout: config.SyncPeriod, | ||
| Node: config.Node, | ||
| } | ||
| 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() || config.Hints.Enabled() { | ||
| options = kubernetes.WatchOptions{ | ||
| SyncTimeout: config.SyncPeriod, | ||
| Namespace: config.Namespace, | ||
| } | ||
| 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 { | ||
| updater := kubernetes.NewNodePodUpdater(p.unlockedUpdate, watcher.Store(), &p.crossUpdate) | ||
| nodeWatcher.AddEventHandler(updater) | ||
| } | ||
|
|
||
| if namespaceWatcher != nil && (config.Hints.Enabled() || metaConf.Namespace.Enabled()) { | ||
| if namespaceWatcher != nil { | ||
| updater := kubernetes.NewNamespacePodUpdater(p.unlockedUpdate, watcher.Store(), &p.crossUpdate) | ||
| namespaceWatcher.AddEventHandler(updater) | ||
| } | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.