Implement index template generation in Golang#3603
Implement index template generation in Golang#3603andrewkroh merged 2 commits intoelastic:masterfrom
Conversation
72ab1c0 to
967d3a0
Compare
02bea93 to
1f9701f
Compare
filebeat/filebeat.template-es2x.json
Outdated
There was a problem hiding this comment.
Hmm, I think "index": true is not valid for 2x. It should be "index": "analyzed", or simply leave the default.
There was a problem hiding this comment.
Ok, lets remove it from the defaults then.
filebeat/filebeat.template-es2x.json
Outdated
There was a problem hiding this comment.
I'm not sure if this indexing the @timestamp makes sense.
There was a problem hiding this comment.
Since we almost never want to disable "doc_values", I wonder if it's worth adding it explicitly to the templates.
There was a problem hiding this comment.
As long as the defaults stay the same, there is no need to add it. Lets remove this too for the moment to keep it the same as it was previously and introduce defaults in case we need it. Defaults "should have been there" in the python script but were ignored ...
e8144ab to
c76b112
Compare
filebeat/filebeat.template-es2x.json
Outdated
There was a problem hiding this comment.
This is probably ignored by ES 2.x, but I guess it's harmless.
There was a problem hiding this comment.
Will only apply it if not 2x as we have the logic for that. We should also make use of it :-)
libbeat/scripts/Makefile
Outdated
There was a problem hiding this comment.
argh, testing target left over. will remove it
|
There seem to be some unit test failures, atm. |
The index template generation is moved to golang. Changes * Use `go run` to execute command * Template generation is part of libbeat, only execution command is outside as it as has some additional logic on how to read the files. * Add assumption that $ES_BEATS is always a relative path * Add support for more fine grained versioning in template generation * Remove python script as not needed anymore
c76b112 to
76d4278
Compare
|
I rebased and squashed now. Test failures were do to changes in the defaults. |
|
LGTM |
andrewkroh
left a comment
There was a problem hiding this comment.
Nice! Overall it looks great and just had a few minor comments.
| func main() { | ||
|
|
||
| version := flag.String("es-version", "", "Elasticsearch version") | ||
| inputFiles := flag.String("files", "", "List of files, comma seperated. This files must be passed with the full path.") |
There was a problem hiding this comment.
I think it would be more conventional to "args" instead of a flag for specifying files. https://golang.org/pkg/flag/#Args
|
|
||
| func main() { | ||
|
|
||
| version := flag.String("es-version", "", "Elasticsearch version") |
There was a problem hiding this comment.
It would be nice to say what the default value is here. Could you call beat.GetDefaultVersion() here to populate the default value so that it shows up in the help.
|
|
||
| version := flag.String("es-version", "", "Elasticsearch version") | ||
| inputFiles := flag.String("files", "", "List of files, comma seperated. This files must be passed with the full path.") | ||
| beatName := flag.String("beatname", "", "Base index name. Normally {beatname}") |
There was a problem hiding this comment.
Is a value required? Probably it is so I would mention that it's required in the description and validate that the value is non-empty.
There was a problem hiding this comment.
done, same for beatname
|
|
||
| templateString, err := template.GetTemplate(*version, *beatName, existingFiles) | ||
| if err != nil { | ||
| fmt.Printf("Error generating template: %+v", err) |
There was a problem hiding this comment.
For any prints or logs I would route them to stderr. fmt.Fprinf(os.Stderr, ...)
libbeat/template/fields.go
Outdated
| case "array": | ||
| mapping = field.array() | ||
| case "group": | ||
| var newPath = "" |
There was a problem hiding this comment.
Use var newPath string instead.
libbeat/template/template.go
Outdated
|
|
||
| func loadYaml(path string) (Fields, error) { | ||
| keys := []Field{} | ||
| cfg, err := common.LoadFile(path) |
There was a problem hiding this comment.
You probably shouldn't use this method since it expects to be loading config files and checks the permissions on the files it reads.
Can you use yaml.Unmarshal more directly?
There was a problem hiding this comment.
I changed it to
cfg, err := yaml.NewConfigWithFile(path)
if err != nil {
return nil, err
}
cfg.Unpack(&keys)
I really like to use go-ucfg here in case we add some config magic to this in the future.
There was a problem hiding this comment.
Yeah, that's better since it bypasses the file mode check.
The index template generation is moved to golang.
Changes
go runto execute commandBlocked by #3655. Needs update after it is merged.