From f6924439cf4d2df8cf18623ce36f4d291a8d2ce8 Mon Sep 17 00:00:00 2001 From: Matthew Kime Date: Mon, 30 May 2022 09:45:36 -0500 Subject: [PATCH] [data views] Remove fields for time pattern functionality (#133075) * remove fields for time pattern functionality --- src/plugins/data/common/index.ts | 1 - src/plugins/data_views/common/index.ts | 1 - src/plugins/data_views/common/types.ts | 8 - .../data_views/data_views_api_client.test.ts | 13 -- .../data_views/data_views_api_client.ts | 14 +- .../server/fetcher/index_patterns_fetcher.ts | 31 ---- .../data_views/server/fetcher/lib/index.ts | 1 - .../fetcher/lib/resolve_time_pattern.test.js | 110 ------------- .../fetcher/lib/resolve_time_pattern.ts | 67 -------- .../lib/time_pattern_to_wildcard.test.ts | 27 ---- .../fetcher/lib/time_pattern_to_wildcard.ts | 51 ------ .../server/index_patterns_api_client.ts | 10 +- src/plugins/data_views/server/routes.ts | 58 ------- .../fields_for_time_pattern_route/errors.js | 22 --- .../fields_for_time_pattern_route/index.js | 15 -- .../fields_for_time_pattern_route/pattern.js | 148 ------------------ .../query_params.js | 93 ----------- .../apis/index_patterns/index.js | 1 - 18 files changed, 2 insertions(+), 669 deletions(-) delete mode 100644 src/plugins/data_views/server/fetcher/lib/resolve_time_pattern.test.js delete mode 100644 src/plugins/data_views/server/fetcher/lib/resolve_time_pattern.ts delete mode 100644 src/plugins/data_views/server/fetcher/lib/time_pattern_to_wildcard.test.ts delete mode 100644 src/plugins/data_views/server/fetcher/lib/time_pattern_to_wildcard.ts delete mode 100644 test/api_integration/apis/index_patterns/fields_for_time_pattern_route/errors.js delete mode 100644 test/api_integration/apis/index_patterns/fields_for_time_pattern_route/index.js delete mode 100644 test/api_integration/apis/index_patterns/fields_for_time_pattern_route/pattern.js delete mode 100644 test/api_integration/apis/index_patterns/fields_for_time_pattern_route/query_params.js diff --git a/src/plugins/data/common/index.ts b/src/plugins/data/common/index.ts index 93a710c38d0c1..dd9c9000adb28 100644 --- a/src/plugins/data/common/index.ts +++ b/src/plugins/data/common/index.ts @@ -116,7 +116,6 @@ export type { SavedObjectsClientCommonFindArgs, SavedObjectsClientCommon, GetFieldsOptions, - GetFieldsOptionsTimePattern, IDataViewsApiClient, SavedObject, AggregationRestrictions, diff --git a/src/plugins/data_views/common/index.ts b/src/plugins/data_views/common/index.ts index 13842b62a9d53..aa60fd3414056 100644 --- a/src/plugins/data_views/common/index.ts +++ b/src/plugins/data_views/common/index.ts @@ -40,7 +40,6 @@ export type { SavedObjectsClientCommonFindArgs, SavedObjectsClientCommon, GetFieldsOptions, - GetFieldsOptionsTimePattern, IDataViewsApiClient, SavedObject, AggregationRestrictions, diff --git a/src/plugins/data_views/common/types.ts b/src/plugins/data_views/common/types.ts index f4bed383d8447..5c4c77a46808d 100644 --- a/src/plugins/data_views/common/types.ts +++ b/src/plugins/data_views/common/types.ts @@ -168,15 +168,7 @@ export interface GetFieldsOptions { filter?: QueryDslQueryContainer; } -export interface GetFieldsOptionsTimePattern { - pattern: string; - metaFields: string[]; - lookBack: number; - interval: string; -} - export interface IDataViewsApiClient { - getFieldsForTimePattern: (options: GetFieldsOptionsTimePattern) => Promise; getFieldsForWildcard: (options: GetFieldsOptions) => Promise; hasUserIndexPattern: () => Promise; } diff --git a/src/plugins/data_views/public/data_views/data_views_api_client.test.ts b/src/plugins/data_views/public/data_views/data_views_api_client.test.ts index 09ee001c218b5..9f8274cc6c8d7 100644 --- a/src/plugins/data_views/public/data_views/data_views_api_client.test.ts +++ b/src/plugins/data_views/public/data_views/data_views_api_client.test.ts @@ -18,19 +18,6 @@ describe('IndexPatternsApiClient', () => { indexPatternsApiClient = new DataViewsApiClient(http); }); - test('uses the right URI to fetch fields for time patterns', async function () { - const expectedPath = '/api/index_patterns/_fields_for_time_pattern'; - - await indexPatternsApiClient.getFieldsForTimePattern({ - pattern: 'blah', - metaFields: [], - lookBack: 5, - interval: '', - }); - - expect(fetchSpy).toHaveBeenCalledWith(expectedPath, expect.any(Object)); - }); - test('uses the right URI to fetch fields for wildcard', async function () { const expectedPath = '/api/index_patterns/_fields_for_wildcard'; diff --git a/src/plugins/data_views/public/data_views/data_views_api_client.ts b/src/plugins/data_views/public/data_views/data_views_api_client.ts index 42aa03882de58..fdf24e21c2e01 100644 --- a/src/plugins/data_views/public/data_views/data_views_api_client.ts +++ b/src/plugins/data_views/public/data_views/data_views_api_client.ts @@ -8,7 +8,7 @@ import { HttpSetup } from '@kbn/core/public'; import { DataViewMissingIndices } from '../../common/lib'; -import { GetFieldsOptions, IDataViewsApiClient, GetFieldsOptionsTimePattern } from '../../common'; +import { GetFieldsOptions, IDataViewsApiClient } from '../../common'; const API_BASE_URL: string = `/api/index_patterns/`; @@ -37,18 +37,6 @@ export class DataViewsApiClient implements IDataViewsApiClient { return API_BASE_URL + path.filter(Boolean).map(encodeURIComponent).join('/'); } - getFieldsForTimePattern(options: GetFieldsOptionsTimePattern) { - const { pattern, lookBack, metaFields } = options; - - const url = this._getUrl(['_fields_for_time_pattern']); - - return this._request(url, { - pattern, - look_back: lookBack, - meta_fields: metaFields, - }).then((resp: any) => resp.fields); - } - getFieldsForWildcard({ pattern, metaFields, diff --git a/src/plugins/data_views/server/fetcher/index_patterns_fetcher.ts b/src/plugins/data_views/server/fetcher/index_patterns_fetcher.ts index ceb01333c5ff0..9d3b8a180d91e 100644 --- a/src/plugins/data_views/server/fetcher/index_patterns_fetcher.ts +++ b/src/plugins/data_views/server/fetcher/index_patterns_fetcher.ts @@ -12,8 +12,6 @@ import type { QueryDslQueryContainer } from '../../common/types'; import { getFieldCapabilities, - resolveTimePattern, - createNoMatchingIndicesError, getCapabilitiesForRollupIndices, mergeCapabilitiesWithFields, } from './lib'; @@ -101,35 +99,6 @@ export class IndexPatternsFetcher { return fieldCapsResponse; } - /** - * Get a list of field objects for a time pattern - * - * @param {Object} [options={}] - * @property {String} options.pattern The moment compatible time pattern - * @property {Number} options.lookBack The number of indices we will pull mappings for - * @property {Number} options.metaFields The list of underscore prefixed fields that should - * be left in the field list (all others are removed). - * @return {Promise>} - */ - async getFieldsForTimePattern(options: { - pattern: string; - metaFields: string[]; - lookBack: number; - interval: string; - }) { - const { pattern, lookBack, metaFields } = options; - const { matches } = await resolveTimePattern(this.elasticsearchClient, pattern); - const indices = matches.slice(0, lookBack); - if (indices.length === 0) { - throw createNoMatchingIndicesError(pattern); - } - return await getFieldCapabilities({ - callCluster: this.elasticsearchClient, - indices, - metaFields, - }); - } - /** * Returns an index pattern list of only those index pattern strings in the given list that return indices * diff --git a/src/plugins/data_views/server/fetcher/lib/index.ts b/src/plugins/data_views/server/fetcher/lib/index.ts index af6c99cd02022..0437c08793a31 100644 --- a/src/plugins/data_views/server/fetcher/lib/index.ts +++ b/src/plugins/data_views/server/fetcher/lib/index.ts @@ -7,7 +7,6 @@ */ export { getFieldCapabilities, shouldReadFieldFromDocValues } from './field_capabilities'; -export { resolveTimePattern } from './resolve_time_pattern'; export { createNoMatchingIndicesError } from './errors'; export * from './merge_capabilities_with_fields'; export * from './map_capabilities'; diff --git a/src/plugins/data_views/server/fetcher/lib/resolve_time_pattern.test.js b/src/plugins/data_views/server/fetcher/lib/resolve_time_pattern.test.js deleted file mode 100644 index e71022bfe6b26..0000000000000 --- a/src/plugins/data_views/server/fetcher/lib/resolve_time_pattern.test.js +++ /dev/null @@ -1,110 +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 - * 2.0 and the Server Side Public License, v 1; you may not use this file except - * in compliance with, at your election, the Elastic License 2.0 or the Server - * Side Public License, v 1. - */ - -/* eslint import/no-duplicates: 0 */ -import sinon from 'sinon'; -import { noop } from 'lodash'; - -import { callIndexAliasApi } from './es_api'; -import * as callIndexAliasApiNS from './es_api'; -import { timePatternToWildcard } from './time_pattern_to_wildcard'; -import * as timePatternToWildcardNS from './time_pattern_to_wildcard'; - -import { resolveTimePattern } from './resolve_time_pattern'; - -const TIME_PATTERN = '[logs-]dddd-YYYY.w'; - -describe('server/index_patterns/service/lib/resolve_time_pattern', () => { - let sandbox; - const esClientMock = { - indices: { - getAlias: () => ({}), - }, - }; - beforeEach(() => (sandbox = sinon.createSandbox())); - afterEach(() => sandbox.restore()); - - describe('resolveTimePattern()', () => { - describe('pre request', () => { - it('uses callIndexAliasApi() fn', async () => { - sandbox.stub(callIndexAliasApiNS, 'callIndexAliasApi').returns({}); - await resolveTimePattern(esClientMock, TIME_PATTERN); - sinon.assert.calledOnce(callIndexAliasApi); - }); - - it('converts the time pattern to a wildcard with timePatternToWildcard', async () => { - const timePattern = {}; - const wildcard = {}; - - sandbox.stub(timePatternToWildcardNS, 'timePatternToWildcard').returns(wildcard); - - await resolveTimePattern(esClientMock, timePattern); - sinon.assert.calledOnce(timePatternToWildcard); - expect(timePatternToWildcard.firstCall.args).toEqual([timePattern]); - }); - - it('passes the converted wildcard as the index to callIndexAliasApi()', async () => { - const timePattern = {}; - const wildcard = {}; - - sandbox.stub(callIndexAliasApiNS, 'callIndexAliasApi').returns({}); - sandbox.stub(timePatternToWildcardNS, 'timePatternToWildcard').returns(wildcard); - - await resolveTimePattern(esClientMock, timePattern); - sinon.assert.calledOnce(callIndexAliasApi); - expect(callIndexAliasApi.firstCall.args[1]).toBe(wildcard); - }); - }); - - describe('read response', () => { - it('returns all aliases names in result.all, ordered by time desc', async () => { - sandbox.stub(callIndexAliasApiNS, 'callIndexAliasApi').returns({ - 'logs-2016.2': {}, - 'logs-Saturday-2017.1': {}, - 'logs-2016.1': {}, - 'logs-Sunday-2017.1': {}, - 'logs-2015': {}, - 'logs-2016.3': {}, - 'logs-Friday-2017.1': {}, - }); - - const resp = await resolveTimePattern(noop, TIME_PATTERN); - expect(resp).toHaveProperty('all'); - expect(resp.all).toEqual([ - 'logs-Saturday-2017.1', - 'logs-Friday-2017.1', - 'logs-Sunday-2017.1', - 'logs-2016.3', - 'logs-2016.2', - 'logs-2016.1', - 'logs-2015', - ]); - }); - - it('returns all indices matching the time pattern in matches, ordered by time desc', async () => { - sandbox.stub(callIndexAliasApiNS, 'callIndexAliasApi').returns({ - 'logs-2016.2': {}, - 'logs-Saturday-2017.1': {}, - 'logs-2016.1': {}, - 'logs-Sunday-2017.1': {}, - 'logs-2015': {}, - 'logs-2016.3': {}, - 'logs-Friday-2017.1': {}, - }); - - const resp = await resolveTimePattern(noop, TIME_PATTERN); - expect(resp).toHaveProperty('matches'); - expect(resp.matches).toEqual([ - 'logs-Saturday-2017.1', - 'logs-Friday-2017.1', - 'logs-Sunday-2017.1', - ]); - }); - }); - }); -}); diff --git a/src/plugins/data_views/server/fetcher/lib/resolve_time_pattern.ts b/src/plugins/data_views/server/fetcher/lib/resolve_time_pattern.ts deleted file mode 100644 index f0da3c6dffeaa..0000000000000 --- a/src/plugins/data_views/server/fetcher/lib/resolve_time_pattern.ts +++ /dev/null @@ -1,67 +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 - * 2.0 and the Server Side Public License, v 1; you may not use this file except - * in compliance with, at your election, the Elastic License 2.0 or the Server - * Side Public License, v 1. - */ - -import { chain } from 'lodash'; -import moment from 'moment'; - -import { ElasticsearchClient } from '@kbn/core/server'; - -import { timePatternToWildcard } from './time_pattern_to_wildcard'; -import { callIndexAliasApi } from './es_api'; - -/** - * Convert a time pattern into a list of indexes it could - * have matched and ones it did match. - * - * @param {Function} callCluster bound function for accessing an es client - * @param {String} timePattern - * @return {Promise} object that lists the indices that match based - * on a wildcard version of the time pattern (all) - * and the indices that actually match the time - * pattern (matches); - */ -export async function resolveTimePattern(callCluster: ElasticsearchClient, timePattern: string) { - const aliases = await callIndexAliasApi(callCluster, timePatternToWildcard(timePattern)); - - const allIndexDetails = chain(aliases) - .reduce( - (acc: string[], index: any, indexName: string) => - acc.concat(indexName, Object.keys(index.aliases || {})), - [] - ) - .sortBy((indexName: string) => indexName) - .sortedUniq() - .map((indexName) => { - const parsed = moment(indexName, timePattern, true); - if (!parsed.isValid()) { - return { - valid: false, - indexName, - order: indexName, - isMatch: false, - }; - } - - return { - valid: true, - indexName, - order: parsed, - isMatch: indexName === parsed.format(timePattern), - }; - }) - .orderBy(['valid', 'order'], ['desc', 'desc']) - .value(); - - return { - all: allIndexDetails.map((details) => details.indexName), - - matches: allIndexDetails - .filter((details) => details.isMatch) - .map((details) => details.indexName), - }; -} diff --git a/src/plugins/data_views/server/fetcher/lib/time_pattern_to_wildcard.test.ts b/src/plugins/data_views/server/fetcher/lib/time_pattern_to_wildcard.test.ts deleted file mode 100644 index 86d8e9830d569..0000000000000 --- a/src/plugins/data_views/server/fetcher/lib/time_pattern_to_wildcard.test.ts +++ /dev/null @@ -1,27 +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 - * 2.0 and the Server Side Public License, v 1; you may not use this file except - * in compliance with, at your election, the Elastic License 2.0 or the Server - * Side Public License, v 1. - */ - -import { timePatternToWildcard } from './time_pattern_to_wildcard'; - -describe('server/index_patterns/service/lib/time_pattern_to_wildcard', () => { - const tests = [ - ['[logstash-]YYYY.MM.DD', 'logstash-*'], - ['YYYY[-department-].w', '*-department-*'], - ['YYYY.MM[.department].w', '*.department*'], - ['YYYY.MM.[department].w[-old]', '*department*-old'], - ]; - - tests.forEach(([input, expected]) => { - it(`parses ${input}`, () => { - const output = timePatternToWildcard(input); - if (output !== expected) { - throw new Error(`expected ${input} to parse to ${expected} but got ${output}`); - } - }); - }); -}); diff --git a/src/plugins/data_views/server/fetcher/lib/time_pattern_to_wildcard.ts b/src/plugins/data_views/server/fetcher/lib/time_pattern_to_wildcard.ts deleted file mode 100644 index e41fd2ec99e85..0000000000000 --- a/src/plugins/data_views/server/fetcher/lib/time_pattern_to_wildcard.ts +++ /dev/null @@ -1,51 +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 - * 2.0 and the Server Side Public License, v 1; you may not use this file except - * in compliance with, at your election, the Elastic License 2.0 or the Server - * Side Public License, v 1. - */ - -/** - * Convert a moment time pattern to an index wildcard - * by extracting all of the "plain text" component and - * replacing all moment pattern components with "*" - * - * @param {String} timePattern - * @return {String} - */ -export function timePatternToWildcard(timePattern: string) { - let wildcard = ''; - let inEscape = false; - let inPattern = false; - - for (let i = 0; i < timePattern.length; i++) { - const ch = timePattern.charAt(i); - switch (ch) { - case '[': - inPattern = false; - if (!inEscape) { - inEscape = true; - } else { - wildcard += ch; - } - break; - case ']': - if (inEscape) { - inEscape = false; - } else if (!inPattern) { - wildcard += ch; - } - break; - default: - if (inEscape) { - wildcard += ch; - } else if (!inPattern) { - wildcard += '*'; - inPattern = true; - } - } - } - - return wildcard; -} diff --git a/src/plugins/data_views/server/index_patterns_api_client.ts b/src/plugins/data_views/server/index_patterns_api_client.ts index d4b4118e06bc8..81003f6bfb60a 100644 --- a/src/plugins/data_views/server/index_patterns_api_client.ts +++ b/src/plugins/data_views/server/index_patterns_api_client.ts @@ -7,11 +7,7 @@ */ import { ElasticsearchClient, SavedObjectsClientContract } from '@kbn/core/server'; -import { - GetFieldsOptions, - GetFieldsOptionsTimePattern, - IDataViewsApiClient, -} from '../common/types'; +import { GetFieldsOptions, IDataViewsApiClient } from '../common/types'; import { DataViewMissingIndices } from '../common/lib'; import { IndexPatternsFetcher } from './fetcher'; import { hasUserIndexPattern } from './has_user_index_pattern'; @@ -52,10 +48,6 @@ export class IndexPatternsApiServer implements IDataViewsApiClient { } }); } - async getFieldsForTimePattern(options: GetFieldsOptionsTimePattern) { - const indexPatterns = new IndexPatternsFetcher(this.esClient); - return await indexPatterns.getFieldsForTimePattern(options); - } async hasUserIndexPattern() { return hasUserIndexPattern({ diff --git a/src/plugins/data_views/server/routes.ts b/src/plugins/data_views/server/routes.ts index 8f6299a58870a..8e5cec0316027 100644 --- a/src/plugins/data_views/server/routes.ts +++ b/src/plugins/data_views/server/routes.ts @@ -6,10 +6,8 @@ * Side Public License, v 1. */ -import { schema } from '@kbn/config-schema'; import { HttpServiceSetup, StartServicesAccessor } from '@kbn/core/server'; import { UsageCounter } from '@kbn/usage-collection-plugin/server'; -import { IndexPatternsFetcher } from './fetcher'; import { routes } from './rest_api_routes'; import type { DataViewsServerPluginStart, DataViewsServerPluginStartDependencies } from './types'; @@ -24,66 +22,10 @@ export function registerRoutes( >, dataViewRestCounter?: UsageCounter ) { - const parseMetaFields = (metaFields: string | string[]) => { - let parsedFields: string[] = []; - if (typeof metaFields === 'string') { - parsedFields = JSON.parse(metaFields); - } else { - parsedFields = metaFields; - } - return parsedFields; - }; - const router = http.createRouter(); routes.forEach((route) => route(router, getStartServices, dataViewRestCounter)); registerFieldForWildcard(router, getStartServices); registerHasDataViewsRoute(router); - - router.get( - { - path: '/api/index_patterns/_fields_for_time_pattern', - validate: { - query: schema.object({ - pattern: schema.string(), - interval: schema.maybe(schema.string()), - look_back: schema.number({ min: 1 }), - meta_fields: schema.oneOf([schema.string(), schema.arrayOf(schema.string())], { - defaultValue: [], - }), - }), - }, - }, - async (context, request, response) => { - const { asCurrentUser } = (await context.core).elasticsearch.client; - const indexPatterns = new IndexPatternsFetcher(asCurrentUser); - const { pattern, interval, look_back: lookBack, meta_fields: metaFields } = request.query; - - let parsedFields: string[] = []; - try { - parsedFields = parseMetaFields(metaFields); - } catch (error) { - return response.badRequest(); - } - - try { - const fields = await indexPatterns.getFieldsForTimePattern({ - pattern, - interval: interval ? interval : '', - lookBack, - metaFields: parsedFields, - }); - - return response.ok({ - body: { fields }, - headers: { - 'content-type': 'application/json', - }, - }); - } catch (error) { - return response.notFound(); - } - } - ); } diff --git a/test/api_integration/apis/index_patterns/fields_for_time_pattern_route/errors.js b/test/api_integration/apis/index_patterns/fields_for_time_pattern_route/errors.js deleted file mode 100644 index d5859c0653940..0000000000000 --- a/test/api_integration/apis/index_patterns/fields_for_time_pattern_route/errors.js +++ /dev/null @@ -1,22 +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 - * 2.0 and the Server Side Public License, v 1; you may not use this file except - * in compliance with, at your election, the Elastic License 2.0 or the Server - * Side Public License, v 1. - */ - -export default function ({ getService }) { - const supertest = getService('supertest'); - - describe('errors', () => { - it('returns 404 when no indices match', () => - supertest - .get('/api/index_patterns/_fields_for_time_pattern') - .query({ - pattern: '[not-really-an-index-]YYYY.MM.DD', - look_back: 1, - }) - .expect(404)); - }); -} diff --git a/test/api_integration/apis/index_patterns/fields_for_time_pattern_route/index.js b/test/api_integration/apis/index_patterns/fields_for_time_pattern_route/index.js deleted file mode 100644 index 7da06392a1190..0000000000000 --- a/test/api_integration/apis/index_patterns/fields_for_time_pattern_route/index.js +++ /dev/null @@ -1,15 +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 - * 2.0 and the Server Side Public License, v 1; you may not use this file except - * in compliance with, at your election, the Elastic License 2.0 or the Server - * Side Public License, v 1. - */ - -export default function ({ loadTestFile }) { - describe('index_patterns/_fields_for_time_pattern', () => { - loadTestFile(require.resolve('./errors')); - loadTestFile(require.resolve('./pattern')); - loadTestFile(require.resolve('./query_params')); - }); -} diff --git a/test/api_integration/apis/index_patterns/fields_for_time_pattern_route/pattern.js b/test/api_integration/apis/index_patterns/fields_for_time_pattern_route/pattern.js deleted file mode 100644 index da04e7c9f4b75..0000000000000 --- a/test/api_integration/apis/index_patterns/fields_for_time_pattern_route/pattern.js +++ /dev/null @@ -1,148 +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 - * 2.0 and the Server Side Public License, v 1; you may not use this file except - * in compliance with, at your election, the Elastic License 2.0 or the Server - * Side Public License, v 1. - */ - -import expect from '@kbn/expect'; - -export default function ({ getService }) { - const supertest = getService('supertest'); - const esArchiver = getService('esArchiver'); - - describe('pattern', () => { - before(() => - esArchiver.load('test/api_integration/fixtures/es_archiver/index_patterns/daily_index') - ); - after(() => - esArchiver.unload('test/api_integration/fixtures/es_archiver/index_patterns/daily_index') - ); - - it('matches indices with compatible patterns', () => - supertest - .get('/api/index_patterns/_fields_for_time_pattern') - .query({ - pattern: '[logs-]YYYY.MM.DD', - look_back: 2, - }) - .expect(200) - .then((resp) => { - expect(resp.body).to.eql({ - fields: [ - { - name: '@timestamp', - type: 'date', - esTypes: ['date'], - aggregatable: true, - searchable: true, - readFromDocValues: true, - metadata_field: false, - }, - { - name: 'Jan01', - type: 'boolean', - esTypes: ['boolean'], - aggregatable: true, - searchable: true, - readFromDocValues: true, - metadata_field: false, - }, - { - name: 'Jan02', - type: 'boolean', - esTypes: ['boolean'], - aggregatable: true, - searchable: true, - readFromDocValues: true, - metadata_field: false, - }, - ], - }); - })); - - it('respects look_back parameter', () => - supertest - .get('/api/index_patterns/_fields_for_time_pattern') - .query({ - pattern: '[logs-]YYYY.MM.DD', - look_back: 1, - }) - .expect(200) - .then((resp) => { - expect(resp.body).to.eql({ - fields: [ - { - name: '@timestamp', - type: 'date', - esTypes: ['date'], - aggregatable: true, - searchable: true, - readFromDocValues: true, - metadata_field: false, - }, - { - name: 'Jan02', - type: 'boolean', - esTypes: ['boolean'], - aggregatable: true, - searchable: true, - readFromDocValues: true, - metadata_field: false, - }, - ], - }); - })); - - it('includes a field for each of `meta_fields` names', () => - supertest - .get('/api/index_patterns/_fields_for_time_pattern') - .query({ - pattern: '[logs-]YYYY.MM.DD', - look_back: 1, - meta_fields: JSON.stringify(['meta1', 'meta2']), - }) - .expect(200) - .then((resp) => { - expect(resp.body).to.eql({ - fields: [ - { - name: '@timestamp', - type: 'date', - esTypes: ['date'], - aggregatable: true, - searchable: true, - readFromDocValues: true, - metadata_field: false, - }, - { - name: 'Jan02', - type: 'boolean', - esTypes: ['boolean'], - aggregatable: true, - searchable: true, - readFromDocValues: true, - metadata_field: false, - }, - { - name: 'meta1', - type: 'string', - aggregatable: false, - searchable: false, - readFromDocValues: false, - metadata_field: true, - }, - { - name: 'meta2', - type: 'string', - aggregatable: false, - searchable: false, - readFromDocValues: false, - metadata_field: true, - }, - ], - }); - })); - }); -} diff --git a/test/api_integration/apis/index_patterns/fields_for_time_pattern_route/query_params.js b/test/api_integration/apis/index_patterns/fields_for_time_pattern_route/query_params.js deleted file mode 100644 index 481f433deeb73..0000000000000 --- a/test/api_integration/apis/index_patterns/fields_for_time_pattern_route/query_params.js +++ /dev/null @@ -1,93 +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 - * 2.0 and the Server Side Public License, v 1; you may not use this file except - * in compliance with, at your election, the Elastic License 2.0 or the Server - * Side Public License, v 1. - */ - -import expect from '@kbn/expect'; - -export default function ({ getService }) { - const supertest = getService('supertest'); - const esArchiver = getService('esArchiver'); - - describe('query params', () => { - before(() => - esArchiver.load('test/api_integration/fixtures/es_archiver/index_patterns/daily_index') - ); - after(() => - esArchiver.unload('test/api_integration/fixtures/es_archiver/index_patterns/daily_index') - ); - - it('requires `pattern` query param', () => - supertest - .get('/api/index_patterns/_fields_for_time_pattern') - .query({ look_back: 1 }) - .expect(400) - .then((resp) => { - expect(resp.body.message).to.contain( - '[request query.pattern]: expected value of type [string] but got [undefined]' - ); - })); - - it('requires `look_back` query param', () => - supertest - .get('/api/index_patterns/_fields_for_time_pattern') - .query({ pattern: 'pattern-*' }) - .expect(400) - .then((resp) => { - expect(resp.body.message).to.contain( - '[request query.look_back]: expected value of type [number] but got [undefined]' - ); - })); - - it('supports `meta_fields` query param in JSON format', () => - supertest - .get('/api/index_patterns/_fields_for_time_pattern') - .query({ - pattern: '[logs-]YYYY.MM.DD', - look_back: 1, - meta_fields: JSON.stringify(['a']), - }) - .expect(200)); - - it('supports `meta_fields` query param in string array format', () => - supertest - .get('/api/index_patterns/_fields_for_time_pattern') - .query({ - pattern: '[logs-]YYYY.MM.DD', - look_back: 1, - meta_fields: ['a', 'b'], - }) - .expect(200)); - - it('requires `look_back` to be a number', () => - supertest - .get('/api/index_patterns/_fields_for_time_pattern') - .query({ - pattern: '[logs-]YYYY.MM.DD', - look_back: 'foo', - }) - .expect(400) - .then((resp) => { - expect(resp.body.message).to.contain( - '[request query.look_back]: expected value of type [number] but got [string]' - ); - })); - - it('requires `look_back` to be greater than one', () => - supertest - .get('/api/index_patterns/_fields_for_time_pattern') - .query({ - pattern: '[logs-]YYYY.MM.DD', - look_back: 0, - }) - .expect(400) - .then((resp) => { - expect(resp.body.message).to.contain( - '[request query.look_back]: Value must be equal to or greater than [1].' - ); - })); - }); -} diff --git a/test/api_integration/apis/index_patterns/index.js b/test/api_integration/apis/index_patterns/index.js index b34012e362cbf..9472f12a85159 100644 --- a/test/api_integration/apis/index_patterns/index.js +++ b/test/api_integration/apis/index_patterns/index.js @@ -9,7 +9,6 @@ export default function ({ loadTestFile }) { describe('index_patterns', () => { loadTestFile(require.resolve('./es_errors')); - loadTestFile(require.resolve('./fields_for_time_pattern_route')); loadTestFile(require.resolve('./fields_for_wildcard_route')); loadTestFile(require.resolve('./index_pattern_crud')); loadTestFile(require.resolve('./scripted_fields_crud'));