Skip to content

Commit

Permalink
[Ingest] Fix data source creation and double system data source (#60069)
Browse files Browse the repository at this point in the history
* Fix Internal Server Error about mapping issue when creating a data source

* Fix double system datasource appearing in default config

* Ensure we can never double assign same datasource ID to agent config
  • Loading branch information
jen-huang authored Mar 13, 2020
1 parent 1a40b97 commit cc535ff
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
13 changes: 9 additions & 4 deletions x-pack/plugins/ingest_manager/server/services/agent_config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/
import { uniq } from 'lodash';
import { SavedObjectsClientContract } from 'kibana/server';
import { AuthenticatedUser } from '../../../security/server';
import { DEFAULT_AGENT_CONFIG, AGENT_CONFIG_SAVED_OBJECT_TYPE } from '../constants';
Expand Down Expand Up @@ -54,7 +55,7 @@ class AgentConfigService {
await soClient.update<AgentConfig>(SAVED_OBJECT_TYPE, id, {
...agentConfig,
revision: oldAgentConfig.revision + 1,
updated_on: new Date().toString(),
updated_on: new Date().toISOString(),
updated_by: user ? user.username : 'system',
});

Expand Down Expand Up @@ -205,7 +206,9 @@ class AgentConfigService {
id,
{
...oldAgentConfig,
datasources: [...((oldAgentConfig.datasources || []) as string[])].concat(datasourceIds),
datasources: uniq(
[...((oldAgentConfig.datasources || []) as string[])].concat(datasourceIds)
),
},
options?.user
);
Expand All @@ -228,8 +231,10 @@ class AgentConfigService {
id,
{
...oldAgentConfig,
datasources: [...((oldAgentConfig.datasources || []) as string[])].filter(
dsId => !datasourceIds.includes(dsId)
datasources: uniq(
[...((oldAgentConfig.datasources || []) as string[])].filter(
dsId => !datasourceIds.includes(dsId)
)
),
},
options?.user
Expand Down
4 changes: 1 addition & 3 deletions x-pack/plugins/ingest_manager/server/services/setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ async function addPackageToConfig(
savedObjectsClient: soClient,
pkgkey: `${packageToInstall.name}-${packageToInstall.version}`,
});
const datasource = await datasourceService.create(soClient, {
await datasourceService.create(soClient, {
name: `${packageInfo.name}-1`,
enabled: true,
package: {
Expand All @@ -82,6 +82,4 @@ async function addPackageToConfig(
config_id: config.id,
output_id: defaultOutput.id,
});
// Assign it to the given agent config
await agentConfigService.assignDatasources(soClient, datasource.config_id, [datasource.id]);
}

0 comments on commit cc535ff

Please sign in to comment.