-
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
Implement index template generation in Golang #3603
Implement index template generation in Golang #3603
Conversation
72ab1c0
to
967d3a0
Compare
02bea93
to
1f9701f
Compare
filebeat/filebeat.template-es2x.json
Outdated
@@ -40,95 +43,123 @@ | |||
"body_sent": { | |||
"properties": { | |||
"bytes": { | |||
"doc_values": true, | |||
"index": true, |
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.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, lets remove it from the defaults then.
filebeat/filebeat.template-es2x.json
Outdated
@@ -24,13 +24,16 @@ | |||
], | |||
"properties": { | |||
"@timestamp": { | |||
"doc_values": true, | |||
"index": true, |
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'm not sure if this indexing the @timestamp
makes sense.
"ignore_above": 1024, | ||
"index": "not_analyzed", | ||
"type": "string" | ||
}, | ||
"content-type": { | ||
"doc_values": true, |
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.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
@@ -535,6 +535,7 @@ | |||
}, | |||
"order": 0, | |||
"settings": { | |||
"index.mapping.total_fields.limit": 10000, |
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.
This is probably ignored by ES 2.x, but I guess it's harmless.
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.
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
|
||
# Generate index-pattern | ||
echo "Generate index pattern" | ||
-rm -f $(PWD)/_meta/kibana/index-pattern/${BEAT_NAME}.json | ||
mkdir -p $(PWD)/_meta/kibana/index-pattern | ||
. ${PYTHON_ENV}/bin/activate && python ${ES_BEATS}/libbeat/scripts/generate_index_pattern.py --index '${BEAT_NAME}-*' --libbeat ${ES_BEATS}/libbeat --beat $(PWD) | ||
|
||
cc: |
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.
What's this target for?
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.
argh, testing target left over. will remove it
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.
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 |
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.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it would be more conventional to "args" instead of a flag for specifying files. https://golang.org/pkg/flag/#Args
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.
done
|
||
func main() { | ||
|
||
version := flag.String("es-version", "", "Elasticsearch version") |
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.
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.
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.
added
|
||
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For any prints or logs I would route them to stderr. fmt.Fprinf(os.Stderr, ...)
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.
done
libbeat/template/fields.go
Outdated
case "array": | ||
mapping = field.array() | ||
case "group": | ||
var newPath = "" |
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.
Use var newPath string
instead.
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.
done
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, that's better since it bypasses the file mode check.
The index template generation is moved to golang.
Changes
go run
to execute commandBlocked by #3655. Needs update after it is merged.