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

[index patterns] Fleep app - Keep saved object field list until field caps provides fields #85370

Merged
Merged
Show file tree
Hide file tree
Changes from 28 commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
118d2f1
keep field list until field caps sees fields
mattkime Dec 9, 2020
976f6b0
catch getFields 404
mattkime Dec 9, 2020
4877b3a
Merge branch 'master' into keep_field_list_until_field_caps_sees_fields
kibanamachine Dec 10, 2020
2338f07
fix typescript and remove unneeded test
mattkime Dec 10, 2020
5acd6b1
Merge branch 'keep_field_list_until_field_caps_sees_fields' of github…
mattkime Dec 10, 2020
0eb6720
Fixing index pattern tests
jonathan-buttner Dec 14, 2020
c9c1ced
Merge branch 'master' of github.com:elastic/kibana into keep_field_li…
mattkime Dec 14, 2020
09e3dd9
use allowNoIndex to support beats usecase
mattkime Dec 15, 2020
6689651
Merge branch 'keep_field_list_until_field_caps_sees_fields' of github…
mattkime Dec 15, 2020
894f6ad
update snapshots
mattkime Dec 15, 2020
2413c17
Merge branch 'master' into keep_field_list_until_field_caps_sees_fields
kibanamachine Dec 15, 2020
7b94413
Merge branch 'master' into keep_field_list_until_field_caps_sees_fields
kibanamachine Dec 15, 2020
2a37599
Merge branch 'master' of github.com:elastic/kibana into keep_field_li…
mattkime Dec 15, 2020
0ba6854
Merge branch 'keep_field_list_until_field_caps_sees_fields' of github…
mattkime Dec 15, 2020
e573a72
use new index pattern attribute allowNoIndex for fleet index patterns
neptunian Dec 15, 2020
be52a22
fix type
neptunian Dec 15, 2020
7cd51e2
update snapshot
neptunian Dec 15, 2020
46b286b
Merge branch 'master' of github.com:elastic/kibana into keep_field_li…
mattkime Dec 15, 2020
83f66c9
add migration for indices, add test
mattkime Dec 15, 2020
7914df3
Merge branch 'keep_field_list_until_field_caps_sees_fields' of github…
mattkime Dec 15, 2020
c6a7523
Fixing resolver test that failed if no data was there
jonathan-buttner Dec 15, 2020
6398378
Merge branch 'keep_field_list_until_field_caps_sees_fields' of github…
jonathan-buttner Dec 15, 2020
f4bf382
add docs
mattkime Dec 16, 2020
db95d0e
Merge branch 'keep_field_list_until_field_caps_sees_fields' of github…
mattkime Dec 16, 2020
078635b
add allowNoIndex to rest API
mattkime Dec 16, 2020
feec3f7
Merge branch 'master' into keep_field_list_until_field_caps_sees_fields
jonathan-buttner Dec 16, 2020
e95acdf
Merge branch 'master' of github.com:elastic/kibana into keep_field_li…
mattkime Dec 18, 2020
edb0a95
Merge branch 'keep_field_list_until_field_caps_sees_fields' of github…
mattkime Dec 18, 2020
be52b07
Merge branch 'master' into keep_field_list_until_field_caps_sees_fields
kibanamachine Dec 19, 2020
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->

[Home](./index.md) &gt; [kibana-plugin-plugins-data-public](./kibana-plugin-plugins-data-public.md) &gt; [IndexPattern](./kibana-plugin-plugins-data-public.indexpattern.md) &gt; [allowNoIndex](./kibana-plugin-plugins-data-public.indexpattern.allownoindex.md)

## IndexPattern.allowNoIndex property

prevents errors when index pattern exists before indices

<b>Signature:</b>

```typescript
readonly allowNoIndex: boolean;
```
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ getAsSavedObjectBody(): {
fieldFormatMap: string | undefined;
type: string | undefined;
typeMeta: string | undefined;
allowNoIndex: true | undefined;
};
```
<b>Returns:</b>
Expand All @@ -33,5 +34,6 @@ getAsSavedObjectBody(): {
fieldFormatMap: string | undefined;
type: string | undefined;
typeMeta: string | undefined;
allowNoIndex: true | undefined;
}`

Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export declare class IndexPattern implements IIndexPattern

