diff --git a/x-pack/legacy/plugins/infra/public/containers/source/source.tsx b/x-pack/legacy/plugins/infra/public/containers/source/source.tsx index 9632a5bda0792..8b931545a5c6c 100644 --- a/x-pack/legacy/plugins/infra/public/containers/source/source.tsx +++ b/x-pack/legacy/plugins/infra/public/containers/source/source.tsx @@ -21,6 +21,19 @@ import { updateSourceMutation } from './update_source.gql_query'; type Source = SourceQuery.Query['source']; +const pickIndexPattern = (source: Source | undefined, type: 'logs' | 'metrics' | 'both') => { + if (!source) { + return 'unknown-index'; + } + if (type === 'logs') { + return source.configuration.logAlias; + } + if (type === 'metrics') { + return source.configuration.metricAlias; + } + return `${source.configuration.logAlias},${source.configuration.metricAlias}`; +}; + export const useSource = ({ sourceId }: { sourceId: string }) => { const apolloClient = useApolloClient(); const [source, setSource] = useState(undefined); @@ -108,13 +121,12 @@ export const useSource = ({ sourceId }: { sourceId: string }) => { [apolloClient, sourceId] ); - const derivedIndexPattern = useMemo( - () => ({ + const createDerivedIndexPattern = (type: 'logs' | 'metrics' | 'both') => { + return { fields: source ? source.status.indexFields : [], - title: source ? `${source.configuration.logAlias}` : 'unknown-index', - }), - [source] - ); + title: pickIndexPattern(source, type), + }; + }; const isLoading = useMemo( () => @@ -146,7 +158,7 @@ export const useSource = ({ sourceId }: { sourceId: string }) => { return { createSourceConfiguration, - derivedIndexPattern, + createDerivedIndexPattern, logIndicesExist, isLoading, isLoadingSource: loadSourceRequest.state === 'pending', diff --git a/x-pack/legacy/plugins/infra/public/containers/with_source/with_source.tsx b/x-pack/legacy/plugins/infra/public/containers/with_source/with_source.tsx index 3ed3852484e71..0512888ecd4ea 100644 --- a/x-pack/legacy/plugins/infra/public/containers/with_source/with_source.tsx +++ b/x-pack/legacy/plugins/infra/public/containers/with_source/with_source.tsx @@ -15,7 +15,7 @@ interface WithSourceProps { children: RendererFunction<{ configuration?: SourceQuery.Query['source']['configuration']; create: (sourceProperties: UpdateSourceInput) => Promise | undefined; - derivedIndexPattern: StaticIndexPattern; + createDerivedIndexPattern: (type: 'logs' | 'metrics' | 'both') => StaticIndexPattern; exists?: boolean; hasFailed: boolean; isLoading: boolean; @@ -33,7 +33,7 @@ interface WithSourceProps { export const WithSource: React.FunctionComponent = ({ children }) => { const { createSourceConfiguration, - derivedIndexPattern, + createDerivedIndexPattern, source, sourceExists, sourceId, @@ -50,7 +50,7 @@ export const WithSource: React.FunctionComponent = ({ children return children({ create: createSourceConfiguration, configuration: source && source.configuration, - derivedIndexPattern, + createDerivedIndexPattern, exists: sourceExists, hasFailed: hasFailedLoadingSource, isLoading, diff --git a/x-pack/legacy/plugins/infra/public/pages/infrastructure/index.tsx b/x-pack/legacy/plugins/infra/public/pages/infrastructure/index.tsx index 11b5799fe7286..3cc40be7e5fe0 100644 --- a/x-pack/legacy/plugins/infra/public/pages/infrastructure/index.tsx +++ b/x-pack/legacy/plugins/infra/public/pages/infrastructure/index.tsx @@ -68,11 +68,11 @@ export const InfrastructurePage = injectI18n(({ match, intl }: InfrastructurePag path={`${match.path}/metrics-explorer`} render={props => ( - {({ configuration, derivedIndexPattern }) => ( + {({ configuration, createDerivedIndexPattern }) => ( diff --git a/x-pack/legacy/plugins/infra/public/pages/infrastructure/snapshot/index.tsx b/x-pack/legacy/plugins/infra/public/pages/infrastructure/snapshot/index.tsx index 5c28715e4e538..9b4efa44d483a 100644 --- a/x-pack/legacy/plugins/infra/public/pages/infrastructure/snapshot/index.tsx +++ b/x-pack/legacy/plugins/infra/public/pages/infrastructure/snapshot/index.tsx @@ -38,7 +38,7 @@ export const SnapshotPage = injectUICapabilities( const { intl, uiCapabilities } = props; const { showIndicesConfiguration } = useContext(SourceConfigurationFlyoutState.Context); const { - derivedIndexPattern, + createDerivedIndexPattern, hasFailedLoadingSource, isLoading, loadSourceFailureMessage, @@ -84,7 +84,7 @@ export const SnapshotPage = injectUICapabilities( ) : metricIndicesExist ? ( <> - + diff --git a/x-pack/legacy/plugins/infra/public/pages/infrastructure/snapshot/page_content.tsx b/x-pack/legacy/plugins/infra/public/pages/infrastructure/snapshot/page_content.tsx index a47b82d17d77e..f6c9bb27e36c0 100644 --- a/x-pack/legacy/plugins/infra/public/pages/infrastructure/snapshot/page_content.tsx +++ b/x-pack/legacy/plugins/infra/public/pages/infrastructure/snapshot/page_content.tsx @@ -19,10 +19,10 @@ import { WithSource } from '../../../containers/with_source'; export const SnapshotPageContent: React.SFC = () => ( - {({ configuration, derivedIndexPattern, sourceId }) => ( + {({ configuration, createDerivedIndexPattern, sourceId }) => ( {({ wafflemap }) => ( - + {({ filterQueryAsJson, applyFilterQuery }) => ( {({ currentTimeRange, isAutoReloading }) => ( diff --git a/x-pack/legacy/plugins/infra/public/pages/infrastructure/snapshot/toolbar.tsx b/x-pack/legacy/plugins/infra/public/pages/infrastructure/snapshot/toolbar.tsx index e70e79a18a66a..0d3fda093b223 100644 --- a/x-pack/legacy/plugins/infra/public/pages/infrastructure/snapshot/toolbar.tsx +++ b/x-pack/legacy/plugins/infra/public/pages/infrastructure/snapshot/toolbar.tsx @@ -26,10 +26,10 @@ export const SnapshotToolbar = injectI18n(({ intl }) => ( - {({ derivedIndexPattern }) => ( - + {({ createDerivedIndexPattern }) => ( + {({ isLoadingSuggestions, loadSuggestions, suggestions }) => ( - + {({ applyFilterQueryFromKueryExpression, filterQueryDraft, @@ -73,7 +73,7 @@ export const SnapshotToolbar = injectI18n(({ intl }) => ( - {({ derivedIndexPattern }) => ( + {({ createDerivedIndexPattern }) => ( {({ changeMetric, @@ -106,7 +106,7 @@ export const SnapshotToolbar = injectI18n(({ intl }) => ( groupBy={groupBy} nodeType={nodeType} onChange={changeGroupBy} - fields={derivedIndexPattern.fields} + fields={createDerivedIndexPattern('metrics').fields} onChangeCustomOptions={changeCustomOptions} customOptions={customOptions} /> diff --git a/x-pack/legacy/plugins/infra/public/pages/logs/page_logs_content.tsx b/x-pack/legacy/plugins/infra/public/pages/logs/page_logs_content.tsx index 7f4b52604e469..007584d4cacc8 100644 --- a/x-pack/legacy/plugins/infra/public/pages/logs/page_logs_content.tsx +++ b/x-pack/legacy/plugins/infra/public/pages/logs/page_logs_content.tsx @@ -32,7 +32,7 @@ import { SourceConfigurationFlyoutState } from '../../components/source_configur import { LogHighlightsBridge } from '../../containers/logs/log_highlights'; export const LogsPageLogsContent: React.FunctionComponent = () => { - const { derivedIndexPattern, source, sourceId, version } = useContext(Source.Context); + const { createDerivedIndexPattern, source, sourceId, version } = useContext(Source.Context); const { intervalSize, textScale, textWrap } = useContext(LogViewConfiguration.Context); const { setFlyoutVisibility, @@ -45,6 +45,8 @@ export const LogsPageLogsContent: React.FunctionComponent = () => { } = useContext(LogFlyoutState.Context); const { showLogsConfiguration } = useContext(SourceConfigurationFlyoutState.Context); + const derivedIndexPattern = createDerivedIndexPattern('logs'); + return ( <> diff --git a/x-pack/legacy/plugins/infra/public/pages/logs/page_toolbar.tsx b/x-pack/legacy/plugins/infra/public/pages/logs/page_toolbar.tsx index 2255cbff3d0cd..95b09548299c4 100644 --- a/x-pack/legacy/plugins/infra/public/pages/logs/page_toolbar.tsx +++ b/x-pack/legacy/plugins/infra/public/pages/logs/page_toolbar.tsx @@ -26,7 +26,8 @@ import { Source } from '../../containers/source'; import { WithKueryAutocompletion } from '../../containers/with_kuery_autocompletion'; export const LogsToolbar = injectI18n(({ intl }) => { - const { derivedIndexPattern } = useContext(Source.Context); + const { createDerivedIndexPattern } = useContext(Source.Context); + const derivedIndexPattern = createDerivedIndexPattern('logs'); const { availableIntervalSizes, availableTextScales,