From 2f905e7d867f16898de2bf63bb2c8bb4fcb6666e Mon Sep 17 00:00:00 2001 From: Rudolf Meijering Date: Tue, 7 Jul 2020 16:53:47 +0200 Subject: [PATCH] CI Reporter for saved objects field count (#70580) * CI Reporter for saved objects field count * Metrics needs to be an array * Fix type failures * Link to field count issue * Revert "Link to field count issue" This reverts commit 8c0126b838c54a18efc9e200dc10842166468934. * Break down field count per type * Don't log total metric as metrics report already calculates this * Add saved objects field count ci metrics test to codeowners * Address review comments * Add field count CI metrics for disabled plugins Co-authored-by: Elastic Machine --- .github/CODEOWNERS | 1 + Jenkinsfile | 1 + ...nkins_xpack_saved_objects_field_metrics.sh | 9 +++ .../test/saved_objects_field_count/config.ts | 38 +++++++++++ .../test/saved_objects_field_count/runner.ts | 68 +++++++++++++++++++ 5 files changed, 117 insertions(+) create mode 100755 test/scripts/jenkins_xpack_saved_objects_field_metrics.sh create mode 100644 x-pack/test/saved_objects_field_count/config.ts create mode 100644 x-pack/test/saved_objects_field_count/runner.ts diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS index bec0a0a33bad2..4aab9943022d4 100644 --- a/.github/CODEOWNERS +++ b/.github/CODEOWNERS @@ -144,6 +144,7 @@ /x-pack/plugins/licensing/ @elastic/kibana-platform /x-pack/plugins/global_search/ @elastic/kibana-platform /x-pack/plugins/cloud/ @elastic/kibana-platform +/x-pack/test/saved_objects_field_count/ @elastic/kibana-platform /packages/kbn-config-schema/ @elastic/kibana-platform /src/legacy/server/config/ @elastic/kibana-platform /src/legacy/server/http/ @elastic/kibana-platform diff --git a/Jenkinsfile b/Jenkinsfile index 7869fa68788bd..f6f77ccae8427 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -41,6 +41,7 @@ kibanaPipeline(timeoutMinutes: 155, checkPrChanges: true, setCommitStatus: true) 'xpack-ciGroup9': kibanaPipeline.xpackCiGroupProcess(9), 'xpack-ciGroup10': kibanaPipeline.xpackCiGroupProcess(10), 'xpack-accessibility': kibanaPipeline.functionalTestProcess('xpack-accessibility', './test/scripts/jenkins_xpack_accessibility.sh'), + 'xpack-savedObjectsFieldMetrics': kibanaPipeline.functionalTestProcess('xpack-savedObjectsFieldMetrics', './test/scripts/jenkins_xpack_saved_objects_field_metrics.sh'), // 'xpack-pageLoadMetrics': kibanaPipeline.functionalTestProcess('xpack-pageLoadMetrics', './test/scripts/jenkins_xpack_page_load_metrics.sh'), 'xpack-securitySolutionCypress': { processNumber -> whenChanged(['x-pack/plugins/security_solution/', 'x-pack/test/security_solution_cypress/']) { diff --git a/test/scripts/jenkins_xpack_saved_objects_field_metrics.sh b/test/scripts/jenkins_xpack_saved_objects_field_metrics.sh new file mode 100755 index 0000000000000..d3ca8839a7dab --- /dev/null +++ b/test/scripts/jenkins_xpack_saved_objects_field_metrics.sh @@ -0,0 +1,9 @@ +#!/usr/bin/env bash + +source test/scripts/jenkins_test_setup_xpack.sh + +checks-reporter-with-killswitch "Capture Kibana Saved Objects field count metrics" \ + node scripts/functional_tests \ + --debug --bail \ + --kibana-install-dir "$installDir" \ + --config test/saved_objects_field_count/config.ts; diff --git a/x-pack/test/saved_objects_field_count/config.ts b/x-pack/test/saved_objects_field_count/config.ts new file mode 100644 index 0000000000000..a0e9f7a62e2c9 --- /dev/null +++ b/x-pack/test/saved_objects_field_count/config.ts @@ -0,0 +1,38 @@ +/* + * 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 { FtrConfigProviderContext } from '@kbn/test/types/ftr'; +import { testRunner } from './runner'; + +export default async function ({ readConfigFile }: FtrConfigProviderContext) { + const kibanaCommonTestsConfig = await readConfigFile( + require.resolve('../../../test/common/config.js') + ); + + return { + ...kibanaCommonTestsConfig.getAll(), + + testRunner, + + esTestCluster: { + license: 'trial', + from: 'snapshot', + serverArgs: ['path.repo=/tmp/'], + }, + + kbnTestServer: { + ...kibanaCommonTestsConfig.get('kbnTestServer'), + serverArgs: [ + ...kibanaCommonTestsConfig.get('kbnTestServer.serverArgs'), + // Enable plugins that are disabled by default to include their metrics + // TODO: Find a way to automatically enable all discovered plugins + '--xpack.ingestManager.enabled=true', + '--xpack.lists.enabled=true', + '--xpack.securitySolution.enabled=true', + ], + }, + }; +} diff --git a/x-pack/test/saved_objects_field_count/runner.ts b/x-pack/test/saved_objects_field_count/runner.ts new file mode 100644 index 0000000000000..cfcfe61697299 --- /dev/null +++ b/x-pack/test/saved_objects_field_count/runner.ts @@ -0,0 +1,68 @@ +/* + * 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 { CiStatsReporter } from '@kbn/dev-utils'; +import { FtrProviderContext } from './../functional/ftr_provider_context'; + +const IGNORED_FIELDS = [ + // The following fields are returned by the _field_caps API but aren't counted + // towards the index field limit. + '_seq_no', + '_id', + '_version', + '_field_names', + '_ignored', + '_feature', + '_index', + '_routing', + '_source', + '_type', + '_nested_path', + '_timestamp', + // migrationVersion is dynamic so will be anywhere between 1..type count + // depending on which objects are present in the index when querying the + // field caps API. See https://github.com/elastic/kibana/issues/70815 + 'migrationVersion', +]; + +export async function testRunner({ getService }: FtrProviderContext) { + const log = getService('log'); + const es = getService('es'); + + const reporter = CiStatsReporter.fromEnv(log); + + log.debug('Saved Objects field count metrics starting'); + + const { + body: { fields }, + } = await es.fieldCaps({ + index: '.kibana', + fields: '*', + }); + + const fieldCountPerTypeMap: Map = Object.keys(fields) + .map((f) => f.split('.')[0]) + .filter((f) => !IGNORED_FIELDS.includes(f)) + .reduce((accumulator, f) => { + accumulator.set(f, accumulator.get(f) + 1 || 1); + return accumulator; + }, new Map()); + + const metrics = Array.from(fieldCountPerTypeMap.entries()) + .sort((a, b) => a[0].localeCompare(b[0])) + .map(([fieldType, count]) => ({ + group: 'Saved Objects .kibana field count', + id: fieldType, + value: count, + })); + + log.debug( + 'Saved Objects field count metrics:\n', + metrics.map(({ id, value }) => `${id}:${value}`).join('\n') + ); + await reporter.metrics(metrics); + log.debug('Saved Objects field count metrics done'); +}