Skip to content

Commit 2300d2d

Browse files
fake-harisdolarukibanamachinecsr
authored
Add Scout events reporter integration (elastic#245528)
## Summary Adds Scout events reporter integration to the kbn-cypress-config package, enabling automatic test run tracking and reporting for Cypress tests when Scout reporting is enabled. ### Changes - **Scout reporter integration** ([index.ts](src/platform/packages/shared/kbn-cypress-config/index.ts)) - Added `getReportingOptionOverrides()` to inject Scout reporter into Cypress multi-reporter configuration - Auto-detects test category (API, Unit, or UI) based on config file path - Parses existing reporter configuration and appends Scout reporter when `SCOUT_REPORTER_ENABLED` is true - Extracts config file path and project root from CLI arguments - **Custom Cypress reporter** ([reporter.ts](src/platform/packages/shared/kbn-cypress-config/src/reporting/scout_events/reporter.ts)) - Implements `ScoutCypressReporter` class that hooks into Mocha's test lifecycle - Captures test run events (start, end, test begin, test end) - Integrates with code owners to track team ownership for test files - Generates structured Scout events with environment metadata, test status, and duration --------- Co-authored-by: David Olaru <dolaru@elastic.co> Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com> Co-authored-by: Cesare de Cal <cesare.decal@elastic.co>
1 parent cedfcb6 commit 2300d2d

43 files changed

Lines changed: 680 additions & 37 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.buildkite/scripts/steps/functional/apm_cypress.sh

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,9 @@ echo "--- APM Cypress Tests"
1313
cd "$XPACK_DIR/solutions/observability/plugins/apm/ftr_e2e"
1414

1515
set +e
16-
yarn cypress:run; status=$?; yarn junit:merge || :; exit $status
16+
yarn cypress:run; status=$?; yarn junit:merge || :
17+
18+
# Scout reporter
19+
upload_scout_cypress_events "Cypress tests"
20+
21+
exit $status

.buildkite/scripts/steps/functional/asset_inventory.sh

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,9 @@ cd x-pack/solutions/security/test/security_solution_cypress
1313

1414
set +e
1515

16-
yarn cypress:asset_inventory:run:ess; status=$?; yarn junit:merge || :; exit $status
16+
yarn cypress:asset_inventory:run:ess; status=$?; yarn junit:merge || :
17+
18+
# Scout reporter
19+
upload_scout_cypress_events "Cypress tests"
20+
21+
exit $status

.buildkite/scripts/steps/functional/asset_inventory_serverless.sh

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,9 @@ cd x-pack/solutions/security/test/security_solution_cypress
1313

1414
set +e
1515

16-
yarn cypress:asset_inventory:run:serverless; status=$?; yarn junit:merge || :; exit $status
16+
yarn cypress:asset_inventory:run:serverless; status=$?; yarn junit:merge || :
17+
18+
# Scout reporter
19+
upload_scout_cypress_events "Cypress tests"
20+
21+
exit $status

.buildkite/scripts/steps/functional/cloud_security_posture.sh

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,9 @@ cd x-pack/solutions/security/test/security_solution_cypress
1313

1414
set +e
1515

16-
yarn cypress:cloud_security_posture:run:ess; status=$?; yarn junit:merge || :; exit $status
16+
yarn cypress:cloud_security_posture:run:ess; status=$?; yarn junit:merge || :
17+
18+
# Scout reporter
19+
upload_scout_cypress_events "Cypress tests"
20+
21+
exit $status

.buildkite/scripts/steps/functional/cloud_security_posture_serverless.sh

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,9 @@ cd x-pack/solutions/security/test/security_solution_cypress
1313

1414
set +e
1515

16-
yarn cypress:cloud_security_posture:run:serverless; status=$?; yarn junit:merge || :; exit $status
16+
yarn cypress:cloud_security_posture:run:serverless; status=$?; yarn junit:merge || :
17+
18+
# Scout reporter
19+
upload_scout_cypress_events "Cypress tests"
20+
21+
exit $status

.buildkite/scripts/steps/functional/common.sh

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,34 @@ source .buildkite/scripts/common/util.sh
1212

1313
is_test_execution_step
1414

15+
# Upload Scout reporter events after Cypress test execution
16+
upload_scout_cypress_events() {
17+
local test_name="${1:-Cypress tests}"
18+
19+
if [[ "${SCOUT_REPORTER_ENABLED:-}" =~ ^(1|true)$ ]]; then
20+
# Save current directory and navigate to Kibana root
21+
local current_dir=$(pwd)
22+
cd "${KIBANA_DIR:-$(git rev-parse --show-toplevel)}"
23+
24+
# Check if reports exist before uploading
25+
if compgen -G '.scout/reports/*' > /dev/null; then
26+
echo "--- Upload Scout reporter events to AppEx QA's team cluster for $test_name"
27+
node scripts/scout upload-events --dontFailOnError
28+
29+
# Clean up only Cypress event reports to avoid double ingestion
30+
# Only remove scout-cypress-* directories, preserving other test reports and failure reports
31+
if compgen -G '.scout/reports/scout-cypress-*' > /dev/null; then
32+
echo "🧹 Cleaning up Scout Cypress event reports"
33+
rm -rf .scout/reports/scout-cypress-*
34+
fi
35+
else
36+
echo "❌ No Scout reports found for $test_name"
37+
fi
38+
39+
# Return to original directory
40+
cd "$current_dir"
41+
else
42+
echo "SCOUT_REPORTER_ENABLED=$SCOUT_REPORTER_ENABLED, skipping event upload."
43+
fi
44+
}
45+

.buildkite/scripts/steps/functional/defend_workflows.sh

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,9 @@ cd x-pack/solutions/security/plugins/security_solution
1414
set +e
1515
BK_ANALYTICS_API_KEY=$(vault_get security-solution-ci defend-workflows-bk-api-key)
1616

17-
BK_ANALYTICS_API_KEY=$BK_ANALYTICS_API_KEY yarn cypress:dw:run; status=$?; yarn junit:merge || :; exit $status
17+
BK_ANALYTICS_API_KEY=$BK_ANALYTICS_API_KEY yarn cypress:dw:run; status=$?; yarn junit:merge || :
18+
19+
# Scout reporter
20+
upload_scout_cypress_events "Cypress tests"
21+
22+
exit $status

.buildkite/scripts/steps/functional/defend_workflows_serverless.sh

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,9 @@ cd x-pack/solutions/security/plugins/security_solution
1414
set +e
1515
BK_ANALYTICS_API_KEY=$(vault_get security-solution-ci defend-workflows-bk-api-key)
1616

17-
BK_ANALYTICS_API_KEY=$BK_ANALYTICS_API_KEY yarn cypress:dw:serverless:run; status=$?; yarn junit:merge || :; exit $status
17+
BK_ANALYTICS_API_KEY=$BK_ANALYTICS_API_KEY yarn cypress:dw:serverless:run; status=$?; yarn junit:merge || :
18+
19+
# Scout reporter
20+
upload_scout_cypress_events "Cypress tests"
21+
22+
exit $status

.buildkite/scripts/steps/functional/fleet_cypress.sh

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,14 @@ echo "--- Fleet Cypress tests (Chrome)"
1212
cd x-pack/platform/plugins/shared/fleet
1313

1414
set +e
15-
yarn cypress:run:reporter; status=$?; yarn cypress_space_awareness:run:reporter; space_status=$?; yarn junit:merge || :; [ "$status" -ne 0 ] && exit $status || [ "$space_status" -ne 0 ] && exit $space_status || exit 0
15+
yarn cypress:run:reporter; status=$?; yarn cypress_space_awareness:run:reporter; space_status=$?; yarn junit:merge || :
16+
17+
# Scout reporter
18+
upload_scout_cypress_events "Fleet Cypress tests"
19+
20+
# Exit with appropriate status
21+
if [ "$status" -ne 0 ]; then
22+
exit $status
23+
elif [ "$space_status" -ne 0 ]; then
24+
exit $space_status
25+
fi

.buildkite/scripts/steps/functional/osquery_cypress.sh

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,9 @@ echo "--- Osquery Cypress tests"
1313
cd x-pack/platform/plugins/shared/osquery
1414

1515
set +e
16-
yarn cypress:run; status=$?; yarn junit:merge || :; exit $status
16+
yarn cypress:run; status=$?; yarn junit:merge || :
17+
18+
# Scout reporter
19+
upload_scout_cypress_events "Cypress tests"
20+
21+
exit $status

0 commit comments

Comments
 (0)