Skip to content

Commit d970761

Browse files
authored
[7.x] CI Reporter for saved objects field count (#70580) (#70969)
* 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 8c0126b. * 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 <elasticmachine@users.noreply.github.com> # Conflicts: # .github/CODEOWNERS * Don't backport CODEOWNERS file to 7.x
1 parent 0a2dfa6 commit d970761

File tree

4 files changed

+116
-0
lines changed

4 files changed

+116
-0
lines changed

Jenkinsfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ kibanaPipeline(timeoutMinutes: 155, checkPrChanges: true, setCommitStatus: true)
4141
'xpack-ciGroup9': kibanaPipeline.xpackCiGroupProcess(9),
4242
'xpack-ciGroup10': kibanaPipeline.xpackCiGroupProcess(10),
4343
'xpack-accessibility': kibanaPipeline.functionalTestProcess('xpack-accessibility', './test/scripts/jenkins_xpack_accessibility.sh'),
44+
'xpack-savedObjectsFieldMetrics': kibanaPipeline.functionalTestProcess('xpack-savedObjectsFieldMetrics', './test/scripts/jenkins_xpack_saved_objects_field_metrics.sh'),
4445
// 'xpack-pageLoadMetrics': kibanaPipeline.functionalTestProcess('xpack-pageLoadMetrics', './test/scripts/jenkins_xpack_page_load_metrics.sh'),
4546
'xpack-securitySolutionCypress': { processNumber ->
4647
whenChanged(['x-pack/plugins/security_solution/', 'x-pack/test/security_solution_cypress/']) {
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#!/usr/bin/env bash
2+
3+
source test/scripts/jenkins_test_setup_xpack.sh
4+
5+
checks-reporter-with-killswitch "Capture Kibana Saved Objects field count metrics" \
6+
node scripts/functional_tests \
7+
--debug --bail \
8+
--kibana-install-dir "$installDir" \
9+
--config test/saved_objects_field_count/config.ts;
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the Elastic License;
4+
* you may not use this file except in compliance with the Elastic License.
5+
*/
6+
7+
import { FtrConfigProviderContext } from '@kbn/test/types/ftr';
8+
import { testRunner } from './runner';
9+
10+
export default async function ({ readConfigFile }: FtrConfigProviderContext) {
11+
const kibanaCommonTestsConfig = await readConfigFile(
12+
require.resolve('../../../test/common/config.js')
13+
);
14+
15+
return {
16+
...kibanaCommonTestsConfig.getAll(),
17+
18+
testRunner,
19+
20+
esTestCluster: {
21+
license: 'trial',
22+
from: 'snapshot',
23+
serverArgs: ['path.repo=/tmp/'],
24+
},
25+
26+
kbnTestServer: {
27+
...kibanaCommonTestsConfig.get('kbnTestServer'),
28+
serverArgs: [
29+
...kibanaCommonTestsConfig.get('kbnTestServer.serverArgs'),
30+
// Enable plugins that are disabled by default to include their metrics
31+
// TODO: Find a way to automatically enable all discovered plugins
32+
'--xpack.ingestManager.enabled=true',
33+
'--xpack.lists.enabled=true',
34+
'--xpack.securitySolution.enabled=true',
35+
],
36+
},
37+
};
38+
}
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the Elastic License;
4+
* you may not use this file except in compliance with the Elastic License.
5+
*/
6+
7+
import { CiStatsReporter } from '@kbn/dev-utils';
8+
import { FtrProviderContext } from './../functional/ftr_provider_context';
9+
10+
const IGNORED_FIELDS = [
11+
// The following fields are returned by the _field_caps API but aren't counted
12+
// towards the index field limit.
13+
'_seq_no',
14+
'_id',
15+
'_version',
16+
'_field_names',
17+
'_ignored',
18+
'_feature',
19+
'_index',
20+
'_routing',
21+
'_source',
22+
'_type',
23+
'_nested_path',
24+
'_timestamp',
25+
// migrationVersion is dynamic so will be anywhere between 1..type count
26+
// depending on which objects are present in the index when querying the
27+
// field caps API. See https://github.com/elastic/kibana/issues/70815
28+
'migrationVersion',
29+
];
30+
31+
export async function testRunner({ getService }: FtrProviderContext) {
32+
const log = getService('log');
33+
const es = getService('es');
34+
35+
const reporter = CiStatsReporter.fromEnv(log);
36+
37+
log.debug('Saved Objects field count metrics starting');
38+
39+
const {
40+
body: { fields },
41+
} = await es.fieldCaps({
42+
index: '.kibana',
43+
fields: '*',
44+
});
45+
46+
const fieldCountPerTypeMap: Map<string, number> = Object.keys(fields)
47+
.map((f) => f.split('.')[0])
48+
.filter((f) => !IGNORED_FIELDS.includes(f))
49+
.reduce((accumulator, f) => {
50+
accumulator.set(f, accumulator.get(f) + 1 || 1);
51+
return accumulator;
52+
}, new Map());
53+
54+
const metrics = Array.from(fieldCountPerTypeMap.entries())
55+
.sort((a, b) => a[0].localeCompare(b[0]))
56+
.map(([fieldType, count]) => ({
57+
group: 'Saved Objects .kibana field count',
58+
id: fieldType,
59+
value: count,
60+
}));
61+
62+
log.debug(
63+
'Saved Objects field count metrics:\n',
64+
metrics.map(({ id, value }) => `${id}:${value}`).join('\n')
65+
);
66+
await reporter.metrics(metrics);
67+
log.debug('Saved Objects field count metrics done');
68+
}

0 commit comments

Comments
 (0)