Skip to content
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

[EDR Workflows][E2E] Recreate agent on createEndpointHost task fail #169092

Merged
merged 47 commits into from
Oct 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
3a18c45
Do not set date if its outside of range.
szwarckonrad Oct 13, 2023
70a9f67
Merge branch 'main' into unskip-automated-response-actions
szwarckonrad Oct 16, 2023
e233a46
test
szwarckonrad Oct 16, 2023
78b7534
test
szwarckonrad Oct 17, 2023
8ddff62
test
szwarckonrad Oct 17, 2023
7525a3a
test
szwarckonrad Oct 17, 2023
d3405b7
Merge branch 'main' into before-all-debug
szwarckonrad Oct 17, 2023
88d6fbc
test
szwarckonrad Oct 17, 2023
3b3c0fd
test
szwarckonrad Oct 17, 2023
1d22225
Merge branch 'main' into before-all-debug
szwarckonrad Oct 17, 2023
c2895db
test
szwarckonrad Oct 17, 2023
d159e59
Merge remote-tracking branch 'origin/before-all-debug' into before-al…
szwarckonrad Oct 17, 2023
f724c6e
test
szwarckonrad Oct 17, 2023
d2504a8
test
szwarckonrad Oct 18, 2023
c8466f6
test
szwarckonrad Oct 18, 2023
6077045
test
szwarckonrad Oct 18, 2023
514210a
test
szwarckonrad Oct 18, 2023
5412146
test
szwarckonrad Oct 18, 2023
53b27db
test
szwarckonrad Oct 18, 2023
583460f
test
szwarckonrad Oct 18, 2023
bffac11
test
szwarckonrad Oct 18, 2023
ea72221
Merge branch 'main' into before-all-debug
szwarckonrad Oct 19, 2023
3036288
more verbose logging
szwarckonrad Oct 19, 2023
8a75f91
more verbose logging
szwarckonrad Oct 19, 2023
21cb936
more verbose logging
szwarckonrad Oct 19, 2023
f85e456
more verbose logging
szwarckonrad Oct 19, 2023
a7b4656
more verbose logging
szwarckonrad Oct 19, 2023
4c20920
align form as well
szwarckonrad Oct 19, 2023
d5ff45f
align form as well
szwarckonrad Oct 19, 2023
e3208b8
align form as well
szwarckonrad Oct 19, 2023
c38f63d
align form as well
szwarckonrad Oct 19, 2023
d080524
align form as well
szwarckonrad Oct 19, 2023
c65e397
align form as well
szwarckonrad Oct 19, 2023
0cffcaf
align form as well
szwarckonrad Oct 19, 2023
e14ba40
align form as well
szwarckonrad Oct 23, 2023
c2307d0
Revert "align form as well"
szwarckonrad Oct 23, 2023
e68126c
align form as well
szwarckonrad Oct 23, 2023
a2f7e49
wip
szwarckonrad Oct 23, 2023
ebcbb6b
wip
szwarckonrad Oct 23, 2023
ad90137
Merge branch 'main' into before-all-debug
patrykkopycinski Oct 23, 2023
af7c22e
wip
szwarckonrad Oct 24, 2023
97abb64
wip
szwarckonrad Oct 24, 2023
ad1c468
wip
szwarckonrad Oct 24, 2023
3db8475
Merge branch 'main' into before-all-debug
szwarckonrad Oct 24, 2023
490544f
wip
szwarckonrad Oct 25, 2023
d161695
Merge remote-tracking branch 'origin/before-all-debug' into before-al…
szwarckonrad Oct 25, 2023
347ab8a
Merge branch 'main' into before-all-debug
szwarckonrad Oct 25, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .buildkite/pipelines/flaky_tests/pipeline.ts
Original file line number Diff line number Diff line change
Expand Up @@ -162,10 +162,11 @@ for (const testSuite of testSuites) {
`Group configuration was not found in groups.json for the following cypress suite: {${suiteName}}.`
);
}
const agentQueue = suiteName.includes('defend_workflows') ? 'n2-4-virt' : 'n2-4-spot';
steps.push({
command: `.buildkite/scripts/steps/functional/${suiteName}.sh`,
label: group.name,
agents: { queue: 'n2-4-spot' },
agents: { queue: agentQueue },
depends_on: 'build',
parallelism: testSuite.count,
concurrency,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@ import { createEndpointHost } from '../../tasks/create_endpoint_host';
import { deleteAllLoadedEndpointData } from '../../tasks/delete_all_endpoint_data';
import { enableAllPolicyProtections } from '../../tasks/endpoint_policy';

// FLAKY: https://github.com/elastic/kibana/issues/168340
describe.skip(
describe(
'Automated Response Actions',
{
tags: [
Expand Down Expand Up @@ -76,8 +75,7 @@ describe.skip(
disableExpandableFlyoutAdvancedSettings();
});

// FLAKY: https://github.com/elastic/kibana/issues/168427
describe.skip('From alerts', () => {
describe('From alerts', () => {
let ruleId: string;
let ruleName: string;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,7 @@ import { createEndpointHost } from '../../tasks/create_endpoint_host';
import { deleteAllLoadedEndpointData } from '../../tasks/delete_all_endpoint_data';
import { enableAllPolicyProtections } from '../../tasks/endpoint_policy';

// FLAKY: https://github.com/elastic/kibana/issues/168284
describe.skip('Endpoints page', { tags: ['@ess', '@serverless'] }, () => {
describe('Endpoints page', { tags: ['@ess', '@serverless'] }, () => {
let indexedPolicy: IndexedFleetEndpointPolicyResponse;
let policy: PolicyData;
let createdHost: CreateAndEnrollEndpointHostResponse;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -332,16 +332,39 @@ export const dataLoadersForRealEndpoints = (
options: Omit<CreateAndEnrollEndpointHostOptions, 'log' | 'kbnClient'>
): Promise<CreateAndEnrollEndpointHostResponse> => {
const { kbnClient, log } = await stackServicesPromise;
return createAndEnrollEndpointHost({
useClosestVersionMatch: true,
...options,
log,
kbnClient,
}).then((newHost) => {
return waitForEndpointToStreamData(kbnClient, newHost.agentId, 360000).then(() => {

let retryAttempt = 0;
const attemptCreateEndpointHost = async (): Promise<CreateAndEnrollEndpointHostResponse> => {
try {
log.info(`Creating endpoint host, attempt ${retryAttempt}`);
const newHost = await createAndEnrollEndpointHost({
useClosestVersionMatch: true,
...options,
log,
kbnClient,
});
await waitForEndpointToStreamData(kbnClient, newHost.agentId, 360000);
return newHost;
});
});
} catch (err) {
log.info(`Caught error when setting up the agent: ${err}`);
if (retryAttempt === 0 && err.agentId) {
retryAttempt++;
await destroyEndpointHost(kbnClient, {
hostname: err.hostname || '', // No hostname in CI env for vagrant
agentId: err.agentId,
});
log.info(`Deleted endpoint host ${err.agentId} and retrying`);
return attemptCreateEndpointHost();
} else {
log.info(
`${retryAttempt} attempts of creating endpoint host failed, reason for the last failure was ${err}`
);
throw err;
}
}
};

return attemptCreateEndpointHost();
},

destroyEndpointHost: async (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@ export const createEndpointHost = (
{
agentPolicyId,
},
{ timeout: timeout ?? 900000 } // 15 minutes, since setup can take 10 minutes and more. Task will time out if is not resolved within this time.
{ timeout: timeout ?? 30 * 60 * 1000 }
);
};
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ const createMultipassVm = async ({
};
};

const deleteMultipassVm = async (vmName: string): Promise<void> => {
export const deleteMultipassVm = async (vmName: string): Promise<void> => {
if (process.env.CI) {
await execa.command(`vagrant destroy -f`, {
env: {
Expand Down Expand Up @@ -339,7 +339,10 @@ const enrollHostWithFleet = async ({
]);
}
log.info(`Waiting for Agent to check-in with Fleet`);
const agent = await waitForHostToEnroll(kbnClient, vmName, 240000);

const agent = await waitForHostToEnroll(kbnClient, vmName, 8 * 60 * 1000);

log.info(`Agent enrolled with Fleet, status: `, agent.status);

return {
agentId: agent.id,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,15 +147,19 @@ export const waitForHostToEnroll = async (
return elapsedTime > timeoutMs;
};
let found: Agent | undefined;
let agentId: string | undefined;

while (!found && !hasTimedOut()) {
found = await retryOnError(
async () =>
fetchFleetAgents(kbnClient, {
perPage: 1,
kuery: `(local_metadata.host.hostname.keyword : "${hostname}") and (status:online)`,
kuery: `(local_metadata.host.hostname.keyword : "${hostname}")`,
showInactive: false,
}).then((response) => response.items[0]),
}).then((response) => {
agentId = response.items[0]?.id;
return response.items.filter((agent) => agent.status === 'online')[0];
}),
RETRYABLE_TRANSIENT_ERRORS
);

Expand All @@ -166,7 +170,14 @@ export const waitForHostToEnroll = async (
}

if (!found) {
throw new Error(`Timed out waiting for host [${hostname}] to show up in Fleet`);
throw Object.assign(
new Error(
`Timed out waiting for host [${hostname}] to show up in Fleet in ${
timeoutMs / 60 / 1000
} seconds`
),
{ agentId, hostname }
);
}

return found;
Expand Down