From ec3bc7d021e04acd27554f8f69eae789a5b6bda9 Mon Sep 17 00:00:00 2001 From: Ahmad Bamieh Date: Tue, 26 Jan 2021 14:59:13 +0200 Subject: [PATCH] update functional tests --- .../src/kbn_client/kbn_client_ui_settings.ts | 17 ----- src/core/server/ui_settings/routes/get.ts | 13 +--- .../server/collectors/management/schema.ts | 1 + .../server/collectors/management/types.ts | 1 + test/api_integration/apis/telemetry/index.js | 1 - .../api_integration/apis/telemetry/index.js | 1 - .../apis/telemetry/management_collection.ts | 65 ------------------- x-pack/test/usage_collection/config.ts | 5 +- .../stack_management_usage_test/kibana.json | 9 +++ .../public/index.ts | 11 ++++ .../public/plugin.ts | 17 +++++ .../public/types.ts | 14 ++++ .../stack_management_usage_test/tsconfig.json | 12 ++++ .../stack_management_usage/index.ts | 45 +++++++++++++ 14 files changed, 115 insertions(+), 97 deletions(-) delete mode 100644 x-pack/test/api_integration/apis/telemetry/management_collection.ts create mode 100644 x-pack/test/usage_collection/plugins/stack_management_usage_test/kibana.json create mode 100644 x-pack/test/usage_collection/plugins/stack_management_usage_test/public/index.ts create mode 100644 x-pack/test/usage_collection/plugins/stack_management_usage_test/public/plugin.ts create mode 100644 x-pack/test/usage_collection/plugins/stack_management_usage_test/public/types.ts create mode 100644 x-pack/test/usage_collection/plugins/stack_management_usage_test/tsconfig.json create mode 100644 x-pack/test/usage_collection/test_suites/stack_management_usage/index.ts diff --git a/packages/kbn-dev-utils/src/kbn_client/kbn_client_ui_settings.ts b/packages/kbn-dev-utils/src/kbn_client/kbn_client_ui_settings.ts index ebc479a15729d5..828344f5771214 100644 --- a/packages/kbn-dev-utils/src/kbn_client/kbn_client_ui_settings.ts +++ b/packages/kbn-dev-utils/src/kbn_client/kbn_client_ui_settings.ts @@ -11,7 +11,6 @@ import { ToolingLog } from '../tooling_log'; import { KbnClientRequester, uriencode } from './kbn_client_requester'; export type UiSettingValues = Record; - interface UiSettingsApiResponse { settings: { [key: string]: { @@ -21,10 +20,6 @@ interface UiSettingsApiResponse { }; } -interface UiSettingsWithRegisteredApiResponse extends UiSettingsApiResponse { - registered: Record; -} - export class KbnClientUiSettings { constructor( private readonly log: ToolingLog, @@ -84,18 +79,6 @@ export class KbnClientUiSettings { }); } - /** - * Returns all registered kibana settings - */ - async getAllRegistered() { - const { data } = await this.requester.request>({ - path: '/api/kibana/settings?_allRegistered=true', - method: 'GET', - }); - - return data.registered; - } - /** * Add fields to the config doc (like setting timezone and defaultIndex) */ diff --git a/src/core/server/ui_settings/routes/get.ts b/src/core/server/ui_settings/routes/get.ts index b801d229d974da..06cb43f2d11a56 100644 --- a/src/core/server/ui_settings/routes/get.ts +++ b/src/core/server/ui_settings/routes/get.ts @@ -6,28 +6,17 @@ * Public License, v 1. */ -import { schema } from '@kbn/config-schema'; import { IRouter } from '../../http'; import { SavedObjectsErrorHelpers } from '../../saved_objects'; export function registerGetRoute(router: IRouter) { router.get( - { - path: '/api/kibana/settings', - validate: { - query: schema.object({ - _allRegistered: schema.maybe(schema.boolean()), - }), - }, - }, + { path: '/api/kibana/settings', validate: false }, async (context, request, response) => { try { - const { _allRegistered } = request.query; const uiSettingsClient = context.core.uiSettings.client; - return response.ok({ body: { - registered: _allRegistered ? uiSettingsClient.getRegistered() : undefined, settings: await uiSettingsClient.getUserProvided(), }, }); diff --git a/src/plugins/kibana_usage_collection/server/collectors/management/schema.ts b/src/plugins/kibana_usage_collection/server/collectors/management/schema.ts index 13c3ba5df5ffc2..2d02cfcf4959aa 100644 --- a/src/plugins/kibana_usage_collection/server/collectors/management/schema.ts +++ b/src/plugins/kibana_usage_collection/server/collectors/management/schema.ts @@ -129,4 +129,5 @@ export const stackManagementSchema: MakeSchemaFrom = { 'securitySolution:rulesTableRefresh': { type: 'text' }, 'apm:enableSignificantTerms': { type: 'boolean' }, 'apm:enableServiceOverview': { type: 'boolean' }, + 'apm:enableCorrelations': { type: 'boolean' }, }; diff --git a/src/plugins/kibana_usage_collection/server/collectors/management/types.ts b/src/plugins/kibana_usage_collection/server/collectors/management/types.ts index d7ffddb00f3fa3..88425e3eba8d1b 100644 --- a/src/plugins/kibana_usage_collection/server/collectors/management/types.ts +++ b/src/plugins/kibana_usage_collection/server/collectors/management/types.ts @@ -29,6 +29,7 @@ export interface UsageStats { 'securitySolution:rulesTableRefresh': string; 'apm:enableSignificantTerms': boolean; 'apm:enableServiceOverview': boolean; + 'apm:enableCorrelations': boolean; 'visualize:enableLabs': boolean; 'visualization:heatmap:maxBuckets': number; 'visualization:colorMapping': string; diff --git a/test/api_integration/apis/telemetry/index.js b/test/api_integration/apis/telemetry/index.js index 4b9dbb84c9ca3c..627e295f7301dd 100644 --- a/test/api_integration/apis/telemetry/index.js +++ b/test/api_integration/apis/telemetry/index.js @@ -9,7 +9,6 @@ export default function ({ loadTestFile }) { describe('Telemetry', () => { loadTestFile(require.resolve('./telemetry_local')); - loadTestFile(require.resolve('./ui_settings')); loadTestFile(require.resolve('./opt_in')); loadTestFile(require.resolve('./telemetry_optin_notice_seen')); }); diff --git a/x-pack/test/api_integration/apis/telemetry/index.js b/x-pack/test/api_integration/apis/telemetry/index.js index 58d657d86ee120..5f13b0b7284684 100644 --- a/x-pack/test/api_integration/apis/telemetry/index.js +++ b/x-pack/test/api_integration/apis/telemetry/index.js @@ -8,7 +8,6 @@ export default function ({ loadTestFile }) { describe('Telemetry', () => { loadTestFile(require.resolve('./telemetry')); loadTestFile(require.resolve('./telemetry_local')); - loadTestFile(require.resolve('./management_collection')); loadTestFile(require.resolve('./opt_in')); loadTestFile(require.resolve('./telemetry_optin_notice_seen')); }); diff --git a/x-pack/test/api_integration/apis/telemetry/management_collection.ts b/x-pack/test/api_integration/apis/telemetry/management_collection.ts deleted file mode 100644 index e45cd2d5fcaa52..00000000000000 --- a/x-pack/test/api_integration/apis/telemetry/management_collection.ts +++ /dev/null @@ -1,65 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License; - * you may not use this file except in compliance with the Elastic License. - */ - -import * as ts from 'typescript'; -import * as path from 'path'; -import expect from '@kbn/expect'; -import { getInterfacesDescriptors, loadProgram } from '@kbn/telemetry-tools'; -import { FtrProviderContext } from '../../ftr_provider_context'; -// @ts-ignore - -export default function ({ getService }: FtrProviderContext) { - const kibanaServer = getService('kibanaServer'); - const uiSettingsCollectorTypesPath = path.resolve( - process.cwd(), - '../src/plugins/kibana_usage_collection/server/collectors/management/types.ts' - ); - - describe('Management Collection', () => { - let interfaceObject: Record; - let registeredSettings: Record; - - before(async () => { - const { program } = loadProgram([uiSettingsCollectorTypesPath]); - const sourceFile = program.getSourceFile(uiSettingsCollectorTypesPath); - if (!sourceFile) { - throw Error('sourceFile is undefined!'); - } - - const interfacesObjects: Array> = getInterfacesDescriptors( - sourceFile, - program, - 'UsageStats' - ); - if (interfacesObjects.length !== 1) { - throw Error('Unable to parse interface UsageStats correctly'); - } - - interfaceObject = interfacesObjects[0]; - registeredSettings = await kibanaServer.uiSettings.getAllRegistered(); - }); - - it('registers all UI Settings in the UsageStats interface', () => { - const unreportedUISettings = Object.keys(registeredSettings) - .filter((key) => key !== 'buildNum') - .filter((key) => typeof interfaceObject[key] === 'undefined'); - - expect(unreportedUISettings).to.eql([]); - }); - - it('registers all sensitive UI settings as boolean type', async () => { - const sensitiveSettings = Object.entries(registeredSettings) - .filter(([, config]) => config.sensitive) - .map(([key]) => key); - - const nonBooleanSensitiveProps = sensitiveSettings - .map((key) => ({ key, ...interfaceObject[key] })) - .filter((keyDescriptor) => keyDescriptor.kind !== ts.SyntaxKind.BooleanKeyword); - - expect(nonBooleanSensitiveProps).to.eql([]); - }); - }); -} diff --git a/x-pack/test/usage_collection/config.ts b/x-pack/test/usage_collection/config.ts index 27b12a1ff298c1..d31ecc444d00d8 100644 --- a/x-pack/test/usage_collection/config.ts +++ b/x-pack/test/usage_collection/config.ts @@ -24,7 +24,10 @@ export default async function ({ readConfigFile }: FtrConfigProviderContext) { return { ...xpackFunctionalConfig.getAll(), // list paths to the files that contain your plugins tests - testFiles: [resolve(__dirname, './test_suites/application_usage')], + testFiles: [ + resolve(__dirname, './test_suites/application_usage'), + resolve(__dirname, './test_suites/stack_management_usage'), + ], services, pageObjects, diff --git a/x-pack/test/usage_collection/plugins/stack_management_usage_test/kibana.json b/x-pack/test/usage_collection/plugins/stack_management_usage_test/kibana.json new file mode 100644 index 00000000000000..b586de3fa4d793 --- /dev/null +++ b/x-pack/test/usage_collection/plugins/stack_management_usage_test/kibana.json @@ -0,0 +1,9 @@ +{ + "id": "StackManagementUsageTest", + "version": "1.0.0", + "kibanaVersion": "kibana", + "configPath": ["xpack", "StackManagementUsageTest"], + "requiredPlugins": [], + "server": false, + "ui": true +} diff --git a/x-pack/test/usage_collection/plugins/stack_management_usage_test/public/index.ts b/x-pack/test/usage_collection/plugins/stack_management_usage_test/public/index.ts new file mode 100644 index 00000000000000..82aae6988052a7 --- /dev/null +++ b/x-pack/test/usage_collection/plugins/stack_management_usage_test/public/index.ts @@ -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; + * you may not use this file except in compliance with the Elastic License. + */ + +import { StackManagementUsageTest } from './plugin'; + +export function plugin() { + return new StackManagementUsageTest(); +} diff --git a/x-pack/test/usage_collection/plugins/stack_management_usage_test/public/plugin.ts b/x-pack/test/usage_collection/plugins/stack_management_usage_test/public/plugin.ts new file mode 100644 index 00000000000000..3cd10a1d4c178c --- /dev/null +++ b/x-pack/test/usage_collection/plugins/stack_management_usage_test/public/plugin.ts @@ -0,0 +1,17 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License; + * you may not use this file except in compliance with the Elastic License. + */ + +import { Plugin, CoreSetup, CoreStart } from 'kibana/public'; +import './types'; + +export class StackManagementUsageTest implements Plugin { + public setup(core: CoreSetup) {} + + public start(core: CoreStart) { + const allUiSettings = core.uiSettings.getAll(); + window.__registeredUiSettings__ = allUiSettings; + } +} diff --git a/x-pack/test/usage_collection/plugins/stack_management_usage_test/public/types.ts b/x-pack/test/usage_collection/plugins/stack_management_usage_test/public/types.ts new file mode 100644 index 00000000000000..c49ec89d94b9fb --- /dev/null +++ b/x-pack/test/usage_collection/plugins/stack_management_usage_test/public/types.ts @@ -0,0 +1,14 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License; + * you may not use this file except in compliance with the Elastic License. + */ + +import { IUiSettingsClient } from 'src/core/public'; +export {}; // Hack to declare this file as a module so TS allows us to extend the Global Window interface + +declare global { + interface Window { + __registeredUiSettings__: ReturnType; + } +} diff --git a/x-pack/test/usage_collection/plugins/stack_management_usage_test/tsconfig.json b/x-pack/test/usage_collection/plugins/stack_management_usage_test/tsconfig.json new file mode 100644 index 00000000000000..f1bf94a38de8fd --- /dev/null +++ b/x-pack/test/usage_collection/plugins/stack_management_usage_test/tsconfig.json @@ -0,0 +1,12 @@ +{ + "extends": "../../../../../tsconfig.base.json", + "compilerOptions": { + "outDir": "./target", + "skipLibCheck": true + }, + "include": [ + "public/**/*.ts", + "public/**/*.tsx", + ], + "exclude": [] +} diff --git a/x-pack/test/usage_collection/test_suites/stack_management_usage/index.ts b/x-pack/test/usage_collection/test_suites/stack_management_usage/index.ts new file mode 100644 index 00000000000000..c52a6c67e29090 --- /dev/null +++ b/x-pack/test/usage_collection/test_suites/stack_management_usage/index.ts @@ -0,0 +1,45 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License; + * you may not use this file except in compliance with the Elastic License. + */ + +import expect from '@kbn/expect'; +import _ from 'lodash'; +import { FtrProviderContext } from '../../ftr_provider_context'; +import { stackManagementSchema } from '../../../../../src/plugins/kibana_usage_collection/server/collectors/management/schema'; + +export default function ({ getService, getPageObjects }: FtrProviderContext) { + describe('Stack Management', function () { + this.tags('ciGroup1'); + const { common } = getPageObjects(['common']); + const browser = getService('browser'); + + let registeredSettings: Record; + + before(async () => { + await common.navigateToApp('home'); // Navigate to Home to make sure all the appIds are loaded + registeredSettings = await browser.execute(() => window.__registeredUiSettings__); + }); + + it('registers all UI Settings in the UsageStats interface', () => { + const unreportedUISettings = Object.keys(registeredSettings) + .filter((key) => key !== 'buildNum') + .filter((key) => typeof _.get(stackManagementSchema, key) === 'undefined'); + + expect(unreportedUISettings).to.eql([]); + }); + + it('registers all sensitive UI settings as boolean type', async () => { + const sensitiveSettings = Object.entries(registeredSettings) + .filter(([, config]) => config.sensitive) + .map(([key]) => key); + + const nonBooleanSensitiveProps = sensitiveSettings + .map((key) => ({ key, ..._.get(stackManagementSchema, key) })) + .filter((keyDescriptor) => keyDescriptor.type !== 'boolean'); + + expect(nonBooleanSensitiveProps).to.eql([]); + }); + }); +}