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

[Ingest Manager] Fix datasource validation for streams without vars #67950

Merged
Show file tree
Hide file tree
Changes from 1 commit
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 @@ -178,6 +190,20 @@ describe('Ingest Manager - validateDatasource()', () => {
},
],
},
{
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 @@ -251,6 +277,20 @@ describe('Ingest Manager - validateDatasource()', () => {
},
],
},
{
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-disabled2': {},
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this an intentional addition, and if yes, can it have a more descriptive name than just the 2 added at the end?

},
},
'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-disabled2': {},
},
},
'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-disabled2': {},
},
},
'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);
};