-
Notifications
You must be signed in to change notification settings - Fork 8.3k
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
[Fleet] Fix loading fields for transform destination index template #177608
Merged
nchaulet
merged 5 commits into
elastic:main
from
nchaulet:feature-fix-transform-loading-fields
Feb 23, 2024
Merged
Changes from 4 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
cc17566
[Fleet] Fix loading fields for transform destination index template
nchaulet 43bb7cb
Merge branch 'main' of github.com:elastic/kibana into feature-fix-tra…
nchaulet 08422a4
fix test
nchaulet 11d3f09
add unit test
nchaulet e3d875a
fix test
nchaulet 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
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
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
91 changes: 91 additions & 0 deletions
91
x-pack/plugins/fleet/server/services/epm/elasticsearch/transform/mappings.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,91 @@ | ||
/* | ||
* 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 { loadMappingForTransform } from './mappings'; | ||
|
||
describe('loadMappingForTransform', () => { | ||
it('should return a mappings without properties if there is no fields resource', () => { | ||
const fields = loadMappingForTransform( | ||
{ | ||
packageInfo: {} as any, | ||
assetsMap: new Map(), | ||
paths: [], | ||
}, | ||
'test' | ||
); | ||
|
||
expect(fields).toEqual({ properties: {} }); | ||
}); | ||
|
||
it('should merge shallow mapping without properties if there is no fields resource', () => { | ||
const fields = loadMappingForTransform( | ||
{ | ||
packageInfo: {} as any, | ||
assetsMap: new Map([ | ||
[ | ||
'/package/ti_opencti/2.1.0/elasticsearch/transform/latest_ioc/fields/ecs.yml', | ||
Buffer.from( | ||
` | ||
- description: Description of the threat feed in a UI friendly format. | ||
name: threat.feed.description | ||
type: keyword | ||
- description: The name of the threat feed in UI friendly format. | ||
name: threat.feed.name | ||
type: keyword` | ||
), | ||
], | ||
[ | ||
'/package/ti_opencti/2.1.0/elasticsearch/transform/latest_ioc/fields/ecs-extra.yml', | ||
Buffer.from( | ||
` | ||
- description: The display name indicator in an UI friendly format | ||
level: extended | ||
name: threat.indicator.name | ||
type: keyword` | ||
), | ||
], | ||
]), | ||
paths: [ | ||
'/package/ti_opencti/2.1.0/elasticsearch/transform/latest_ioc/fields/ecs.yml', | ||
'/package/ti_opencti/2.1.0/elasticsearch/transform/latest_ioc/fields/ecs-extra.yml', | ||
], | ||
}, | ||
'latest_ioc' | ||
); | ||
|
||
expect(fields).toMatchInlineSnapshot(` | ||
Object { | ||
"properties": Object { | ||
"threat": Object { | ||
"properties": Object { | ||
"feed": Object { | ||
"properties": Object { | ||
"description": Object { | ||
"ignore_above": 1024, | ||
"type": "keyword", | ||
}, | ||
"name": Object { | ||
"ignore_above": 1024, | ||
"type": "keyword", | ||
}, | ||
}, | ||
}, | ||
"indicator": Object { | ||
"properties": Object { | ||
"name": Object { | ||
"ignore_above": 1024, | ||
"type": "keyword", | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
} | ||
`); | ||
}); | ||
}); |
18 changes: 18 additions & 0 deletions
18
x-pack/plugins/fleet/server/services/epm/elasticsearch/transform/mappings.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,18 @@ | ||
/* | ||
* 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 { type PackageInstallContext } from '../../../../../common/types/models'; | ||
import { loadTransformFieldsFromYaml, processFields } from '../../fields/field'; | ||
import { generateMappings } from '../template/template'; | ||
|
||
export function loadMappingForTransform( | ||
packageInstallContext: PackageInstallContext, | ||
transformModuleId: string | ||
) { | ||
const fields = loadTransformFieldsFromYaml(packageInstallContext, transformModuleId); | ||
const validFields = processFields(fields); | ||
return generateMappings(validFields); | ||
} |
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
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.
@chrisberkhout Can you confirm it's the expected behaviour given the two fields files above
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.
Yes, that's right.