diff --git a/x-pack/plugins/infra/common/http_api/log_sources/log_source_configuration.ts b/x-pack/plugins/infra/common/http_api/log_sources/log_source_configuration.ts index e8bf63843c623..3fc42b661ddab 100644 --- a/x-pack/plugins/infra/common/http_api/log_sources/log_source_configuration.ts +++ b/x-pack/plugins/infra/common/http_api/log_sources/log_source_configuration.ts @@ -20,6 +20,9 @@ export const logSourceConfigurationOriginRT = rt.keyof({ export type LogSourceConfigurationOrigin = rt.TypeOf; const logSourceFieldsConfigurationRT = rt.strict({ + container: rt.string, + host: rt.string, + pod: rt.string, timestamp: rt.string, tiebreaker: rt.string, }); diff --git a/x-pack/plugins/infra/common/inventory_models/index.ts b/x-pack/plugins/infra/common/inventory_models/index.ts index 1ddf92516c409..5abb169882b3f 100644 --- a/x-pack/plugins/infra/common/inventory_models/index.ts +++ b/x-pack/plugins/infra/common/inventory_models/index.ts @@ -30,7 +30,6 @@ export const findInventoryModel = (type: InventoryItemType) => { }; interface InventoryFields { - message: string[]; host: string; pod: string; container: string; diff --git a/x-pack/plugins/infra/public/pages/link_to/redirect_to_node_logs.tsx b/x-pack/plugins/infra/public/pages/link_to/redirect_to_node_logs.tsx index 37203084124f5..fb621a5ed002a 100644 --- a/x-pack/plugins/infra/public/pages/link_to/redirect_to_node_logs.tsx +++ b/x-pack/plugins/infra/public/pages/link_to/redirect_to_node_logs.tsx @@ -5,21 +5,20 @@ */ import { i18n } from '@kbn/i18n'; - -import { flowRight } from 'lodash'; +import flowRight from 'lodash/flowRight'; import React from 'react'; import { Redirect, RouteComponentProps } from 'react-router-dom'; - +import { useMount } from 'react-use'; +import { useKibana } from '../../../../../../src/plugins/kibana_react/public'; +import { findInventoryFields } from '../../../common/inventory_models'; +import { InventoryItemType } from '../../../common/inventory_models/types'; import { LoadingPage } from '../../components/loading_page'; import { replaceLogFilterInQueryString } from '../../containers/logs/log_filter'; import { replaceLogPositionInQueryString } from '../../containers/logs/log_position'; +import { useLogSource } from '../../containers/logs/log_source'; import { replaceSourceIdInQueryString } from '../../containers/source_id'; -import { SourceConfigurationFields } from '../../graphql/types'; -import { getFilterFromLocation, getTimeFromLocation } from './query_params'; -import { useSource } from '../../containers/source/source'; -import { findInventoryFields } from '../../../common/inventory_models'; -import { InventoryItemType } from '../../../common/inventory_models/types'; import { LinkDescriptor } from '../../hooks/use_link_props'; +import { getFilterFromLocation, getTimeFromLocation } from './query_params'; type RedirectToNodeLogsType = RouteComponentProps<{ nodeId: string; @@ -27,22 +26,22 @@ type RedirectToNodeLogsType = RouteComponentProps<{ sourceId?: string; }>; -const getFieldByNodeType = ( - nodeType: InventoryItemType, - fields: SourceConfigurationFields.Fields -) => { - const inventoryFields = findInventoryFields(nodeType, fields); - return inventoryFields.id; -}; - export const RedirectToNodeLogs = ({ match: { params: { nodeId, nodeType, sourceId = 'default' }, }, location, }: RedirectToNodeLogsType) => { - const { source, isLoading } = useSource({ sourceId }); - const configuration = source && source.configuration; + const { services } = useKibana(); + const { isLoading, loadSourceConfiguration, sourceConfiguration } = useLogSource({ + fetch: services.http.fetch, + sourceId, + }); + const fields = sourceConfiguration?.configuration.fields; + + useMount(() => { + loadSourceConfiguration(); + }); if (isLoading) { return ( @@ -55,13 +54,11 @@ export const RedirectToNodeLogs = ({ })} /> ); - } - - if (!configuration) { + } else if (fields == null) { return null; } - const nodeFilter = `${getFieldByNodeType(nodeType, configuration.fields)}: ${nodeId}`; + const nodeFilter = `${findInventoryFields(nodeType, fields).id}: ${nodeId}`; const userFilter = getFilterFromLocation(location); const filter = userFilter ? `(${nodeFilter}) and (${userFilter})` : nodeFilter;