| Property | Modifiers | Type | Description |
| --- | --- | --- | --- |
| [allowNoIndex](./kibana-plugin-plugins-data-public.indexpattern.allownoindex.md) | | <code>boolean</code> | prevents errors when index pattern exists before indices |
| [deleteFieldFormat](./kibana-plugin-plugins-data-public.indexpattern.deletefieldformat.md) | | <code>(fieldName: string) =&gt; void</code> | |
| [fieldAttrs](./kibana-plugin-plugins-data-public.indexpattern.fieldattrs.md) | | <code>FieldAttrs</code> | |
| [fieldFormatMap](./kibana-plugin-plugins-data-public.indexpattern.fieldformatmap.md) | | <code>Record&lt;string, any&gt;</code> | |
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->

[Home](./index.md) &gt; [kibana-plugin-plugins-data-public](./kibana-plugin-plugins-data-public.md) &gt; [IndexPatternAttributes](./kibana-plugin-plugins-data-public.indexpatternattributes.md) &gt; [allowNoIndex](./kibana-plugin-plugins-data-public.indexpatternattributes.allownoindex.md)

## IndexPatternAttributes.allowNoIndex property

prevents errors when index pattern exists before indices

<b>Signature:</b>

```typescript
allowNoIndex?: boolean;
```
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export interface IndexPatternAttributes

| Property | Type | Description |
| --- | --- | --- |
| [allowNoIndex](./kibana-plugin-plugins-data-public.indexpatternattributes.allownoindex.md) | <code>boolean</code> | prevents errors when index pattern exists before indices |
| [fieldAttrs](./kibana-plugin-plugins-data-public.indexpatternattributes.fieldattrs.md) | <code>string</code> | |
| [fieldFormatMap](./kibana-plugin-plugins-data-public.indexpatternattributes.fieldformatmap.md) | <code>string</code> | |
| [fields](./kibana-plugin-plugins-data-public.indexpatternattributes.fields.md) | <code>string</code> | |
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->

[Home](./index.md) &gt; [kibana-plugin-plugins-data-public](./kibana-plugin-plugins-data-public.md) &gt; [IndexPatternSpec](./kibana-plugin-plugins-data-public.indexpatternspec.md) &gt; [allowNoIndex](./kibana-plugin-plugins-data-public.indexpatternspec.allownoindex.md)

## IndexPatternSpec.allowNoIndex property

<b>Signature:</b>

```typescript
allowNoIndex?: boolean;
```
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export interface IndexPatternSpec

| Property | Type | Description |
| --- | --- | --- |
| [allowNoIndex](./kibana-plugin-plugins-data-public.indexpatternspec.allownoindex.md) | <code>boolean</code> | |
| [fieldAttrs](./kibana-plugin-plugins-data-public.indexpatternspec.fieldattrs.md) | <code>FieldAttrs</code> | |
| [fieldFormats](./kibana-plugin-plugins-data-public.indexpatternspec.fieldformats.md) | <code>Record&lt;string, SerializedFieldFormat&gt;</code> | |
| [fields](./kibana-plugin-plugins-data-public.indexpatternspec.fields.md) | <code>IndexPatternFieldMap</code> | |
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->

[Home](./index.md) &gt; [kibana-plugin-plugins-data-server](./kibana-plugin-plugins-data-server.md) &gt; [IndexPattern](./kibana-plugin-plugins-data-server.indexpattern.md) &gt; [allowNoIndex](./kibana-plugin-plugins-data-server.indexpattern.allownoindex.md)

## IndexPattern.allowNoIndex property

prevents errors when index pattern exists before indices

<b>Signature:</b>

