Skip to content

Commit

Permalink
Revert "Index patterns api - load field list on server (#81218)"
Browse files Browse the repository at this point in the history
This reverts commit e683ece.
  • Loading branch information
spalger committed Nov 4, 2020
1 parent c1b7830 commit af73961
Show file tree
Hide file tree
Showing 49 changed files with 386 additions and 484 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@ Get field list by providing an index patttern (or spec)
<b>Signature:</b>

```typescript
getFieldsForIndexPattern: (indexPattern: IndexPattern | IndexPatternSpec, options?: GetFieldsOptions | undefined) => Promise<any>;
getFieldsForIndexPattern: (indexPattern: IndexPattern | IndexPatternSpec, options?: GetFieldsOptions) => Promise<any>;
```
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@ Get field list by providing { pattern }
<b>Signature:</b>

```typescript
getFieldsForWildcard: (options: GetFieldsOptions) => Promise<any>;
getFieldsForWildcard: (options?: GetFieldsOptions) => Promise<any>;
```
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ export declare class IndexPatternsService
| [get](./kibana-plugin-plugins-data-public.indexpatternsservice.get.md) | | <code>(id: string) =&gt; Promise&lt;IndexPattern&gt;</code> | Get an index pattern by id. Cache optimized |
| [getCache](./kibana-plugin-plugins-data-public.indexpatternsservice.getcache.md) | | <code>() =&gt; Promise&lt;SavedObject&lt;IndexPatternSavedObjectAttrs&gt;[] &#124; null &#124; undefined&gt;</code> | |
| [getDefault](./kibana-plugin-plugins-data-public.indexpatternsservice.getdefault.md) | | <code>() =&gt; Promise&lt;IndexPattern &#124; null&gt;</code> | Get default index pattern |
| [getFieldsForIndexPattern](./kibana-plugin-plugins-data-public.indexpatternsservice.getfieldsforindexpattern.md) | | <code>(indexPattern: IndexPattern &#124; IndexPatternSpec, options?: GetFieldsOptions &#124; undefined) =&gt; Promise&lt;any&gt;</code> | Get field list by providing an index patttern (or spec) |
| [getFieldsForWildcard](./kibana-plugin-plugins-data-public.indexpatternsservice.getfieldsforwildcard.md) | | <code>(options: GetFieldsOptions) =&gt; Promise&lt;any&gt;</code> | Get field list by providing { pattern } |
| [getFieldsForIndexPattern](./kibana-plugin-plugins-data-public.indexpatternsservice.getfieldsforindexpattern.md) | | <code>(indexPattern: IndexPattern &#124; IndexPatternSpec, options?: GetFieldsOptions) =&gt; Promise&lt;any&gt;</code> | Get field list by providing an index patttern (or spec) |
| [getFieldsForWildcard](./kibana-plugin-plugins-data-public.indexpatternsservice.getfieldsforwildcard.md) | | <code>(options?: GetFieldsOptions) =&gt; Promise&lt;any&gt;</code> | Get field list by providing { pattern } |
| [getIds](./kibana-plugin-plugins-data-public.indexpatternsservice.getids.md) | | <code>(refresh?: boolean) =&gt; Promise&lt;string[]&gt;</code> | Get list of index pattern ids |
| [getIdsWithTitle](./kibana-plugin-plugins-data-public.indexpatternsservice.getidswithtitle.md) | | <code>(refresh?: boolean) =&gt; Promise&lt;Array&lt;{</code><br/><code> id: string;</code><br/><code> title: string;</code><br/><code> }&gt;&gt;</code> | Get list of index pattern ids with titles |
| [getTitles](./kibana-plugin-plugins-data-public.indexpatternsservice.gettitles.md) | | <code>(refresh?: boolean) =&gt; Promise&lt;string[]&gt;</code> | Get list of index pattern titles |
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,14 @@ getFieldsForWildcard(options: {
fieldCapsOptions?: {
allow_no_indices: boolean;
};
type?: string;
rollupIndex?: string;
}): Promise<FieldDescriptor[]>;
```

## Parameters

| Parameter | Type | Description |
| --- | --- | --- |
| options | <code>{</code><br/><code> pattern: string &#124; string[];</code><br/><code> metaFields?: string[];</code><br/><code> fieldCapsOptions?: {</code><br/><code> allow_no_indices: boolean;</code><br/><code> };</code><br/><code> type?: string;</code><br/><code> rollupIndex?: string;</code><br/><code> }</code> | |
| options | <code>{</code><br/><code> pattern: string &#124; string[];</code><br/><code> metaFields?: string[];</code><br/><code> fieldCapsOptions?: {</code><br/><code> allow_no_indices: boolean;</code><br/><code> };</code><br/><code> }</code> | |

<b>Returns:</b>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

```typescript
start(core: CoreStart, { fieldFormats, logger }: IndexPatternsServiceStartDeps): {
indexPatternsServiceFactory: (savedObjectsClient: SavedObjectsClientContract, elasticsearchClient: ElasticsearchClient) => Promise<IndexPatternsCommonService>;
indexPatternsServiceFactory: (savedObjectsClient: SavedObjectsClientContract) => Promise<IndexPatternsCommonService>;
};
```

Expand All @@ -22,6 +22,6 @@ start(core: CoreStart, { fieldFormats, logger }: IndexPatternsServiceStartDeps):
<b>Returns:</b>

`{
indexPatternsServiceFactory: (savedObjectsClient: SavedObjectsClientContract, elasticsearchClient: ElasticsearchClient) => Promise<IndexPatternsCommonService>;
indexPatternsServiceFactory: (savedObjectsClient: SavedObjectsClientContract) => Promise<IndexPatternsCommonService>;
}`

Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@

| Function | Description |
| --- | --- |
| [getCapabilitiesForRollupIndices(indices)](./kibana-plugin-plugins-data-server.getcapabilitiesforrollupindices.md) | |
| [getDefaultSearchParams(uiSettingsClient)](./kibana-plugin-plugins-data-server.getdefaultsearchparams.md) | |
| [getShardTimeout(config)](./kibana-plugin-plugins-data-server.getshardtimeout.md) | |
| [getTime(indexPattern, timeRange, options)](./kibana-plugin-plugins-data-server.gettime.md) | |
Expand Down Expand Up @@ -77,7 +76,6 @@
| [esQuery](./kibana-plugin-plugins-data-server.esquery.md) | |
| [fieldFormats](./kibana-plugin-plugins-data-server.fieldformats.md) | |
| [indexPatterns](./kibana-plugin-plugins-data-server.indexpatterns.md) | |
| [mergeCapabilitiesWithFields](./kibana-plugin-plugins-data-server.mergecapabilitieswithfields.md) | |
| [search](./kibana-plugin-plugins-data-server.search.md) | |
| [UI\_SETTINGS](./kibana-plugin-plugins-data-server.ui_settings.md) | |

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ start(core: CoreStart): {
fieldFormatServiceFactory: (uiSettings: import("../../../core/server").IUiSettingsClient) => Promise<import("../common").FieldFormatsRegistry>;
};
indexPatterns: {
indexPatternsServiceFactory: (savedObjectsClient: Pick<import("../../../core/server").SavedObjectsClient, "update" | "find" | "get" | "delete" | "errors" | "create" | "bulkCreate" | "checkConflicts" | "bulkGet" | "addToNamespaces" | "deleteFromNamespaces" | "bulkUpdate" | "removeReferencesTo">, elasticsearchClient: import("../../../core/server").ElasticsearchClient) => Promise<import("../public").IndexPatternsService>;
indexPatternsServiceFactory: (savedObjectsClient: Pick<import("../../../core/server").SavedObjectsClient, "update" | "find" | "get" | "delete" | "errors" | "create" | "bulkCreate" | "checkConflicts" | "bulkGet" | "addToNamespaces" | "deleteFromNamespaces" | "bulkUpdate" | "removeReferencesTo">) => Promise<import("../public").IndexPatternsService>;
};
search: ISearchStart<import("./search").IEsSearchRequest, import("./search").IEsSearchResponse<any>>;
};
Expand All @@ -31,7 +31,7 @@ start(core: CoreStart): {
fieldFormatServiceFactory: (uiSettings: import("../../../core/server").IUiSettingsClient) => Promise<import("../common").FieldFormatsRegistry>;
};
indexPatterns: {
indexPatternsServiceFactory: (savedObjectsClient: Pick<import("../../../core/server").SavedObjectsClient, "update" | "find" | "get" | "delete" | "errors" | "create" | "bulkCreate" | "checkConflicts" | "bulkGet" | "addToNamespaces" | "deleteFromNamespaces" | "bulkUpdate" | "removeReferencesTo">, elasticsearchClient: import("../../../core/server").ElasticsearchClient) => Promise<import("../public").IndexPatternsService>;
indexPatternsServiceFactory: (savedObjectsClient: Pick<import("../../../core/server").SavedObjectsClient, "update" | "find" | "get" | "delete" | "errors" | "create" | "bulkCreate" | "checkConflicts" | "bulkGet" | "addToNamespaces" | "deleteFromNamespaces" | "bulkUpdate" | "removeReferencesTo">) => Promise<import("../public").IndexPatternsService>;
};
search: ISearchStart<import("./search").IEsSearchRequest, import("./search").IEsSearchResponse<any>>;
}`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -215,13 +215,13 @@ export class IndexPatternsService {
* Get field list by providing { pattern }
* @param options
*/
getFieldsForWildcard = async (options: GetFieldsOptions) => {
getFieldsForWildcard = async (options: GetFieldsOptions = {}) => {
const metaFields = await this.config.get(UI_SETTINGS.META_FIELDS);
return this.apiClient.getFieldsForWildcard({
pattern: options.pattern,
metaFields,
type: options.type,
rollupIndex: options.rollupIndex,
params: options.params || {},
});
};

Expand All @@ -231,13 +231,13 @@ export class IndexPatternsService {
*/
getFieldsForIndexPattern = async (
indexPattern: IndexPattern | IndexPatternSpec,
options?: GetFieldsOptions
options: GetFieldsOptions = {}
) =>
this.getFieldsForWildcard({
type: indexPattern.type,
rollupIndex: indexPattern?.typeMeta?.params?.rollup_index,
...options,
pattern: indexPattern.title as string,
...options,
type: indexPattern.type,
params: indexPattern.typeMeta && indexPattern.typeMeta.params,
});

/**
Expand Down Expand Up @@ -374,10 +374,10 @@ export class IndexPatternsService {
try {
spec.fields = isFieldRefreshRequired
? await this.refreshFieldSpecMap(spec.fields || {}, id, spec.title as string, {
pattern: title as string,
pattern: title,
metaFields: await this.config.get(UI_SETTINGS.META_FIELDS),
type,
rollupIndex: typeMeta?.params?.rollupIndex,
params: typeMeta && typeMeta.params,
})
: spec.fields;
} catch (err) {
Expand Down
13 changes: 3 additions & 10 deletions src/plugins/data/common/index_patterns/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,22 +86,15 @@ export interface SavedObjectsClientCommon {
}

export interface GetFieldsOptions {
pattern: string;
pattern?: string;
type?: string;
params?: any;
lookBack?: boolean;
metaFields?: string[];
rollupIndex?: string;
}

export interface GetFieldsOptionsTimePattern {
pattern: string;
metaFields: string[];
lookBack: number;
interval: string;
}

export interface IIndexPatternsApiClient {
getFieldsForTimePattern: (options: GetFieldsOptionsTimePattern) => Promise<any>;
getFieldsForTimePattern: (options: GetFieldsOptions) => Promise<any>;
getFieldsForWildcard: (options: GetFieldsOptions) => Promise<any>;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,20 +32,23 @@ describe('IndexPatternsApiClient', () => {
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: '',
});
await indexPatternsApiClient.getFieldsForTimePattern();

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

await indexPatternsApiClient.getFieldsForWildcard({ pattern: 'blah' });
await indexPatternsApiClient.getFieldsForWildcard();

expect(fetchSpy).toHaveBeenCalledWith(expectedPath, expect.any(Object));
});

test('uses the right URI to fetch fields for wildcard given a type', async function () {
const expectedPath = '/api/index_patterns/rollup/_fields_for_wildcard';

await indexPatternsApiClient.getFieldsForWildcard({ type: 'rollup' });

expect(fetchSpy).toHaveBeenCalledWith(expectedPath, expect.any(Object));
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,7 @@

import { HttpSetup } from 'src/core/public';
import { IndexPatternMissingIndices } from '../../../common/index_patterns/lib';
import {
GetFieldsOptions,
IIndexPatternsApiClient,
GetFieldsOptionsTimePattern,
} from '../../../common/index_patterns/types';
import { GetFieldsOptions, IIndexPatternsApiClient } from '../../../common/index_patterns/types';

const API_BASE_URL: string = `/api/index_patterns/`;

Expand Down Expand Up @@ -52,7 +48,7 @@ export class IndexPatternsApiClient implements IIndexPatternsApiClient {
return API_BASE_URL + path.filter(Boolean).map(encodeURIComponent).join('/');
}

getFieldsForTimePattern(options: GetFieldsOptionsTimePattern) {
getFieldsForTimePattern(options: GetFieldsOptions = {}) {
const { pattern, lookBack, metaFields } = options;

const url = this._getUrl(['_fields_for_time_pattern']);
Expand All @@ -64,12 +60,27 @@ export class IndexPatternsApiClient implements IIndexPatternsApiClient {
}).then((resp: any) => resp.fields);
}

getFieldsForWildcard({ pattern, metaFields, type, rollupIndex }: GetFieldsOptions) {
return this._request(this._getUrl(['_fields_for_wildcard']), {
pattern,
meta_fields: metaFields,
type,
rollup_index: rollupIndex,
}).then((resp: any) => resp.fields);
getFieldsForWildcard(options: GetFieldsOptions = {}) {
const { pattern, metaFields, type, params } = options;

let url;
let query;

if (type) {
url = this._getUrl([type, '_fields_for_wildcard']);
query = {
pattern,
meta_fields: metaFields,
params: JSON.stringify(params),
};
} else {
url = this._getUrl(['_fields_for_wildcard']);
query = {
pattern,
meta_fields: metaFields,
};
}

return this._request(url, query).then((resp: any) => resp.fields);
}
}
4 changes: 2 additions & 2 deletions src/plugins/data/public/public.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -1339,9 +1339,9 @@ export class IndexPatternsService {
// (undocumented)
getCache: () => Promise<SavedObject<IndexPatternSavedObjectAttrs>[] | null | undefined>;
getDefault: () => Promise<IndexPattern | null>;
getFieldsForIndexPattern: (indexPattern: IndexPattern | IndexPatternSpec, options?: GetFieldsOptions | undefined) => Promise<any>;
getFieldsForIndexPattern: (indexPattern: IndexPattern | IndexPatternSpec, options?: GetFieldsOptions) => Promise<any>;
// Warning: (ae-forgotten-export) The symbol "GetFieldsOptions" needs to be exported by the entry point index.d.ts
getFieldsForWildcard: (options: GetFieldsOptions) => Promise<any>;
getFieldsForWildcard: (options?: GetFieldsOptions) => Promise<any>;
getIds: (refresh?: boolean) => Promise<string[]>;
getIdsWithTitle: (refresh?: boolean) => Promise<Array<{
id: string;
Expand Down
2 changes: 0 additions & 2 deletions src/plugins/data/server/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,8 +134,6 @@ export {
FieldDescriptor as IndexPatternFieldDescriptor,
shouldReadFieldFromDocValues, // used only in logstash_fields fixture
FieldDescriptor,
mergeCapabilitiesWithFields,
getCapabilitiesForRollupIndices,
} from './index_patterns';

export {
Expand Down
6 changes: 1 addition & 5 deletions src/plugins/data/server/index_patterns/fetcher/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,4 @@
*/

export * from './index_patterns_fetcher';
export {
shouldReadFieldFromDocValues,
mergeCapabilitiesWithFields,
getCapabilitiesForRollupIndices,
} from './lib';
export { shouldReadFieldFromDocValues } from './lib';
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,8 @@
*/

import { ElasticsearchClient } from 'kibana/server';
import { keyBy } from 'lodash';

import {
getFieldCapabilities,
resolveTimePattern,
createNoMatchingIndicesError,
getCapabilitiesForRollupIndices,
mergeCapabilitiesWithFields,
} from './lib';
import { getFieldCapabilities, resolveTimePattern, createNoMatchingIndicesError } from './lib';

export interface FieldDescriptor {
aggregatable: boolean;
Expand Down Expand Up @@ -65,44 +58,11 @@ export class IndexPatternsFetcher {
pattern: string | string[];
metaFields?: string[];
fieldCapsOptions?: { allow_no_indices: boolean };
type?: string;
rollupIndex?: string;
}): Promise<FieldDescriptor[]> {
const { pattern, metaFields, fieldCapsOptions, type, rollupIndex } = options;
const fieldCapsResponse = await getFieldCapabilities(
this.elasticsearchClient,
pattern,
metaFields,
{
allow_no_indices: fieldCapsOptions
? fieldCapsOptions.allow_no_indices
: this.allowNoIndices,
}
);
if (type === 'rollup' && rollupIndex) {
const rollupFields: FieldDescriptor[] = [];
const rollupIndexCapabilities = getCapabilitiesForRollupIndices(
(
await this.elasticsearchClient.rollup.getRollupIndexCaps({
index: rollupIndex,
})
).body
)[rollupIndex].aggs;
const fieldCapsResponseObj = keyBy(fieldCapsResponse, 'name');

// Keep meta fields
metaFields!.forEach(
(field: string) =>
fieldCapsResponseObj[field] && rollupFields.push(fieldCapsResponseObj[field])
);

return mergeCapabilitiesWithFields(
rollupIndexCapabilities,
fieldCapsResponseObj,
rollupFields
);
}
return fieldCapsResponse;
const { pattern, metaFields, fieldCapsOptions } = options;
return await getFieldCapabilities(this.elasticsearchClient, pattern, metaFields, {
allow_no_indices: fieldCapsOptions ? fieldCapsOptions.allow_no_indices : this.allowNoIndices,
});
}

/**
Expand Down
Loading

0 comments on commit af73961

Please sign in to comment.