-
Notifications
You must be signed in to change notification settings - Fork 8.3k
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
[Fleet] Fix agent status count #95099
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
/* | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. thanks for adding tests! |
||
* 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 expect from '@kbn/expect'; | ||
|
||
import { FtrProviderContext } from '../../../api_integration/ftr_provider_context'; | ||
import { AGENTS_INDEX } from '../../../../plugins/fleet/common'; | ||
|
||
export default function ({ getService }: FtrProviderContext) { | ||
const es = getService('es'); | ||
const esArchiver = getService('esArchiver'); | ||
const supertest = getService('supertest'); | ||
|
||
describe('fleet_agents_status', () => { | ||
before(async () => { | ||
await esArchiver.loadIfNeeded('fleet/agents'); | ||
// 2 agents online | ||
await es.update({ | ||
id: 'agent1', | ||
refresh: 'wait_for', | ||
index: AGENTS_INDEX, | ||
body: { | ||
doc: { | ||
last_checkin: new Date().toISOString(), | ||
}, | ||
}, | ||
}); | ||
await es.update({ | ||
id: 'agent2', | ||
refresh: 'wait_for', | ||
index: AGENTS_INDEX, | ||
body: { | ||
doc: { | ||
last_checkin: new Date().toISOString(), | ||
}, | ||
}, | ||
}); | ||
// 1 agents offline | ||
await es.update({ | ||
id: 'agent3', | ||
refresh: 'wait_for', | ||
index: AGENTS_INDEX, | ||
body: { | ||
doc: { | ||
last_checkin: new Date(Date.now() - 1000 * 60 * 60 * 60 * 10).toISOString(), | ||
}, | ||
}, | ||
}); | ||
// 1 agent upgrading | ||
await es.update({ | ||
id: 'agent4', | ||
refresh: 'wait_for', | ||
index: AGENTS_INDEX, | ||
body: { | ||
doc: { | ||
last_checkin: new Date().toISOString(), | ||
upgrade_started_at: new Date().toISOString(), | ||
}, | ||
}, | ||
}); | ||
}); | ||
after(async () => { | ||
await esArchiver.unload('fleet/agents'); | ||
}); | ||
|
||
it('should return the status of agents', async () => { | ||
const { body: apiResponse } = await supertest.get(`/api/fleet/agent-status`).expect(200); | ||
|
||
expect(apiResponse).to.eql({ | ||
results: { | ||
events: 0, | ||
total: 4, | ||
online: 2, | ||
error: 0, | ||
offline: 1, | ||
updating: 1, | ||
other: 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The way I interpret lines 134-138 are that if
showUpgradeable
is true,agents
will be narrowed to only include upgradeable agents.What would this return in that case? It appears the count will before the full/initial list, but
agents
would be a list of only upgradeable agents. i.e. potentially an array of 3 items but atotal: 5
.It's totally possible I misunderstand what's happening here. Thanks for researching and sending a PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
showUpgradeable
is a little weird here as the filtering is happening when we get the results,I am wondering if we can implement the show upgradeable as a filter in the ES query it will make things easier, otherwise I guess it's ok to have an inaccurate total for the show upgradeable filter an create an issue for that.