-
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
[Runtime fields] Add support in index template #84184
Merged
Merged
Changes from all commits
Commits
Show all changes
41 commits
Select commit
Hold shift + click to select a range
1ad89cc
Revert changes to add runtime field to mappings properties
sebelga 3ff47f9
Update state and reducer with new actions
sebelga 48ab889
Add tab to mappings editor for runtime fields
sebelga bb4e7f7
Export flyout content props from runtime fields
sebelga 4c657d9
Add default ownFocus "true" to global flyout
sebelga 8514aac
Use NormalizedRuntimeField in state
sebelga 7952308
List runtime fields from state
sebelga 9e7be04
Delete runtime field from list
sebelga 916d9d6
Edit runtime field
sebelga 29c8fe9
List provided runtime fields
sebelga 9c33b0b
Put script inside source prop
sebelga 3085f50
Add create field button below list
sebelga 5f8d8c9
Forward runtime fields to parent component
sebelga d6f6452
Improve error description when creating or updating index template
sebelga a83d6aa
Enhance error from simulate template
sebelga 2c39d68
Use ConfigProvider in mappings editor to provide docLinks to runtime …
sebelga 9b0a240
Fix tests and TS issues
sebelga 0327775
Fix test
sebelga e32fe7e
Add badge to indicate when a field is shadowed
sebelga 7d67daa
Add copy description in runtime fields list
sebelga 36e3bb9
Validate that duplicate runtime fields are not allowed + callout when…
sebelga fcb1e0e
Fix i18n issue
sebelga ed4e84d
Add Api integration tests for the ES error parser
sebelga 800d568
Fix issue validating duplicates when editing a field
sebelga 8919c37
Add missing aria-label to form
sebelga 0148830
Update README.md
sebelga 4f597c3
Update loadEditor handler to accept ctx object
sebelga b25fc70
Add es_error_parser unit test
sebelga a5655a2
Merge remote-tracking branch 'upstream/master' into runtime-fields-in…
sebelga fc20640
Merge remote-tracking branch 'upstream/master' into runtime-fields-in…
sebelga cd2dabf
Remove commented code
sebelga 8a65bc8
Update copy text
sebelga 5f1fb37
Merge branch 'master' into runtime-fields-in-mappings-2
kibanamachine 59a01db
Update x-pack/plugins/index_management/public/application/components/…
sebelga 8fe6dd4
Apply suggestions from code review
sebelga c1fc24a
Change callout color to warning for shadowing field
sebelga 446c2cf
Update link for runtime fields painless syntax
sebelga b3a6cd2
Mark script form field as optional
sebelga 4fa275a
Merge remote-tracking branch 'upstream/master' into runtime-fields-in…
sebelga 89b6dbf
Fix tests
sebelga ea928f6
Fix linting issue
sebelga 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
42 changes: 42 additions & 0 deletions
42
src/plugins/es_ui_shared/__packages_do_not_import__/errors/es_error_parser.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,42 @@ | ||
/* | ||
* Licensed to Elasticsearch B.V. under one or more contributor | ||
* license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright | ||
* ownership. Elasticsearch B.V. licenses this file to you under | ||
* the Apache License, Version 2.0 (the "License"); you may | ||
* not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
import { parseEsError } from './es_error_parser'; | ||
|
||
describe('ES error parser', () => { | ||
test('should return all the cause of the error', () => { | ||
const esError = `{ | ||
"error": { | ||
"reason": "Houston we got a problem", | ||
"caused_by": { | ||
"reason": "First reason", | ||
"caused_by": { | ||
"reason": "Second reason", | ||
"caused_by": { | ||
"reason": "Third reason" | ||
} | ||
} | ||
} | ||
} | ||
}`; | ||
|
||
const parsedError = parseEsError(esError); | ||
expect(parsedError.message).toEqual('Houston we got a problem'); | ||
expect(parsedError.cause).toEqual(['First reason', 'Second reason', 'Third reason']); | ||
}); | ||
}); |
52 changes: 52 additions & 0 deletions
52
src/plugins/es_ui_shared/__packages_do_not_import__/errors/es_error_parser.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,52 @@ | ||
/* | ||
* Licensed to Elasticsearch B.V. under one or more contributor | ||
* license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright | ||
* ownership. Elasticsearch B.V. licenses this file to you under | ||
* the Apache License, Version 2.0 (the "License"); you may | ||
* not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
interface ParsedError { | ||
message: string; | ||
cause: string[]; | ||
} | ||
|
||
const getCause = (obj: any = {}, causes: string[] = []): string[] => { | ||
const updated = [...causes]; | ||
|
||
if (obj.caused_by) { | ||
updated.push(obj.caused_by.reason); | ||
|
||
// Recursively find all the "caused by" reasons | ||
return getCause(obj.caused_by, updated); | ||
} | ||
|
||
return updated.filter(Boolean); | ||
}; | ||
|
||
export const parseEsError = (err: string): ParsedError => { | ||
try { | ||
const { error } = JSON.parse(err); | ||
const cause = getCause(error); | ||
return { | ||
message: error.reason, | ||
cause, | ||
}; | ||
} catch (e) { | ||
return { | ||
message: err, | ||
cause: [], | ||
}; | ||
} | ||
}; |
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
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
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
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.
I just wanted to flag that this functionality is similar to what is in
x-pack/plugins/ingest_pipelines/public/application/components/pipeline_form/pipeline_form_error/error_utils.ts
, but that code has an added, perhaps unnecessary, runtime type guard since the assumption was there are no guarantees on what the error object will be (unknown
).I see this is used on the server side and we guard with the "isEsError" check.
We can replace
flattenErrorsTree
in ingest pipelines with this logic to get maximum re-use because this should also work for the errors returned for processors if this is the standard es error shape. I think we still need to guard in ingest pipelines with the runtime type check though.Let me know what you think!
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, indeed it is similar but much simpler implementation :) If you think your use case deserves all the complexity of
io-ts
andfp-ts
then it's better to have separate implementations. My goal was "just" to read the "caused_by" recursively from the ES error. I put the logic inside atry/catch
so it should not break if ES changes the contract.I personally think that sometimes too much typings can get in the way and simplicity is often a better approach. That's just my personal preference though. 😊