mirror of
https://github.com/elastic/kibana.git
synced 2025-04-23 09:19:04 -04:00
[Lens] Improve message for unsupported aggregation when using a TSDB counter field (#161481)
## Summary This PR improves the message for the case where a visualization where a counter field was used, but it wasn't yet in time series mode, then it gets upgraded to timeseries and ES will restrict its agg support. Added also few new documentation links to TSDS documentation pages. Within a dashboard the error would be a reshape of the ES one: <img width="774" alt="Screenshot 2023-07-17 at 17 58 17" src="766c60e3
-166c-4038-bf04-bbb1d5c08cb2"> Unfortunately it is only possible to show simple text (no link) within a dashboard panel in view mode as it relies on native `Embeddable` types which only allow native JS errors. If user has edit permissions then it would be possible to click the `Edit in Lens` to open the editor and see more information about the error, i.e. the doc link: <img width="513" alt="Screenshot 2023-07-17 at 17 50 39" src="54c19c9f
-7385-405e-8c4c-9061185ac52b"> To test just use the latest ES snapshot with this PR: https://github.com/elastic/elasticsearch/pull/93545 ~~Waiting for a link to some documentation from the ES team to be included here as well.~~ Added link to https://github.com/elastic/elasticsearch/pull/97618 improved documentation. ### Checklist Delete any items that are not applicable to this PR. - [ ] Any text added follows [EUI's writing guidelines](https://elastic.github.io/eui/#/guidelines/writing), uses sentence case text and includes [i18n support](https://github.com/elastic/kibana/blob/main/packages/kbn-i18n/README.md) - [ ] [Documentation](https://www.elastic.co/guide/en/kibana/master/development-documentation.html) was added for features that require explanation or tutorials - [ ] [Unit or functional tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html) were updated or added to match the most common scenarios - [ ] Any UI touched in this PR is usable by keyboard only (learn more about [keyboard accessibility](https://webaim.org/techniques/keyboard/)) - [ ] Any UI touched in this PR does not create any new axe failures (run axe in browser: [FF](https://addons.mozilla.org/en-US/firefox/addon/axe-devtools/), [Chrome](https://chrome.google.com/webstore/detail/axe-web-accessibility-tes/lhdoppojpmngadmnindnejefpokejbdd?hl=en-US)) - [ ] If a plugin configuration key changed, check if it needs to be allowlisted in the cloud and added to the [docker list](https://github.com/elastic/kibana/blob/main/src/dev/build/tasks/os_packages/docker_generator/resources/base/bin/kibana-docker) - [ ] This renders correctly on smaller devices using a responsive layout. (You can test this [in your browser](https://www.browserstack.com/guide/responsive-testing-on-local-server)) - [ ] This was checked for [cross-browser compatibility](https://www.elastic.co/support/matrix#matrix_browsers) ### Risk Matrix Delete this section if it is not applicable to this PR. Before closing this PR, invite QA, stakeholders, and other developers to identify risks that should be tested prior to the change/feature release. When forming the risk matrix, consider some of the following examples and how they may potentially impact the change: | Risk | Probability | Severity | Mitigation/Notes | |---------------------------|-------------|----------|-------------------------| | Multiple Spaces—unexpected behavior in non-default Kibana Space. | Low | High | Integration tests will verify that all features are still supported in non-default Kibana Space and when user switches between spaces. | | Multiple nodes—Elasticsearch polling might have race conditions when multiple Kibana nodes are polling for the same tasks. | High | Low | Tasks are idempotent, so executing them multiple times will not result in logical error, but will degrade performance. To test for this case we add plenty of unit tests around this logic and document manual testing procedure. | | Code should gracefully handle cases when feature X or plugin Y are disabled. | Medium | High | Unit tests will verify that any feature flag or plugin combination still results in our service operational. | | [See more potential risk examples](https://github.com/elastic/kibana/blob/main/RISK_MATRIX.mdx) | ### For maintainers - [ ] This was checked for breaking API changes and was [labeled appropriately](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process)
This commit is contained in:
parent
c9034a3864
commit
a3e1aab363
7 changed files with 190 additions and 33 deletions
|
@ -721,6 +721,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`,
|
||||
|
|
|
@ -489,6 +489,8 @@ export interface DocLinks {
|
|||
datastreamsILM: string;
|
||||
datastreamsNamingScheme: string;
|
||||
datastreamsManualRollover: string;
|
||||
datastreamsTSDS: string;
|
||||
datastreamsTSDSMetrics: string;
|
||||
installElasticAgent: string;
|
||||
installElasticAgentStandalone: string;
|
||||
packageSignatures: string;
|
||||
|
|
|
@ -790,9 +790,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]
|
||||
: [];
|
||||
|
@ -831,11 +831,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}
|
||||
</>
|
||||
}
|
||||
|
|
|
@ -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].',
|
||||
}),
|
||||
]);
|
||||
});
|
||||
});
|
||||
|
|
|
@ -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
|
|
@ -1055,6 +1055,7 @@ export class Embeddable
|
|||
this.logError('runtime');
|
||||
}}
|
||||
noPadding={this.visDisplayOptions.noPadding}
|
||||
docLinks={this.deps.coreStart.docLinks}
|
||||
/>
|
||||
</KibanaThemeProvider>
|
||||
<MessagesBadge
|
||||
|
|
|
@ -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
|
||||
}}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue