From d4231dea579c9cb779d625ae79a1b7416d673f4b Mon Sep 17 00:00:00 2001 From: Matt Kime Date: Thu, 23 Feb 2023 22:46:32 -0600 Subject: [PATCH 1/5] no errors on empty field fetch --- src/plugins/data_views/common/data_views/data_views.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/plugins/data_views/common/data_views/data_views.ts b/src/plugins/data_views/common/data_views/data_views.ts index 65d23292486f3..a8fdfe0734ef5 100644 --- a/src/plugins/data_views/common/data_views/data_views.ts +++ b/src/plugins/data_views/common/data_views/data_views.ts @@ -530,7 +530,7 @@ export class DataViewsService { return this.apiClient.getFieldsForWildcard({ type: dataView.type, rollupIndex: dataView?.typeMeta?.params?.rollup_index, - allowNoIndex: dataView.allowNoIndex, + allowNoIndex: true, pattern: dataView.getIndexPattern(), metaFields, }); @@ -538,12 +538,12 @@ export class DataViewsService { private getFieldsAndIndicesForWildcard = async (options: GetFieldsOptions) => { const metaFields = await this.config.get(META_FIELDS); - return await this.apiClient.getFieldsForWildcard({ + return this.apiClient.getFieldsForWildcard({ pattern: options.pattern, metaFields, type: options.type, rollupIndex: options.rollupIndex, - allowNoIndex: options.allowNoIndex, + allowNoIndex: true, indexFilter: options.indexFilter, }); }; From f1c58bd9ad76fdfa2fdfd63d563a80362ce822fb Mon Sep 17 00:00:00 2001 From: Matt Kime Date: Fri, 24 Feb 2023 05:27:44 -0600 Subject: [PATCH 2/5] test fix and don't show metafields if no fields are loaded. --- .../common/data_views/data_views.test.ts | 51 ++++++++++++++++++- .../field_capabilities/field_capabilities.ts | 5 +- 2 files changed, 52 insertions(+), 4 deletions(-) diff --git a/src/plugins/data_views/common/data_views/data_views.test.ts b/src/plugins/data_views/common/data_views/data_views.test.ts index 01e2b9b1d95f3..9a775a834a957 100644 --- a/src/plugins/data_views/common/data_views/data_views.test.ts +++ b/src/plugins/data_views/common/data_views/data_views.test.ts @@ -162,6 +162,41 @@ describe('IndexPatterns', () => { expect(apiClient.getFieldsForWildcard).toBeCalledTimes(2); }); + test('getFieldsForWildcard called with allowNoIndex set to true as default ', async () => { + const id = '1'; + await indexPatterns.get(id); + expect(apiClient.getFieldsForWildcard).toBeCalledWith({ + allowNoIndex: true, + indexFilter: undefined, + metaFields: false, + pattern: 'something', + rollupIndex: undefined, + type: undefined, + }); + }); + + test('getFieldsForWildcard called with allowNoIndex set to false if configured', async () => { + const id = '2'; + setDocsourcePayload(id, { + id: 'foo', + version: 'foo', + attributes: { + title: 'something', + allowNoIndex: false, + }, + }); + + await indexPatterns.get(id); + expect(apiClient.getFieldsForWildcard).toBeCalledWith({ + allowNoIndex: false, + indexFilter: undefined, + metaFields: false, + pattern: 'something', + rollupIndex: undefined, + type: undefined, + }); + }); + test('does cache ad-hoc data views', async () => { const id = '1'; @@ -577,9 +612,8 @@ describe('IndexPatterns', () => { expect(indexPattern.fields.length).toBe(1); }); - test('refreshFields properly includes allowNoIndex', async () => { + test('refreshFields defaults allowNoIndex to true', async () => { const indexPatternSpec: DataViewSpec = { - allowNoIndex: true, title: 'test', }; @@ -589,5 +623,18 @@ describe('IndexPatterns', () => { // @ts-expect-error expect(apiClient.getFieldsForWildcard.mock.calls[0][0].allowNoIndex).toBe(true); }); + + test('refreshFields properly includes allowNoIndex=false', async () => { + const indexPatternSpec: DataViewSpec = { + allowNoIndex: false, + title: 'test', + }; + + const indexPattern = await indexPatterns.create(indexPatternSpec); + + indexPatterns.refreshFields(indexPattern); + // @ts-expect-error + expect(apiClient.getFieldsForWildcard.mock.calls[0][0].allowNoIndex).toBe(false); + }); }); }); diff --git a/src/plugins/data_views/server/fetcher/lib/field_capabilities/field_capabilities.ts b/src/plugins/data_views/server/fetcher/lib/field_capabilities/field_capabilities.ts index 4ec808c756873..73e550ebd68ce 100644 --- a/src/plugins/data_views/server/fetcher/lib/field_capabilities/field_capabilities.ts +++ b/src/plugins/data_views/server/fetcher/lib/field_capabilities/field_capabilities.ts @@ -50,12 +50,13 @@ export async function getFieldCapabilities(params: FieldCapabilitiesParams) { indexFilter, fields, }); - const fieldsFromFieldCapsByName = keyBy(readFieldCapsResponse(esFieldCaps.body), 'name'); + const fieldCapsArr = readFieldCapsResponse(esFieldCaps.body); + const fieldsFromFieldCapsByName = keyBy(fieldCapsArr, 'name'); const allFieldsUnsorted = Object.keys(fieldsFromFieldCapsByName) // not all meta fields are provided, so remove and manually add .filter((name) => !fieldsFromFieldCapsByName[name].metadata_field) - .concat(metaFields) + .concat(fieldCapsArr.length ? metaFields : []) .reduce<{ names: string[]; map: Map }>( (agg, value) => { // This is intentionally using a Map to be highly optimized with very large indexes AND be safe for user provided data From a89ded11ab660fdbf1fb1b724f2d2aefe452fd18 Mon Sep 17 00:00:00 2001 From: Matt Kime Date: Fri, 24 Feb 2023 07:12:28 -0600 Subject: [PATCH 3/5] remove unneeded jest tests --- .../common/data_views/data_views.test.ts | 35 ------------------- 1 file changed, 35 deletions(-) diff --git a/src/plugins/data_views/common/data_views/data_views.test.ts b/src/plugins/data_views/common/data_views/data_views.test.ts index 9a775a834a957..508d8a66650ce 100644 --- a/src/plugins/data_views/common/data_views/data_views.test.ts +++ b/src/plugins/data_views/common/data_views/data_views.test.ts @@ -175,28 +175,6 @@ describe('IndexPatterns', () => { }); }); - test('getFieldsForWildcard called with allowNoIndex set to false if configured', async () => { - const id = '2'; - setDocsourcePayload(id, { - id: 'foo', - version: 'foo', - attributes: { - title: 'something', - allowNoIndex: false, - }, - }); - - await indexPatterns.get(id); - expect(apiClient.getFieldsForWildcard).toBeCalledWith({ - allowNoIndex: false, - indexFilter: undefined, - metaFields: false, - pattern: 'something', - rollupIndex: undefined, - type: undefined, - }); - }); - test('does cache ad-hoc data views', async () => { const id = '1'; @@ -623,18 +601,5 @@ describe('IndexPatterns', () => { // @ts-expect-error expect(apiClient.getFieldsForWildcard.mock.calls[0][0].allowNoIndex).toBe(true); }); - - test('refreshFields properly includes allowNoIndex=false', async () => { - const indexPatternSpec: DataViewSpec = { - allowNoIndex: false, - title: 'test', - }; - - const indexPattern = await indexPatterns.create(indexPatternSpec); - - indexPatterns.refreshFields(indexPattern); - // @ts-expect-error - expect(apiClient.getFieldsForWildcard.mock.calls[0][0].allowNoIndex).toBe(false); - }); }); }); From 30703b672b05d511261433bb2241f54c44d117c8 Mon Sep 17 00:00:00 2001 From: Matt Kime Date: Wed, 1 Mar 2023 14:50:39 -0600 Subject: [PATCH 4/5] getFieldsForIndexPattern defaults to allowing no indices --- src/plugins/data_views/common/data_views/data_views.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/plugins/data_views/common/data_views/data_views.ts b/src/plugins/data_views/common/data_views/data_views.ts index 46b38c8632ffc..b04374d6c6a03 100644 --- a/src/plugins/data_views/common/data_views/data_views.ts +++ b/src/plugins/data_views/common/data_views/data_views.ts @@ -515,12 +515,12 @@ export class DataViewsService { */ getFieldsForIndexPattern = async ( indexPattern: DataView | DataViewSpec, - options?: GetFieldsOptions + options?: Omit ) => this.getFieldsForWildcard({ type: indexPattern.type, rollupIndex: indexPattern?.typeMeta?.params?.rollup_index, - allowNoIndex: indexPattern.allowNoIndex, + allowNoIndex: true, ...options, pattern: indexPattern.title as string, }); From 54684ff94652c7909232a5f1ed97d3aa8bd2ab36 Mon Sep 17 00:00:00 2001 From: Matt Kime Date: Wed, 22 Mar 2023 08:25:17 -0500 Subject: [PATCH 5/5] fix functiona test --- test/functional/apps/discover/group1/_sidebar.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/functional/apps/discover/group1/_sidebar.ts b/test/functional/apps/discover/group1/_sidebar.ts index 9842cc3df554a..4780f812b50f0 100644 --- a/test/functional/apps/discover/group1/_sidebar.ts +++ b/test/functional/apps/discover/group1/_sidebar.ts @@ -424,9 +424,9 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) { await PageObjects.discover.waitUntilSidebarHasLoaded(); expect(await PageObjects.discover.getSidebarAriaDescription()).to.be( - '0 available fields. 0 meta fields.' + '0 available fields. 0 empty fields. 0 meta fields.' ); - await testSubjects.existOrFail( + await testSubjects.missingOrFail( `${PageObjects.discover.getSidebarSectionSelector('available')}-fetchWarning` ); await testSubjects.existOrFail(