-
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.
[Fleet] added agent logs top errors from 100 hits (#162135)
## Summary Closes #148976 Added back top errors from agent logs by querying 100 hits and counting the top occurrences. ### 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
- Loading branch information
1 parent
b5965a3
commit 10c289d
Showing
5 changed files
with
134 additions
and
25 deletions.
There are no files selected for viewing
84 changes: 84 additions & 0 deletions
84
x-pack/plugins/fleet/server/collectors/agent_logs_top_errors.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,84 @@ | ||
/* | ||
* 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 { ElasticsearchClient } from '@kbn/core-elasticsearch-server'; | ||
|
||
import { getAgentLogsTopErrors } from './agent_logs_top_errors'; | ||
|
||
describe('getAgentLogsTopErrors', () => { | ||
it('should return top 3 errors from 100 hits', async () => { | ||
const esClientMock = { | ||
search: jest.fn().mockImplementation((params) => { | ||
if (params.index === 'logs-elastic_agent-*') | ||
return { | ||
hits: { | ||
hits: [ | ||
{ | ||
_source: { | ||
message: 'error 2', | ||
}, | ||
}, | ||
{ | ||
_source: { | ||
message: 'error 2', | ||
}, | ||
}, | ||
{ | ||
_source: { | ||
message: 'error 3', | ||
}, | ||
}, | ||
{ | ||
_source: { | ||
message: 'error 3', | ||
}, | ||
}, | ||
{ | ||
_source: { | ||
message: 'error 3', | ||
}, | ||
}, | ||
{ | ||
_source: { | ||
message: 'error 1', | ||
}, | ||
}, | ||
], | ||
}, | ||
}; | ||
else | ||
return { | ||
hits: { | ||
hits: [ | ||
{ | ||
_source: { | ||
message: 'fleet server error 2', | ||
}, | ||
}, | ||
{ | ||
_source: { | ||
message: 'fleet server error 2', | ||
}, | ||
}, | ||
{ | ||
_source: { | ||
message: 'fleet server error 1', | ||
}, | ||
}, | ||
], | ||
}, | ||
}; | ||
}), | ||
} as unknown as ElasticsearchClient; | ||
|
||
const topErrors = await getAgentLogsTopErrors(esClientMock); | ||
expect(topErrors).toEqual({ | ||
agent_logs_top_errors: ['error 3', 'error 2', 'error 1'], | ||
fleet_server_logs_top_errors: ['fleet server error 2', 'fleet server error 1'], | ||
}); | ||
}); | ||
}); |
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