```typescript
readonly allowNoIndex: boolean;
```
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ getAsSavedObjectBody(): {
fieldFormatMap: string | undefined;
type: string | undefined;
typeMeta: string | undefined;
allowNoIndex: true | undefined;
};
```
<b>Returns:</b>
Expand All @@ -33,5 +34,6 @@ getAsSavedObjectBody(): {
fieldFormatMap: string | undefined;
type: string | undefined;
typeMeta: string | undefined;
allowNoIndex: true | undefined;
}`

Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export declare class IndexPattern implements IIndexPattern

| Property | Modifiers | Type | Description |
| --- | --- | --- | --- |
| [allowNoIndex](./kibana-plugin-plugins-data-server.indexpattern.allownoindex.md) | | <code>boolean</code> | prevents errors when index pattern exists before indices |
| [deleteFieldFormat](./kibana-plugin-plugins-data-server.indexpattern.deletefieldformat.md) | | <code>(fieldName: string) =&gt; void</code> | |
| [fieldAttrs](./kibana-plugin-plugins-data-server.indexpattern.fieldattrs.md) | | <code>FieldAttrs</code> | |
| [fieldFormatMap](./kibana-plugin-plugins-data-server.indexpattern.fieldformatmap.md) | | <code>Record&lt;string, any&gt;</code> | |
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->

[Home](./index.md) &gt; [kibana-plugin-plugins-data-server](./kibana-plugin-plugins-data-server.md) &gt; [IndexPatternAttributes](./kibana-plugin-plugins-data-server.indexpatternattributes.md) &gt; [allowNoIndex](./kibana-plugin-plugins-data-server.indexpatternattributes.allownoindex.md)

## IndexPatternAttributes.allowNoIndex property

prevents errors when index pattern exists before indices

<b>Signature:</b>

```typescript
allowNoIndex?: boolean;
```
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export interface IndexPatternAttributes

