-
Notifications
You must be signed in to change notification settings - Fork 4.9k
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
filebeat: input v2 compat uses random ID for CheckConfig #41585
Merged
AndersonQ
merged 10 commits into
elastic:main
from
AndersonQ:31767-filestream-id-already-exists
Nov 14, 2024
Merged
Changes from 1 commit
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
32f04e3
filebeat: input v2 compat uses random ID for CheckConfig
AndersonQ 5103cc1
fix changelog
AndersonQ d10e55f
Merge branch 'main' into 31767-filestream-id-already-exists
AndersonQ ab8f727
fix refactor
AndersonQ 0481528
Merge remote-tracking branch 'origin/31767-filestream-id-already-exis…
AndersonQ 67bcd91
fix refactor
AndersonQ fd66a37
use math/rand/v2
AndersonQ 9fc2539
Merge branch 'main' into 31767-filestream-id-already-exists
AndersonQ de41ef4
generateCheckConfig returns nil on error and uses uuid
AndersonQ 51fabd3
Merge remote-tracking branch 'origin/31767-filestream-id-already-exis…
AndersonQ 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 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 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 |
---|---|---|
|
@@ -24,6 +24,8 @@ import ( | |
"context" | ||
"errors" | ||
"fmt" | ||
"math/rand" // using for better performance | ||
"strconv" | ||
"sync" | ||
|
||
"github.com/mitchellh/hashstructure" | ||
|
@@ -73,12 +75,18 @@ func RunnerFactory( | |
} | ||
|
||
func (f *factory) CheckConfig(cfg *conf.C) error { | ||
_, err := f.loader.Configure(cfg) | ||
// just check the config, therefore to avoid potential side effects (ID duplication) | ||
// change the ID. | ||
checkCfg, err := f.generateCheckConfig(cfg) | ||
if err != nil { | ||
f.log.Warnw(fmt.Sprintf("input V2 factory.CheckConfig failed to clone config before checking it. Original config will be checked, it might trigger an input duplication warning: %v", err), "original_config", conf.DebugString(cfg, true)) | ||
} | ||
rdner marked this conversation as resolved.
Show resolved
Hide resolved
|
||
_, err = f.loader.Configure(checkCfg) | ||
rdner marked this conversation as resolved.
Show resolved
Hide resolved
|
||
if err != nil { | ||
return fmt.Errorf("runner factory could not check config: %w", err) | ||
} | ||
|
||
if err = f.loader.Delete(cfg); err != nil { | ||
if err = f.loader.Delete(checkCfg); err != nil { | ||
return fmt.Errorf( | ||
"runner factory failed to delete an input after config check: %w", | ||
err) | ||
|
@@ -176,3 +184,24 @@ func configID(config *conf.C) (string, error) { | |
|
||
return fmt.Sprintf("%16X", id), nil | ||
} | ||
|
||
func (f *factory) generateCheckConfig(config *conf.C) (*conf.C, error) { | ||
testCfg, err := conf.NewConfigFrom(config) | ||
rdner marked this conversation as resolved.
Show resolved
Hide resolved
|
||
if err != nil { | ||
return config, fmt.Errorf("failed to create new config: %w", err) | ||
} | ||
|
||
// let's try to override the `inputID` field, if it fails, give up | ||
inputID, err := testCfg.String("inputID", -1) | ||
if err != nil { | ||
return config, fmt.Errorf("failed to get 'inputID': %w", err) | ||
} | ||
|
||
// using math/rand for performance, generate a 0-9 string | ||
err = testCfg.SetString("inputID", -1, inputID+strconv.Itoa(rand.Intn(10))) | ||
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. Question: |
||
if err != nil { | ||
return config, fmt.Errorf("failed to set 'inputID': %w", err) | ||
} | ||
|
||
return testCfg, nil | ||
} |
This file contains 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.
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.
The issue/PR links are missing, also the line ends in a comma, did you forget to add/commit the rest of the line?