-
Notifications
You must be signed in to change notification settings - Fork 5k
[auditbeat][fim] Update Auditbeat file_integrity module to default to auto backend with intelligent fallback #47498
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
Open
marc-gr
wants to merge
3
commits into
elastic:main
Choose a base branch
from
marc-gr:feat/fim-auto-backend
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+300
−106
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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
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
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 |
|---|---|---|
| @@ -0,0 +1,80 @@ | ||
| // Licensed to Elasticsearch B.V. under one or more contributor | ||
| // license agreements. See the NOTICE file distributed with | ||
| // this work for additional information regarding copyright | ||
| // ownership. Elasticsearch B.V. licenses this file to you under | ||
| // the Apache License, Version 2.0 (the "License"); you may | ||
| // not use this file except in compliance with the License. | ||
| // You may obtain a copy of the License at | ||
| // | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, | ||
| // software distributed under the License is distributed on an | ||
| // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| // KIND, either express or implied. See the License for the | ||
| // specific language governing permissions and limitations | ||
| // under the License. | ||
|
|
||
| package file_integrity | ||
|
|
||
| import ( | ||
| "errors" | ||
| "fmt" | ||
|
|
||
| "github.com/elastic/elastic-agent-libs/logp" | ||
| ) | ||
|
|
||
| // backendInitializer is a function that initializes a backend | ||
| type backendInitializer func(Config, *logp.Logger) (EventProducer, error) | ||
|
|
||
| func NewEventReader(c Config, logger *logp.Logger) (EventProducer, error) { | ||
| // Handle auto backend selection with fallback mechanism | ||
| if c.Backend == BackendAuto || c.Backend == "" { | ||
| return tryBackendsInOrder(supportedBackends, autoBackendOrder, c, logger) | ||
| } | ||
|
|
||
| // Handle explicit backend selection | ||
| return initBackend(supportedBackends, c.Backend, c, logger) | ||
| } | ||
|
|
||
| // tryBackendsInOrder attempts to initialize backends in the specified order | ||
| func tryBackendsInOrder(supportedBackends map[Backend]backendInitializer, backends []Backend, c Config, logger *logp.Logger) (EventProducer, error) { | ||
| logger.Infof("backend auto-selection enabled, trying backends in order: %v", backends) | ||
| var reader EventProducer | ||
| var lastErr error | ||
| for i, backend := range backends { | ||
| l := logger.Named(string(backend)) | ||
| initializer, found := supportedBackends[backend] | ||
| if !found { | ||
| // this should never happen | ||
| l.Fatalf("backend %s not supported, this is a bug", backend) | ||
| } | ||
| if reader, lastErr = initializer(c, l); lastErr == nil { | ||
| l.Infof("selected backend: %s", backend) | ||
| return reader, nil | ||
| } | ||
|
|
||
| // Log fallback message unless this is the last backend | ||
| if i < len(backends)-1 { | ||
| logger.Warnf("%s backend not available: %v, falling back to %s", | ||
| backend, lastErr, backends[i+1]) | ||
| } | ||
| } | ||
| return nil, fmt.Errorf("all backends failed, last error: %w", lastErr) | ||
| } | ||
|
|
||
| // initBackend initializes a specific backend | ||
| func initBackend(supportedBackends map[Backend]backendInitializer, backend Backend, c Config, logger *logp.Logger) (EventProducer, error) { | ||
| l := logger.Named(string(backend)) | ||
| initializer, found := supportedBackends[backend] | ||
| if !found { | ||
| return nil, errors.ErrUnsupported | ||
| } | ||
|
|
||
| reader, err := initializer(c, l) | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
| l.Infof("selected backend: %s", backend) | ||
| return reader, nil | ||
| } |
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
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
Oops, something went wrong.
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I noticed that
newFSNotifyReaderandnewKProbesReader, get watchers and then close them.The ebpf watcher doesn't need to be closed?