| Property | Type | Description |
| --- | --- | --- |
| [allowNoIndex](./kibana-plugin-plugins-data-server.indexpatternattributes.allownoindex.md) | <code>boolean</code> | prevents errors when index pattern exists before indices |
| [fieldAttrs](./kibana-plugin-plugins-data-server.indexpatternattributes.fieldattrs.md) | <code>string</code> | |
| [fieldFormatMap](./kibana-plugin-plugins-data-server.indexpatternattributes.fieldformatmap.md) | <code>string</code> | |
| [fields](./kibana-plugin-plugins-data-server.indexpatternattributes.fields.md) | <code>string</code> | |
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,10 @@ export class IndexPattern implements IIndexPattern {
private fieldFormats: FieldFormatsStartCommon;
// make private once manual field refresh is removed
public fieldAttrs: FieldAttrs;
/**
* prevents errors when index pattern exists before indices
*/
public readonly allowNoIndex: boolean = false;

constructor({
spec = {},
Expand Down Expand Up @@ -110,6 +114,7 @@ export class IndexPattern implements IIndexPattern {
this.typeMeta = spec.typeMeta;
this.fieldAttrs = spec.fieldAttrs || {};
this.intervalName = spec.intervalName;
this.allowNoIndex = spec.allowNoIndex || false;
}

/**
Expand Down Expand Up @@ -204,6 +209,7 @@ export class IndexPattern implements IIndexPattern {
fieldFormats: this.fieldFormatMap,
fieldAttrs: this.fieldAttrs,
intervalName: this.intervalName,
allowNoIndex: this.allowNoIndex,
};
}

Expand Down Expand Up @@ -309,6 +315,7 @@ export class IndexPattern implements IIndexPattern {
fieldFormatMap,
type: this.type,
typeMeta: this.typeMeta ? JSON.stringify(this.typeMeta) : undefined,
allowNoIndex: this.allowNoIndex ? this.allowNoIndex : undefined,
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,21 @@ describe('IndexPatterns', () => {
SOClientGetDelay = 0;
});

test('allowNoIndex flag preserves existing fields when index is missing', async () => {
const id = '2';
setDocsourcePayload(id, {
id: 'foo',
version: 'foo',
attributes: {
title: 'something',
allowNoIndex: true,
fields: '[{"name":"field"}]',
},
});

expect((await indexPatterns.get(id)).fields.length).toBe(1);
});

test('savedObjectCache pre-fetches only title', async () => {
expect(await indexPatterns.getIds()).toEqual(['id']);
expect(savedObjectsClient.find).toHaveBeenCalledWith({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,7 @@ export class IndexPatternsService {
metaFields,
type: options.type,
rollupIndex: options.rollupIndex,
allowNoIndex: options.allowNoIndex,
});
};

Expand Down Expand Up @@ -281,10 +282,21 @@ export class IndexPatternsService {
options: GetFieldsOptions,
fieldAttrs: FieldAttrs = {}
) => {
const scriptedFields = Object.values(fields).filter((field) => field.scripted);
const fieldsAsArr = Object.values(fields);
const scriptedFields = fieldsAsArr.filter((field) => field.scripted);
try {
let updatedFieldList: FieldSpec[];
const newFields = (await this.getFieldsForWildcard(options)) as FieldSpec[];
return this.fieldArrayToMap([...newFields, ...scriptedFields], fieldAttrs);

// If allowNoIndex, only update field list if field caps finds fields. To support
// beats creating index pattern and dashboard before docs
if (!options.allowNoIndex || (newFields && newFields.length > 5)) {
updatedFieldList = [...newFields, ...scriptedFields];
} else {
updatedFieldList = fieldsAsArr;
}

return this.fieldArrayToMap(updatedFieldList, fieldAttrs);
} catch (err) {
if (err instanceof IndexPatternMissingIndices) {
this.onNotification({ title: (err as any).message, color: 'danger', iconType: 'alert' });
Expand Down Expand Up @@ -334,6 +346,7 @@ export class IndexPatternsService {
typeMeta,
type,
fieldAttrs,
allowNoIndex,
},
} = savedObject;

Expand All @@ -355,6 +368,7 @@ export class IndexPatternsService {
type,
fieldFormats: parsedFieldFormatMap,
fieldAttrs: parsedFieldAttrs,
allowNoIndex,
};
};

Expand Down Expand Up @@ -384,6 +398,7 @@ export class IndexPatternsService {
metaFields: await this.config.get(UI_SETTINGS.META_FIELDS),
type,
rollupIndex: typeMeta?.params?.rollup_index,
allowNoIndex: spec.allowNoIndex,
},
spec.fieldAttrs
);
Expand Down
6 changes: 6 additions & 0 deletions src/plugins/data/common/index_patterns/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@ export interface IndexPatternAttributes {
sourceFilters?: string;
fieldFormatMap?: string;
fieldAttrs?: string;
/**
* prevents errors when index pattern exists before indices
*/
allowNoIndex?: boolean;
}

export interface FieldAttrs {
Expand Down Expand Up @@ -101,6 +105,7 @@ export interface GetFieldsOptions {
lookBack?: boolean;
metaFields?: string[];
rollupIndex?: string;
allowNoIndex?: boolean;
}

export interface GetFieldsOptionsTimePattern {
Expand Down Expand Up @@ -193,6 +198,7 @@ export interface IndexPatternSpec {
type?: string;
fieldFormats?: Record<string, SerializedFieldFormat>;
fieldAttrs?: FieldAttrs;
allowNoIndex?: boolean;
}

export interface SourceFilter {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,13 @@ export class IndexPatternsApiClient implements IIndexPatternsApiClient {
}).then((resp: any) => resp.fields);
}

getFieldsForWildcard({ pattern, metaFields, type, rollupIndex }: GetFieldsOptions) {
getFieldsForWildcard({ pattern, metaFields, type, rollupIndex, allowNoIndex }: GetFieldsOptions) {
return this._request(this._getUrl(['_fields_for_wildcard']), {
pattern,
meta_fields: metaFields,
type,
rollup_index: rollupIndex,
}).then((resp: any) => resp.fields);
allow_no_index: allowNoIndex,
}).then((resp: any) => resp.fields || []);
}
}
7 changes: 6 additions & 1 deletion src/plugins/data/public/public.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -1253,6 +1253,7 @@ export class IndexPattern implements IIndexPattern {
// Warning: (ae-forgotten-export) The symbol "IndexPatternDeps" needs to be exported by the entry point index.d.ts
constructor({ spec, fieldFormats, shortDotsEnable, metaFields, }: IndexPatternDeps);
addScriptedField(name: string, script: string, fieldType?: string): Promise<void>;
readonly allowNoIndex: boolean;
// (undocumented)
readonly deleteFieldFormat: (fieldName: string) => void;
// Warning: (ae-forgotten-export) The symbol "FieldAttrs" needs to be exported by the entry point index.d.ts
Expand Down Expand Up @@ -1293,6 +1294,7 @@ export class IndexPattern implements IIndexPattern {
fieldFormatMap: string | undefined;
type: string | undefined;
typeMeta: string | undefined;
allowNoIndex: true | undefined;
};
// (undocumented)
getComputedFields(): {
Expand Down Expand Up @@ -1385,6 +1387,7 @@ export type IndexPatternAggRestrictions = Record<string, {
//
// @public (undocumented)
export interface IndexPatternAttributes {
allowNoIndex?: boolean;
// (undocumented)
fieldAttrs?: string;
// (undocumented)
Expand Down Expand Up @@ -1515,6 +1518,8 @@ export type IndexPatternSelectProps = Required<Omit<EuiComboBoxProps<any>, 'isLo
//
// @public (undocumented)
export interface IndexPatternSpec {
// (undocumented)
allowNoIndex?: boolean;
// (undocumented)
fieldAttrs?: FieldAttrs;
// (undocumented)
Expand Down Expand Up @@ -2561,7 +2566,7 @@ export const UI_SETTINGS: {
// src/plugins/data/common/es_query/filters/phrase_filter.ts:33:3 - (ae-forgotten-export) The symbol "PhraseFilterMeta" needs to be exported by the entry point index.d.ts
// src/plugins/data/common/es_query/filters/phrases_filter.ts:31:3 - (ae-forgotten-export) The symbol "PhrasesFilterMeta" needs to be exported by the entry point index.d.ts
// src/plugins/data/common/index_patterns/index_patterns/index_pattern.ts:64:5 - (ae-forgotten-export) The symbol "FormatFieldFn" needs to be exported by the entry point index.d.ts
// src/plugins/data/common/index_patterns/index_patterns/index_pattern.ts:128:7 - (ae-forgotten-export) The symbol "FieldAttrSet" needs to be exported by the entry point index.d.ts
// src/plugins/data/common/index_patterns/index_patterns/index_pattern.ts:133:7 - (ae-forgotten-export) The symbol "FieldAttrSet" needs to be exported by the entry point index.d.ts
// src/plugins/data/common/search/aggs/types.ts:150:51 - (ae-forgotten-export) The symbol "AggTypesRegistryStart" needs to be exported by the entry point index.d.ts
// src/plugins/data/common/search/search_source/search_source.ts:197:7 - (ae-forgotten-export) The symbol "SearchFieldValue" needs to be exported by the entry point index.d.ts
// src/plugins/data/public/field_formats/field_formats_service.ts:67:3 - (ae-forgotten-export) The symbol "FormatFactory" needs to be exported by the entry point index.d.ts
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,14 @@ export class IndexPatternsApiServer implements IIndexPatternsApiClient {
constructor(elasticsearchClient: ElasticsearchClient) {
this.esClient = elasticsearchClient;
}
async getFieldsForWildcard({ pattern, metaFields, type, rollupIndex }: GetFieldsOptions) {
const indexPatterns = new IndexPatternsFetcher(this.esClient);
async getFieldsForWildcard({
pattern,
metaFields,
type,
rollupIndex,
allowNoIndex,
}: GetFieldsOptions) {
const indexPatterns = new IndexPatternsFetcher(this.esClient, allowNoIndex);
return await indexPatterns.getFieldsForWildcard({
pattern,
metaFields,
Expand Down
Loading