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.
[kbn-scout] Custom event-oriented test reporter & persistence (elasti…
- Loading branch information
1 parent
2a47a87
commit 987af3f
Showing
48 changed files
with
1,761 additions
and
71 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
# @kbn/scout-info | ||
|
||
This package stores information that's commonly used by packages in the `@kbn/scout*` namespace, and any other | ||
package that wishes to extend Scout functionality. | ||
|
||
Check out the `@kbn/scout` package if you want to learn more about Scout. |
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,14 @@ | ||
/* | ||
* 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". | ||
*/ | ||
|
||
module.exports = { | ||
preset: '@kbn/test/jest_node', | ||
rootDir: '../..', | ||
roots: ['<rootDir>/packages/kbn-scout-info'], | ||
}; |
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,6 @@ | ||
{ | ||
"type": "shared-common", | ||
"id": "@kbn/scout-info", | ||
"owner": "@elastic/appex-qa", | ||
"devOnly": true | ||
} |
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,6 @@ | ||
{ | ||
"name": "@kbn/scout-info", | ||
"private": true, | ||
"version": "1.0.0", | ||
"license": "Elastic License 2.0 OR AGPL-3.0-only OR SSPL-1.0" | ||
} |
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,19 @@ | ||
/* | ||
* 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 path from 'node:path'; | ||
import { REPO_ROOT } from '@kbn/repo-info'; | ||
|
||
export const SCOUT_OUTPUT_ROOT = path.resolve(REPO_ROOT, '.scout'); | ||
|
||
// Servers | ||
export const SCOUT_SERVERS_ROOT = path.resolve(SCOUT_OUTPUT_ROOT, 'servers'); | ||
|
||
// Reporting | ||
export const SCOUT_REPORT_OUTPUT_ROOT = path.resolve(SCOUT_OUTPUT_ROOT, 'reports'); |
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,12 @@ | ||
/* | ||
* 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". | ||
*/ | ||
|
||
export const SCOUT_TEST_EVENTS_TEMPLATE_NAME = 'scout-test-events'; | ||
export const SCOUT_TEST_EVENTS_INDEX_PATTERN = `${SCOUT_TEST_EVENTS_TEMPLATE_NAME}-*`; | ||
export const SCOUT_TEST_EVENTS_DATA_STREAM_NAME = `${SCOUT_TEST_EVENTS_TEMPLATE_NAME}-kibana`; |
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,19 @@ | ||
{ | ||
"extends": "../../tsconfig.base.json", | ||
"compilerOptions": { | ||
"outDir": "target/types", | ||
"types": [ | ||
"jest", | ||
"node" | ||
] | ||
}, | ||
"include": [ | ||
"**/*.ts", | ||
], | ||
"exclude": [ | ||
"target/**/*" | ||
], | ||
"kbn_references": [ | ||
"@kbn/repo-info" | ||
] | ||
} |
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,5 @@ | ||
# @kbn/scout-reporting | ||
|
||
This package contains reporting functionality for Scout. | ||
|
||
Check out the `@kbn/scout` package if you want to learn more about Scout. |
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,12 @@ | ||
/* | ||
* 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". | ||
*/ | ||
|
||
export * as cli from './src/cli'; | ||
export * as datasources from './src/datasources'; | ||
export * from './src/reporting'; |
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,14 @@ | ||
/* | ||
* 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". | ||
*/ | ||
|
||
module.exports = { | ||
preset: '@kbn/test/jest_node', | ||
rootDir: '../..', | ||
roots: ['<rootDir>/packages/kbn-scout-reporting'], | ||
}; |
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,6 @@ | ||
{ | ||
"type": "shared-common", | ||
"id": "@kbn/scout-reporting", | ||
"owner": "@elastic/appex-qa", | ||
"devOnly": true | ||
} |
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,6 @@ | ||
{ | ||
"name": "@kbn/scout-reporting", | ||
"private": true, | ||
"version": "1.0.0", | ||
"license": "Elastic License 2.0 OR AGPL-3.0-only OR SSPL-1.0" | ||
} |
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,37 @@ | ||
/* | ||
* 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 as ESClient, ClientOptions as ESClientOptions } from '@elastic/elasticsearch'; | ||
import { ToolingLog } from '@kbn/tooling-log'; | ||
import { createFailError } from '@kbn/dev-cli-errors'; | ||
|
||
/** | ||
* Get an Elasticsearch client for which connectivity has been validated | ||
* | ||
* @param options Elasticsearch client options | ||
* @param log Logger instance | ||
* @throws FailError if cluster information cannot be read from the target Elasticsearch instance | ||
*/ | ||
export async function getValidatedESClient( | ||
options: ESClientOptions, | ||
log: ToolingLog | ||
): Promise<ESClient> { | ||
const es = new ESClient(options); | ||
|
||
await es.info().then( | ||
(esInfo) => { | ||
log.info(`Connected to Elasticsearch node '${esInfo.name}'`); | ||
}, | ||
(err) => { | ||
throw createFailError(`Failed to connect to Elasticsearch\n${err}`); | ||
} | ||
); | ||
|
||
return es; | ||
} |
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,11 @@ | ||
/* | ||
* 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". | ||
*/ | ||
|
||
export { initializeReportDatastream } from './initialize_report_datastream'; | ||
export { uploadEvents } from './upload_events'; |
53 changes: 53 additions & 0 deletions
53
packages/kbn-scout-reporting/src/cli/initialize_report_datastream.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,53 @@ | ||
/* | ||
* 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 { Command } from '@kbn/dev-cli-runner'; | ||
import { ScoutReportDataStream } from '../reporting/report'; | ||
import { getValidatedESClient } from './common'; | ||
|
||
export const initializeReportDatastream: Command<void> = { | ||
name: 'initialize-report-datastream', | ||
description: 'Initialize a Scout report datastream in Elasticsearch', | ||
flags: { | ||
string: ['esURL', 'esAPIKey'], | ||
boolean: ['verifyTLSCerts'], | ||
default: { | ||
esURL: process.env.ES_URL, | ||
esAPIKey: process.env.ES_API_KEY, | ||
}, | ||
help: ` | ||
--esURL (required) Elasticsearch URL [env: ES_URL] | ||
--esAPIKey (required) Elasticsearch API Key [env: ES_API_KEY] | ||
--verifyTLSCerts (optional) Verify TLS certificates | ||
`, | ||
}, | ||
run: async ({ flagsReader, log }) => { | ||
const esURL = flagsReader.requiredString('esURL'); | ||
const esAPIKey = flagsReader.requiredString('esAPIKey'); | ||
|
||
// ES connection | ||
log.info(`Connecting to Elasticsearch at ${esURL}`); | ||
const es = await getValidatedESClient( | ||
{ | ||
node: esURL, | ||
auth: { apiKey: esAPIKey }, | ||
tls: { | ||
rejectUnauthorized: flagsReader.boolean('verifyTLSCerts'), | ||
}, | ||
}, | ||
log | ||
); | ||
|
||
// Initialize the report datastream | ||
const reportDataStream = new ScoutReportDataStream(es, log); | ||
await reportDataStream.initialize(); | ||
|
||
log.success('Scout report data stream initialized'); | ||
}, | ||
}; |
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,61 @@ | ||
/* | ||
* 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 fs from 'node:fs'; | ||
import { Command } from '@kbn/dev-cli-runner'; | ||
import { createFlagError } from '@kbn/dev-cli-errors'; | ||
import { ScoutReportDataStream } from '../reporting/report'; | ||
import { getValidatedESClient } from './common'; | ||
|
||
export const uploadEvents: Command<void> = { | ||
name: 'upload-events', | ||
description: 'Upload events recorded by the Scout reporter to Elasticsearch', | ||
flags: { | ||
string: ['eventLogPath', 'esURL', 'esAPIKey'], | ||
boolean: ['verifyTLSCerts'], | ||
default: { | ||
esURL: process.env.ES_URL, | ||
esAPIKey: process.env.ES_API_KEY, | ||
}, | ||
help: ` | ||
--eventLogPath (required) Path to the event log to upload | ||
--esURL (required) Elasticsearch URL [env: ES_URL] | ||
--esAPIKey (required) Elasticsearch API Key [env: ES_API_KEY] | ||
--verifyTLSCerts (optional) Verify TLS certificates | ||
`, | ||
}, | ||
run: async ({ flagsReader, log }) => { | ||
// Read & validate CLI options | ||
const eventLogPath = flagsReader.requiredString('eventLogPath'); | ||
|
||
if (!fs.existsSync(eventLogPath)) { | ||
throw createFlagError(`Event log path '${eventLogPath}' does not exist.`); | ||
} | ||
|
||
const esURL = flagsReader.requiredString('esURL'); | ||
const esAPIKey = flagsReader.requiredString('esAPIKey'); | ||
|
||
// ES connection | ||
log.info(`Connecting to Elasticsearch at ${esURL}`); | ||
const es = await getValidatedESClient( | ||
{ | ||
node: esURL, | ||
auth: { apiKey: esAPIKey }, | ||
tls: { | ||
rejectUnauthorized: flagsReader.boolean('verifyTLSCerts'), | ||
}, | ||
}, | ||
log | ||
); | ||
|
||
// Event log upload | ||
const reportDataStream = new ScoutReportDataStream(es, log); | ||
await reportDataStream.addEventsFromFile(eventLogPath); | ||
}, | ||
}; |
Oops, something went wrong.