-
Notifications
You must be signed in to change notification settings - Fork 8.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Runtime fields] Add support in index template (#84184)
Co-authored-by: Adam Locke <adam.locke@elastic.co> Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
- Loading branch information
1 parent
43dd487
commit e83bbfd
Showing
78 changed files
with
1,850 additions
and
557 deletions.
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.