Skip to content

Commit

Permalink
Remove defaults from fields.common.yml for more flexibility
Browse files Browse the repository at this point in the history
Having the defaults in code instead of the libbeat fields.yml will allow to reuse the same script also for fields.yml files from a metricbeat module for example without having to merge in the libbeat file. This is a prerequisite for dynamic index template generation in Golang which can be only for a module.

The top level `fields` entry was removed as without the defaults, it is not needed anymore.

All scripts were adjusted for the new format.
  • Loading branch information
ruflin committed Feb 16, 2017
1 parent 12e559b commit d4b74b2
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 26 deletions.
7 changes: 0 additions & 7 deletions libbeat/_meta/fields.common.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,4 @@
defaults:
type: keyword
required: false
index: true
doc_values: true
ignore_above: 1024

fields:
- key: beat
title: Beat
description: >
Expand Down
4 changes: 2 additions & 2 deletions libbeat/scripts/generate_fields_docs.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,15 +84,15 @@ def fields_to_asciidoc(input, output, beat):

# Create sections from available fields
sections = {}
for v in docs["fields"]:
for v in docs:
sections[v["key"]] = v["title"]

for key in sorted(sections):
output.write("* <<exported-fields-{}>>\n".format(key))
output.write("\n--\n")

# Sort alphabetically by key
for section in sorted(docs["fields"], key=lambda field: field["key"]):
for section in sorted(docs, key=lambda field: field["key"]):
section["name"] = section["title"]
section["anchor"] = section["key"]
document_fields(output, section, sections, "")
Expand Down
9 changes: 5 additions & 4 deletions libbeat/scripts/generate_index_pattern.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ def fields_to_index_pattern(args, input):

}

for k, section in enumerate(docs["fields"]):
for k, section in enumerate(docs):
fields_to_json(section, "", output)

# add meta fields
Expand Down Expand Up @@ -149,9 +149,10 @@ def get_index_pattern_name(index):
with open(fields_yml, 'r') as f:
fields = f.read()

# Prepend beat fields from libbeat
with open(args.libbeat + "/_meta/fields.generated.yml") as f:
fields = f.read() + fields
if os.path.basename(args.beat) != "libbeat":
# Prepend beat fields from libbeat
with open(args.libbeat + "/_meta/fields.generated.yml") as f:
fields = f.read() + fields

# with open(target, 'w') as output:
output = fields_to_index_pattern(args, fields)
Expand Down
23 changes: 11 additions & 12 deletions libbeat/scripts/generate_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,16 @@ def fields_to_es_template(args, input, output, index, version):
print("fields.yml is empty. Cannot generate template.")
return

# Each template needs defaults
if "defaults" not in docs.keys():
print("No defaults are defined. Each template needs at" +
" least defaults defined.")
return

defaults = docs["defaults"]
defaults = {
"type": "keyword",
"required": False,
"index": True,
"doc_values": True,
"ignore_above": 1024,
}

for k, section in enumerate(docs["fields"]):
docs["fields"][k] = dedot(section)
for k, section in enumerate(docs):
docs[k] = dedot(section)

# skeleton
template = {
Expand Down Expand Up @@ -105,9 +105,8 @@ def fields_to_es_template(args, input, output, index, version):
}
})

for section in docs["fields"]:
prop, dynamic = fill_section_properties(args, section,
defaults, "")
for section in docs:
prop, dynamic = fill_section_properties(args, section, defaults, "")
properties.update(prop)
dynamic_templates.extend(dynamic)

Expand Down
2 changes: 1 addition & 1 deletion libbeat/tests/system/beat/beat.py
Original file line number Diff line number Diff line change
Expand Up @@ -429,7 +429,7 @@ def extract_fields(doc_list, name):
fields = []
dictfields = []

for item in doc["fields"]:
for item in doc:
subfields, subdictfields = extract_fields(item["fields"], "")
fields.extend(subfields)
dictfields.extend(subdictfields)
Expand Down

0 comments on commit d4b74b2

Please sign in to comment.