-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Ingest] Allow to enable monitoring of elastic agent
- Loading branch information
Showing
6 changed files
with
227 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
123 changes: 123 additions & 0 deletions
123
x-pack/plugins/ingest_manager/server/services/agent_config.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,123 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
import { agentConfigService } from './agent_config'; | ||
import { savedObjectsClientMock } from '../../../../../src/core/server/saved_objects/service/saved_objects_client.mock'; | ||
import { Output } from '../types'; | ||
|
||
function getSavedObjectMock(configAttributes: any) { | ||
const mock = savedObjectsClientMock.create(); | ||
|
||
mock.get.mockImplementation(async (type: string, id: string) => { | ||
return { | ||
type, | ||
id, | ||
references: [], | ||
attributes: configAttributes, | ||
}; | ||
}); | ||
|
||
return mock; | ||
} | ||
|
||
jest.mock('./output', () => { | ||
return { | ||
outputService: { | ||
getDefaultOutputId: () => 'test-id', | ||
get: (): Output => { | ||
return { | ||
id: 'test-id', | ||
is_default: true, | ||
name: 'default', | ||
// @ts-ignore | ||
type: 'elasticsearch', | ||
hosts: ['http://127.0.0.1:9201'], | ||
}; | ||
}, | ||
}, | ||
}; | ||
}); | ||
|
||
describe('agent config', () => { | ||
describe('getFullConfig', () => { | ||
it('should return a config without monitoring if not monitoring is not enabled', async () => { | ||
const soClient = getSavedObjectMock({ | ||
revision: 1, | ||
}); | ||
const config = await agentConfigService.getFullConfig(soClient, 'config'); | ||
|
||
expect(config).toMatchObject({ | ||
id: 'config', | ||
outputs: { | ||
default: { | ||
type: 'elasticsearch', | ||
hosts: ['http://127.0.0.1:9201'], | ||
ca_sha256: undefined, | ||
api_key: undefined, | ||
}, | ||
}, | ||
datasources: [], | ||
revision: 1, | ||
}); | ||
}); | ||
|
||
it('should return a config with monitoring if monitoring is enabled for logs', async () => { | ||
const soClient = getSavedObjectMock({ | ||
revision: 1, | ||
monitoring_enabled: ['logs'], | ||
}); | ||
const config = await agentConfigService.getFullConfig(soClient, 'config'); | ||
|
||
expect(config).toMatchObject({ | ||
id: 'config', | ||
outputs: { | ||
default: { | ||
type: 'elasticsearch', | ||
hosts: ['http://127.0.0.1:9201'], | ||
ca_sha256: undefined, | ||
api_key: undefined, | ||
}, | ||
}, | ||
datasources: [], | ||
revision: 1, | ||
'settings.monitoring': { | ||
use_output: 'default', | ||
enabled: true, | ||
logs: true, | ||
metrics: false, | ||
}, | ||
}); | ||
}); | ||
|
||
it('should return a config with monitoring if monitoring is enabled for metrics', async () => { | ||
const soClient = getSavedObjectMock({ | ||
revision: 1, | ||
monitoring_enabled: ['metrics'], | ||
}); | ||
const config = await agentConfigService.getFullConfig(soClient, 'config'); | ||
|
||
expect(config).toMatchObject({ | ||
id: 'config', | ||
outputs: { | ||
default: { | ||
type: 'elasticsearch', | ||
hosts: ['http://127.0.0.1:9201'], | ||
ca_sha256: undefined, | ||
api_key: undefined, | ||
}, | ||
}, | ||
datasources: [], | ||
revision: 1, | ||
'settings.monitoring': { | ||
use_output: 'default', | ||
enabled: true, | ||
logs: false, | ||
metrics: true, | ||
}, | ||
}); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters