Skip to content

Commit

Permalink
Exclude disabled datasources and streams from agent config (#62869)
Browse files Browse the repository at this point in the history
  • Loading branch information
jen-huang authored Apr 8, 2020
1 parent 941a487 commit d4f2bd7
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ describe('Ingest Manager - storedDatasourceToAgentDatasource', () => {
},
{
id: 'test-logs-bar',
enabled: false,
enabled: true,
dataset: 'bar',
config: {
barVar: { value: 'bar-value' },
Expand Down Expand Up @@ -119,7 +119,7 @@ describe('Ingest Manager - storedDatasourceToAgentDatasource', () => {
},
{
id: 'test-logs-bar',
enabled: false,
enabled: true,
dataset: 'bar',
barVar: 'bar-value',
barVar2: [1, 2],
Expand All @@ -140,6 +140,44 @@ describe('Ingest Manager - storedDatasourceToAgentDatasource', () => {
});
});

it('returns agent datasource config without disabled streams', () => {
expect(
storedDatasourceToAgentDatasource({
...mockDatasource,
inputs: [
{
...mockInput,
streams: [{ ...mockInput.streams[0] }, { ...mockInput.streams[1], enabled: false }],
},
],
})
).toEqual({
id: 'mock-datasource',
namespace: 'default',
enabled: true,
use_output: 'default',
inputs: [
{
type: 'test-logs',
enabled: true,
inputVar: 'input-value',
inputVar3: {
testField: 'test',
},
streams: [
{
id: 'test-logs-foo',
enabled: true,
dataset: 'foo',
fooVar: 'foo-value',
fooVar2: [1, 2],
},
],
},
],
});
});

it('returns agent datasource config without disabled inputs', () => {
expect(
storedDatasourceToAgentDatasource({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,14 +51,16 @@ export const storedDatasourceToAgentDatasource = (
const fullInput = {
...input,
...Object.entries(input.config || {}).reduce(configReducer, {}),
streams: input.streams.map(stream => {
const fullStream = {
...stream,
...Object.entries(stream.config || {}).reduce(configReducer, {}),
};
delete fullStream.config;
return fullStream;
}),
streams: input.streams
.filter(stream => stream.enabled)
.map(stream => {
const fullStream = {
...stream,
...Object.entries(stream.config || {}).reduce(configReducer, {}),
};
delete fullStream.config;
return fullStream;
}),
};
delete fullInput.config;
return fullInput;
Expand Down
6 changes: 3 additions & 3 deletions x-pack/plugins/ingest_manager/server/services/agent_config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -319,9 +319,9 @@ class AgentConfigService {
return outputs;
}, {} as FullAgentConfig['outputs']),
},
datasources: (config.datasources as Datasource[]).map(ds =>
storedDatasourceToAgentDatasource(ds)
),
datasources: (config.datasources as Datasource[])
.filter(datasource => datasource.enabled)
.map(ds => storedDatasourceToAgentDatasource(ds)),
revision: config.revision,
};

Expand Down

0 comments on commit d4f2bd7

Please sign in to comment.