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] [skip-ci] Index pattern “pattern list” support #89330

Closed
wants to merge 45 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
533f617
logging
stephmilovic Jan 11, 2021
21e0138
Merge branch 'master' into index-alias-collection
stephmilovic Jan 11, 2021
dd8814d
getting fields like a siem
stephmilovic Jan 11, 2021
9acf492
a little temp ui
stephmilovic Jan 11, 2021
3b05751
little ui
stephmilovic Jan 12, 2021
9df909c
cleaning
stephmilovic Jan 12, 2021
c487780
more
stephmilovic Jan 13, 2021
0328955
broken but need to test pr
stephmilovic Jan 13, 2021
485789d
Merge branch 'master' into index-alias-collection
stephmilovic Jan 13, 2021
a2de575
fix bug
stephmilovic Jan 13, 2021
ab13362
added those properties
stephmilovic Jan 14, 2021
b844bf6
add validation for pattern lists
stephmilovic Jan 14, 2021
7b6b12d
wip oh man
stephmilovic Jan 15, 2021
415c9e5
Merge branch 'master' into index-alias-collection
stephmilovic Jan 19, 2021
17001f4
back to working
stephmilovic Jan 19, 2021
b06bd6a
fix merge
stephmilovic Jan 20, 2021
3a5f2d3
working on form
stephmilovic Jan 20, 2021
bd54c68
to hooks
stephmilovic Jan 21, 2021
83bcade
hookin left and right
stephmilovic Jan 21, 2021
0265406
my god it works
stephmilovic Jan 21, 2021
b345b63
grammar fix
stephmilovic Jan 21, 2021
8b0d9c5
revert to class on wizard
stephmilovic Jan 21, 2021
3f9be16
shorten import
stephmilovic Jan 21, 2021
efb826a
fix merge conflicts
stephmilovic Jan 21, 2021
1573ccc
Merge branch 'master' into index-alias-collection
stephmilovic Jan 25, 2021
3c73237
tests
stephmilovic Jan 25, 2021
b0c80c7
type fixing and discover sidebar
stephmilovic Jan 26, 2021
c3c4371
get rid of silly
stephmilovic Jan 26, 2021
becae4c
hooked up search source
stephmilovic Jan 26, 2021
f465951
discover ui
stephmilovic Jan 26, 2021
f59eb5b
type and test fixing
stephmilovic Jan 26, 2021
564e82f
discover test fixing
stephmilovic Jan 26, 2021
f5b8f00
Fix stub imports
stephmilovic Jan 26, 2021
6ecfac5
more test fiixng
stephmilovic Jan 27, 2021
5f863a2
comment out ts err
stephmilovic Jan 27, 2021
f51ee62
Fix mistake saving active list
stephmilovic Jan 27, 2021
6ee27a6
small tsvb change
stephmilovic Jan 28, 2021
c602f39
avoid some unnecessary promises
stephmilovic Jan 28, 2021
af21bde
better notes
stephmilovic Jan 28, 2021
82c93f6
time lion
stephmilovic Jan 28, 2021
0cd9cf0
make scripted fields work
stephmilovic Jan 28, 2021
da7a4b6
change to find
stephmilovic Jan 28, 2021
d95fbb3
remove console log
stephmilovic Jan 28, 2021
a288e45
fix doc function
stephmilovic Jan 29, 2021
950a8c0
better name
stephmilovic Jan 29, 2021
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
14 changes: 13 additions & 1 deletion src/plugins/data/common/index_patterns/index_pattern.stub.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,29 @@
import { IIndexPattern } from '.';
import { stubFields } from './field.stub';

export const mockPatternLists = {
patternListActive: ['auditbeat-*', 'filebeat-*', 'packetbeat-*', 'winlogbeat-*'],
patternList: [
'apm-*-transaction*',
'auditbeat-*',
'endgame-*',
'filebeat-*',
'packetbeat-*',
'winlogbeat-*',
],
};
export const stubIndexPattern: IIndexPattern = {
id: 'logstash-*',
fields: stubFields,
title: 'logstash-*',
...mockPatternLists,
timeFieldName: '@timestamp',
getTimeField: () => ({ name: '@timestamp', type: 'date' }),
};

