forked from elastic/kibana
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Inventory] Adding initial e2e structure (elastic#196560)
closes elastic#193992 How to open cypress dashboard locally: ``` node x-pack/plugins/observability_solution/inventory/scripts/test/e2e.js --open ``` How to run cypress tests: ``` node x-pack/plugins/observability_solution/inventory/scripts/test/e2e.js ``` How to run cypress tests multiple times: ``` node x-pack/plugins/observability_solution/inventory/scripts/test/e2e.js --server node x-pack/plugins/observability_solution/inventory/scripts/test/e2e.js --runner --times=X ``` --------- Co-authored-by: kibanamachine <[email protected]> (cherry picked from commit 3bfa7c0) # Conflicts: # .github/CODEOWNERS # packages/kbn-apm-synthtrace-client/src/lib/entities/container_entity.ts # packages/kbn-apm-synthtrace-client/src/lib/entities/host_entity.ts # packages/kbn-apm-synthtrace-client/src/lib/entities/service_entity.ts # packages/kbn-apm-synthtrace/index.ts # packages/kbn-apm-synthtrace/src/cli/scenario.ts # packages/kbn-apm-synthtrace/src/lib/entities/entities_synthtrace_es_client.ts # packages/kbn-apm-synthtrace/src/lib/entities/entities_synthtrace_kibana_client.ts # packages/kbn-spec-to-console/lib/convert/parts.js
- Loading branch information
1 parent
232115c
commit 9bc4301
Showing
42 changed files
with
3,198 additions
and
63,455 deletions.
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
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,17 @@ | ||
steps: | ||
- command: .buildkite/scripts/steps/functional/inventory_cypress.sh | ||
label: 'Inventory Cypress Tests' | ||
agents: | ||
machineType: n2-standard-4 | ||
preemptible: true | ||
depends_on: | ||
- build | ||
- quick_checks | ||
timeout_in_minutes: 120 | ||
parallelism: 1 | ||
retry: | ||
automatic: | ||
- exit_status: '-1' | ||
limit: 3 | ||
- exit_status: '*' | ||
limit: 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
#!/usr/bin/env bash | ||
|
||
set -euo pipefail | ||
|
||
source .buildkite/scripts/common/util.sh | ||
|
||
.buildkite/scripts/bootstrap.sh | ||
.buildkite/scripts/download_build_artifacts.sh | ||
|
||
export JOB=kibana-inventory-onboarding-cypress | ||
|
||
echo "--- Observability Inventory Cypress Tests" | ||
|
||
cd "$XPACK_DIR" | ||
|
||
node plugins/observability_solution/inventory/scripts/test/e2e.js \ | ||
--kibana-install-dir "$KIBANA_BUILD_LOCATION" \ |
Large diffs are not rendered by default.
Oops, something went wrong.
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
42 changes: 42 additions & 0 deletions
42
packages/kbn-apm-synthtrace-client/src/lib/entities/container_entity.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,42 @@ | ||
/* | ||
* 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", the "GNU Affero General Public License v3.0 only", and the "Server Side | ||
* Public License v 1"; you may not use this file except in compliance with, at | ||
* your election, the "Elastic License 2.0", the "GNU Affero General Public | ||
* License v3.0 only", or the "Server Side Public License, v 1". | ||
*/ | ||
|
||
import { EntityDataStreamType, EntityFields } from '.'; | ||
import { Serializable } from '../serializable'; | ||
|
||
class ContainerEntity extends Serializable<EntityFields> { | ||
constructor(fields: EntityFields) { | ||
super({ | ||
...fields, | ||
'entity.type': 'container', | ||
'entity.definitionId': 'builtin_containers_from_ecs_data', | ||
'entity.identityFields': ['container.id'], | ||
}); | ||
} | ||
} | ||
|
||
export function containerEntity({ | ||
agentName, | ||
dataStreamType, | ||
containerId, | ||
entityId, | ||
}: { | ||
agentName: string[]; | ||
dataStreamType: EntityDataStreamType[]; | ||
containerId: string; | ||
entityId: string; | ||
}) { | ||
return new ContainerEntity({ | ||
'source_data_stream.type': dataStreamType, | ||
'agent.name': agentName, | ||
'container.id': containerId, | ||
'entity.displayName': containerId, | ||
'entity.id': entityId, | ||
}); | ||
} |
42 changes: 42 additions & 0 deletions
42
packages/kbn-apm-synthtrace-client/src/lib/entities/host_entity.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,42 @@ | ||
/* | ||
* 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", the "GNU Affero General Public License v3.0 only", and the "Server Side | ||
* Public License v 1"; you may not use this file except in compliance with, at | ||
* your election, the "Elastic License 2.0", the "GNU Affero General Public | ||
* License v3.0 only", or the "Server Side Public License, v 1". | ||
*/ | ||
|
||
import { EntityDataStreamType, EntityFields } from '.'; | ||
import { Serializable } from '../serializable'; | ||
|
||
class HostEntity extends Serializable<EntityFields> { | ||
constructor(fields: EntityFields) { | ||
super({ | ||
...fields, | ||
'entity.type': 'host', | ||
'entity.definitionId': 'builtin_hosts_from_ecs_data', | ||
'entity.identityFields': ['host.name'], | ||
}); | ||
} | ||
} | ||
|
||
export function hostEntity({ | ||
agentName, | ||
dataStreamType, | ||
hostName, | ||
entityId, | ||
}: { | ||
agentName: string[]; | ||
dataStreamType: EntityDataStreamType[]; | ||
hostName: string; | ||
entityId: string; | ||
}) { | ||
return new HostEntity({ | ||
'source_data_stream.type': dataStreamType, | ||
'agent.name': agentName, | ||
'host.name': hostName, | ||
'entity.displayName': hostName, | ||
'entity.id': entityId, | ||
}); | ||
} |
45 changes: 45 additions & 0 deletions
45
packages/kbn-apm-synthtrace-client/src/lib/entities/service_entity.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,45 @@ | ||
/* | ||
* 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", the "GNU Affero General Public License v3.0 only", and the "Server Side | ||
* Public License v 1"; you may not use this file except in compliance with, at | ||
* your election, the "Elastic License 2.0", the "GNU Affero General Public | ||
* License v3.0 only", or the "Server Side Public License, v 1". | ||
*/ | ||
|
||
import { EntityDataStreamType, EntityFields } from '.'; | ||
import { Serializable } from '../serializable'; | ||
|
||
class ServiceEntity extends Serializable<EntityFields> { | ||
constructor(fields: EntityFields) { | ||
super({ | ||
...fields, | ||
'entity.type': 'service', | ||
'entity.definitionId': 'builtin_services_from_ecs_data', | ||
'entity.identityFields': ['service.name'], | ||
}); | ||
} | ||
} | ||
|
||
export function serviceEntity({ | ||
agentName, | ||
dataStreamType, | ||
serviceName, | ||
environment, | ||
entityId, | ||
}: { | ||
agentName: string[]; | ||
serviceName: string; | ||
dataStreamType: EntityDataStreamType[]; | ||
environment?: string; | ||
entityId: string; | ||
}) { | ||
return new ServiceEntity({ | ||
'service.name': serviceName, | ||
'entity.displayName': serviceName, | ||
'service.environment': environment, | ||
'source_data_stream.type': dataStreamType, | ||
'agent.name': agentName, | ||
'entity.id': entityId, | ||
}); | ||
} |
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
93 changes: 93 additions & 0 deletions
93
packages/kbn-apm-synthtrace/src/lib/entities/entities_synthtrace_es_client.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,93 @@ | ||
/* | ||
* 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", the "GNU Affero General Public License v3.0 only", and the "Server Side | ||
* Public License v 1"; you may not use this file except in compliance with, at | ||
* your election, the "Elastic License 2.0", the "GNU Affero General Public | ||
* License v3.0 only", or the "Server Side Public License, v 1". | ||
*/ | ||
|
||
import { Client } from '@elastic/elasticsearch'; | ||
import { EntityFields, ESDocumentWithOperation } from '@kbn/apm-synthtrace-client'; | ||
import { pipeline, Readable, Transform } from 'stream'; | ||
import { SynthtraceEsClient, SynthtraceEsClientOptions } from '../shared/base_client'; | ||
import { getDedotTransform } from '../shared/get_dedot_transform'; | ||
import { getSerializeTransform } from '../shared/get_serialize_transform'; | ||
import { Logger } from '../utils/create_logger'; | ||
|
||
export type EntitiesSynthtraceEsClientOptions = Omit<SynthtraceEsClientOptions, 'pipeline'>; | ||
|
||
interface Pipeline { | ||
includeSerialization?: boolean; | ||
} | ||
|
||
export class EntitiesSynthtraceEsClient extends SynthtraceEsClient<EntityFields> { | ||
constructor(options: { client: Client; logger: Logger } & EntitiesSynthtraceEsClientOptions) { | ||
super({ | ||
...options, | ||
pipeline: entitiesPipeline(), | ||
}); | ||
this.indices = ['.entities.v1.latest.builtin*']; | ||
} | ||
|
||
getDefaultPipeline({ includeSerialization }: Pipeline = { includeSerialization: true }) { | ||
return entitiesPipeline({ includeSerialization }); | ||
} | ||
} | ||
|
||
function entitiesPipeline({ includeSerialization }: Pipeline = { includeSerialization: true }) { | ||
return (base: Readable) => { | ||
const serializationTransform = includeSerialization ? [getSerializeTransform()] : []; | ||
|
||
return pipeline( | ||
// @ts-expect-error Some weird stuff here with the type definition for pipeline. We have tests! | ||
base, | ||
...serializationTransform, | ||
lastSeenTimestampTransform(), | ||
getRoutingTransform(), | ||
getDedotTransform(), | ||
(err: unknown) => { | ||
if (err) { | ||
throw err; | ||
} | ||
} | ||
); | ||
}; | ||
} | ||
|
||
function lastSeenTimestampTransform() { | ||
return new Transform({ | ||
objectMode: true, | ||
transform(document: ESDocumentWithOperation<EntityFields>, encoding, callback) { | ||
const timestamp = document['@timestamp']; | ||
if (timestamp) { | ||
const isoString = new Date(timestamp).toISOString(); | ||
document['entity.lastSeenTimestamp'] = isoString; | ||
document['event.ingested'] = isoString; | ||
delete document['@timestamp']; | ||
} | ||
callback(null, document); | ||
}, | ||
}); | ||
} | ||
|
||
function getRoutingTransform() { | ||
return new Transform({ | ||
objectMode: true, | ||
transform(document: ESDocumentWithOperation<EntityFields>, encoding, callback) { | ||
const entityType: string | undefined = document['entity.type']; | ||
if (entityType === undefined) { | ||
throw new Error(`entity.type was not defined: ${JSON.stringify(document)}`); | ||
} | ||
const entityIndexName = `${entityType}s`; | ||
document._action = { | ||
index: { | ||
_index: `.entities.v1.latest.builtin_${entityIndexName}_from_ecs_data`, | ||
_id: document['entity.id'], | ||
}, | ||
}; | ||
|
||
callback(null, document); | ||
}, | ||
}); | ||
} |
Oops, something went wrong.