[8.9] [Lens] Improve message for unsupported aggregation when using a TSDB counter field (#161481) (#164144)

# Backport

This will backport the following commits from `main` to `8.9`:
- [[Lens] Improve message for unsupported aggregation when using a TSDB
counter field (#161481)](https://github.com/elastic/kibana/pull/161481)

<!--- Backport version: 8.9.8 -->

### 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-07-20T07:11:22Z","message":"[Lens]
Improve message for unsupported aggregation when using a TSDB counter
field (#161481)\n\n## Summary\r\n\r\nThis PR improves the message for
the case where a visualization where a\r\ncounter field was used, but it
wasn't yet in time series mode, then it\r\ngets upgraded to timeseries
and ES will restrict its agg support.\r\nAdded also few new
documentation links to TSDS documentation pages.\r\n\r\nWithin a
dashboard the error would be a reshape of the ES one:\r\n\r\n<img
width=\"774\" alt=\"Screenshot 2023-07-17 at 17 58
17\"\r\nsrc=\"766c60e3-166c-4038-bf04-bbb1d5c08cb2\">\r\n\r\nUnfortunately
it is only possible to show simple text (no link) within a\r\ndashboard
panel in view mode as it relies on native `Embeddable` types\r\nwhich
only allow native JS errors.\r\n\r\nIf user has edit permissions then it
would be possible to click the\r\n`Edit in Lens` to open the editor and
see more information about the\r\nerror, i.e. the doc link:\r\n\r\n<img
width=\"513\" alt=\"Screenshot 2023-07-17 at 17 50
39\"\r\nsrc=\"54c19c9f-7385-405e-8c4c-9061185ac52b\">\r\n\r\nTo
test just use the latest ES snapshot with this
PR:\r\nhttps://github.com/elastic/elasticsearch/pull/93545\r\n\r\n~~Waiting
for a link to some documentation from the ES team to be\r\nincluded here
as well.~~\r\nAdded link to
https://github.com/elastic/elasticsearch/pull/97618\r\nimproved
documentation.\r\n\r\n### Checklist\r\n\r\nDelete any items that are not
applicable to this PR.\r\n\r\n- [ ] Any text added follows [EUI's
writing\r\nguidelines](https://elastic.github.io/eui/#/guidelines/writing),
uses\r\nsentence case text and includes
[i18n\r\nsupport](https://github.com/elastic/kibana/blob/main/packages/kbn-i18n/README.md)\r\n-
[
]\r\n[Documentation](https://www.elastic.co/guide/en/kibana/master/development-documentation.html)\r\nwas
added for features that require explanation or tutorials\r\n- [ ] [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\r\n- [ ] Any UI
touched in this PR is usable by keyboard only (learn more\r\nabout
[keyboard accessibility](https://webaim.org/techniques/keyboard/))\r\n-
[ ] Any UI touched in this PR does not create any new axe
failures\r\n(run axe in
browser:\r\n[FF](https://addons.mozilla.org/en-US/firefox/addon/axe-devtools/),\r\n[Chrome](https://chrome.google.com/webstore/detail/axe-web-accessibility-tes/lhdoppojpmngadmnindnejefpokejbdd?hl=en-US))\r\n-
[ ] If a plugin configuration key changed, check if it needs to
be\r\nallowlisted in the cloud and added to the
[docker\r\nlist](https://github.com/elastic/kibana/blob/main/src/dev/build/tasks/os_packages/docker_generator/resources/base/bin/kibana-docker)\r\n-
[ ] This renders correctly on smaller devices using a
responsive\r\nlayout. (You can test this [in
your\r\nbrowser](https://www.browserstack.com/guide/responsive-testing-on-local-server))\r\n-
[ ] This was checked for
[cross-browser\r\ncompatibility](https://www.elastic.co/support/matrix#matrix_browsers)\r\n\r\n\r\n###
Risk Matrix\r\n\r\nDelete this section if it is not applicable to this
PR.\r\n\r\nBefore closing this PR, invite QA, stakeholders, and other
developers to\r\nidentify risks that should be tested prior to the
change/feature\r\nrelease.\r\n\r\nWhen forming the risk matrix, consider
some of the following examples\r\nand how they may potentially impact
the change:\r\n\r\n| Risk | Probability | Severity | Mitigation/Notes
|\r\n\r\n|---------------------------|-------------|----------|-------------------------|\r\n|
Multiple Spaces&mdash;unexpected behavior in non-default Kibana
Space.\r\n| Low | High | Integration tests will verify that all features
are still\r\nsupported in non-default Kibana Space and when user
switches between\r\nspaces. |\r\n| Multiple nodes&mdash;Elasticsearch
polling might have race conditions\r\nwhen multiple Kibana nodes are
polling for the same tasks. | High | Low\r\n| Tasks are idempotent, so
executing them multiple times will not result\r\nin logical error, but
will degrade performance. To test for this case we\r\nadd plenty of unit
tests around this logic and document manual testing\r\nprocedure. |\r\n|
Code should gracefully handle cases when feature X or plugin Y
are\r\ndisabled. | Medium | High | Unit tests will verify that any
feature flag\r\nor plugin combination still results in our service
operational. |\r\n| [See more potential
risk\r\nexamples](https://github.com/elastic/kibana/blob/main/RISK_MATRIX.mdx)
|\r\n\r\n\r\n### For maintainers\r\n\r\n- [ ] This was checked for
breaking API changes and was
[labeled\r\nappropriately](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process)","sha":"a3e1aab3634c2b318f8aac77a50134c9cccb6d25","branchLabelMapping":{"^v8.10.0$":"main","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["Team:Visualizations","release_note:skip","Feature:Lens","backport:prev-minor","v8.10.0","v8.11.0"],"number":161481,"url":"https://github.com/elastic/kibana/pull/161481","mergeCommit":{"message":"[Lens]
Improve message for unsupported aggregation when using a TSDB counter
field (#161481)\n\n## Summary\r\n\r\nThis PR improves the message for
the case where a visualization where a\r\ncounter field was used, but it
wasn't yet in time series mode, then it\r\ngets upgraded to timeseries
and ES will restrict its agg support.\r\nAdded also few new
documentation links to TSDS documentation pages.\r\n\r\nWithin a
dashboard the error would be a reshape of the ES one:\r\n\r\n<img
width=\"774\" alt=\"Screenshot 2023-07-17 at 17 58
17\"\r\nsrc=\"766c60e3-166c-4038-bf04-bbb1d5c08cb2\">\r\n\r\nUnfortunately
it is only possible to show simple text (no link) within a\r\ndashboard
panel in view mode as it relies on native `Embeddable` types\r\nwhich
only allow native JS errors.\r\n\r\nIf user has edit permissions then it
would be possible to click the\r\n`Edit in Lens` to open the editor and
see more information about the\r\nerror, i.e. the doc link:\r\n\r\n<img
width=\"513\" alt=\"Screenshot 2023-07-17 at 17 50
39\"\r\nsrc=\"54c19c9f-7385-405e-8c4c-9061185ac52b\">\r\n\r\nTo
test just use the latest ES snapshot with this
PR:\r\nhttps://github.com/elastic/elasticsearch/pull/93545\r\n\r\n~~Waiting
for a link to some documentation from the ES team to be\r\nincluded here
as well.~~\r\nAdded link to
https://github.com/elastic/elasticsearch/pull/97618\r\nimproved
documentation.\r\n\r\n### Checklist\r\n\r\nDelete any items that are not
applicable to this PR.\r\n\r\n- [ ] Any text added follows [EUI's
writing\r\nguidelines](https://elastic.github.io/eui/#/guidelines/writing),
uses\r\nsentence case text and includes
[i18n\r\nsupport](https://github.com/elastic/kibana/blob/main/packages/kbn-i18n/README.md)\r\n-
[
]\r\n[Documentation](https://www.elastic.co/guide/en/kibana/master/development-documentation.html)\r\nwas
added for features that require explanation or tutorials\r\n- [ ] [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\r\n- [ ] Any UI
touched in this PR is usable by keyboard only (learn more\r\nabout
[keyboard accessibility](https://webaim.org/techniques/keyboard/))\r\n-
[ ] Any UI touched in this PR does not create any new axe
failures\r\n(run axe in
browser:\r\n[FF](https://addons.mozilla.org/en-US/firefox/addon/axe-devtools/),\r\n[Chrome](https://chrome.google.com/webstore/detail/axe-web-accessibility-tes/lhdoppojpmngadmnindnejefpokejbdd?hl=en-US))\r\n-
[ ] If a plugin configuration key changed, check if it needs to
be\r\nallowlisted in the cloud and added to the
[docker\r\nlist](https://github.com/elastic/kibana/blob/main/src/dev/build/tasks/os_packages/docker_generator/resources/base/bin/kibana-docker)\r\n-
[ ] This renders correctly on smaller devices using a
responsive\r\nlayout. (You can test this [in
your\r\nbrowser](https://www.browserstack.com/guide/responsive-testing-on-local-server))\r\n-
[ ] This was checked for
[cross-browser\r\ncompatibility](https://www.elastic.co/support/matrix#matrix_browsers)\r\n\r\n\r\n###
Risk Matrix\r\n\r\nDelete this section if it is not applicable to this
PR.\r\n\r\nBefore closing this PR, invite QA, stakeholders, and other
developers to\r\nidentify risks that should be tested prior to the
change/feature\r\nrelease.\r\n\r\nWhen forming the risk matrix, consider
some of the following examples\r\nand how they may potentially impact
the change:\r\n\r\n| Risk | Probability | Severity | Mitigation/Notes
|\r\n\r\n|---------------------------|-------------|----------|-------------------------|\r\n|
Multiple Spaces&mdash;unexpected behavior in non-default Kibana
Space.\r\n| Low | High | Integration tests will verify that all features
are still\r\nsupported in non-default Kibana Space and when user
switches between\r\nspaces. |\r\n| Multiple nodes&mdash;Elasticsearch
polling might have race conditions\r\nwhen multiple Kibana nodes are
polling for the same tasks. | High | Low\r\n| Tasks are idempotent, so
executing them multiple times will not result\r\nin logical error, but
will degrade performance. To test for this case we\r\nadd plenty of unit
tests around this logic and document manual testing\r\nprocedure. |\r\n|
Code should gracefully handle cases when feature X or plugin Y
are\r\ndisabled. | Medium | High | Unit tests will verify that any
feature flag\r\nor plugin combination still results in our service
operational. |\r\n| [See more potential
risk\r\nexamples](https://github.com/elastic/kibana/blob/main/RISK_MATRIX.mdx)
|\r\n\r\n\r\n### For maintainers\r\n\r\n- [ ] This was checked for
breaking API changes and was
[labeled\r\nappropriately](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process)","sha":"a3e1aab3634c2b318f8aac77a50134c9cccb6d25"}},"sourceBranch":"main","suggestedTargetBranches":["8.11"],"targetPullRequestStates":[{"branch":"main","label":"v8.10.0","labelRegex":"^v8.10.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/161481","number":161481,"mergeCommit":{"message":"[Lens]
Improve message for unsupported aggregation when using a TSDB counter
field (#161481)\n\n## Summary\r\n\r\nThis PR improves the message for
the case where a visualization where a\r\ncounter field was used, but it
wasn't yet in time series mode, then it\r\ngets upgraded to timeseries
and ES will restrict its agg support.\r\nAdded also few new
documentation links to TSDS documentation pages.\r\n\r\nWithin a
dashboard the error would be a reshape of the ES one:\r\n\r\n<img
width=\"774\" alt=\"Screenshot 2023-07-17 at 17 58
17\"\r\nsrc=\"766c60e3-166c-4038-bf04-bbb1d5c08cb2\">\r\n\r\nUnfortunately
it is only possible to show simple text (no link) within a\r\ndashboard
panel in view mode as it relies on native `Embeddable` types\r\nwhich
only allow native JS errors.\r\n\r\nIf user has edit permissions then it
would be possible to click the\r\n`Edit in Lens` to open the editor and
see more information about the\r\nerror, i.e. the doc link:\r\n\r\n<img
width=\"513\" alt=\"Screenshot 2023-07-17 at 17 50
39\"\r\nsrc=\"54c19c9f-7385-405e-8c4c-9061185ac52b\">\r\n\r\nTo
test just use the latest ES snapshot with this
PR:\r\nhttps://github.com/elastic/elasticsearch/pull/93545\r\n\r\n~~Waiting
for a link to some documentation from the ES team to be\r\nincluded here
as well.~~\r\nAdded link to
https://github.com/elastic/elasticsearch/pull/97618\r\nimproved
documentation.\r\n\r\n### Checklist\r\n\r\nDelete any items that are not
applicable to this PR.\r\n\r\n- [ ] Any text added follows [EUI's
writing\r\nguidelines](https://elastic.github.io/eui/#/guidelines/writing),
uses\r\nsentence case text and includes
[i18n\r\nsupport](https://github.com/elastic/kibana/blob/main/packages/kbn-i18n/README.md)\r\n-
[
]\r\n[Documentation](https://www.elastic.co/guide/en/kibana/master/development-documentation.html)\r\nwas
added for features that require explanation or tutorials\r\n- [ ] [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\r\n- [ ] Any UI
touched in this PR is usable by keyboard only (learn more\r\nabout
[keyboard accessibility](https://webaim.org/techniques/keyboard/))\r\n-
[ ] Any UI touched in this PR does not create any new axe
failures\r\n(run axe in
browser:\r\n[FF](https://addons.mozilla.org/en-US/firefox/addon/axe-devtools/),\r\n[Chrome](https://chrome.google.com/webstore/detail/axe-web-accessibility-tes/lhdoppojpmngadmnindnejefpokejbdd?hl=en-US))\r\n-
[ ] If a plugin configuration key changed, check if it needs to
be\r\nallowlisted in the cloud and added to the
[docker\r\nlist](https://github.com/elastic/kibana/blob/main/src/dev/build/tasks/os_packages/docker_generator/resources/base/bin/kibana-docker)\r\n-
[ ] This renders correctly on smaller devices using a
responsive\r\nlayout. (You can test this [in
your\r\nbrowser](https://www.browserstack.com/guide/responsive-testing-on-local-server))\r\n-
[ ] This was checked for
[cross-browser\r\ncompatibility](https://www.elastic.co/support/matrix#matrix_browsers)\r\n\r\n\r\n###
Risk Matrix\r\n\r\nDelete this section if it is not applicable to this
PR.\r\n\r\nBefore closing this PR, invite QA, stakeholders, and other
developers to\r\nidentify risks that should be tested prior to the
change/feature\r\nrelease.\r\n\r\nWhen forming the risk matrix, consider
some of the following examples\r\nand how they may potentially impact
the change:\r\n\r\n| Risk | Probability | Severity | Mitigation/Notes
|\r\n\r\n|---------------------------|-------------|----------|-------------------------|\r\n|
Multiple Spaces&mdash;unexpected behavior in non-default Kibana
Space.\r\n| Low | High | Integration tests will verify that all features
are still\r\nsupported in non-default Kibana Space and when user
switches between\r\nspaces. |\r\n| Multiple nodes&mdash;Elasticsearch
polling might have race conditions\r\nwhen multiple Kibana nodes are
polling for the same tasks. | High | Low\r\n| Tasks are idempotent, so
executing them multiple times will not result\r\nin logical error, but
will degrade performance. To test for this case we\r\nadd plenty of unit
tests around this logic and document manual testing\r\nprocedure. |\r\n|
Code should gracefully handle cases when feature X or plugin Y
are\r\ndisabled. | Medium | High | Unit tests will verify that any
feature flag\r\nor plugin combination still results in our service
operational. |\r\n| [See more potential
risk\r\nexamples](https://github.com/elastic/kibana/blob/main/RISK_MATRIX.mdx)
|\r\n\r\n\r\n### For maintainers\r\n\r\n- [ ] This was checked for
breaking API changes and was
[labeled\r\nappropriately](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process)","sha":"a3e1aab3634c2b318f8aac77a50134c9cccb6d25"}},{"branch":"8.11","label":"v8.11.0","labelRegex":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"}]}]
BACKPORT-->
This commit is contained in:
Marco Liberati 2023-08-17 14:53:45 +02:00 committed by GitHub
parent 876d341bf3
commit b63845506e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 190 additions and 33 deletions

View file

@ -715,6 +715,8 @@ export const getDocLinks = ({ kibanaBranch }: GetDocLinkOptions): DocLinks => {
datastreamsILM: `${FLEET_DOCS}data-streams.html#data-streams-ilm`,
datastreamsNamingScheme: `${FLEET_DOCS}data-streams.html#data-streams-naming-scheme`,
datastreamsManualRollover: `${ELASTICSEARCH_DOCS}use-a-data-stream.html#manually-roll-over-a-data-stream`,
datastreamsTSDS: `${ELASTICSEARCH_DOCS}tsds.html`,
datastreamsTSDSMetrics: `${ELASTICSEARCH_DOCS}tsds.html#time-series-metric`,
installElasticAgent: `${FLEET_DOCS}install-fleet-managed-elastic-agent.html`,
installElasticAgentStandalone: `${FLEET_DOCS}install-standalone-elastic-agent.html`,
upgradeElasticAgent: `${FLEET_DOCS}upgrade-elastic-agent.html`,

View file

@ -483,6 +483,8 @@ export interface DocLinks {
datastreamsILM: string;
datastreamsNamingScheme: string;
datastreamsManualRollover: string;
datastreamsTSDS: string;
datastreamsTSDSMetrics: string;
installElasticAgent: string;
installElasticAgentStandalone: string;
packageSignatures: string;

View file

@ -788,9 +788,9 @@ export const VisualizationWrapper = ({
executionContext={executionContext}
renderMode="edit"
renderError={(errorMessage?: string | null, error?: ExpressionRenderError | null) => {
const errorsFromRequest = getOriginalRequestErrorMessages(error);
const errorsFromRequest = getOriginalRequestErrorMessages(error || null, core.docLinks);
const visibleErrorMessages = errorsFromRequest.length
? errorsFromRequest
? errorsFromRequest.map((e) => e.longMessage || e.shortMessage)
: errorMessage
? [errorMessage]
: [];
@ -829,11 +829,15 @@ export const VisualizationWrapper = ({
</p>
{localState.expandError
? visibleErrorMessages.map((visibleErrorMessage) => (
<p className="eui-textBreakWord" key={visibleErrorMessage}>
{visibleErrorMessage}
</p>
))
? visibleErrorMessages.map((visibleErrorMessage) =>
typeof visibleErrorMessage === 'string' ? (
<p className="eui-textBreakWord" key={visibleErrorMessage}>
{visibleErrorMessage}
</p>
) : (
visibleErrorMessage
)
)
: null}
</>
}

View file

@ -6,6 +6,9 @@
*/
import { getOriginalRequestErrorMessages } from './error_helper';
import type { CoreStart } from '@kbn/core/public';
const docLinksMock = { links: { fleet: { datastreamsTSDSMetrics: '' } } } as CoreStart['docLinks'];
const runtimeFieldError = {
stack: 'Error: EsError\n...',
@ -163,33 +166,136 @@ const indexpatternAccessError = {
},
};
const tsdbCounterUsedWithWrongOperationError = {
stack:
'Error: EsError: Field [bytes_counter] of type [long][counter] is not supported for aggregation [sum]',
message:
'[layeredXyVis] > [esaggs] > EsError: Field [bytes_counter] of type [long][counter] is not supported for aggregation [sum]',
name: 'Error',
original: {
attributes: {
type: 'status_exception',
reason: 'error while executing search',
caused_by: {
type: 'search_phase_execution_exception',
reason: 'all shards failed',
phase: 'query',
grouped: true,
failed_shards: [
{
shard: 0,
index: 'tsdb_index',
reason: {
type: 'illegal_argument_exception',
reason:
'Field [bytes_counter] of type [long][counter] is not supported for aggregation [sum]',
},
},
],
caused_by: {
type: 'illegal_argument_exception',
reason:
'Field [bytes_counter] of type [long][counter] is not supported for aggregation [sum]',
caused_by: {
type: 'illegal_argument_exception',
reason:
'Field [bytes_counter] of type [long][counter] is not supported for aggregation [sum]',
},
},
},
},
err: {
message:
'status_exception\n\tCaused by:\n\t\tsearch_phase_execution_exception: all shards failed',
statusCode: 400,
attributes: {
type: 'status_exception',
reason: 'error while executing search',
caused_by: {
type: 'search_phase_execution_exception',
reason: 'all shards failed',
phase: 'query',
grouped: true,
failed_shards: [
{
shard: 0,
index: 'tsdb_index',
reason: {
type: 'illegal_argument_exception',
reason:
'Field [bytes_counter] of type [long][counter] is not supported for aggregation [sum]',
},
},
],
caused_by: {
type: 'illegal_argument_exception',
reason:
'Field [bytes_counter] of type [long][counter] is not supported for aggregation [sum]',
caused_by: {
type: 'illegal_argument_exception',
reason:
'Field [bytes_counter] of type [long][counter] is not supported for aggregation [sum]',
},
},
},
},
},
},
};
describe('lens_error_helpers', () => {
describe('getOriginalRequestErrorMessages', () => {
it('should report no errors if not parsable', () => {
expect(getOriginalRequestErrorMessages(null)).toEqual([]);
expect(getOriginalRequestErrorMessages(null, docLinksMock)).toEqual([]);
});
it('should report an error for a runtime field error', () => {
expect(getOriginalRequestErrorMessages(runtimeFieldError)).toEqual([
'Request error: number_format_exception, For input string: "hello" in "emit(Integer.parseInt(\'hello\'))" (Painless script)',
expect(getOriginalRequestErrorMessages(runtimeFieldError, docLinksMock)).toEqual([
expect.objectContaining({
shortMessage:
'Request error: number_format_exception, For input string: "hello" in "emit(Integer.parseInt(\'hello\'))" (Painless script)',
}),
]);
});
it('should report an error for a scripted field error', () => {
expect(getOriginalRequestErrorMessages(scriptedFieldError)).toEqual([
'Request error: aggregation_execution_exception, Unsupported script value [hello], expected a number, date, or boolean in Painless script',
expect(getOriginalRequestErrorMessages(scriptedFieldError, docLinksMock)).toEqual([
expect.objectContaining({
shortMessage:
'Request error: aggregation_execution_exception, Unsupported script value [hello], expected a number, date, or boolean in Painless script',
}),
]);
});
it('should report the original es aggs error for runtime fields for indexpattern not accessible', () => {
expect(getOriginalRequestErrorMessages(indexpatternAccessError as Error)).toEqual([
indexpatternAccessError.message,
expect(
getOriginalRequestErrorMessages(indexpatternAccessError as Error, docLinksMock)
).toEqual([
expect.objectContaining({
shortMessage: indexpatternAccessError.message,
}),
]);
});
it("should report a network custom message when there's a network/connection problem", () => {
expect(getOriginalRequestErrorMessages(networkError as Error)).toEqual([
'Network error, try again later or contact your administrator.',
expect(getOriginalRequestErrorMessages(networkError as Error, docLinksMock)).toEqual([
expect.objectContaining({
shortMessage: 'Network error, try again later or contact your administrator.',
}),
]);
});
it('should report two specific errors in case of an unsupported operation applied to a TSDB counter', () => {
expect(
getOriginalRequestErrorMessages(
tsdbCounterUsedWithWrongOperationError as Error,
docLinksMock
)
).toEqual([
expect.objectContaining({
shortMessage:
'The field [bytes_counter] of Time series type [counter] has been used with the unsupported operation [sum].',
}),
]);
});
});

View file

@ -8,8 +8,12 @@
import { i18n } from '@kbn/i18n';
import { isEqual, uniqWith } from 'lodash';
import { ExpressionRenderError } from '@kbn/expressions-plugin/public';
import type { CoreStart } from '@kbn/core/public';
import { isEsError } from '@kbn/data-plugin/public';
import type { IEsError, Reason } from '@kbn/data-plugin/public';
import React from 'react';
import { EuiLink } from '@elastic/eui';
import { RemovableUserMessage } from '../types';
type ErrorCause = Required<IEsError>['attributes'];
@ -39,6 +43,13 @@ const isRequestError = (e: Error | RequestError): e is RequestError => {
return false;
};
const isTSDBError = (e: ReasonDescription): boolean => {
return (
e.type === 'illegal_argument_exception' &&
/\]\[counter\] is not supported for aggregation/.test(e.reason)
);
};
// what happens for runtime field used on indexpatterns not accessible to the user?
// they will throw on the kibana side as data will be undefined
const isEsAggError = (e: Error | EsAggError): e is EsAggError => {
@ -101,8 +112,11 @@ function getErrorSources(e: Error) {
return [];
}
export function getOriginalRequestErrorMessages(error?: ExpressionRenderError | null): string[] {
const errorMessages = [];
export function getOriginalRequestErrorMessages(
error: ExpressionRenderError | null,
docLinks: CoreStart['docLinks']
): RemovableUserMessage[] {
const errorMessages: Array<string | { short: string; long: React.ReactNode }> = [];
if (error && 'original' in error && error.original) {
if (isEsAggError(error.original)) {
if (isNetworkError(error.original)) {
@ -130,6 +144,34 @@ export function getOriginalRequestErrorMessages(error?: ExpressionRenderError |
},
})
);
} else if (isTSDBError(rootError)) {
const [fieldName, _type, _isCounter, opUsed] = rootError.reason.match(/\[(\w)*\]/g)!;
const shortMessage = i18n.translate(
'xpack.lens.editorFrame.expressionTSDBDetailedMessage',
{
defaultMessage:
'The field {field} of Time series type [counter] has been used with the unsupported operation {op}.',
values: {
field: fieldName,
op: opUsed,
},
}
);
const message = (
<>
<p className="eui-textBreakWord">{shortMessage}</p>
<EuiLink href={docLinks.links.fleet.datastreamsTSDSMetrics} external target="_blank">
{i18n.translate('xpack.lens.editorFrame.expressionTSDBCounterInfo', {
defaultMessage:
'See more about Time series field types and [counter] supported aggregations',
})}
</EuiLink>
</>
);
errorMessages.push({
short: shortMessage,
long: message,
});
} else {
errorMessages.push(
i18n.translate('xpack.lens.editorFrame.expressionFailureMessage', {
@ -144,9 +186,16 @@ export function getOriginalRequestErrorMessages(error?: ExpressionRenderError |
}
}
} else if (error?.message) {
errorMessages.push(error?.message);
errorMessages.push(error.message);
}
return errorMessages;
return errorMessages.map((message) => ({
uniqueId: typeof message === 'string' ? message : message.short,
severity: 'error',
displayLocations: [{ id: 'visualizationOnEmbeddable' }],
longMessage: typeof message === 'string' ? '' : message.long,
shortMessage: typeof message === 'string' ? message : message.short,
fixableInEditor: false,
}));
}
// NOTE - if you are adding a new error message, add it as a UserMessage in get_application_error_messages

View file

@ -964,6 +964,7 @@ export class Embeddable
this.logError('runtime');
}}
noPadding={this.visDisplayOptions.noPadding}
docLinks={this.deps.coreStart.docLinks}
/>
</KibanaThemeProvider>
<MessagesBadge

View file

@ -12,7 +12,7 @@ import {
ReactExpressionRendererProps,
ReactExpressionRendererType,
} from '@kbn/expressions-plugin/public';
import type { KibanaExecutionContext } from '@kbn/core/public';
import type { CoreStart, KibanaExecutionContext } from '@kbn/core/public';
import { ExecutionContextSearch } from '@kbn/data-plugin/public';
import { DefaultInspectorAdapters, RenderMode } from '@kbn/expressions-plugin/common';
import classNames from 'classnames';
@ -46,6 +46,7 @@ export interface ExpressionWrapperProps {
executionContext?: KibanaExecutionContext;
lensInspector: LensInspector;
noPadding?: boolean;
docLinks: CoreStart['docLinks'];
}
export function ExpressionWrapper({
@ -71,6 +72,7 @@ export function ExpressionWrapper({
executionContext,
lensInspector,
noPadding,
docLinks,
}: ExpressionWrapperProps) {
if (!expression) return null;
return (
@ -93,18 +95,9 @@ export function ExpressionWrapper({
syncCursor={syncCursor}
executionContext={executionContext}
renderError={(errorMessage, error) => {
const messages = getOriginalRequestErrorMessages(error);
addUserMessages(
messages.map((message) => ({
uniqueId: message,
severity: 'error',
displayLocations: [{ id: 'visualizationOnEmbeddable' }],
longMessage: message,
shortMessage: message,
fixableInEditor: false,
}))
);
onRuntimeError(messages[0] ?? errorMessage);
const messages = getOriginalRequestErrorMessages(error || null, docLinks);
addUserMessages(messages);
onRuntimeError(messages[0].shortMessage ?? (errorMessage || ''));
return <></>; // the embeddable will take care of displaying the messages
}}