Skip to content
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

Merged
merged 2 commits into from
Feb 24, 2017

Conversation

ruflin
Copy link
Contributor

@ruflin ruflin commented Feb 16, 2017

The index template generation is moved to golang.

Changes

  • Improve defaults as they were (accidentally?) not used before as the properties were always overwritten by fresh properties
  • 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

Blocked by #3655. Needs update after it is merged.

@ruflin ruflin added the in progress Pull request is currently in progress. label Feb 16, 2017
@ruflin ruflin force-pushed the dynamic-template-generation branch from 72ab1c0 to 967d3a0 Compare February 22, 2017 20:44
@ruflin ruflin force-pushed the dynamic-template-generation branch from 02bea93 to 1f9701f Compare February 23, 2017 09:33
@ruflin ruflin added review and removed in progress Pull request is currently in progress. labels Feb 23, 2017
@@ -40,95 +43,123 @@
"body_sent": {
"properties": {
"bytes": {
"doc_values": true,
"index": true,
Copy link
Contributor

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.

Copy link
Contributor Author

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.

@@ -24,13 +24,16 @@
],
"properties": {
"@timestamp": {
"doc_values": true,
"index": true,
Copy link
Contributor

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,
Copy link
Contributor

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.

Copy link
Contributor Author

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 ...

@ruflin ruflin force-pushed the dynamic-template-generation branch from e8144ab to c76b112 Compare February 23, 2017 10:58
@@ -535,6 +535,7 @@
},
"order": 0,
"settings": {
"index.mapping.total_fields.limit": 10000,
Copy link
Contributor

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.

Copy link
Contributor Author

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 :-)


# 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:
Copy link
Contributor

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?

Copy link
Contributor Author

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

Copy link
Contributor

@tsg tsg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

@tsg
Copy link
Contributor

tsg commented Feb 23, 2017

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
@ruflin ruflin force-pushed the dynamic-template-generation branch from c76b112 to 76d4278 Compare February 23, 2017 11:23
@ruflin
Copy link
Contributor Author

ruflin commented Feb 23, 2017

I rebased and squashed now. Test failures were do to changes in the defaults.

@monicasarbu
Copy link
Contributor

LGTM

Copy link
Member

@andrewkroh andrewkroh left a 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.")
Copy link
Member

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

Copy link
Contributor Author

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")
Copy link
Member

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.

Copy link
Contributor Author

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}")
Copy link
Member

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.

Copy link
Contributor Author

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)
Copy link
Member

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, ...)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

case "array":
mapping = field.array()
case "group":
var newPath = ""
Copy link
Member

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done


func loadYaml(path string) (Fields, error) {
keys := []Field{}
cfg, err := common.LoadFile(path)
Copy link
Member

@andrewkroh andrewkroh Feb 23, 2017

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?

Copy link
Contributor Author

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.

Copy link
Member

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.

@andrewkroh andrewkroh merged commit 4e1a173 into elastic:master Feb 24, 2017
@ruflin ruflin deleted the dynamic-template-generation branch February 27, 2017 13:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants