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] Include data source UUID in agent config yaml #64027

Merged
merged 1 commit into from
Apr 21, 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
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/
import { NewDatasource, DatasourceInput } from '../types';
import { Datasource, NewDatasource, DatasourceInput } from '../types';
import { storedDatasourceToAgentDatasource } from './datasource_to_agent_datasource';

describe('Ingest Manager - storedDatasourceToAgentDatasource', () => {
const mockDatasource: NewDatasource = {
const mockNewDatasource: NewDatasource = {
name: 'mock-datasource',
description: '',
config_id: '',
Expand All @@ -17,6 +17,12 @@ describe('Ingest Manager - storedDatasourceToAgentDatasource', () => {
inputs: [],
};

const mockDatasource: Datasource = {
...mockNewDatasource,
id: 'some-uuid',
revision: 1,
};

const mockInput: DatasourceInput = {
type: 'test-logs',
enabled: true,
Expand Down Expand Up @@ -70,7 +76,8 @@ describe('Ingest Manager - storedDatasourceToAgentDatasource', () => {

it('returns agent datasource config for datasource with no inputs', () => {
expect(storedDatasourceToAgentDatasource(mockDatasource)).toEqual({
id: 'mock-datasource',
id: 'some-uuid',
name: 'mock-datasource',
namespace: 'default',
enabled: true,
use_output: 'default',
Expand All @@ -87,7 +94,8 @@ describe('Ingest Manager - storedDatasourceToAgentDatasource', () => {
},
})
).toEqual({
id: 'mock-datasource',
id: 'some-uuid',
name: 'mock-datasource',
namespace: 'default',
enabled: true,
use_output: 'default',
Expand All @@ -99,9 +107,21 @@ describe('Ingest Manager - storedDatasourceToAgentDatasource', () => {
});
});

it('uses name for id when id is not provided in case of new datasource', () => {
expect(storedDatasourceToAgentDatasource(mockNewDatasource)).toEqual({
id: 'mock-datasource',
name: 'mock-datasource',
namespace: 'default',
enabled: true,
use_output: 'default',
inputs: [],
});
});

it('returns agent datasource config with flattened input and package stream', () => {
expect(storedDatasourceToAgentDatasource({ ...mockDatasource, inputs: [mockInput] })).toEqual({
id: 'mock-datasource',
id: 'some-uuid',
name: 'mock-datasource',
namespace: 'default',
enabled: true,
use_output: 'default',
Expand Down Expand Up @@ -140,7 +160,8 @@ describe('Ingest Manager - storedDatasourceToAgentDatasource', () => {
],
})
).toEqual({
id: 'mock-datasource',
id: 'some-uuid',
name: 'mock-datasource',
namespace: 'default',
enabled: true,
use_output: 'default',
Expand Down Expand Up @@ -169,7 +190,8 @@ describe('Ingest Manager - storedDatasourceToAgentDatasource', () => {
inputs: [{ ...mockInput, enabled: false }],
})
).toEqual({
id: 'mock-datasource',
id: 'some-uuid',
name: 'mock-datasource',
namespace: 'default',
enabled: true,
use_output: 'default',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ export const storedDatasourceToAgentDatasource = (
const { name, namespace, enabled, package: pkg, inputs } = datasource;

const fullDatasource: FullAgentConfigDatasource = {
id: name,
id: 'id' in datasource ? datasource.id : name,
name,
namespace,
enabled,
use_output: DEFAULT_OUTPUT.name, // TODO: hardcoded to default output for now
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,10 @@ export interface AgentConfig extends NewAgentConfig, SavedObjectAttributes {
revision: number;
}

export type FullAgentConfigDatasource = Pick<Datasource, 'namespace' | 'enabled'> & {
id: string;
export type FullAgentConfigDatasource = Pick<
Datasource,
'id' | 'name' | 'namespace' | 'enabled'
> & {
package?: Pick<DatasourcePackage, 'name' | 'version'>;
use_output: string;
inputs: Array<
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@ import { Loading } from '../../../../../components';

const CONFIG_KEYS_ORDER = [
'id',
'name',
'revision',
'type',
'outputs',
'datasources',
'enabled',
Expand All @@ -52,7 +54,7 @@ export const ConfigYamlView = memo<{ config: AgentConfig }>(({ config }) => {
return (
<EuiFlexGroup>
<EuiFlexItem grow={7}>
<EuiCodeBlock language="yaml" isCopyable>
<EuiCodeBlock language="yaml" isCopyable overflowHeight={500}>
{dump(fullConfigRequest.data.item, {
sortKeys: (keyA: string, keyB: string) => {
const indexA = CONFIG_KEYS_ORDER.indexOf(keyA);
Expand Down