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] Fix data source creation and double system data source #60069

Merged
merged 3 commits into from
Mar 13, 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
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]);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Line removed as this is done in datasourceService.create

}