diff --git a/x-pack/plugins/ingest_manager/public/applications/ingest_manager/sections/agent_config/create_datasource_page/services/validate_datasource.test.ts b/x-pack/plugins/ingest_manager/public/applications/ingest_manager/sections/agent_config/create_datasource_page/services/validate_datasource.test.ts index 992ace3530f409..67cde2dec3a56e 100644 --- a/x-pack/plugins/ingest_manager/public/applications/ingest_manager/sections/agent_config/create_datasource_page/services/validate_datasource.test.ts +++ b/x-pack/plugins/ingest_manager/public/applications/ingest_manager/sections/agent_config/create_datasource_page/services/validate_datasource.test.ts @@ -106,6 +106,18 @@ describe('Ingest Manager - validateDatasource()', () => { { dataset: 'disabled2', input: 'disabled2', title: 'Disabled 2', enabled: false }, ], }, + { + type: 'with-no-stream-vars', + enabled: true, + vars: [{ required: true, name: 'var-name', type: 'text' }], + streams: [ + { + id: 'with-no-stream-vars-bar', + dataset: 'bar', + enabled: true, + }, + ], + }, ], }, ], @@ -172,12 +184,26 @@ describe('Ingest Manager - validateDatasource()', () => { vars: { 'var-name': { value: undefined, type: 'text' } }, }, { - id: 'with-disabled-streams-disabled2', + id: 'with-disabled-streams-disabled-without-vars', dataset: 'disabled2', enabled: false, }, ], }, + { + type: 'with-no-stream-vars', + enabled: true, + vars: { + 'var-name': { value: 'test', type: 'text' }, + }, + streams: [ + { + id: 'with-no-stream-vars-bar', + dataset: 'bar', + enabled: true, + }, + ], + }, ], }; @@ -245,12 +271,26 @@ describe('Ingest Manager - validateDatasource()', () => { }, }, { - id: 'with-disabled-streams-disabled2', + id: 'with-disabled-streams-disabled-without-vars', dataset: 'disabled2', enabled: false, }, ], }, + { + type: 'with-no-stream-vars', + enabled: true, + vars: { + 'var-name': { value: undefined, type: 'text' }, + }, + streams: [ + { + id: 'with-no-stream-vars-bar', + dataset: 'bar', + enabled: true, + }, + ], + }, ], }; @@ -274,7 +314,18 @@ describe('Ingest Manager - validateDatasource()', () => { }, }, 'with-disabled-streams': { - streams: { 'with-disabled-streams-disabled': { vars: { 'var-name': null } } }, + streams: { + 'with-disabled-streams-disabled': { + vars: { 'var-name': null }, + }, + 'with-disabled-streams-disabled-without-vars': {}, + }, + }, + 'with-no-stream-vars': { + streams: { + 'with-no-stream-vars-bar': {}, + }, + vars: { 'var-name': null }, }, }, }; @@ -307,7 +358,16 @@ describe('Ingest Manager - validateDatasource()', () => { }, }, 'with-disabled-streams': { - streams: { 'with-disabled-streams-disabled': { vars: { 'var-name': null } } }, + streams: { + 'with-disabled-streams-disabled': { vars: { 'var-name': null } }, + 'with-disabled-streams-disabled-without-vars': {}, + }, + }, + 'with-no-stream-vars': { + vars: { + 'var-name': ['var-name is required'], + }, + streams: { 'with-no-stream-vars-bar': {} }, }, }, }); @@ -354,7 +414,18 @@ describe('Ingest Manager - validateDatasource()', () => { }, }, 'with-disabled-streams': { - streams: { 'with-disabled-streams-disabled': { vars: { 'var-name': null } } }, + streams: { + 'with-disabled-streams-disabled': { + vars: { 'var-name': null }, + }, + 'with-disabled-streams-disabled-without-vars': {}, + }, + }, + 'with-no-stream-vars': { + vars: { + 'var-name': ['var-name is required'], + }, + streams: { 'with-no-stream-vars-bar': {} }, }, }, }); diff --git a/x-pack/plugins/ingest_manager/public/applications/ingest_manager/sections/agent_config/create_datasource_page/services/validate_datasource.ts b/x-pack/plugins/ingest_manager/public/applications/ingest_manager/sections/agent_config/create_datasource_page/services/validate_datasource.ts index 61273e1fb3db9b..5b4cfe170a4786 100644 --- a/x-pack/plugins/ingest_manager/public/applications/ingest_manager/sections/agent_config/create_datasource_page/services/validate_datasource.ts +++ b/x-pack/plugins/ingest_manager/public/applications/ingest_manager/sections/agent_config/create_datasource_page/services/validate_datasource.ts @@ -110,36 +110,31 @@ export const validateDatasource = ( // Validate each input stream with config fields if (input.streams.length) { input.streams.forEach((stream) => { - if (!stream.vars) { - return; - } - - const streamValidationResults: DatasourceConfigValidationResults = { - vars: undefined, - }; - - const streamVarsByName = ( - ( - registryInputsByType[input.type].streams.find( - (registryStream) => registryStream.dataset === stream.dataset - ) || {} - ).vars || [] - ).reduce((vars, registryVar) => { - vars[registryVar.name] = registryVar; - return vars; - }, {} as Record); + const streamValidationResults: DatasourceConfigValidationResults = {}; // Validate stream-level config fields - streamValidationResults.vars = Object.entries(stream.vars).reduce( - (results, [name, configEntry]) => { - results[name] = - input.enabled && stream.enabled - ? validateDatasourceConfig(configEntry, streamVarsByName[name]) - : null; - return results; - }, - {} as ValidationEntry - ); + if (stream.vars) { + const streamVarsByName = ( + ( + registryInputsByType[input.type].streams.find( + (registryStream) => registryStream.dataset === stream.dataset + ) || {} + ).vars || [] + ).reduce((vars, registryVar) => { + vars[registryVar.name] = registryVar; + return vars; + }, {} as Record); + streamValidationResults.vars = Object.entries(stream.vars).reduce( + (results, [name, configEntry]) => { + results[name] = + input.enabled && stream.enabled + ? validateDatasourceConfig(configEntry, streamVarsByName[name]) + : null; + return results; + }, + {} as ValidationEntry + ); + } inputValidationResults.streams![stream.id] = streamValidationResults; }); @@ -228,5 +223,6 @@ export const validationHasErrors = ( | DatasourceConfigValidationResults ) => { const flattenedValidation = getFlattenedObject(validationResults); + return !!Object.entries(flattenedValidation).find(([, value]) => !!value); };