[Fleet] Add support for Runtime Fields#161129
Conversation
🤖 GitHub commentsExpand to view the GitHub comments
Just comment with:
|
|
@elasticmachine merge upstream |
| runtimeProperties: fieldProps, | ||
| }); | ||
| } | ||
| return; |
There was a problem hiding this comment.
Reading the docs, it looks like these runtime fields should not be added to the properties section. That's why it has been added here this return.
| const pathMatch = path.includes('*') ? path : `${path}.*`; | ||
|
|
||
| let dynProperties: Properties = getDefaultProperties(field); | ||
| let matchingType: string | undefined; | ||
| switch (field.object_type) { | ||
| case 'keyword': | ||
| dynProperties.type = field.object_type; | ||
| matchingType = field.object_type_mapping_type ?? 'string'; | ||
| break; | ||
| case 'double': | ||
| case 'long': | ||
| case 'boolean': | ||
| dynProperties = { | ||
| type: field.object_type, | ||
| time_series_metric: field.metric_type, | ||
| }; | ||
| matchingType = field.object_type_mapping_type ?? field.object_type; | ||
| default: | ||
| break; | ||
| } |
There was a problem hiding this comment.
Similar to what it is done in this block:
but as runtime fields support fewer types, there were removed the ones not supported
| ctx.addDynamicMapping({ | ||
| path, | ||
| pathMatch, | ||
| matchingType, | ||
| properties: dynProperties, | ||
| runtimeProperties: fieldProps, | ||
| }); |
There was a problem hiding this comment.
This adds a runtime field mapping in a dynamic template:
https://www.elastic.co/guide/en/elasticsearch/reference/current/dynamic-templates.html#dynamic-mapping-runtime-fields
| if (dynamicMapping.runtimeProperties !== undefined) { | ||
| dynamicTemplate.runtime = dynamicMapping.runtimeProperties; | ||
| } else { | ||
| dynamicTemplate.mapping = dynamicMapping.properties; | ||
| } |
There was a problem hiding this comment.
In a dynamic template, mapping and runtime cannot be defined at the same time in the object.
💚 Build Succeeded
Metrics [docs]Unknown metric groupsESLint disabled line counts
Total ESLint disabled count
History
To update your PR or re-run it, just comment with: cc @mrodm |
|
Pinging @elastic/fleet (Team:Fleet) |
|
|
||
| if (!('settings' in packageTemplate)) { | ||
| throw new Error('no mappings on package template'); | ||
| throw new Error('no settings on package template'); |
Summary
Closes #155255
Closes elastic/package-spec#39
Add support in Fleet for Runtime fields, based on these docs:
Given these field definitions in packages:
and this definition in the manifest
This PR adds the required fields into the
mappingskey when installing the package. For this example, the resulting mappings are (just showing the relevant data for these changes):{ ".ds-logs-runtime_fields.foo-default-2023.07.10-000001": { "mappings": { "dynamic_templates": [ { "labels.*": { "path_match": "labels.*", "match_mapping_type": "double", "runtime": { "type": "long" } } } ], "runtime": { "day_of_week_two": { "type": "keyword", "script": { "source": "emit(doc['@timestamp'].value.dayOfWeekEnum.getDisplayName(TextStyle.FULL, Locale.ROOT))", "lang": "painless" } }, "labels.a": { "type": "long" }, "labels.b": { "type": "long" }, "lowercase": { "type": "keyword", "script": { "source": "emit(doc['uppercase'].value.toLowerCase())", "lang": "painless" } }, "responses.runtime_group_boolean": { "type": "boolean" }, "runtime.date": { "type": "date", "script": { "source": "emit(doc['@timestamp'].value.toEpochMilli())", "lang": "painless" }, "format": "yyyy-MM-dd" }, "runtime.day": { "type": "keyword", "script": { "source": "emit(doc['@timestamp'].value.dayOfWeekEnum.getDisplayName(TextStyle.FULL, Locale.ROOT))", "lang": "painless" } }, "runtime.epoch_milli": { "type": "long", "script": { "source": "emit(doc['@timestamp'].value.toEpochMilli())", "lang": "painless" } }, "runtime_boolean": { "type": "boolean" }, "to_be_long": { "type": "long" } }, "properties": { "@timestamp": { "type": "date", "ignore_malformed": false }, "bar": { "type": "boolean" }, "data_stream": { "properties": { "dataset": { "type": "constant_keyword" }, "namespace": { "type": "constant_keyword" }, "type": { "type": "constant_keyword" } } }, "labels": { "type": "object" }, "message": { "type": "keyword", "ignore_above": 1024 }, "responses": { "properties": { "foo": { "type": "boolean" } } }, "uppercase": { "type": "keyword", "ignore_above": 1024 }, "user": { "properties": { "id": { "type": "keyword", "ignore_above": 1024 } } } } } } }Tested manually installing a package containing runtime field definitions as the example above.
Tested also indexing some documents and retrieving the runtime fields:
_sourcedisabled):Checklist
Delete any items that are not applicable to this PR.
(https://chrome.google.com/webstore/detail/axe-web-accessibility-tes/lhdoppojpmngadmnindnejefpokejbdd?hl=en-US))