Skip to content

Commit

Permalink
Revert "[data views] Move fields_for_wildcard to internal route (#159637
Browse files Browse the repository at this point in the history
)"

This reverts commit 65205ab.
  • Loading branch information
mattkime authored Jun 14, 2023
1 parent 6f1fe0c commit 38ab538
Show file tree
Hide file tree
Showing 10 changed files with 28 additions and 35 deletions.
6 changes: 0 additions & 6 deletions src/plugins/data_views/common/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -62,7 +61,7 @@ export class DataViewsApiClient implements IDataViewsApiClient {
fields,
} = options;
return this._request<FieldsForWildcardResponse>(
FIELDS_FOR_WILDCARD_PATH,
this._getUrl(['_fields_for_wildcard']),
{
pattern,
meta_fields: metaFields,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand All @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand All @@ -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' } } });
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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: '*',
Expand All @@ -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(),
Expand All @@ -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: '*',
Expand All @@ -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: '*',
Expand All @@ -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: '*',
Expand All @@ -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: '*',
Expand All @@ -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: '*',
Expand All @@ -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: '*',
Expand All @@ -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: '*',
Expand All @@ -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: '*',
Expand All @@ -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: '*',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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, {
Expand All @@ -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, {
Expand All @@ -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',
Expand Down Expand Up @@ -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, {
Expand All @@ -212,15 +211,15 @@ 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);
});

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',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 }) {
Expand All @@ -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;
Expand Down

0 comments on commit 38ab538

Please sign in to comment.