forked from elastic/kibana
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[One Discover] Add row indicators for log documents (elastic#190676)
## 📓 Summary Closes elastic#190457 This change extracts the logic around the logs document controls/indicator from Logs Explorer and registers the same controls in Discover through the extension point added in elastic#188762. The controls are registered only for the `logs-data-source-profile` contextual profile. https://github.com/user-attachments/assets/40adfb19-357f-46e1-9d69-fc9c0860c832 ## 👣 Next steps - [ ] elastic#190670 - [ ] elastic#190460 --------- Co-authored-by: Marco Antonio Ghiani <[email protected]> Co-authored-by: kibanamachine <[email protected]>
- Loading branch information
1 parent
c4dd4d1
commit ac66e7c
Showing
43 changed files
with
406 additions
and
226 deletions.
There are no files selected for viewing
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
121 changes: 121 additions & 0 deletions
121
packages/kbn-discover-utils/src/components/custom_control_columns/degraded_docs_control.tsx
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,121 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the "Elastic License | ||
* 2.0", the "GNU Affero General Public License v3.0 only", and the "Server Side | ||
* Public License v 1"; you may not use this file except in compliance with, at | ||
* your election, the "Elastic License 2.0", the "GNU Affero General Public | ||
* License v3.0 only", or the "Server Side Public License, v 1". | ||
*/ | ||
|
||
import { i18n } from '@kbn/i18n'; | ||
import React from 'react'; | ||
import { EuiCode, EuiSpacer } from '@elastic/eui'; | ||
import { | ||
RowControlColumn, | ||
RowControlComponent, | ||
RowControlProps, | ||
RowControlRowProps, | ||
} from './types'; | ||
import { DEGRADED_DOCS_FIELDS } from '../../field_constants'; | ||
|
||
interface DegradedDocsControlProps extends Partial<RowControlProps> { | ||
enabled?: boolean; | ||
} | ||
|
||
/** | ||
* Degraded docs control factory function. | ||
* @param props Optional props for the generated Control component, useful to override onClick, etc | ||
*/ | ||
export const createDegradedDocsControl = (props?: DegradedDocsControlProps): RowControlColumn => ({ | ||
id: 'connectedDegradedDocs', | ||
headerAriaLabel: actionsHeaderAriaLabelDegradedAction, | ||
renderControl: (Control, rowProps) => { | ||
return <DegradedDocs Control={Control} rowProps={rowProps} {...props} />; | ||
}, | ||
}); | ||
|
||
const actionsHeaderAriaLabelDegradedAction = i18n.translate( | ||
'discover.customControl.degradedDocArialLabel', | ||
{ defaultMessage: 'Access to degraded docs' } | ||
); | ||
|
||
const degradedDocButtonLabelWhenPresent = i18n.translate( | ||
'discover.customControl.degradedDocPresent', | ||
{ | ||
defaultMessage: | ||
"This document couldn't be parsed correctly. Not all fields are properly populated", | ||
} | ||
); | ||
|
||
const degradedDocButtonLabelWhenNotPresent = i18n.translate( | ||
'discover.customControl.degradedDocNotPresent', | ||
{ defaultMessage: 'All fields in this document were parsed correctly' } | ||
); | ||
|
||
const degradedDocButtonLabelWhenDisabled = i18n.translate( | ||
'discover.customControl.degradedDocDisabled', | ||
{ | ||
defaultMessage: | ||
'Degraded document field detection is currently disabled for this search. To enable it, include the METADATA directive for the `_ignored` field in your ES|QL query. For example:', | ||
} | ||
); | ||
|
||
const DegradedDocs = ({ | ||
Control, | ||
enabled = true, | ||
rowProps: { record }, | ||
...props | ||
}: { | ||
Control: RowControlComponent; | ||
rowProps: RowControlRowProps; | ||
} & DegradedDocsControlProps) => { | ||
const isDegradedDocumentExists = DEGRADED_DOCS_FIELDS.some( | ||
(field) => field in record.raw && record.raw[field] !== null | ||
); | ||
|
||
if (!enabled) { | ||
const codeSample = 'FROM logs-* METADATA _ignored'; | ||
|
||
const tooltipContent = ( | ||
<div> | ||
{degradedDocButtonLabelWhenDisabled} | ||
<EuiSpacer size="s" /> | ||
<EuiCode>{codeSample}</EuiCode> | ||
</div> | ||
); | ||
|
||
return ( | ||
<Control | ||
disabled | ||
data-test-subj="docTableDegradedDocDisabled" | ||
tooltipContent={tooltipContent} | ||
label={`${degradedDocButtonLabelWhenDisabled} ${codeSample}`} | ||
iconType="indexClose" | ||
onClick={undefined} | ||
{...props} | ||
/> | ||
); | ||
} | ||
|
||
return isDegradedDocumentExists ? ( | ||
<Control | ||
data-test-subj="docTableDegradedDocExist" | ||
color="danger" | ||
tooltipContent={degradedDocButtonLabelWhenPresent} | ||
label={degradedDocButtonLabelWhenPresent} | ||
iconType="indexClose" | ||
onClick={undefined} | ||
{...props} | ||
/> | ||
) : ( | ||
<Control | ||
data-test-subj="docTableDegradedDocDoesNotExist" | ||
color="text" | ||
tooltipContent={degradedDocButtonLabelWhenNotPresent} | ||
label={degradedDocButtonLabelWhenNotPresent} | ||
iconType="indexClose" | ||
onClick={undefined} | ||
{...props} | ||
/> | ||
); | ||
}; |
11 changes: 11 additions & 0 deletions
11
packages/kbn-discover-utils/src/components/custom_control_columns/index.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,11 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the "Elastic License | ||
* 2.0", the "GNU Affero General Public License v3.0 only", and the "Server Side | ||
* Public License v 1"; you may not use this file except in compliance with, at | ||
* your election, the "Elastic License 2.0", the "GNU Affero General Public | ||
* License v3.0 only", or the "Server Side Public License, v 1". | ||
*/ | ||
|
||
export { createDegradedDocsControl } from './degraded_docs_control'; | ||
export { createStacktraceControl } from './stacktrace_control'; |
79 changes: 79 additions & 0 deletions
79
packages/kbn-discover-utils/src/components/custom_control_columns/stacktrace_control.tsx
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,79 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the "Elastic License | ||
* 2.0", the "GNU Affero General Public License v3.0 only", and the "Server Side | ||
* Public License v 1"; you may not use this file except in compliance with, at | ||
* your election, the "Elastic License 2.0", the "GNU Affero General Public | ||
* License v3.0 only", or the "Server Side Public License, v 1". | ||
*/ | ||
|
||
import { i18n } from '@kbn/i18n'; | ||
import React from 'react'; | ||
import { | ||
RowControlColumn, | ||
RowControlComponent, | ||
RowControlProps, | ||
RowControlRowProps, | ||
} from './types'; | ||
import { LogDocument } from '../../data_types'; | ||
import { getStacktraceFields } from '../../utils/get_stack_trace_fields'; | ||
|
||
/** | ||
* Stacktrace control factory function. | ||
* @param props Optional props for the generated Control component, useful to override onClick, etc | ||
*/ | ||
export const createStacktraceControl = (props?: Partial<RowControlProps>): RowControlColumn => ({ | ||
id: 'connectedStacktraceDocs', | ||
headerAriaLabel: actionsHeaderAriaLabelStacktraceAction, | ||
renderControl: (Control, rowProps) => { | ||
return <Stacktrace Control={Control} rowProps={rowProps} {...props} />; | ||
}, | ||
}); | ||
|
||
const actionsHeaderAriaLabelStacktraceAction = i18n.translate( | ||
'discover.customControl.stacktraceArialLabel', | ||
{ defaultMessage: 'Access to available stacktraces' } | ||
); | ||
|
||
const stacktraceAvailableControlButton = i18n.translate( | ||
'discover.customControl.stacktrace.available', | ||
{ defaultMessage: 'Stacktraces available' } | ||
); | ||
|
||
const stacktraceNotAvailableControlButton = i18n.translate( | ||
'discover.customControl.stacktrace.notAvailable', | ||
{ defaultMessage: 'Stacktraces not available' } | ||
); | ||
|
||
const Stacktrace = ({ | ||
Control, | ||
rowProps: { record }, | ||
...props | ||
}: { | ||
Control: RowControlComponent; | ||
rowProps: RowControlRowProps; | ||
} & Partial<RowControlProps>) => { | ||
const stacktrace = getStacktraceFields(record as LogDocument); | ||
const hasValue = Object.values(stacktrace).some(Boolean); | ||
|
||
return hasValue ? ( | ||
<Control | ||
data-test-subj="docTableStacktraceExist" | ||
label={stacktraceAvailableControlButton} | ||
tooltipContent={stacktraceAvailableControlButton} | ||
iconType="apmTrace" | ||
onClick={undefined} | ||
{...props} | ||
/> | ||
) : ( | ||
<Control | ||
disabled | ||
data-test-subj="docTableStacktraceDoesNotExist" | ||
label={stacktraceNotAvailableControlButton} | ||
tooltipContent={stacktraceNotAvailableControlButton} | ||
iconType="apmTrace" | ||
onClick={undefined} | ||
{...props} | ||
/> | ||
); | ||
}; |
36 changes: 36 additions & 0 deletions
36
packages/kbn-discover-utils/src/components/custom_control_columns/types.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,36 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the "Elastic License | ||
* 2.0", the "GNU Affero General Public License v3.0 only", and the "Server Side | ||
* Public License v 1"; you may not use this file except in compliance with, at | ||
* your election, the "Elastic License 2.0", the "GNU Affero General Public | ||
* License v3.0 only", or the "Server Side Public License, v 1". | ||
*/ | ||
|
||
import { EuiButtonIconProps, EuiDataGridControlColumn, IconType } from '@elastic/eui'; | ||
import React, { FC, ReactElement } from 'react'; | ||
import { DataTableRecord } from '../../types'; | ||
|
||
export interface RowControlRowProps { | ||
rowIndex: number; | ||
record: DataTableRecord; | ||
} | ||
|
||
export interface RowControlProps { | ||
'data-test-subj'?: string; | ||
color?: EuiButtonIconProps['color']; | ||
disabled?: boolean; | ||
label: string; | ||
iconType: IconType; | ||
onClick: ((props: RowControlRowProps) => void) | undefined; | ||
tooltipContent?: React.ReactNode; | ||
} | ||
|
||
export type RowControlComponent = FC<RowControlProps>; | ||
|
||
export interface RowControlColumn { | ||
id: string; | ||
headerAriaLabel: string; | ||
headerCellRender?: EuiDataGridControlColumn['headerCellRender']; | ||
renderControl: (Control: RowControlComponent, props: RowControlRowProps) => ReactElement; | ||
} |
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
27 changes: 27 additions & 0 deletions
27
packages/kbn-discover-utils/src/utils/get_stack_trace_fields.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,27 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the "Elastic License | ||
* 2.0", the "GNU Affero General Public License v3.0 only", and the "Server Side | ||
* Public License v 1"; you may not use this file except in compliance with, at | ||
* your election, the "Elastic License 2.0", the "GNU Affero General Public | ||
* License v3.0 only", or the "Server Side Public License, v 1". | ||
*/ | ||
|
||
import { getFieldFromDoc, LogDocument, StackTraceFields } from '..'; | ||
import { | ||
ERROR_EXCEPTION_STACKTRACE, | ||
ERROR_LOG_STACKTRACE, | ||
ERROR_STACK_TRACE, | ||
} from '../field_constants'; | ||
|
||
export const getStacktraceFields = (doc: LogDocument): StackTraceFields => { | ||
const errorStackTrace = getFieldFromDoc(doc, ERROR_STACK_TRACE); | ||
const errorExceptionStackTrace = getFieldFromDoc(doc, ERROR_EXCEPTION_STACKTRACE); | ||
const errorLogStackTrace = getFieldFromDoc(doc, ERROR_LOG_STACKTRACE); | ||
|
||
return { | ||
[ERROR_STACK_TRACE]: errorStackTrace, | ||
[ERROR_EXCEPTION_STACKTRACE]: errorExceptionStackTrace, | ||
[ERROR_LOG_STACKTRACE]: errorLogStackTrace, | ||
}; | ||
}; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,7 +11,7 @@ | |
}, | ||
"include": [ | ||
"**/*.ts", | ||
"**/*.tsx", | ||
"**/*.tsx" | ||
], | ||
"exclude": [ | ||
"target/**/*" | ||
|
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.