Skip to content

Commit

Permalink
[8.x] [APM] Migrate traces tests to deployment agnostic (#200561) (#2…
Browse files Browse the repository at this point in the history
…01386)

# Backport

This will backport the following commits from `main` to `8.x`:
- [[APM] Migrate traces tests to deployment agnostic
(#200561)](#200561)

<!--- Backport version: 9.4.3 -->

### Questions ?
Please refer to the [Backport tool
documentation](https://github.com/sqren/backport)

<!--BACKPORT [{"author":{"name":"Carlos
Crespo","email":"[email protected]"},"sourceCommit":{"committedDate":"2024-11-22T13:47:06Z","message":"[APM]
Migrate traces tests to deployment agnostic (#200561)\n\n##
Summary\r\n\r\nCloses
[#198995](https://github.com/elastic/kibana/issues/198995)\r\nCloses
https://github.com/elastic/kibana/issues/198996\r\nPart of
https://github.com/elastic/kibana/issues/193245\r\n\r\nThis PR contains
the changes to migrate `traces` test folder to\r\nDeployment-agnostic
testing strategy.\r\nIt also adds support for deployment-agnostic
snapshots validation\r\n\r\n### How to test\r\n\r\n-
Serverless\r\n\r\n```\r\nnode scripts/functional_tests_server --config
x-pack/test/api_integration/deployment_agnostic/configs/serverless/oblt.serverless.config.ts\r\nnode
scripts/functional_test_runner --config
x-pack/test/api_integration/deployment_agnostic/configs/serverless/oblt.serverless.config.ts
--grep=\"APM\"\r\n```\r\n\r\nIt's recommended to be run
against\r\n[MKI](https://github.com/crespocarlos/kibana/blob/main/x-pack/test_serverless/README.md#run-tests-on-mki)\r\n\r\n-
Stateful\r\n```\r\nnode scripts/functional_tests_server --config
x-pack/test/api_integration/deployment_agnostic/configs/stateful/oblt.stateful.config.ts\r\nnode
scripts/functional_test_runner --config
x-pack/test/api_integration/deployment_agnostic/configs/stateful/oblt.stateful.config.ts
--grep=\"APM\"\r\n```\r\n\r\n- [ ] ~(OPTIONAL, only if a test has been
unskipped) Run flaky test\r\nsuite~\r\n- [x] local run for
serverless\r\n- [x] local run for stateful\r\n- [x] MKI run for
serverless\r\n\r\n---------\r\n\r\nCo-authored-by: Elastic Machine
<[email protected]>","sha":"3917d02c51e9c4a83013fe83c87b77fb12bd1fbb","branchLabelMapping":{"^v9.0.0$":"main","^v8.18.0$":"8.x","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:skip","v9.0.0","backport:prev-minor","ci:project-deploy-observability","Team:obs-ux-infra_services"],"title":"[APM]
Migrate traces tests to deployment
agnostic","number":200561,"url":"https://github.com/elastic/kibana/pull/200561","mergeCommit":{"message":"[APM]
Migrate traces tests to deployment agnostic (#200561)\n\n##
Summary\r\n\r\nCloses
[#198995](https://github.com/elastic/kibana/issues/198995)\r\nCloses
https://github.com/elastic/kibana/issues/198996\r\nPart of
https://github.com/elastic/kibana/issues/193245\r\n\r\nThis PR contains
the changes to migrate `traces` test folder to\r\nDeployment-agnostic
testing strategy.\r\nIt also adds support for deployment-agnostic
snapshots validation\r\n\r\n### How to test\r\n\r\n-
Serverless\r\n\r\n```\r\nnode scripts/functional_tests_server --config
x-pack/test/api_integration/deployment_agnostic/configs/serverless/oblt.serverless.config.ts\r\nnode
scripts/functional_test_runner --config
x-pack/test/api_integration/deployment_agnostic/configs/serverless/oblt.serverless.config.ts
--grep=\"APM\"\r\n```\r\n\r\nIt's recommended to be run
against\r\n[MKI](https://github.com/crespocarlos/kibana/blob/main/x-pack/test_serverless/README.md#run-tests-on-mki)\r\n\r\n-
Stateful\r\n```\r\nnode scripts/functional_tests_server --config
x-pack/test/api_integration/deployment_agnostic/configs/stateful/oblt.stateful.config.ts\r\nnode
scripts/functional_test_runner --config
x-pack/test/api_integration/deployment_agnostic/configs/stateful/oblt.stateful.config.ts
--grep=\"APM\"\r\n```\r\n\r\n- [ ] ~(OPTIONAL, only if a test has been
unskipped) Run flaky test\r\nsuite~\r\n- [x] local run for
serverless\r\n- [x] local run for stateful\r\n- [x] MKI run for
serverless\r\n\r\n---------\r\n\r\nCo-authored-by: Elastic Machine
<[email protected]>","sha":"3917d02c51e9c4a83013fe83c87b77fb12bd1fbb"}},"sourceBranch":"main","suggestedTargetBranches":[],"targetPullRequestStates":[{"branch":"main","label":"v9.0.0","branchLabelMappingKey":"^v9.0.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/200561","number":200561,"mergeCommit":{"message":"[APM]
Migrate traces tests to deployment agnostic (#200561)\n\n##
Summary\r\n\r\nCloses
[#198995](https://github.com/elastic/kibana/issues/198995)\r\nCloses
https://github.com/elastic/kibana/issues/198996\r\nPart of
https://github.com/elastic/kibana/issues/193245\r\n\r\nThis PR contains
the changes to migrate `traces` test folder to\r\nDeployment-agnostic
testing strategy.\r\nIt also adds support for deployment-agnostic
snapshots validation\r\n\r\n### How to test\r\n\r\n-
Serverless\r\n\r\n```\r\nnode scripts/functional_tests_server --config
x-pack/test/api_integration/deployment_agnostic/configs/serverless/oblt.serverless.config.ts\r\nnode
scripts/functional_test_runner --config
x-pack/test/api_integration/deployment_agnostic/configs/serverless/oblt.serverless.config.ts
--grep=\"APM\"\r\n```\r\n\r\nIt's recommended to be run
against\r\n[MKI](https://github.com/crespocarlos/kibana/blob/main/x-pack/test_serverless/README.md#run-tests-on-mki)\r\n\r\n-
Stateful\r\n```\r\nnode scripts/functional_tests_server --config
x-pack/test/api_integration/deployment_agnostic/configs/stateful/oblt.stateful.config.ts\r\nnode
scripts/functional_test_runner --config
x-pack/test/api_integration/deployment_agnostic/configs/stateful/oblt.stateful.config.ts
--grep=\"APM\"\r\n```\r\n\r\n- [ ] ~(OPTIONAL, only if a test has been
unskipped) Run flaky test\r\nsuite~\r\n- [x] local run for
serverless\r\n- [x] local run for stateful\r\n- [x] MKI run for
serverless\r\n\r\n---------\r\n\r\nCo-authored-by: Elastic Machine
<[email protected]>","sha":"3917d02c51e9c4a83013fe83c87b77fb12bd1fbb"}}]}]
BACKPORT-->

Co-authored-by: Carlos Crespo <[email protected]>
Co-authored-by: Elastic Machine <[email protected]>
  • Loading branch information
3 people authored Nov 26, 2024
1 parent c6b22ca commit e127a29
Show file tree
Hide file tree
Showing 22 changed files with 1,261 additions and 1,574 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,11 @@ export const loadTests = ({
updateBaselines,
};

decorateSnapshotUi({ lifecycle, updateSnapshots, isCi: !!process.env.CI });
decorateSnapshotUi({
lifecycle,
updateSnapshots,
isCi: !!process.env.CI,
});

function loadTestFile(path: string) {
if (typeof path !== 'string' || !isAbsolute(path)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,13 @@ const globalState: {
registered: boolean;
currentTest: Test | null;
snapshotStates: Record<string, ISnapshotState>;
deploymentAgnostic: boolean;
} = {
updateSnapshot: 'none',
registered: false,
currentTest: null,
snapshotStates: {},
deploymentAgnostic: false,
};

const modifyStackTracePrepareOnce = once(() => {
Expand Down Expand Up @@ -125,7 +127,7 @@ export function decorateSnapshotUi({
const snapshotState = globalState.snapshotStates[file];

if (snapshotState && !test.isPassed()) {
snapshotState.markSnapshotsAsCheckedForTest(test.fullTitle());
snapshotState.markSnapshotsAsCheckedForTest(getTestTitle(test));
}
});

Expand Down Expand Up @@ -194,7 +196,7 @@ export function expectSnapshot(received: any) {

const context: SnapshotContext = {
snapshotState,
currentTestName: test.fullTitle(),
currentTestName: getTestTitle(test),
};

return {
Expand All @@ -204,6 +206,18 @@ export function expectSnapshot(received: any) {
};
}

function getTestTitle(test: Test) {
return (
test
.fullTitle()
// remove deployment type from test title so that a single snapshot can be used for all deployment types
.replace(
/^(Serverless|Stateful)\s+([^\-]+)\s*-?\s*Deployment-agnostic/g,
'Deployment-agnostic'
)
);
}

function expectToMatchSnapshot(snapshotContext: SnapshotContext, received: any) {
const matcher = toMatchSnapshot.bind(snapshotContext as any);
const result = matcher(received) as SyncExpectationResult;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ export default function apmApiIntegrationTests({
loadTestFile(require.resolve('./suggestions'));
loadTestFile(require.resolve('./throughput'));
loadTestFile(require.resolve('./time_range_metadata'));
loadTestFile(require.resolve('./traces'));
loadTestFile(require.resolve('./transactions'));
});
}
Loading

0 comments on commit e127a29

Please sign in to comment.