From 7f0943351799c6dd36007f8426052db11f6dc916 Mon Sep 17 00:00:00 2001 From: Josh Dover Date: Wed, 25 Mar 2020 16:30:21 -0600 Subject: [PATCH] Fix types --- src/plugins/apm_oss/server/mocks.ts | 1 + .../server/lib/apm/extract_index_patterns.ts | 36 ++++++++++++------- 2 files changed, 25 insertions(+), 12 deletions(-) diff --git a/src/plugins/apm_oss/server/mocks.ts b/src/plugins/apm_oss/server/mocks.ts index 68cb00440802e..30904ab30d865 100644 --- a/src/plugins/apm_oss/server/mocks.ts +++ b/src/plugins/apm_oss/server/mocks.ts @@ -24,6 +24,7 @@ import { APMOSSPluginSetup } from './plugin'; const apmStar = 'apm-*'; const defaultConfig = { + enabled: true, errorIndices: apmStar, indexPattern: apmStar, metricsIndices: apmStar, diff --git a/x-pack/plugins/upgrade_assistant/server/lib/apm/extract_index_patterns.ts b/x-pack/plugins/upgrade_assistant/server/lib/apm/extract_index_patterns.ts index dd142dded6e71..f45ebf60f0264 100644 --- a/x-pack/plugins/upgrade_assistant/server/lib/apm/extract_index_patterns.ts +++ b/x-pack/plugins/upgrade_assistant/server/lib/apm/extract_index_patterns.ts @@ -3,16 +3,28 @@ * or more contributor license agreements. Licensed under the Elastic License; * you may not use this file except in compliance with the Elastic License. */ -import { uniq } from 'lodash'; +import { uniq, pick } from 'lodash'; +import { APMOSSConfig } from '../../../../../../src/plugins/apm_oss/server'; -export const extractIndexPatterns = (apmConfig: Record): string[] => - uniq( - [ - 'sourcemapIndices', - 'errorIndices', - 'transactionIndices', - 'spanIndices', - 'metricsIndices', - 'onboardingIndices', - ].map(type => apmConfig[type]!) - ); +type APMIndexConfig = Pick< + APMOSSConfig, + | 'sourcemapIndices' + | 'errorIndices' + | 'transactionIndices' + | 'spanIndices' + | 'metricsIndices' + | 'onboardingIndices' +>; + +export const extractIndexPatterns = (apmConfig: APMOSSConfig): string[] => { + const indexConfigs = pick(apmConfig, [ + 'sourcemapIndices', + 'errorIndices', + 'transactionIndices', + 'spanIndices', + 'metricsIndices', + 'onboardingIndices', + ]); + + return uniq(Object.values(indexConfigs)); +};