|
| 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