Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[data views] Move fields_for_wildcard to internal route #159637

Merged
merged 4 commits into from
Jun 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/plugins/data_views/common/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,3 +51,9 @@ 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,6 +8,7 @@

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 @@ -19,8 +20,6 @@ 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,6 +10,7 @@ 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 @@ -61,7 +62,7 @@ export class DataViewsApiClient implements IDataViewsApiClient {
fields,
} = options;
return this._request<FieldsForWildcardResponse>(
this._getUrl(['_fields_for_wildcard']),
FIELDS_FOR_WILDCARD_PATH,
{
pattern,
meta_fields: metaFields,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ 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 @@ -38,7 +39,6 @@ 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,6 +8,7 @@

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 @@ -25,7 +26,7 @@ export default function ({ getService }: FtrProviderContext) {

it('flags fields with mismatched types as conflicting', () =>
supertest
.get('/api/index_patterns/_fields_for_wildcard')
.get(FIELDS_FOR_WILDCARD_PATH)
.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,6 +8,7 @@

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 @@ -34,7 +35,7 @@ export default function ({ getService }: FtrProviderContext) {

it('can filter', async () => {
const a = await supertest
.put('/api/index_patterns/_fields_for_wildcard')
.put(FIELDS_FOR_WILDCARD_PATH)
.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,6 +8,7 @@

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 @@ -25,14 +26,14 @@ export default function ({ getService }: FtrProviderContext) {

it('requires a pattern query param', () =>
supertest
.get('/api/index_patterns/_fields_for_wildcard')
.get(FIELDS_FOR_WILDCARD_PATH)
.set(ELASTIC_HTTP_VERSION_HEADER, INITIAL_REST_VERSION_INTERNAL)
.query({})
.expect(400));

it('accepts include_unmapped param', () =>
supertest
.get('/api/index_patterns/_fields_for_wildcard')
.get(FIELDS_FOR_WILDCARD_PATH)
.set(ELASTIC_HTTP_VERSION_HEADER, INITIAL_REST_VERSION_INTERNAL)
.query({
pattern: '*',
Expand All @@ -42,7 +43,7 @@ export default function ({ getService }: FtrProviderContext) {

it('rejects unexpected query params', () =>
supertest
.get('/api/index_patterns/_fields_for_wildcard')
.get(FIELDS_FOR_WILDCARD_PATH)
.set(ELASTIC_HTTP_VERSION_HEADER, INITIAL_REST_VERSION_INTERNAL)
.query({
pattern: randomness.word(),
Expand All @@ -53,7 +54,7 @@ export default function ({ getService }: FtrProviderContext) {
describe('fields', () => {
it('accepts a JSON formatted fields query param', () =>
supertest
.get('/api/index_patterns/_fields_for_wildcard')
.get(FIELDS_FOR_WILDCARD_PATH)
.set(ELASTIC_HTTP_VERSION_HEADER, INITIAL_REST_VERSION_INTERNAL)
.query({
pattern: '*',
Expand All @@ -63,7 +64,7 @@ export default function ({ getService }: FtrProviderContext) {

it('accepts meta_fields query param in string array', () =>
supertest
.get('/api/index_patterns/_fields_for_wildcard')
.get(FIELDS_FOR_WILDCARD_PATH)
.set(ELASTIC_HTTP_VERSION_HEADER, INITIAL_REST_VERSION_INTERNAL)
.query({
pattern: '*',
Expand All @@ -73,7 +74,7 @@ export default function ({ getService }: FtrProviderContext) {

it('accepts single array fields query param', () =>
supertest
.get('/api/index_patterns/_fields_for_wildcard')
.get(FIELDS_FOR_WILDCARD_PATH)
.set(ELASTIC_HTTP_VERSION_HEADER, INITIAL_REST_VERSION_INTERNAL)
.query({
pattern: '*',
Expand All @@ -83,7 +84,7 @@ export default function ({ getService }: FtrProviderContext) {

it('accepts single fields query param', () =>
supertest
.get('/api/index_patterns/_fields_for_wildcard')
.get(FIELDS_FOR_WILDCARD_PATH)
.set(ELASTIC_HTTP_VERSION_HEADER, INITIAL_REST_VERSION_INTERNAL)
.query({
pattern: '*',
Expand All @@ -93,7 +94,7 @@ export default function ({ getService }: FtrProviderContext) {

it('rejects a comma-separated list of fields', () =>
supertest
.get('/api/index_patterns/_fields_for_wildcard')
.get(FIELDS_FOR_WILDCARD_PATH)
.set(ELASTIC_HTTP_VERSION_HEADER, INITIAL_REST_VERSION_INTERNAL)
.query({
pattern: '*',
Expand All @@ -105,7 +106,7 @@ export default function ({ getService }: FtrProviderContext) {
describe('meta_fields', () => {
it('accepts a JSON formatted meta_fields query param', () =>
supertest
.get('/api/index_patterns/_fields_for_wildcard')
.get(FIELDS_FOR_WILDCARD_PATH)
.set(ELASTIC_HTTP_VERSION_HEADER, INITIAL_REST_VERSION_INTERNAL)
.query({
pattern: '*',
Expand All @@ -115,7 +116,7 @@ export default function ({ getService }: FtrProviderContext) {

it('accepts meta_fields query param in string array', () =>
supertest
.get('/api/index_patterns/_fields_for_wildcard')
.get(FIELDS_FOR_WILDCARD_PATH)
.set(ELASTIC_HTTP_VERSION_HEADER, INITIAL_REST_VERSION_INTERNAL)
.query({
pattern: '*',
Expand All @@ -125,7 +126,7 @@ export default function ({ getService }: FtrProviderContext) {

it('accepts single meta_fields query param', () =>
supertest
.get('/api/index_patterns/_fields_for_wildcard')
.get(FIELDS_FOR_WILDCARD_PATH)
.set(ELASTIC_HTTP_VERSION_HEADER, INITIAL_REST_VERSION_INTERNAL)
.query({
pattern: '*',
Expand All @@ -135,7 +136,7 @@ export default function ({ getService }: FtrProviderContext) {

it('rejects a comma-separated list of meta_fields', () =>
supertest
.get('/api/index_patterns/_fields_for_wildcard')
.get(FIELDS_FOR_WILDCARD_PATH)
.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,6 +8,7 @@

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 @@ -84,7 +85,7 @@ export default function ({ getService }: FtrProviderContext) {

it('returns a flattened version of the fields in es', async () => {
await supertest
.get('/api/index_patterns/_fields_for_wildcard')
.get(FIELDS_FOR_WILDCARD_PATH)
.set(ELASTIC_HTTP_VERSION_HEADER, INITIAL_REST_VERSION_INTERNAL)
.query({ pattern: 'basic_index' })
.expect(200, {
Expand All @@ -96,7 +97,7 @@ export default function ({ getService }: FtrProviderContext) {

it('returns a single field as requested', async () => {
await supertest
.get('/api/index_patterns/_fields_for_wildcard')
.get(FIELDS_FOR_WILDCARD_PATH)
.set(ELASTIC_HTTP_VERSION_HEADER, INITIAL_REST_VERSION_INTERNAL)
.query({ pattern: 'basic_index', fields: JSON.stringify(['bar']) })
.expect(200, {
Expand All @@ -107,7 +108,7 @@ export default function ({ getService }: FtrProviderContext) {

it('always returns a field for all passed meta fields', async () => {
await supertest
.get('/api/index_patterns/_fields_for_wildcard')
.get(FIELDS_FOR_WILDCARD_PATH)
.set(ELASTIC_HTTP_VERSION_HEADER, INITIAL_REST_VERSION_INTERNAL)
.query({
pattern: 'basic_index',
Expand Down Expand Up @@ -200,7 +201,7 @@ export default function ({ getService }: FtrProviderContext) {

it('returns fields when one pattern exists and the other does not', async () => {
await supertest
.get('/api/index_patterns/_fields_for_wildcard')
.get(FIELDS_FOR_WILDCARD_PATH)
.set(ELASTIC_HTTP_VERSION_HEADER, INITIAL_REST_VERSION_INTERNAL)
.query({ pattern: 'bad_index,basic_index' })
.expect(200, {
Expand All @@ -211,15 +212,15 @@ export default function ({ getService }: FtrProviderContext) {

it('returns 404 when neither exists', async () => {
await supertest
.get('/api/index_patterns/_fields_for_wildcard')
.get(FIELDS_FOR_WILDCARD_PATH)
.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('/api/index_patterns/_fields_for_wildcard')
.get(FIELDS_FOR_WILDCARD_PATH)
.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,7 +6,6 @@
*/

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,8 +21,6 @@ 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