-
Notifications
You must be signed in to change notification settings - Fork 14
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
add formatting pattern support #151
base: main
Are you sure you want to change the base?
Conversation
72495ad
to
9ce2671
Compare
9ce2671
to
8efeddc
Compare
@gpop63 This is good that we are able to add the |
@aliabbas-elastic Currently I only added it for |
@gpop63 Ok. I think it's fine for now as we are able to generate the required formats. |
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.
LGTM
@gpop63 @aliabbas-elastic What do you think of this?
This is just an example config. Suppose hostIP is of type Why not have a split operator like the one I showed in the config? Gives us more flexibility. Also, there could be cases where the IP is there but not the port, as well as the IP with a port. There could be more such cases for different types. Given that values for some types could be very dynamic, shouldn't be nice if we do this? The code will look something like this: func replacePattern(pattern string) (string, error) {
options := strings.Split(pattern, "|")
chosenOption := options[rand.Intn(len(options))]
// Define a map of placeholder replacements
replacements := map[string]func() string{
"{ipv4}": func() string {
// logic
},
"{ipv6}": func() string {
// logic
},
"{port}": // logic
"{hostname}": // logic
}
// Replace each placeholder in the chosen option
for placeholder, replacementFunc := range replacements {
if strings.Contains(chosenOption, placeholder) {
chosenOption = strings.Replace(chosenOption, placeholder, replacementFunc(), -1)
}
}
return chosenOption, nil
} chosenOption randomly chooses one of them and then the rest. Also, we do not need to depend on regexp as the patterns are simple. We can just do string matching. |
Overview
This PR introduces the capability to generate field values in a specific format.
A set of standard pattern generators are added:
ipv4
,ipv6
,port
andstring
. Regex is used to identify formatting patterns in the field value, which must conform to the{generator}
format.Example:
Test with actual config
configs.yml
fields.yml
gotext.tpl
Relates: #141