export const stubIndexPatternWithFields: IIndexPattern = {
id: '1234',
title: 'logstash-*',
...mockPatternLists,
fields: [
{
name: 'response',
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 @@ -11,6 +11,18 @@ import stubbedLogstashFields from './logstash_fields';

const mockLogstashFields = stubbedLogstashFields();

export const mockPatternLists = {
patternListActive: ['auditbeat-*', 'filebeat-*', 'packetbeat-*', 'winlogbeat-*'],
patternList: [
'apm-*-transaction*',
'auditbeat-*',
'endgame-*',
'filebeat-*',
'packetbeat-*',
'winlogbeat-*',
],
};

export function stubbedSavedObjectIndexPattern(id: string | null = null) {
return {
id,
Expand All @@ -20,6 +32,7 @@ export function stubbedSavedObjectIndexPattern(id: string | null = null) {
customFormats: {},
fields: mockLogstashFields,
title: 'title',
patternList: mockPatternLists.patternList,
},
version: '2',
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,10 @@ import { IndexPattern } from './index_pattern';
import { DuplicateField } from '../../../../kibana_utils/common';
// @ts-expect-error
import mockLogStashFields from './fixtures/logstash_fields';
import { stubbedSavedObjectIndexPattern } from './fixtures/stubbed_saved_object_index_pattern';
import {
mockPatternLists,
stubbedSavedObjectIndexPattern,
} from './fixtures/stubbed_saved_object_index_pattern';
import { IndexPatternField } from '../fields';

import { fieldFormatsMock } from '../../field_formats/mocks';
Expand Down Expand Up @@ -46,7 +49,7 @@ function create(id: string) {
const {
type,
version,
attributes: { timeFieldName, fields, title },
attributes: { timeFieldName, fields, title, patternList },
} = stubbedSavedObjectIndexPattern(id);

return new IndexPattern({
Expand All @@ -58,6 +61,8 @@ function create(id: string) {
fields: { ...fields, runtime_field: runtimeField },
title,
runtimeFieldMap,
patternList,
patternListActive: mockPatternLists.patternListActive,
},
fieldFormats: fieldFormatsMock,
shortDotsEnable: false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,21 +29,25 @@ interface IndexPatternDeps {

interface SavedObjectBody {
fieldAttrs?: string;
title?: string;
timeFieldName?: string;
intervalName?: string;
fieldFormatMap?: string;
fields?: string;
intervalName?: string;
patternList?: string[];
sourceFilters?: string;
fieldFormatMap?: string;
typeMeta?: string;
timeFieldName?: string;
title?: string;
type?: string;
typeMeta?: string;
}

type FormatFieldFn = (hit: Record<string, any>, fieldName: string) => any;

export class IndexPattern implements IIndexPattern {
public id?: string;
public id: string = '';
public title: string = '';

public patternList: string[];
public patternListActive: string[];
public fieldFormatMap: Record<string, any>;
/**
* Only used by rollup indices, used by rollup specific endpoint to load field list
Expand Down Expand Up @@ -84,7 +88,12 @@ export class IndexPattern implements IIndexPattern {
public readonly allowNoIndex: boolean = false;

constructor({
spec = {},
spec = {
id: '',
title: '',
patternList: [],
patternListActive: [],
},
fieldFormats,
shortDotsEnable = false,
metaFields = [],
Expand Down Expand Up @@ -120,6 +129,8 @@ export class IndexPattern implements IIndexPattern {
this.intervalName = spec.intervalName;
this.allowNoIndex = spec.allowNoIndex || false;
this.runtimeFieldMap = spec.runtimeFieldMap || {};
this.patternListActive = spec.patternListActive;
this.patternList = spec.patternList;
}

/**
Expand Down Expand Up @@ -221,6 +232,8 @@ export class IndexPattern implements IIndexPattern {
fieldAttrs: this.fieldAttrs,
intervalName: this.intervalName,
allowNoIndex: this.allowNoIndex,
patternListActive: this.patternListActive,
patternList: this.patternList,
};
}

Expand Down Expand Up @@ -316,19 +329,20 @@ export class IndexPattern implements IIndexPattern {
const runtimeFieldMap = this.runtimeFieldMap;

return {
allowNoIndex: this.allowNoIndex ? this.allowNoIndex : undefined,
fieldAttrs: fieldAttrs ? JSON.stringify(fieldAttrs) : undefined,
title: this.title,
timeFieldName: this.timeFieldName,
intervalName: this.intervalName,
sourceFilters: this.sourceFilters ? JSON.stringify(this.sourceFilters) : undefined,
fieldFormatMap,
fields: this.fields
? JSON.stringify(this.fields.filter((field) => field.scripted))
: undefined,
fieldFormatMap,
intervalName: this.intervalName,
patternList: this.patternList,
runtimeFieldMap: runtimeFieldMap ? JSON.stringify(runtimeFieldMap) : undefined,
sourceFilters: this.sourceFilters ? JSON.stringify(this.sourceFilters) : undefined,
timeFieldName: this.timeFieldName,
title: this.title,
type: this.type,
typeMeta: this.typeMeta ? JSON.stringify(this.typeMeta) : undefined,
allowNoIndex: this.allowNoIndex ? this.allowNoIndex : undefined,
runtimeFieldMap: runtimeFieldMap ? JSON.stringify(runtimeFieldMap) : undefined,
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,19 @@
import { defaults } from 'lodash';
import { IndexPatternsService, IndexPattern } from '.';
import { fieldFormatsMock } from '../../field_formats/mocks';
import { stubbedSavedObjectIndexPattern } from './fixtures/stubbed_saved_object_index_pattern';
import {
mockPatternLists,
stubbedSavedObjectIndexPattern,
} from './fixtures/stubbed_saved_object_index_pattern';
import { UiSettingsCommon, SavedObjectsClientCommon, SavedObject } from '../types';

const createFieldsFetcher = jest.fn().mockImplementation(() => ({
getFieldsForWildcard: jest.fn().mockImplementation(() => {
return new Promise((resolve) => resolve([]));
}),
validatePatternListActive: jest.fn().mockImplementation(() => {
return new Promise((resolve) => resolve(mockPatternLists.patternListActive));
}),
every: jest.fn(),
}));

Expand All @@ -32,7 +38,14 @@ describe('IndexPatterns', () => {
let SOClientGetDelay = 0;

beforeEach(() => {
const indexPatternObj = { id: 'id', version: 'a', attributes: { title: 'title' } };
const indexPatternObj = {
id: 'id',
version: 'a',
attributes: {
title: 'something',
patternList: mockPatternLists.patternList,
},
};
savedObjectsClient = {} as SavedObjectsClientCommon;
savedObjectsClient.find = jest.fn(
() => Promise.resolve([indexPatternObj]) as Promise<Array<SavedObject<any>>>
Expand Down Expand Up @@ -87,6 +100,7 @@ describe('IndexPatterns', () => {
version: 'foo',
attributes: {
title: 'something',
patternList: ['filebeat-*'],
},
});

Expand Down Expand Up @@ -122,7 +136,7 @@ describe('IndexPatterns', () => {
expect(await indexPatterns.getIds()).toEqual(['id']);
expect(savedObjectsClient.find).toHaveBeenCalledWith({
type: 'index-pattern',
fields: ['title'],
fields: ['patternList', 'title'],
perPage: 10000,
});
});
Expand Down Expand Up @@ -183,15 +197,16 @@ describe('IndexPatterns', () => {
});

test('create', async () => {
const id = '1234';
const title = 'kibana-*';
indexPatterns.refreshFields = jest.fn();

const indexPattern = await indexPatterns.create({ title }, true);
const indexPattern = await indexPatterns.create({ id, title, ...mockPatternLists }, true);
expect(indexPattern).toBeInstanceOf(IndexPattern);
expect(indexPattern.title).toBe(title);
expect(indexPatterns.refreshFields).not.toBeCalled();

await indexPatterns.create({ title });
await indexPatterns.create({ id, title, ...mockPatternLists });
expect(indexPatterns.refreshFields).toBeCalled();
});

Expand All @@ -202,28 +217,30 @@ describe('IndexPatterns', () => {

expect(savedObjectsClient.find).lastCalledWith({
type: 'index-pattern',
fields: ['title'],
fields: ['patternList', 'title'],
search,
searchFields: ['title'],
perPage: size,
});
});

test('createAndSave', async () => {
const id = '1234';
const title = 'kibana-*';
indexPatterns.createSavedObject = jest.fn();
indexPatterns.setDefault = jest.fn();
await indexPatterns.createAndSave({ title });
await indexPatterns.createAndSave({ id, title, patternList: mockPatternLists.patternList });
expect(indexPatterns.createSavedObject).toBeCalled();
expect(indexPatterns.setDefault).toBeCalled();
});

test('savedObjectToSpec', () => {
test('savedObjectToSpec', async () => {
const savedObject = {
id: 'id',
version: 'version',
attributes: {
title: 'kibana-*',
patternList: mockPatternLists.patternList,
timeFieldName: '@timestamp',
fields: '[]',
sourceFilters: '[{"value":"item1"},{"value":"item2"}]',
Expand All @@ -234,8 +251,9 @@ describe('IndexPatterns', () => {
type: 'index-pattern',
references: [],
};
const spec = await indexPatterns.savedObjectToSpec(savedObject);

expect(indexPatterns.savedObjectToSpec(savedObject)).toMatchSnapshot();
expect(spec).toMatchSnapshot();
});

test('failed requests are not cached', async () => {
Expand Down
Loading