Skip to content

Commit

Permalink
update cypress task
Browse files Browse the repository at this point in the history
review changes @paul-tavares
  • Loading branch information
ashokaditya committed May 23, 2023
1 parent 555a9bf commit ca1919b
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ export interface IndexedEndpointAndFleetActionsForHostResponse {
endpointActionResponsesIndex: string;
}

export interface IndexEndpointAndFleetActionsForHostOptions {
numResponseActions?: number;
}
/**
* Indexes a random number of Endpoint (via Fleet) Actions for a given host
* (NOTE: ensure that fleet is setup first before calling this loading function)
Expand All @@ -43,11 +46,13 @@ export interface IndexedEndpointAndFleetActionsForHostResponse {
export const indexEndpointAndFleetActionsForHost = async (
esClient: Client,
endpointHost: HostMetadata,
fleetActionGenerator: FleetActionGenerator = defaultFleetActionGenerator
fleetActionGenerator: FleetActionGenerator = defaultFleetActionGenerator,
options: IndexEndpointAndFleetActionsForHostOptions = {}
): Promise<IndexedEndpointAndFleetActionsForHostResponse> => {
const ES_INDEX_OPTIONS = { headers: { 'X-elastic-product-origin': 'fleet' } };
const agentId = endpointHost.elastic.agent.id;
const total = fleetActionGenerator.randomN(5) + 11; // generate at least 11 actions
const actionsCount = options.numResponseActions ?? 1;
const total = fleetActionGenerator.randomN(5) + actionsCount;
const response: IndexedEndpointAndFleetActionsForHostResponse = {
actions: [],
actionResponses: [],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import type {
import {
deleteIndexedEndpointAndFleetActions,
indexEndpointAndFleetActionsForHost,
type IndexEndpointAndFleetActionsForHostOptions,
} from './index_endpoint_fleet_actions';

import type {
Expand Down Expand Up @@ -88,6 +89,7 @@ export async function indexEndpointHostDocs({
enrollFleet,
generator,
withResponseActions = true,
numResponseActions,
}: {
numDocs: number;
client: Client;
Expand All @@ -99,6 +101,7 @@ export async function indexEndpointHostDocs({
enrollFleet: boolean;
generator: EndpointDocGenerator;
withResponseActions?: boolean;
numResponseActions?: IndexEndpointAndFleetActionsForHostOptions['numResponseActions'];
}): Promise<IndexedHostsResponse> {
const timeBetweenDocs = 6 * 3600 * 1000; // 6 hours between metadata documents
const timestamp = new Date().getTime();
Expand Down Expand Up @@ -198,7 +201,10 @@ export async function indexEndpointHostDocs({
const actionsResponse = await indexEndpointAndFleetActionsForHost(
client,
hostMetadata,
undefined
undefined,
{
numResponseActions,
}
);
mergeAndAppendArrays(response, actionsResponse);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,8 @@ export async function indexHostsAndAlerts(
fleet: boolean,
options: TreeOptions = {},
DocGenerator: typeof EndpointDocGenerator = EndpointDocGenerator,
withResponseActions = true
withResponseActions = true,
numResponseActions?: number
): Promise<IndexedHostsAndAlertsResponse> {
const random = seedrandom(seed);
const epmEndpointPackage = await getEndpointPackageInfo(kbnClient);
Expand Down Expand Up @@ -117,6 +118,7 @@ export async function indexHostsAndAlerts(
enrollFleet: fleet,
generator,
withResponseActions,
numResponseActions,
});

mergeAndAppendArrays(response, indexedHosts);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ describe('Response actions history page', () => {
// let actionData: ReturnTypeFromChainable<typeof indexActionResponses>;

before(() => {
indexEndpointHosts().then((indexEndpoints) => {
indexEndpointHosts({ numResponseActions: 11 }).then((indexEndpoints) => {
endpointData = indexEndpoints;
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,14 +114,22 @@ export const dataLoaders = (

indexEndpointHosts: async (options: IndexEndpointHostsCyTaskOptions = {}) => {
const { kbnClient, esClient } = await stackServicesPromise;
const { count: numHosts, version, os, isolation, withResponseActions } = options;
const {
count: numHosts,
version,
os,
isolation,
withResponseActions,
numResponseActions,
} = options;

return cyLoadEndpointDataHandler(esClient, kbnClient, {
numHosts,
version,
os,
isolation,
withResponseActions,
numResponseActions,
});
},

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ export interface CyLoadEndpointDataOptions
generatorSeed: string;
waitUntilTransformed: boolean;
withResponseActions: boolean;
numResponseActions?: number;
isolation: boolean;
bothIsolatedAndNormalEndpoints?: boolean;
}
Expand All @@ -63,6 +64,7 @@ export const cyLoadEndpointDataHandler = async (
os,
withResponseActions,
isolation,
numResponseActions,
} = options;

const DocGenerator = EndpointDocGenerator.custom({
Expand Down Expand Up @@ -91,7 +93,8 @@ export const cyLoadEndpointDataHandler = async (
enableFleetIntegration,
undefined,
DocGenerator,
withResponseActions
withResponseActions,
numResponseActions
);

if (waitUntilTransformed) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export type ReturnTypeFromChainable<C extends PossibleChainable> = C extends Cyp
: never;

export type IndexEndpointHostsCyTaskOptions = Partial<
{ count: number; withResponseActions: boolean } & Pick<
{ count: number; withResponseActions: boolean; numResponseActions?: number } & Pick<
CyLoadEndpointDataOptions,
'version' | 'os' | 'isolation'
>
Expand Down

0 comments on commit ca1919b

Please sign in to comment.