import React , { FC } from 'react' ; import { EuiBadge , EuiInMemoryTable , EuiFlexGroup , EuiFlexItem } from '@elastic/eui' ; import { FormattedMessage } from '@kbn/i18n-react' ; import { EuiBasicTableColumn } from '@elastic/eui/src/components/basic_table/basic_table' ; import { i18n } from '@kbn/i18n' ; import { useFieldFormatter } from '../../../contexts/kibana/use_field_formatter' ; import { FIELD_FORMAT_IDS } from '../../../../../../../../src/plugins/field_formats/common' ; import { IngestStatsResponse } from './pipelines' ; import { HelpIcon } from '../../../components/help_icon' ; interface ProcessorsStatsProps { stats : Exclude < IngestStatsResponse , undefined > [ 'pipelines' ] [ string ] [ 'processors' ] ; } type ProcessorStatsItem = ProcessorsStatsProps [ 'stats' ] [ number ] [ string ] & { id : string ; } ; export const ProcessorsStats = ( { stats } ) => { const durationFormatter = useFieldFormatter ( FIELD_FORMAT_IDS . DURATION ) ; const items = stats . map ( ( v , i ) => { const key = Object . keys ( v ) [ 0 ] ; return { ... v [ key ] , id : `${ key }_${ i }` , } ; } ) ; const columns = [ { field : 'type' , name : i18n . translate ( 'xpack.ml.trainedModels.modelsList.pipelines.processorStats.typeHeader' , { defaultMessage : 'Processor type' , } ) , width : '100px' , sortable : true , truncateText : false , render : ( type ) => { return < EuiBadge color = "hollow" > { type } < /EuiBadge>; } , 'data-test-subj' : 'mlProcessorStatsType' , } , { field : 'stats.count' , name : ( < EuiFlexGroup gutterSize = "xs" > < EuiFlexItem grow = { false } > < FormattedMessage id = "xpack.ml.trainedModels.modelsList.pipelines.processorStats.countHeader" defaultMessage = "Count" / > < /EuiFlexItem> < EuiFlexItem grow = { false } > < HelpIcon content = { < FormattedMessage id = "xpack.ml.trainedModels.modelsList.pipelines.processorStats.countDescription" defaultMessage = "Total number of documents ingested during the lifetime of this node" / > } /> < /EuiFlexItem> < /EuiFlexGroup>), width : '100px' , truncateText : true , 'data-test-subj' : 'mlProcessorStatsCount' , } , ... ( true ? [ ] : [ { field : 'stats.time_in_millis' , name : ( < EuiFlexGroup gutterSize = "xs" > < EuiFlexItem grow = { false } > < FormattedMessage id = "xpack.ml.trainedModels.modelsList.pipelines.processorStats.timePerDocHeader" defaultMessage = "Time per doc" / > < /EuiFlexItem> < EuiFlexItem grow = { false } > < HelpIcon content = { < FormattedMessage id = "xpack.ml.trainedModels.modelsList.pipelines.processorStats.timePerDocDescription" defaultMessage = "Total time spent preprocessing ingest documents during the lifetime of this node" / > } /> < /EuiFlexItem> < /EuiFlexGroup>), width : '100px' , truncateText : false , 'data-test-subj' : 'mlProcessorStatsTimePerDoc' , render : ( v ) => { return durationFormatter ( v ) ; } , } , ] ) , { field : 'stats.current' , name : ( < EuiFlexGroup gutterSize = "xs" > < EuiFlexItem grow = { false } > < FormattedMessage id = "xpack.ml.trainedModels.modelsList.pipelines.processorStats.currentHeader" defaultMessage = "Current" / > < /EuiFlexItem> < EuiFlexItem grow = { false } > < HelpIcon content = { < FormattedMessage id = "xpack.ml.trainedModels.modelsList.pipelines.processorStats.currentDescription" defaultMessage = "Total number of documents currently being ingested" / > } /> < /EuiFlexItem> < /EuiFlexGroup>), width : '100px' , truncateText : false , 'data-test-subj' : 'mlProcessorStatsCurrent' , } , { field : 'stats.failed' , name : ( < EuiFlexGroup gutterSize = "xs" > < EuiFlexItem grow = { false } > < FormattedMessage id = "xpack.ml.trainedModels.modelsList.pipelines.processorStats.failedHeader" defaultMessage = "Failed" / > < /EuiFlexItem> < EuiFlexItem grow = { false } > < HelpIcon content = { < FormattedMessage id = "xpack.ml.trainedModels.modelsList.pipelines.processorStats.failedDescription" defaultMessage = "Total number of failed ingest operations during the lifetime of this node" / > } /> < /EuiFlexItem> < /EuiFlexGroup>), width : '100px' , 'data-test-subj' : 'mlProcessorStatsFailed' , } , ] ; return ( < EuiInMemoryTable < ProcessorStatsItem > allowNeutralSort = { false } columns = { columns } hasActions = { false } isExpandable = { false } isSelectable = { false } items = { items } itemId = { 'id' } rowProps = { ( item ) => ( { 'data-test-subj' : `mlProcessorStatsTableRow row-${ item . id }` , } ) } onTableChange = { ( ) => { } } data - test - subj = { 'mlProcessorStatsTable' } />); } ;