[Fleet] re-enable flaky telemetry test with new agent checks (#166830)

Closes #164998

It seems the final agent is not loading correctly sometimes, we do
`wait_for` when we create the agents so it is a bit strange.

I have added a check that all agents are created before the test, if the
y are not loaded then I log all the agents so this will help us diagnose
any further flakiness better.

Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
This commit is contained in:
Mark Hopkin 2023-09-21 10:12:52 +01:00 committed by GitHub
parent d2feac06d4
commit 07b31f1d49
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -14,6 +14,8 @@ import { FtrProviderContext } from '../../api_integration/ftr_provider_context';
import { skipIfNoDockerRegistry, generateAgent } from '../helpers';
import { setupFleetAndAgents } from './agents/services';
const AGENT_COUNT_WAIT_ATTEMPTS = 3;
export default function (providerContext: FtrProviderContext) {
const { getService } = providerContext;
const supertest = getService('supertest');
@ -22,8 +24,7 @@ export default function (providerContext: FtrProviderContext) {
let agentCount = 0;
let pkgVersion: string;
// FLAKY: https://github.com/elastic/kibana/issues/164998
describe.skip('fleet_telemetry', () => {
describe('fleet_telemetry', () => {
skipIfNoDockerRegistry(providerContext);
before(async () => {
await kibanaServer.savedObjects.cleanStandardList();
@ -125,7 +126,35 @@ export default function (providerContext: FtrProviderContext) {
);
});
async function waitForAgents(expectedAgentCount: number, attempts: number, _attemptsMade = 0) {
const { body: apiResponse } = await supertest
.get(`/api/fleet/agents?showInactive=true`)
.set('kbn-xsrf', 'xxxx')
.expect(200);
if (apiResponse.list.length === expectedAgentCount) {
return apiResponse;
}
if (_attemptsMade >= attempts) {
throw new Error(
`Agents not loaded correctly, failing test. All agents: \n: ${JSON.stringify(
apiResponse.list,
null,
2
)}`
);
}
await new Promise((resolve) => setTimeout(resolve, 1000));
return waitForAgents(expectedAgentCount, attempts, _attemptsMade + 1);
}
it('should return the correct telemetry values for fleet', async () => {
// it appears agent 9 is not being loaded sometimes
// first check if all the agents have been correctly loaded
await waitForAgents(agentCount, AGENT_COUNT_WAIT_ATTEMPTS);
const {
body: [{ stats: apiResponse }],
} = await supertest
@ -140,13 +169,13 @@ export default function (providerContext: FtrProviderContext) {
.expect(200);
expect(apiResponse.stack_stats.kibana.plugins.fleet.agents).eql({
total_enrolled: 8,
total_enrolled: 8, // does not include inactive
healthy: 3,
unhealthy: 3,
offline: 1,
unenrolled: 0,
inactive: 1,
updating: 1,
updating: 1, // includes enrolling + unenrolling + updating
total_all_statuses: 8,
});