From 38ab538789dab7308755330373025c6373adf1ee Mon Sep 17 00:00:00 2001 From: Matthew Kime Date: Wed, 14 Jun 2023 18:07:33 -0500 Subject: [PATCH] Revert "[data views] Move fields_for_wildcard to internal route (#159637)" This reverts commit 65205ab0b7598aab4670b766bf60d54dec8ba47d. --- src/plugins/data_views/common/constants.ts | 6 ----- .../data_views/data_views_api_client.test.ts | 3 ++- .../data_views/data_views_api_client.ts | 3 +-- .../rest_api_routes/internal/fields_for.ts | 2 +- .../fields_for_wildcard_route/conflicts.ts | 3 +-- .../fields_for_wildcard_route/filter.ts | 3 +-- .../fields_for_wildcard_route/params.ts | 25 +++++++++---------- .../fields_for_wildcard_route/response.ts | 13 +++++----- .../apis/management/rollup/constants.js | 1 + .../rollup/index_patterns_extensions.js | 4 ++- 10 files changed, 28 insertions(+), 35 deletions(-) diff --git a/src/plugins/data_views/common/constants.ts b/src/plugins/data_views/common/constants.ts index 02a05ab2a44d7..2c766115bac7c 100644 --- a/src/plugins/data_views/common/constants.ts +++ b/src/plugins/data_views/common/constants.ts @@ -51,9 +51,3 @@ export const DATA_VIEW_SAVED_OBJECT_TYPE = 'index-pattern'; * @public */ export const PLUGIN_NAME = 'DataViews'; - -/** - * Fields for wildcard path. - * @public - */ -export const FIELDS_FOR_WILDCARD_PATH = '/internal/data_views/_fields_for_wildcard'; 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 90a208650a965..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 @@ -8,7 +8,6 @@ import { http } from './data_views_api_client.test.mock'; import { DataViewsApiClient } from './data_views_api_client'; -import { FIELDS_FOR_WILDCARD_PATH as expectedPath } from '../../common/constants'; describe('IndexPatternsApiClient', () => { let fetchSpy: jest.SpyInstance; @@ -20,6 +19,8 @@ describe('IndexPatternsApiClient', () => { }); test('uses the right URI to fetch fields for wildcard', async function () { + const expectedPath = '/api/index_patterns/_fields_for_wildcard'; + await indexPatternsApiClient.getFieldsForWildcard({ pattern: 'blah' }); expect(fetchSpy).toHaveBeenCalledWith(expectedPath, expect.any(Object)); 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 bb53c68eafaa7..e80e95f33ebab 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 @@ -10,7 +10,6 @@ import { HttpSetup } from '@kbn/core/public'; import { DataViewMissingIndices } from '../../common/lib'; import { GetFieldsOptions, IDataViewsApiClient } from '../../common'; import { FieldsForWildcardResponse } from '../../common/types'; -import { FIELDS_FOR_WILDCARD_PATH } from '../../common/constants'; const API_BASE_URL: string = `/api/index_patterns/`; const version = '1'; @@ -62,7 +61,7 @@ export class DataViewsApiClient implements IDataViewsApiClient { fields, } = options; return this._request( - FIELDS_FOR_WILDCARD_PATH, + this._getUrl(['_fields_for_wildcard']), { pattern, meta_fields: metaFields, diff --git a/src/plugins/data_views/server/rest_api_routes/internal/fields_for.ts b/src/plugins/data_views/server/rest_api_routes/internal/fields_for.ts index f9689be30991b..849f233e2a0d3 100644 --- a/src/plugins/data_views/server/rest_api_routes/internal/fields_for.ts +++ b/src/plugins/data_views/server/rest_api_routes/internal/fields_for.ts @@ -17,7 +17,6 @@ import type { DataViewsServerPluginStartDependencies, } from '../../types'; import type { FieldDescriptorRestResponse } from '../route_types'; -import { FIELDS_FOR_WILDCARD_PATH as path } from '../../../common/constants'; /** * Accepts one of the following: @@ -39,6 +38,7 @@ export const parseFields = (fields: string | string[]): string[] => { } }; +const path = '/api/index_patterns/_fields_for_wildcard'; const access = 'internal'; type IBody = { index_filter?: estypes.QueryDslQueryContainer } | undefined; diff --git a/test/api_integration/apis/data_views/fields_for_wildcard_route/conflicts.ts b/test/api_integration/apis/data_views/fields_for_wildcard_route/conflicts.ts index d21b03ef8a7cc..ca49fb1ab93bc 100644 --- a/test/api_integration/apis/data_views/fields_for_wildcard_route/conflicts.ts +++ b/test/api_integration/apis/data_views/fields_for_wildcard_route/conflicts.ts @@ -8,7 +8,6 @@ import { ELASTIC_HTTP_VERSION_HEADER } from '@kbn/core-http-common'; import { INITIAL_REST_VERSION_INTERNAL } from '@kbn/data-views-plugin/server/constants'; -import { FIELDS_FOR_WILDCARD_PATH } from '@kbn/data-views-plugin/common/constants'; import expect from '@kbn/expect'; import { FtrProviderContext } from '../../../ftr_provider_context'; @@ -26,7 +25,7 @@ export default function ({ getService }: FtrProviderContext) { it('flags fields with mismatched types as conflicting', () => supertest - .get(FIELDS_FOR_WILDCARD_PATH) + .get('/api/index_patterns/_fields_for_wildcard') .set(ELASTIC_HTTP_VERSION_HEADER, INITIAL_REST_VERSION_INTERNAL) .query({ pattern: 'logs-*' }) .expect(200) diff --git a/test/api_integration/apis/data_views/fields_for_wildcard_route/filter.ts b/test/api_integration/apis/data_views/fields_for_wildcard_route/filter.ts index 34b8b52d1c710..f05f1c0406be1 100644 --- a/test/api_integration/apis/data_views/fields_for_wildcard_route/filter.ts +++ b/test/api_integration/apis/data_views/fields_for_wildcard_route/filter.ts @@ -8,7 +8,6 @@ import { ELASTIC_HTTP_VERSION_HEADER } from '@kbn/core-http-common'; import { INITIAL_REST_VERSION_INTERNAL } from '@kbn/data-views-plugin/server/constants'; -import { FIELDS_FOR_WILDCARD_PATH } from '@kbn/data-views-plugin/common/constants'; import expect from '@kbn/expect'; import { FtrProviderContext } from '../../../ftr_provider_context'; @@ -35,7 +34,7 @@ export default function ({ getService }: FtrProviderContext) { it('can filter', async () => { const a = await supertest - .put(FIELDS_FOR_WILDCARD_PATH) + .put('/api/index_patterns/_fields_for_wildcard') .set(ELASTIC_HTTP_VERSION_HEADER, INITIAL_REST_VERSION_INTERNAL) .query({ pattern: 'helloworld*' }) .send({ index_filter: { exists: { field: 'bye' } } }); diff --git a/test/api_integration/apis/data_views/fields_for_wildcard_route/params.ts b/test/api_integration/apis/data_views/fields_for_wildcard_route/params.ts index 044b04540a030..5592c1cc5d8e9 100644 --- a/test/api_integration/apis/data_views/fields_for_wildcard_route/params.ts +++ b/test/api_integration/apis/data_views/fields_for_wildcard_route/params.ts @@ -8,7 +8,6 @@ import { ELASTIC_HTTP_VERSION_HEADER } from '@kbn/core-http-common'; import { INITIAL_REST_VERSION_INTERNAL } from '@kbn/data-views-plugin/server/constants'; -import { FIELDS_FOR_WILDCARD_PATH } from '@kbn/data-views-plugin/common/constants'; import { FtrProviderContext } from '../../../ftr_provider_context'; export default function ({ getService }: FtrProviderContext) { @@ -26,14 +25,14 @@ export default function ({ getService }: FtrProviderContext) { it('requires a pattern query param', () => supertest - .get(FIELDS_FOR_WILDCARD_PATH) + .get('/api/index_patterns/_fields_for_wildcard') .set(ELASTIC_HTTP_VERSION_HEADER, INITIAL_REST_VERSION_INTERNAL) .query({}) .expect(400)); it('accepts include_unmapped param', () => supertest - .get(FIELDS_FOR_WILDCARD_PATH) + .get('/api/index_patterns/_fields_for_wildcard') .set(ELASTIC_HTTP_VERSION_HEADER, INITIAL_REST_VERSION_INTERNAL) .query({ pattern: '*', @@ -43,7 +42,7 @@ export default function ({ getService }: FtrProviderContext) { it('rejects unexpected query params', () => supertest - .get(FIELDS_FOR_WILDCARD_PATH) + .get('/api/index_patterns/_fields_for_wildcard') .set(ELASTIC_HTTP_VERSION_HEADER, INITIAL_REST_VERSION_INTERNAL) .query({ pattern: randomness.word(), @@ -54,7 +53,7 @@ export default function ({ getService }: FtrProviderContext) { describe('fields', () => { it('accepts a JSON formatted fields query param', () => supertest - .get(FIELDS_FOR_WILDCARD_PATH) + .get('/api/index_patterns/_fields_for_wildcard') .set(ELASTIC_HTTP_VERSION_HEADER, INITIAL_REST_VERSION_INTERNAL) .query({ pattern: '*', @@ -64,7 +63,7 @@ export default function ({ getService }: FtrProviderContext) { it('accepts meta_fields query param in string array', () => supertest - .get(FIELDS_FOR_WILDCARD_PATH) + .get('/api/index_patterns/_fields_for_wildcard') .set(ELASTIC_HTTP_VERSION_HEADER, INITIAL_REST_VERSION_INTERNAL) .query({ pattern: '*', @@ -74,7 +73,7 @@ export default function ({ getService }: FtrProviderContext) { it('accepts single array fields query param', () => supertest - .get(FIELDS_FOR_WILDCARD_PATH) + .get('/api/index_patterns/_fields_for_wildcard') .set(ELASTIC_HTTP_VERSION_HEADER, INITIAL_REST_VERSION_INTERNAL) .query({ pattern: '*', @@ -84,7 +83,7 @@ export default function ({ getService }: FtrProviderContext) { it('accepts single fields query param', () => supertest - .get(FIELDS_FOR_WILDCARD_PATH) + .get('/api/index_patterns/_fields_for_wildcard') .set(ELASTIC_HTTP_VERSION_HEADER, INITIAL_REST_VERSION_INTERNAL) .query({ pattern: '*', @@ -94,7 +93,7 @@ export default function ({ getService }: FtrProviderContext) { it('rejects a comma-separated list of fields', () => supertest - .get(FIELDS_FOR_WILDCARD_PATH) + .get('/api/index_patterns/_fields_for_wildcard') .set(ELASTIC_HTTP_VERSION_HEADER, INITIAL_REST_VERSION_INTERNAL) .query({ pattern: '*', @@ -106,7 +105,7 @@ export default function ({ getService }: FtrProviderContext) { describe('meta_fields', () => { it('accepts a JSON formatted meta_fields query param', () => supertest - .get(FIELDS_FOR_WILDCARD_PATH) + .get('/api/index_patterns/_fields_for_wildcard') .set(ELASTIC_HTTP_VERSION_HEADER, INITIAL_REST_VERSION_INTERNAL) .query({ pattern: '*', @@ -116,7 +115,7 @@ export default function ({ getService }: FtrProviderContext) { it('accepts meta_fields query param in string array', () => supertest - .get(FIELDS_FOR_WILDCARD_PATH) + .get('/api/index_patterns/_fields_for_wildcard') .set(ELASTIC_HTTP_VERSION_HEADER, INITIAL_REST_VERSION_INTERNAL) .query({ pattern: '*', @@ -126,7 +125,7 @@ export default function ({ getService }: FtrProviderContext) { it('accepts single meta_fields query param', () => supertest - .get(FIELDS_FOR_WILDCARD_PATH) + .get('/api/index_patterns/_fields_for_wildcard') .set(ELASTIC_HTTP_VERSION_HEADER, INITIAL_REST_VERSION_INTERNAL) .query({ pattern: '*', @@ -136,7 +135,7 @@ export default function ({ getService }: FtrProviderContext) { it('rejects a comma-separated list of meta_fields', () => supertest - .get(FIELDS_FOR_WILDCARD_PATH) + .get('/api/index_patterns/_fields_for_wildcard') .set(ELASTIC_HTTP_VERSION_HEADER, INITIAL_REST_VERSION_INTERNAL) .query({ pattern: '*', diff --git a/test/api_integration/apis/data_views/fields_for_wildcard_route/response.ts b/test/api_integration/apis/data_views/fields_for_wildcard_route/response.ts index 39bb7c474630f..7c33001c3f91e 100644 --- a/test/api_integration/apis/data_views/fields_for_wildcard_route/response.ts +++ b/test/api_integration/apis/data_views/fields_for_wildcard_route/response.ts @@ -8,7 +8,6 @@ import { ELASTIC_HTTP_VERSION_HEADER } from '@kbn/core-http-common'; import { INITIAL_REST_VERSION_INTERNAL } from '@kbn/data-views-plugin/server/constants'; -import { FIELDS_FOR_WILDCARD_PATH } from '@kbn/data-views-plugin/common/constants'; import expect from '@kbn/expect'; import { sortBy } from 'lodash'; import { FtrProviderContext } from '../../../ftr_provider_context'; @@ -85,7 +84,7 @@ export default function ({ getService }: FtrProviderContext) { it('returns a flattened version of the fields in es', async () => { await supertest - .get(FIELDS_FOR_WILDCARD_PATH) + .get('/api/index_patterns/_fields_for_wildcard') .set(ELASTIC_HTTP_VERSION_HEADER, INITIAL_REST_VERSION_INTERNAL) .query({ pattern: 'basic_index' }) .expect(200, { @@ -97,7 +96,7 @@ export default function ({ getService }: FtrProviderContext) { it('returns a single field as requested', async () => { await supertest - .get(FIELDS_FOR_WILDCARD_PATH) + .get('/api/index_patterns/_fields_for_wildcard') .set(ELASTIC_HTTP_VERSION_HEADER, INITIAL_REST_VERSION_INTERNAL) .query({ pattern: 'basic_index', fields: JSON.stringify(['bar']) }) .expect(200, { @@ -108,7 +107,7 @@ export default function ({ getService }: FtrProviderContext) { it('always returns a field for all passed meta fields', async () => { await supertest - .get(FIELDS_FOR_WILDCARD_PATH) + .get('/api/index_patterns/_fields_for_wildcard') .set(ELASTIC_HTTP_VERSION_HEADER, INITIAL_REST_VERSION_INTERNAL) .query({ pattern: 'basic_index', @@ -201,7 +200,7 @@ export default function ({ getService }: FtrProviderContext) { it('returns fields when one pattern exists and the other does not', async () => { await supertest - .get(FIELDS_FOR_WILDCARD_PATH) + .get('/api/index_patterns/_fields_for_wildcard') .set(ELASTIC_HTTP_VERSION_HEADER, INITIAL_REST_VERSION_INTERNAL) .query({ pattern: 'bad_index,basic_index' }) .expect(200, { @@ -212,7 +211,7 @@ export default function ({ getService }: FtrProviderContext) { it('returns 404 when neither exists', async () => { await supertest - .get(FIELDS_FOR_WILDCARD_PATH) + .get('/api/index_patterns/_fields_for_wildcard') .set(ELASTIC_HTTP_VERSION_HEADER, INITIAL_REST_VERSION_INTERNAL) .query({ pattern: 'bad_index,bad_index_2' }) .expect(404); @@ -220,7 +219,7 @@ export default function ({ getService }: FtrProviderContext) { it('returns 404 when no patterns exist', async () => { await supertest - .get(FIELDS_FOR_WILDCARD_PATH) + .get('/api/index_patterns/_fields_for_wildcard') .set(ELASTIC_HTTP_VERSION_HEADER, INITIAL_REST_VERSION_INTERNAL) .query({ pattern: 'bad_index', diff --git a/x-pack/test/api_integration/apis/management/rollup/constants.js b/x-pack/test/api_integration/apis/management/rollup/constants.js index 2a6cd71286a81..4e64b8b4e7903 100644 --- a/x-pack/test/api_integration/apis/management/rollup/constants.js +++ b/x-pack/test/api_integration/apis/management/rollup/constants.js @@ -6,6 +6,7 @@ */ export const API_BASE_PATH = '/api/rollup'; +export const INDEX_PATTERNS_EXTENSION_BASE_PATH = '/api/index_patterns'; export const ROLLUP_INDEX_NAME = 'rollup_index'; export const INDEX_TO_ROLLUP_MAPPINGS = { properties: { diff --git a/x-pack/test/api_integration/apis/management/rollup/index_patterns_extensions.js b/x-pack/test/api_integration/apis/management/rollup/index_patterns_extensions.js index 77b2beac86ec4..78c525b70f36c 100644 --- a/x-pack/test/api_integration/apis/management/rollup/index_patterns_extensions.js +++ b/x-pack/test/api_integration/apis/management/rollup/index_patterns_extensions.js @@ -7,10 +7,10 @@ import { ELASTIC_HTTP_VERSION_HEADER } from '@kbn/core-http-common'; import { INITIAL_REST_VERSION_INTERNAL } from '@kbn/data-views-plugin/server/constants'; -import { FIELDS_FOR_WILDCARD_PATH as BASE_URI } from '@kbn/data-views-plugin/common/constants'; import expect from '@kbn/expect'; import { stringify } from 'query-string'; import { registerHelpers } from './rollup.test_helpers'; +import { INDEX_PATTERNS_EXTENSION_BASE_PATH } from './constants'; import { getRandomString } from './lib'; export default function ({ getService }) { @@ -21,6 +21,8 @@ export default function ({ getService }) { describe('index patterns extension', () => { describe('Fields for wildcards', () => { + const BASE_URI = `${INDEX_PATTERNS_EXTENSION_BASE_PATH}/_fields_for_wildcard`; + describe('query params validation', () => { let uri; let body;