Skip to content

Commit 290bb88

Browse files
rgmzebeahan
authored andcommitted
feat: include alias path when generating template (#877)
# Conflicts: # CHANGELOG.next.md
1 parent 14141ec commit 290bb88

File tree

7 files changed

+44
-1
lines changed

7 files changed

+44
-1
lines changed

CHANGELOG.next.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@ Thanks, you're awesome :-) -->
2828

2929
#### Added
3030

31+
* Added ability to supply free-form usage documentation per fieldset. #988
32+
* Added the `path` key when type is `alias`, to support the [alias field type](https://www.elastic.co/guide/en/elasticsearch/reference/current/alias.html). #877
33+
3134
#### Improvements
3235

3336
#### Deprecated

schemas/README.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,18 @@ Supported keys to describe expected values for a field
151151
Optionally, entries in this list can specify 'expected\_event\_types'.
152152
- expected\_event\_types: list of expected "event.type" values to use in association
153153
with that category.
154+
155+
Supported keys when using the [alias field type](https://www.elastic.co/guide/en/elasticsearch/reference/current/alias.html)
156+
157+
```YAML
158+
- name: a_field
159+
level: extended
160+
type: alias
161+
path: another_field
162+
description: >
163+
An alias of another field.
164+
```
165+
- path (optional): The full path to the [aliases' target field](https://www.elastic.co/guide/en/elasticsearch/reference/current/alias.html#alias-targets).
154166

155167
#### Multi\_fields
156168

scripts/generators/beats.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ def fieldset_field_array(source_fields, df_whitelist, fieldset_prefix):
3434
allowed_keys = ['name', 'level', 'required', 'type', 'object_type',
3535
'ignore_above', 'multi_fields', 'format', 'input_format',
3636
'output_format', 'output_precision', 'description',
37-
'example', 'enabled', 'index']
37+
'example', 'enabled', 'index', 'path']
3838
multi_fields_allowed_keys = ['name', 'type', 'norms', 'default_field', 'normalizer', 'ignore_above']
3939

4040
fields = []

scripts/generators/es_template.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,8 @@ def entry_for(field):
5959
ecs_helpers.dict_copy_existing_keys(field, field_entry, ['ignore_above'])
6060
elif field['type'] == 'text':
6161
ecs_helpers.dict_copy_existing_keys(field, field_entry, ['norms'])
62+
elif field['type'] == 'alias':
63+
ecs_helpers.dict_copy_existing_keys(field, field_entry, ['path'])
6264

6365
if 'multi_fields' in field:
6466
field_entry['fields'] = {}

scripts/schema/cleaner.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,12 @@ def field_mandatory_attributes(field):
158158
return
159159
current_field_attributes = sorted(field['field_details'].keys())
160160
missing_attributes = ecs_helpers.list_subtract(FIELD_MANDATORY_ATTRIBUTES, current_field_attributes)
161+
162+
# The `alias` type requires a target path.
163+
# https://github.com/elastic/ecs/issues/876
164+
if field['field_details'].get('type') == 'alias' and 'path' not in current_field_attributes:
165+
missing_attributes.append('path')
166+
161167
if len(missing_attributes) > 0:
162168
msg = "Field is missing the following mandatory attributes: {}.\nFound these: {}.\nField details: {}"
163169
raise ValueError(msg.format(', '.join(missing_attributes),

scripts/tests/test_es_template.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,19 @@ def test_entry_for_index(self):
109109
}
110110
self.assertEqual(es_template.entry_for(test_map), exp)
111111

112+
def test_entry_for_alias(self):
113+
test_map = {
114+
'name': 'test.alias',
115+
'type': 'alias',
116+
'path': 'alias.target'
117+
}
118+
119+
exp = {
120+
'type': 'alias',
121+
'path': 'alias.target'
122+
}
123+
self.assertEqual(es_template.entry_for(test_map), exp)
124+
112125

113126
if __name__ == '__main__':
114127
unittest.main()

scripts/tests/unit/test_schema_cleaner.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,13 @@ def test_field_raises_on_missing_required_attributes(self):
157157
"mandatory attributes: {}".format(missing_attribute)):
158158
cleaner.field_mandatory_attributes(field)
159159

160+
def test_field_raises_on_alias_missing_path_attribute(self):
161+
field = self.schema_process()['process']['fields']['pid']
162+
field['field_details']['type'] = "alias"
163+
with self.assertRaisesRegex(ValueError,
164+
"mandatory attributes: {}".format("path")):
165+
cleaner.field_mandatory_attributes(field)
166+
160167
def test_field_simple_cleanup(self):
161168
my_field = {
162169
'field_details': {

0 commit comments

Comments
 (0)