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

[7.x] [Ingest Manager] Fix datasource validation for streams without vars (#67950) #68150

Merged
merged 1 commit into from
Jun 4, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
Expand Up @@ -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,
},
],
},
],
},
],
Expand Down Expand Up @@ -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,
},
],
},
],
};

Expand Down Expand Up @@ -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,
},
],
},
],
};

Expand All @@ -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 },
},
},
};
Expand Down Expand Up @@ -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': {} },
},
},
});
Expand Down Expand Up @@ -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': {} },
},
},
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, RegistryVarsEntry>);
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<string, RegistryVarsEntry>);
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;
});
Expand Down Expand Up @@ -228,5 +223,6 @@ export const validationHasErrors = (
| DatasourceConfigValidationResults
) => {
const flattenedValidation = getFlattenedObject(validationResults);

return !!Object.entries(flattenedValidation).find(([, value]) => !!value);
};