diff --git a/x-pack/plugins/ingest_manager/server/services/agent_config.ts b/x-pack/plugins/ingest_manager/server/services/agent_config.ts index c0eb614102b29..e5b20de3bf911 100644 --- a/x-pack/plugins/ingest_manager/server/services/agent_config.ts +++ b/x-pack/plugins/ingest_manager/server/services/agent_config.ts @@ -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'; @@ -54,7 +55,7 @@ class AgentConfigService { await soClient.update(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', }); @@ -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 ); @@ -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 diff --git a/x-pack/plugins/ingest_manager/server/services/setup.ts b/x-pack/plugins/ingest_manager/server/services/setup.ts index f770e9d17ffb1..4b79cd639b613 100644 --- a/x-pack/plugins/ingest_manager/server/services/setup.ts +++ b/x-pack/plugins/ingest_manager/server/services/setup.ts @@ -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: { @@ -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]); }