mirror of
https://github.com/elastic/kibana.git
synced 2025-04-24 09:48:58 -04:00
# Backport This will backport the following commits from `main` to `8.11`: - [[ES|QL] Improve warning handling for messages without positioning (#169066)](https://github.com/elastic/kibana/pull/169066) <!--- Backport version: 8.9.7 --> ### Questions ? Please refer to the [Backport tool documentation](https://github.com/sqren/backport) <!--BACKPORT [{"author":{"name":"Marco Liberati","email":"dej611@users.noreply.github.com"},"sourceCommit":{"committedDate":"2023-10-17T11:33:56Z","message":"[ES|QL] Improve warning handling for messages without positioning (#169066)\n\n## Summary\r\n\r\nThis PR improves the warning unmarshalling for ES|QL providing support\r\nfor messages without positioning (`Line x:xx: ...`).\r\n\r\n<img width=\"438\" alt=\"Screenshot 2023-10-17 at 10 11 12\"\r\nsrc=\"4c9f2621
-e4f8-4ea1-946a-0b6869946858\">\r\n\r\n### Checklist\r\n\r\nDelete any items that are not applicable to this PR.\r\n\r\n- [x] [Unit or functional\r\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\r\nwere updated or added to match the most common scenarios","sha":"d7b9a2ab719148bec97387b6153b4ac8fd3fe38c","branchLabelMapping":{"^v8.12.0$":"main","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["Team:Visualizations","release_note:skip","backport:prev-minor","Feature:ES|QL","v8.12.0","v8.11.1"],"number":169066,"url":"https://github.com/elastic/kibana/pull/169066","mergeCommit":{"message":"[ES|QL] Improve warning handling for messages without positioning (#169066)\n\n## Summary\r\n\r\nThis PR improves the warning unmarshalling for ES|QL providing support\r\nfor messages without positioning (`Line x:xx: ...`).\r\n\r\n<img width=\"438\" alt=\"Screenshot 2023-10-17 at 10 11 12\"\r\nsrc=\"4c9f2621
-e4f8-4ea1-946a-0b6869946858\">\r\n\r\n### Checklist\r\n\r\nDelete any items that are not applicable to this PR.\r\n\r\n- [x] [Unit or functional\r\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\r\nwere updated or added to match the most common scenarios","sha":"d7b9a2ab719148bec97387b6153b4ac8fd3fe38c"}},"sourceBranch":"main","suggestedTargetBranches":["8.11"],"targetPullRequestStates":[{"branch":"main","label":"v8.12.0","labelRegex":"^v8.12.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/169066","number":169066,"mergeCommit":{"message":"[ES|QL] Improve warning handling for messages without positioning (#169066)\n\n## Summary\r\n\r\nThis PR improves the warning unmarshalling for ES|QL providing support\r\nfor messages without positioning (`Line x:xx: ...`).\r\n\r\n<img width=\"438\" alt=\"Screenshot 2023-10-17 at 10 11 12\"\r\nsrc=\"4c9f2621
-e4f8-4ea1-946a-0b6869946858\">\r\n\r\n### Checklist\r\n\r\nDelete any items that are not applicable to this PR.\r\n\r\n- [x] [Unit or functional\r\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\r\nwere updated or added to match the most common scenarios","sha":"d7b9a2ab719148bec97387b6153b4ac8fd3fe38c"}},{"branch":"8.11","label":"v8.11.1","labelRegex":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"}]}] BACKPORT--> Co-authored-by: Marco Liberati <dej611@users.noreply.github.com>
This commit is contained in:
parent
0c0c1777f7
commit
50f400e178
2 changed files with 119 additions and 33 deletions
|
@ -114,6 +114,73 @@ describe('helpers', function () {
|
|||
},
|
||||
]);
|
||||
});
|
||||
|
||||
it('should return the correct array of warnings if multiple warnins are detected without line indicators', function () {
|
||||
const warning =
|
||||
'299 Elasticsearch-8.10.0-SNAPSHOT-adb9fce96079b421c2575f0d2d445f492eb5f075 "Field [geo.coordinates] cannot be retrieved, it is unsupported or not indexed; returning null.", 299 Elasticsearch-8.10.0-SNAPSHOT-adb9fce96079b421c2575f0d2d445f492eb5f075 "Field [ip_range] cannot be retrieved, it is unsupported or not indexed; returning null.", 299 Elasticsearch-8.10.0-SNAPSHOT-adb9fce96079b421c2575f0d2d445f492eb5f075 "Field [timestamp_range] cannot be retrieved, it is unsupported or not indexed; returning null."';
|
||||
expect(parseWarning(warning)).toEqual([
|
||||
{
|
||||
endColumn: 10,
|
||||
endLineNumber: 1,
|
||||
message:
|
||||
'Field [geo.coordinates] cannot be retrieved, it is unsupported or not indexed; returning null.',
|
||||
severity: 8,
|
||||
startColumn: 1,
|
||||
startLineNumber: 1,
|
||||
},
|
||||
{
|
||||
endColumn: 10,
|
||||
endLineNumber: 1,
|
||||
message:
|
||||
'Field [ip_range] cannot be retrieved, it is unsupported or not indexed; returning null.',
|
||||
severity: 8,
|
||||
startColumn: 1,
|
||||
startLineNumber: 1,
|
||||
},
|
||||
{
|
||||
endColumn: 10,
|
||||
endLineNumber: 1,
|
||||
message:
|
||||
'Field [timestamp_range] cannot be retrieved, it is unsupported or not indexed; returning null.',
|
||||
severity: 8,
|
||||
startColumn: 1,
|
||||
startLineNumber: 1,
|
||||
},
|
||||
]);
|
||||
});
|
||||
it('should return the correct array of warnings if multiple warnins of different types', function () {
|
||||
const warning =
|
||||
'299 Elasticsearch-8.10.0-SNAPSHOT-adb9fce96079b421c2575f0d2d445f492eb5f075 "Field [geo.coordinates] cannot be retrieved, it is unsupported or not indexed; returning null.", 299 Elasticsearch-8.10.0-SNAPSHOT-adb9fce96079b421c2575f0d2d445f492eb5f075 "Field [ip_range] cannot be retrieved, it is unsupported or not indexed; returning null.", 299 Elasticsearch-8.10.0-SNAPSHOT-adb9fce96079b421c2575f0d2d445f492eb5f075 "Line 1:52: evaluation of [date_parse(geo.dest)] failed, treating result as null. Only first 20 failures recorded."';
|
||||
expect(parseWarning(warning)).toEqual([
|
||||
{
|
||||
endColumn: 10,
|
||||
endLineNumber: 1,
|
||||
message:
|
||||
'Field [geo.coordinates] cannot be retrieved, it is unsupported or not indexed; returning null.',
|
||||
severity: 8,
|
||||
startColumn: 1,
|
||||
startLineNumber: 1,
|
||||
},
|
||||
{
|
||||
endColumn: 10,
|
||||
endLineNumber: 1,
|
||||
message:
|
||||
'Field [ip_range] cannot be retrieved, it is unsupported or not indexed; returning null.',
|
||||
severity: 8,
|
||||
startColumn: 1,
|
||||
startLineNumber: 1,
|
||||
},
|
||||
{
|
||||
endColumn: 138,
|
||||
endLineNumber: 1,
|
||||
message:
|
||||
'evaluation of [date_parse(geo.dest)] failed, treating result as null. Only first 20 failures recorded.',
|
||||
severity: 8,
|
||||
startColumn: 52,
|
||||
startLineNumber: 1,
|
||||
},
|
||||
]);
|
||||
});
|
||||
});
|
||||
|
||||
describe('getInlineEditorText', function () {
|
||||
|
|
|
@ -43,41 +43,60 @@ export const useDebounceWithOptions = (
|
|||
);
|
||||
};
|
||||
|
||||
const quotedWarningMessageRegexp = /"(.*?)"/g;
|
||||
|
||||
export const parseWarning = (warning: string): MonacoError[] => {
|
||||
if (warning.includes('Line')) {
|
||||
const splitByLine = warning.split('Line');
|
||||
splitByLine.shift();
|
||||
return splitByLine.map((item) => {
|
||||
const [lineNumber, startPosition, warningMessage] = item.split(':');
|
||||
const [trimmedMessage] = warningMessage.split('"');
|
||||
// initialize the length to 10 in case no error word found
|
||||
let errorLength = 10;
|
||||
const [_, wordWithError] = trimmedMessage.split('[');
|
||||
if (wordWithError) {
|
||||
errorLength = wordWithError.length - 1;
|
||||
}
|
||||
return {
|
||||
message: trimmedMessage.trimStart(),
|
||||
startColumn: Number(startPosition),
|
||||
startLineNumber: Number(lineNumber),
|
||||
endColumn: Number(startPosition) + errorLength,
|
||||
endLineNumber: Number(lineNumber),
|
||||
severity: monaco.MarkerSeverity.Error,
|
||||
};
|
||||
});
|
||||
} else {
|
||||
// unknown warning message
|
||||
return [
|
||||
{
|
||||
message: warning,
|
||||
startColumn: 1,
|
||||
startLineNumber: 1,
|
||||
endColumn: 10,
|
||||
endLineNumber: 1,
|
||||
severity: monaco.MarkerSeverity.Error,
|
||||
},
|
||||
];
|
||||
if (quotedWarningMessageRegexp.test(warning)) {
|
||||
const matches = warning.match(quotedWarningMessageRegexp);
|
||||
if (matches) {
|
||||
return matches.map((message) => {
|
||||
// start extracting the quoted message and with few default positioning
|
||||
let warningMessage = message.replace(/"/g, '');
|
||||
let startColumn = 1;
|
||||
let startLineNumber = 1;
|
||||
// initialize the length to 10 in case no error word found
|
||||
let errorLength = 10;
|
||||
// if there's line number encoded in the message use it as new positioning
|
||||
// and replace the actual message without it
|
||||
if (/Line (\d+):(\d+):/.test(warningMessage)) {
|
||||
const [encodedLine, encodedColumn, innerMessage] = warningMessage.split(':');
|
||||
warningMessage = innerMessage;
|
||||
if (!Number.isNaN(Number(encodedColumn))) {
|
||||
startColumn = Number(encodedColumn);
|
||||
startLineNumber = Number(encodedLine.replace('Line ', ''));
|
||||
}
|
||||
// extract the length of the "expression" within the message
|
||||
// and try to guess the correct size for the editor marker to highlight
|
||||
if (/\[.*\]/.test(warningMessage)) {
|
||||
const [_, wordWithError] = warningMessage.split('[');
|
||||
if (wordWithError) {
|
||||
errorLength = wordWithError.length;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
message: warningMessage.trimStart(),
|
||||
startColumn,
|
||||
startLineNumber,
|
||||
endColumn: startColumn + errorLength - 1,
|
||||
endLineNumber: startLineNumber,
|
||||
severity: monaco.MarkerSeverity.Error,
|
||||
};
|
||||
});
|
||||
}
|
||||
}
|
||||
// unknown warning message
|
||||
return [
|
||||
{
|
||||
message: warning,
|
||||
startColumn: 1,
|
||||
startLineNumber: 1,
|
||||
endColumn: 10,
|
||||
endLineNumber: 1,
|
||||
severity: monaco.MarkerSeverity.Error,
|
||||
},
|
||||
];
|
||||
};
|
||||
|
||||
export const parseErrors = (errors: Error[], code: string): MonacoError[] => {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue