-
Notifications
You must be signed in to change notification settings - Fork 8.2k
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
[UII] Fill in empty values for constant_keyword
fields from existing mappings
#188145
Merged
Merged
Changes from 1 commit
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
a728786
When there is no value for a constant_keyword mapping, retrieve it fr…
jen-huang f7e2ee5
Merge remote-tracking branch 'upstream/main' into constant-keyword-ro…
jen-huang 9f7aa7c
Only look through `properties`
jen-huang c241efd
Merge branch 'main' into constant-keyword-rollover
jen-huang 653815a
Fix missing values being null instead of undefined
jen-huang 5d541ce
Merge branch 'constant-keyword-rollover' of github.com:jen-huang/kiba…
jen-huang File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
217 changes: 217 additions & 0 deletions
217
x-pack/plugins/fleet/server/services/epm/elasticsearch/template/utils.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,217 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
import { fillConstantKeywordValues } from './utils'; | ||
|
||
describe('fillConstantKeywordValues', () => { | ||
const oldMappings = { | ||
dynamic: false, | ||
_meta: { | ||
managed_by: 'fleet', | ||
managed: true, | ||
package: { | ||
name: 'elastic_agent', | ||
}, | ||
}, | ||
dynamic_templates: [ | ||
{ | ||
ecs_timestamp: { | ||
match: '@timestamp', | ||
mapping: { | ||
ignore_malformed: false, | ||
type: 'date', | ||
}, | ||
}, | ||
}, | ||
], | ||
date_detection: false, | ||
properties: { | ||
'@timestamp': { | ||
type: 'date', | ||
ignore_malformed: false, | ||
}, | ||
load: { | ||
properties: { | ||
'1': { | ||
type: 'double', | ||
}, | ||
'5': { | ||
type: 'double', | ||
}, | ||
'15': { | ||
type: 'double', | ||
}, | ||
}, | ||
}, | ||
event: { | ||
properties: { | ||
agent_id_status: { | ||
type: 'keyword', | ||
ignore_above: 1024, | ||
}, | ||
dataset: { | ||
type: 'constant_keyword', | ||
value: 'elastic_agent.metricbeat', | ||
}, | ||
ingested: { | ||
type: 'date', | ||
format: 'strict_date_time_no_millis||strict_date_optional_time||epoch_millis', | ||
ignore_malformed: false, | ||
}, | ||
}, | ||
}, | ||
message: { | ||
type: 'match_only_text', | ||
}, | ||
'dot.field': { | ||
type: 'keyword', | ||
}, | ||
}, | ||
}; | ||
|
||
const newMappings = { | ||
dynamic: false, | ||
_meta: { | ||
managed_by: 'fleet', | ||
managed: true, | ||
package: { | ||
name: 'elastic_agent', | ||
}, | ||
}, | ||
dynamic_templates: [ | ||
{ | ||
ecs_timestamp: { | ||
match: '@timestamp', | ||
mapping: { | ||
ignore_malformed: false, | ||
type: 'date', | ||
}, | ||
}, | ||
}, | ||
], | ||
date_detection: false, | ||
properties: { | ||
'@timestamp': { | ||
type: 'date', | ||
ignore_malformed: false, | ||
}, | ||
load: { | ||
properties: { | ||
'1': { | ||
type: 'double', | ||
}, | ||
'5': { | ||
type: 'double', | ||
}, | ||
'15': { | ||
type: 'double', | ||
}, | ||
}, | ||
}, | ||
event: { | ||
properties: { | ||
agent_id_status: { | ||
type: 'keyword', | ||
ignore_above: 1024, | ||
}, | ||
dataset: { | ||
type: 'constant_keyword', | ||
}, | ||
ingested: { | ||
type: 'date', | ||
format: 'strict_date_time_no_millis||strict_date_optional_time||epoch_millis', | ||
ignore_malformed: false, | ||
}, | ||
}, | ||
}, | ||
message: { | ||
type: 'match_only_text', | ||
}, | ||
'dot.field': { | ||
type: 'keyword', | ||
}, | ||
some_new_field: { | ||
type: 'keyword', | ||
}, | ||
}, | ||
}; | ||
|
||
it('should fill in missing constant_keyword values from old mappings correctly', () => { | ||
// @ts-ignore | ||
expect(fillConstantKeywordValues(oldMappings, newMappings)).toMatchObject({ | ||
dynamic: false, | ||
_meta: { | ||
managed_by: 'fleet', | ||
managed: true, | ||
package: { | ||
name: 'elastic_agent', | ||
}, | ||
}, | ||
dynamic_templates: [ | ||
{ | ||
ecs_timestamp: { | ||
match: '@timestamp', | ||
mapping: { | ||
ignore_malformed: false, | ||
type: 'date', | ||
}, | ||
}, | ||
}, | ||
], | ||
date_detection: false, | ||
properties: { | ||
'@timestamp': { | ||
type: 'date', | ||
ignore_malformed: false, | ||
}, | ||
load: { | ||
properties: { | ||
'1': { | ||
type: 'double', | ||
}, | ||
'5': { | ||
type: 'double', | ||
}, | ||
'15': { | ||
type: 'double', | ||
}, | ||
}, | ||
}, | ||
event: { | ||
properties: { | ||
agent_id_status: { | ||
type: 'keyword', | ||
ignore_above: 1024, | ||
}, | ||
dataset: { | ||
type: 'constant_keyword', | ||
value: 'elastic_agent.metricbeat', | ||
}, | ||
ingested: { | ||
type: 'date', | ||
format: 'strict_date_time_no_millis||strict_date_optional_time||epoch_millis', | ||
ignore_malformed: false, | ||
}, | ||
}, | ||
}, | ||
message: { | ||
type: 'match_only_text', | ||
}, | ||
'dot.field': { | ||
type: 'keyword', | ||
}, | ||
some_new_field: { | ||
type: 'keyword', | ||
}, | ||
}, | ||
}); | ||
}); | ||
|
||
it('should return the same mappings if old mappings are not provided', () => { | ||
// @ts-ignore | ||
expect(fillConstantKeywordValues({}, newMappings)).toMatchObject(newMappings); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 there any value to check specifically for
.properties
instead of going through everything?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.
good idea, I updated this function