forked from elastic/kibana
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Fleet] Task to publish Agent metrics (elastic#168435)
## Summary Closes elastic/ingest-dev#2396 Added a new kibana task that publishes Agent metrics every minute to data streams installed by fleet_server package. Opened the pr for review, there are a few things to finalize, but the core logic won't change much. To test locally: - Install fleet_server package 1.4.0 from [this](elastic/integrations#8145) pr to get the mappings - Start kibana locally, wait for a few minutes for the metrics task to run (every minute) - Go to discover, `metrics-*` index pattern, filter on `data_stream.dataset: fleet_server.*` - Expect data to be populated in `fleet_server.agent_status` and `fleet_server.agent_versions` datasets. <img width="1787" alt="image" src="https://github.com/elastic/kibana/assets/90178898/615af9df-fe4b-4c17-8c8c-88646c403a18"> ### Checklist - [x] [Unit or functional tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html) were updated or added to match the most common scenarios --------- Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com>
- Loading branch information
1 parent
3b8a116
commit cf0ec92
Showing
16 changed files
with
737 additions
and
15 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
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
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
92 changes: 92 additions & 0 deletions
92
x-pack/plugins/fleet/server/services/metrics/fetch_agent_metrics.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,92 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
import type { ElasticsearchClientMock } from '@kbn/core/server/mocks'; | ||
import { coreMock } from '@kbn/core/server/mocks'; | ||
import type { CoreSetup } from '@kbn/core/server'; | ||
|
||
import { fetchAgentMetrics } from './fetch_agent_metrics'; | ||
|
||
jest.mock('../../collectors/agent_collectors', () => { | ||
return { | ||
getAgentUsage: jest.fn().mockResolvedValue({}), | ||
}; | ||
}); | ||
|
||
describe('fetchAgentMetrics', () => { | ||
const { createSetup: coreSetupMock } = coreMock; | ||
const abortController = new AbortController(); | ||
let mockCore: CoreSetup; | ||
let esClient: ElasticsearchClientMock; | ||
|
||
beforeEach(async () => { | ||
mockCore = coreSetupMock(); | ||
const [{ elasticsearch }] = await mockCore.getStartServices(); | ||
esClient = elasticsearch.client.asInternalUser as ElasticsearchClientMock; | ||
}); | ||
|
||
it('should fetch agent metrics', async () => { | ||
esClient.search.mockResolvedValue({ | ||
took: 5, | ||
timed_out: false, | ||
_shards: { | ||
total: 1, | ||
successful: 1, | ||
skipped: 0, | ||
failed: 0, | ||
}, | ||
hits: { | ||
total: { | ||
value: 0, | ||
relation: 'eq', | ||
}, | ||
hits: [], | ||
}, | ||
aggregations: { | ||
versions: { | ||
buckets: [ | ||
{ | ||
key: '8.12.0', | ||
doc_count: 1, | ||
}, | ||
], | ||
}, | ||
upgrade_details: { | ||
buckets: [ | ||
{ | ||
key: 'UPG_REQUESTED', | ||
doc_count: 1, | ||
}, | ||
], | ||
}, | ||
}, | ||
}); | ||
|
||
const result = await fetchAgentMetrics(mockCore, abortController); | ||
|
||
expect(result).toEqual({ | ||
agents: {}, | ||
agents_per_version: [ | ||
{ | ||
version: '8.12.0', | ||
count: 1, | ||
}, | ||
], | ||
upgrading_step: { | ||
downloading: 0, | ||
extracting: 0, | ||
failed: 0, | ||
replacing: 0, | ||
requested: 1, | ||
restarting: 0, | ||
rollback: 0, | ||
scheduled: 0, | ||
watching: 0, | ||
}, | ||
}); | ||
}); | ||
}); |
Oops, something went wrong.