Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[kbn-scout] Add Synthtrace as a fixture #210505

Merged
merged 18 commits into from
Feb 14, 2025

Conversation

rmyz
Copy link
Contributor

@rmyz rmyz commented Feb 11, 2025

Summary

Closes #210340

This PR adds synthtrace clients to scout as a test fixture, so you can use it in your test to generate data.

The clients added were apmSynthtraceEsClient, infraSynthtraceEsClient and otelSynthtraceEsClient.

How to use them in parallel tests

As synthtrace ingests data into our indices, and sequential runs would be the perfect way to introduce flakiness in our tests, there is a better way to ingest data, using a hook, at the setup phase with globalSetup.
We need to create a global_setup.ts file and link it into our playwright config.
Then we can use something like

async function globalSetup(config: FullConfig) {
  const data = {
    apm: [
      opbeans({
        from: new Date(start).getTime(),
        to: new Date(end).getTime(),
      }),
    ],
    infra: [
      generateHosts({
        from: new Date(start).toISOString(),
        to: new Date(end).toISOString(),
      }),
    ],
    otel: [
      sendotlp({
        from: new Date(start).getTime(),
        to: new Date(end).getTime(),
      }),
    ],
  };

  return ingestSynthtraceDataHook(config, data);
}

Each key (apm, infra, otel) accepts an array of generators.

How to use them in sequential tests

Warning

This should not be the standard behaviour, we should embrace parallelism and use sequential testing when there is no other way.

apmSynthtraceEsClient

 test.before(
    async ({ apmSynthtraceEsClient }) => {
      await apmSynthtraceEsClient.index(
        opbeans({
          from: new Date(start).getTime(),
          to: new Date(end).getTime(),
        })
      );
    }
  );

opbeans file used in the example.

otelSynthtraceEsClient

 test.before(
    async ({otelSynthtraceEsClient }) => {
      await otelSynthtraceEsClient.index(
        sendotlp({
          from: new Date(start).getTime(),
          to: new Date(end).getTime(),
        })
      );
    }
  );

sendotlp file which will create the data.

infraSynthtraceEsClient

 test.before(
    async ({ infraSynthtraceEsClient }) => {
      await infraSynthtraceEsClient.index(
        generateHosts({
          from: new Date(start).toISOString(),
          to: new Date(end).toISOString(),
        })
      );
    }
  );

generateHosts file used to generate data.

@rmyz rmyz self-assigned this Feb 11, 2025
@rmyz
Copy link
Contributor Author

rmyz commented Feb 11, 2025

/ci

@rmyz rmyz added release_note:skip Skip the PR/issue when compiling release notes backport:skip This commit does not require backporting apm:synthtrace APM Synthtrace Topics Team:obs-ux-infra_services Observability Infrastructure & Services User Experience Team test:scout labels Feb 11, 2025
@rmyz rmyz mentioned this pull request Feb 11, 2025
10 tasks
@rmyz
Copy link
Contributor Author

rmyz commented Feb 11, 2025

/ci

@rmyz
Copy link
Contributor Author

rmyz commented Feb 11, 2025

/ci

Copy link
Member

@jennypavlova jennypavlova left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Q: is there a way to test atm or do we need the fixture from the other draft (I tested there but wanted to check here if it's possible - it should work the same so I can just copy it from there, just wanted to fist check with you if we want to test it again)

@rmyz
Copy link
Contributor Author

rmyz commented Feb 12, 2025

Q: is there a way to test atm or do we need the fixture from the other draft (I tested there but wanted to check here if it's possible - it should work the same so I can just copy it from there, just wanted to fist check with you if we want to test it again)

It should be the same, the only change I made is for the naming, so the synthtrace clients that we expose are: apmSynthtraceEsClient, infraSynthtraceEsClient and otelSynthtraceEsClient.

Copy link
Member

@jennypavlova jennypavlova left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The code LGTM 💯 Thanks for the fixes!

@rmyz
Copy link
Contributor Author

rmyz commented Feb 12, 2025

Tested parallelism using this playwright config as it was already configured, and created a few tests using synthtrace, works fine ✅

@rmyz
Copy link
Contributor Author

rmyz commented Feb 12, 2025

Tested all clients and they are working ✅

@rmyz rmyz marked this pull request as ready for review February 12, 2025 11:18
@rmyz rmyz requested a review from a team as a code owner February 12, 2025 11:19
@elasticmachine
Copy link
Contributor

Pinging @elastic/obs-ux-infra_services-team (Team:obs-ux-infra_services)

Copy link
Member

@dmlemeshko dmlemeshko left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @rmyz , nice work!

I left questions to better understand the use case and hopefully make few improvements.

Copy link
Contributor

@crespocarlos crespocarlos left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the changes! just a couple questions

if (Object.hasOwn(data, key)) {
const typedKey = key as keyof SynthtraceIngestionData;
if (data[typedKey].length > 0) {
const client = await getClient(typedKey, esClient, kbnUrl, scoutConfig.auth, log);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: getSynthtraceClient to make this name more specific.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

changed

const kbnUrl = scoutConfig.hosts.kibana;

for (const key of Object.keys(data)) {
if (Object.hasOwn(data, key)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need to check if Object.hasOwn(data, key)? It's already iterating over data keys.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removed, not needed

Copy link
Contributor

@crespocarlos crespocarlos left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. thanks for applying the suggestions

@rmyz rmyz enabled auto-merge (squash) February 14, 2025 14:23
Copy link
Contributor

@miloszmarcinkowski miloszmarcinkowski left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm sorry for the late review. Nice job with synthtrace 🚀

})
);
} catch (e) {
log.debug(`[setup] error ingesting ${key} synthtrace data`, e);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
log.debug(`[setup] error ingesting ${key} synthtrace data`, e);
log.error(`[setup] error ingesting ${key} synthtrace data`, e);

nit: it can be logged as error here

@rmyz rmyz merged commit e21c5d0 into elastic:main Feb 14, 2025
9 checks passed
@elasticmachine
Copy link
Contributor

💚 Build Succeeded

Metrics [docs]

Public APIs missing comments

Total count of every public API that lacks a comment. Target amount is 0. Run node scripts/build_api_docs --plugin [yourplugin] --stats comments for more detailed information.

id before after diff
@kbn/scout 93 99 +6

Public APIs missing exports

Total count of every type that is part of your API that should be exported but is not. This will cause broken links in the API documentation system. Target amount is 0. Run node scripts/build_api_docs --plugin [yourplugin] --stats exports for more detailed information.

id before after diff
@kbn/scout 14 15 +1
Unknown metric groups

API count

id before after diff
@kbn/scout 383 389 +6

History

cc @rmyz

@dmlemeshko dmlemeshko added v9.0.0 v8.19.0 backport:version Backport to applied version labels and removed backport:skip This commit does not require backporting labels Feb 15, 2025
@kibanamachine
Copy link
Contributor

Starting backport for target branches: 8.x, 9.0

https://github.com/elastic/kibana/actions/runs/13344704434

@kibanamachine
Copy link
Contributor

Starting backport for target branches: 8.x, 9.0

https://github.com/elastic/kibana/actions/runs/13344704463

kibanamachine pushed a commit to kibanamachine/kibana that referenced this pull request Feb 15, 2025
## Summary

Closes elastic#210340

This PR adds synthtrace clients to scout as a test fixture, so you can
use it in your test to generate data.

The clients added were `apmSynthtraceEsClient`,
`infraSynthtraceEsClient` and `otelSynthtraceEsClient`.

## How to use them in parallel tests

As `synthtrace` ingests data into our indices, and sequential runs would
be the perfect way to introduce flakiness in our tests, there is a
better way to ingest data, using a hook, at the setup phase with
`globalSetup`.
We need to create a `global_setup.ts` file and link it into our
playwright config.
Then we can use something like
```
async function globalSetup(config: FullConfig) {
  const data = {
    apm: [
      opbeans({
        from: new Date(start).getTime(),
        to: new Date(end).getTime(),
      }),
    ],
    infra: [
      generateHosts({
        from: new Date(start).toISOString(),
        to: new Date(end).toISOString(),
      }),
    ],
    otel: [
      sendotlp({
        from: new Date(start).getTime(),
        to: new Date(end).getTime(),
      }),
    ],
  };

  return ingestSynthtraceDataHook(config, data);
}
```
Each key (apm, infra, otel) accepts an array of generators.

## How to use them in sequential tests
> [!WARNING]
> This should not be the standard behaviour, we should embrace
parallelism and use sequential testing when there is no other way.

### apmSynthtraceEsClient
```ts
 test.before(
    async ({ apmSynthtraceEsClient }) => {
      await apmSynthtraceEsClient.index(
        opbeans({
          from: new Date(start).getTime(),
          to: new Date(end).getTime(),
        })
      );
    }
  );
```
[opbeans
file](https://github.com/elastic/kibana/blob/main/x-pack/solutions/observability/plugins/apm/ftr_e2e/cypress/fixtures/synthtrace/opbeans.ts)
used in the example.

### otelSynthtraceEsClient
```ts
 test.before(
    async ({otelSynthtraceEsClient }) => {
      await otelSynthtraceEsClient.index(
        sendotlp({
          from: new Date(start).getTime(),
          to: new Date(end).getTime(),
        })
      );
    }
  );
```
[sendotlp
file](https://github.com/elastic/kibana/blob/main/x-pack/solutions/observability/plugins/apm/ftr_e2e/cypress/fixtures/synthtrace/sendotlp.ts)
which will create the data.

### infraSynthtraceEsClient
```ts
 test.before(
    async ({ infraSynthtraceEsClient }) => {
      await infraSynthtraceEsClient.index(
        generateHosts({
          from: new Date(start).toISOString(),
          to: new Date(end).toISOString(),
        })
      );
    }
  );
```
[generateHosts
file](https://github.com/elastic/kibana/blob/main/x-pack/solutions/observability/plugins/inventory/e2e/cypress/e2e/alert_count/generate_data.ts#L82)
used to generate data.

---------

Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com>
(cherry picked from commit e21c5d0)
kibanamachine pushed a commit to kibanamachine/kibana that referenced this pull request Feb 15, 2025
## Summary

Closes elastic#210340

This PR adds synthtrace clients to scout as a test fixture, so you can
use it in your test to generate data.

The clients added were `apmSynthtraceEsClient`,
`infraSynthtraceEsClient` and `otelSynthtraceEsClient`.

## How to use them in parallel tests

As `synthtrace` ingests data into our indices, and sequential runs would
be the perfect way to introduce flakiness in our tests, there is a
better way to ingest data, using a hook, at the setup phase with
`globalSetup`.
We need to create a `global_setup.ts` file and link it into our
playwright config.
Then we can use something like
```
async function globalSetup(config: FullConfig) {
  const data = {
    apm: [
      opbeans({
        from: new Date(start).getTime(),
        to: new Date(end).getTime(),
      }),
    ],
    infra: [
      generateHosts({
        from: new Date(start).toISOString(),
        to: new Date(end).toISOString(),
      }),
    ],
    otel: [
      sendotlp({
        from: new Date(start).getTime(),
        to: new Date(end).getTime(),
      }),
    ],
  };

  return ingestSynthtraceDataHook(config, data);
}
```
Each key (apm, infra, otel) accepts an array of generators.

## How to use them in sequential tests
> [!WARNING]
> This should not be the standard behaviour, we should embrace
parallelism and use sequential testing when there is no other way.

### apmSynthtraceEsClient
```ts
 test.before(
    async ({ apmSynthtraceEsClient }) => {
      await apmSynthtraceEsClient.index(
        opbeans({
          from: new Date(start).getTime(),
          to: new Date(end).getTime(),
        })
      );
    }
  );
```
[opbeans
file](https://github.com/elastic/kibana/blob/main/x-pack/solutions/observability/plugins/apm/ftr_e2e/cypress/fixtures/synthtrace/opbeans.ts)
used in the example.

### otelSynthtraceEsClient
```ts
 test.before(
    async ({otelSynthtraceEsClient }) => {
      await otelSynthtraceEsClient.index(
        sendotlp({
          from: new Date(start).getTime(),
          to: new Date(end).getTime(),
        })
      );
    }
  );
```
[sendotlp
file](https://github.com/elastic/kibana/blob/main/x-pack/solutions/observability/plugins/apm/ftr_e2e/cypress/fixtures/synthtrace/sendotlp.ts)
which will create the data.

### infraSynthtraceEsClient
```ts
 test.before(
    async ({ infraSynthtraceEsClient }) => {
      await infraSynthtraceEsClient.index(
        generateHosts({
          from: new Date(start).toISOString(),
          to: new Date(end).toISOString(),
        })
      );
    }
  );
```
[generateHosts
file](https://github.com/elastic/kibana/blob/main/x-pack/solutions/observability/plugins/inventory/e2e/cypress/e2e/alert_count/generate_data.ts#L82)
used to generate data.

---------

Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com>
(cherry picked from commit e21c5d0)
@kibanamachine
Copy link
Contributor

💔 Some backports could not be created

Status Branch Result
8.x Backport failed because of merge conflicts

You might need to backport the following PRs to 8.x:
- [scout] adding test helper @kbn/scout-oblt package and uptate onboarding tests (#209761)
- [Scout] add maps test (#204607)
9.0

Note: Successful backport PRs will be merged automatically after passing CI.

Manual backport

To create the backport manually run:

node scripts/backport --pr 210505

Questions ?

Please refer to the Backport tool documentation

1 similar comment
@kibanamachine
Copy link
Contributor

💔 Some backports could not be created

Status Branch Result
8.x Backport failed because of merge conflicts

You might need to backport the following PRs to 8.x:
- [scout] adding test helper @kbn/scout-oblt package and uptate onboarding tests (#209761)
- [Scout] add maps test (#204607)
9.0

Note: Successful backport PRs will be merged automatically after passing CI.

Manual backport

To create the backport manually run:

node scripts/backport --pr 210505

Questions ?

Please refer to the Backport tool documentation

kibanamachine added a commit that referenced this pull request Feb 15, 2025
# Backport

This will backport the following commits from `main` to `9.0`:
- [[kbn-scout] Add Synthtrace as a fixture
(#210505)](#210505)

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

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

<!--BACKPORT [{"author":{"name":"Sergi
Romeu","email":"sergi.romeu@elastic.co"},"sourceCommit":{"committedDate":"2025-02-14T18:52:22Z","message":"[kbn-scout]
Add Synthtrace as a fixture (#210505)\n\n## Summary\n\nCloses
#210340\n\nThis PR adds synthtrace clients to scout as a test fixture,
so you can\nuse it in your test to generate data.\n\nThe clients added
were `apmSynthtraceEsClient`,\n`infraSynthtraceEsClient` and
`otelSynthtraceEsClient`.\n\n## How to use them in parallel tests\n\nAs
`synthtrace` ingests data into our indices, and sequential runs
would\nbe the perfect way to introduce flakiness in our tests, there is
a\nbetter way to ingest data, using a hook, at the setup phase
with\n`globalSetup`.\nWe need to create a `global_setup.ts` file and
link it into our\nplaywright config.\nThen we can use something
like\n```\nasync function globalSetup(config: FullConfig) {\n const data
= {\n apm: [\n opbeans({\n from: new Date(start).getTime(),\n to: new
Date(end).getTime(),\n }),\n ],\n infra: [\n generateHosts({\n from: new
Date(start).toISOString(),\n to: new Date(end).toISOString(),\n }),\n
],\n otel: [\n sendotlp({\n from: new Date(start).getTime(),\n to: new
Date(end).getTime(),\n }),\n ],\n };\n\n return
ingestSynthtraceDataHook(config, data);\n}\n```\nEach key (apm, infra,
otel) accepts an array of generators.\n\n## How to use them in
sequential tests\n> [!WARNING] \n> This should not be the standard
behaviour, we should embrace\nparallelism and use sequential testing
when there is no other way.\n\n### apmSynthtraceEsClient\n```ts\n
test.before(\n async ({ apmSynthtraceEsClient }) => {\n await
apmSynthtraceEsClient.index(\n opbeans({\n from: new
Date(start).getTime(),\n to: new Date(end).getTime(),\n })\n );\n }\n
);\n```\n[opbeans\nfile](https://github.com/elastic/kibana/blob/main/x-pack/solutions/observability/plugins/apm/ftr_e2e/cypress/fixtures/synthtrace/opbeans.ts)\nused
in the example.\n\n### otelSynthtraceEsClient\n```ts\n test.before(\n
async ({otelSynthtraceEsClient }) => {\n await
otelSynthtraceEsClient.index(\n sendotlp({\n from: new
Date(start).getTime(),\n to: new Date(end).getTime(),\n })\n );\n }\n
);\n```\n[sendotlp\nfile](https://github.com/elastic/kibana/blob/main/x-pack/solutions/observability/plugins/apm/ftr_e2e/cypress/fixtures/synthtrace/sendotlp.ts)\nwhich
will create the data.\n\n### infraSynthtraceEsClient\n```ts\n
test.before(\n async ({ infraSynthtraceEsClient }) => {\n await
infraSynthtraceEsClient.index(\n generateHosts({\n from: new
Date(start).toISOString(),\n to: new Date(end).toISOString(),\n })\n
);\n }\n
);\n```\n[generateHosts\nfile](https://github.com/elastic/kibana/blob/main/x-pack/solutions/observability/plugins/inventory/e2e/cypress/e2e/alert_count/generate_data.ts#L82)\nused
to generate data.\n\n---------\n\nCo-authored-by: kibanamachine
<42973632+kibanamachine@users.noreply.github.com>","sha":"e21c5d0e9175ffd1bea0ad78ffe26cb973cc489f","branchLabelMapping":{"^v9.1.0$":"main","^v8.19.0$":"8.x","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:skip","v9.0.0","apm:synthtrace","Team:obs-ux-infra_services","backport:version","test:scout","v9.1.0","v8.19.0"],"title":"[kbn-scout]
Add Synthtrace as a
fixture","number":210505,"url":"https://github.com/elastic/kibana/pull/210505","mergeCommit":{"message":"[kbn-scout]
Add Synthtrace as a fixture (#210505)\n\n## Summary\n\nCloses
#210340\n\nThis PR adds synthtrace clients to scout as a test fixture,
so you can\nuse it in your test to generate data.\n\nThe clients added
were `apmSynthtraceEsClient`,\n`infraSynthtraceEsClient` and
`otelSynthtraceEsClient`.\n\n## How to use them in parallel tests\n\nAs
`synthtrace` ingests data into our indices, and sequential runs
would\nbe the perfect way to introduce flakiness in our tests, there is
a\nbetter way to ingest data, using a hook, at the setup phase
with\n`globalSetup`.\nWe need to create a `global_setup.ts` file and
link it into our\nplaywright config.\nThen we can use something
like\n```\nasync function globalSetup(config: FullConfig) {\n const data
= {\n apm: [\n opbeans({\n from: new Date(start).getTime(),\n to: new
Date(end).getTime(),\n }),\n ],\n infra: [\n generateHosts({\n from: new
Date(start).toISOString(),\n to: new Date(end).toISOString(),\n }),\n
],\n otel: [\n sendotlp({\n from: new Date(start).getTime(),\n to: new
Date(end).getTime(),\n }),\n ],\n };\n\n return
ingestSynthtraceDataHook(config, data);\n}\n```\nEach key (apm, infra,
otel) accepts an array of generators.\n\n## How to use them in
sequential tests\n> [!WARNING] \n> This should not be the standard
behaviour, we should embrace\nparallelism and use sequential testing
when there is no other way.\n\n### apmSynthtraceEsClient\n```ts\n
test.before(\n async ({ apmSynthtraceEsClient }) => {\n await
apmSynthtraceEsClient.index(\n opbeans({\n from: new
Date(start).getTime(),\n to: new Date(end).getTime(),\n })\n );\n }\n
);\n```\n[opbeans\nfile](https://github.com/elastic/kibana/blob/main/x-pack/solutions/observability/plugins/apm/ftr_e2e/cypress/fixtures/synthtrace/opbeans.ts)\nused
in the example.\n\n### otelSynthtraceEsClient\n```ts\n test.before(\n
async ({otelSynthtraceEsClient }) => {\n await
otelSynthtraceEsClient.index(\n sendotlp({\n from: new
Date(start).getTime(),\n to: new Date(end).getTime(),\n })\n );\n }\n
);\n```\n[sendotlp\nfile](https://github.com/elastic/kibana/blob/main/x-pack/solutions/observability/plugins/apm/ftr_e2e/cypress/fixtures/synthtrace/sendotlp.ts)\nwhich
will create the data.\n\n### infraSynthtraceEsClient\n```ts\n
test.before(\n async ({ infraSynthtraceEsClient }) => {\n await
infraSynthtraceEsClient.index(\n generateHosts({\n from: new
Date(start).toISOString(),\n to: new Date(end).toISOString(),\n })\n
);\n }\n
);\n```\n[generateHosts\nfile](https://github.com/elastic/kibana/blob/main/x-pack/solutions/observability/plugins/inventory/e2e/cypress/e2e/alert_count/generate_data.ts#L82)\nused
to generate data.\n\n---------\n\nCo-authored-by: kibanamachine
<42973632+kibanamachine@users.noreply.github.com>","sha":"e21c5d0e9175ffd1bea0ad78ffe26cb973cc489f"}},"sourceBranch":"main","suggestedTargetBranches":["9.0","8.x"],"targetPullRequestStates":[{"branch":"9.0","label":"v9.0.0","branchLabelMappingKey":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"},{"branch":"main","label":"v9.1.0","branchLabelMappingKey":"^v9.1.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/210505","number":210505,"mergeCommit":{"message":"[kbn-scout]
Add Synthtrace as a fixture (#210505)\n\n## Summary\n\nCloses
#210340\n\nThis PR adds synthtrace clients to scout as a test fixture,
so you can\nuse it in your test to generate data.\n\nThe clients added
were `apmSynthtraceEsClient`,\n`infraSynthtraceEsClient` and
`otelSynthtraceEsClient`.\n\n## How to use them in parallel tests\n\nAs
`synthtrace` ingests data into our indices, and sequential runs
would\nbe the perfect way to introduce flakiness in our tests, there is
a\nbetter way to ingest data, using a hook, at the setup phase
with\n`globalSetup`.\nWe need to create a `global_setup.ts` file and
link it into our\nplaywright config.\nThen we can use something
like\n```\nasync function globalSetup(config: FullConfig) {\n const data
= {\n apm: [\n opbeans({\n from: new Date(start).getTime(),\n to: new
Date(end).getTime(),\n }),\n ],\n infra: [\n generateHosts({\n from: new
Date(start).toISOString(),\n to: new Date(end).toISOString(),\n }),\n
],\n otel: [\n sendotlp({\n from: new Date(start).getTime(),\n to: new
Date(end).getTime(),\n }),\n ],\n };\n\n return
ingestSynthtraceDataHook(config, data);\n}\n```\nEach key (apm, infra,
otel) accepts an array of generators.\n\n## How to use them in
sequential tests\n> [!WARNING] \n> This should not be the standard
behaviour, we should embrace\nparallelism and use sequential testing
when there is no other way.\n\n### apmSynthtraceEsClient\n```ts\n
test.before(\n async ({ apmSynthtraceEsClient }) => {\n await
apmSynthtraceEsClient.index(\n opbeans({\n from: new
Date(start).getTime(),\n to: new Date(end).getTime(),\n })\n );\n }\n
);\n```\n[opbeans\nfile](https://github.com/elastic/kibana/blob/main/x-pack/solutions/observability/plugins/apm/ftr_e2e/cypress/fixtures/synthtrace/opbeans.ts)\nused
in the example.\n\n### otelSynthtraceEsClient\n```ts\n test.before(\n
async ({otelSynthtraceEsClient }) => {\n await
otelSynthtraceEsClient.index(\n sendotlp({\n from: new
Date(start).getTime(),\n to: new Date(end).getTime(),\n })\n );\n }\n
);\n```\n[sendotlp\nfile](https://github.com/elastic/kibana/blob/main/x-pack/solutions/observability/plugins/apm/ftr_e2e/cypress/fixtures/synthtrace/sendotlp.ts)\nwhich
will create the data.\n\n### infraSynthtraceEsClient\n```ts\n
test.before(\n async ({ infraSynthtraceEsClient }) => {\n await
infraSynthtraceEsClient.index(\n generateHosts({\n from: new
Date(start).toISOString(),\n to: new Date(end).toISOString(),\n })\n
);\n }\n
);\n```\n[generateHosts\nfile](https://github.com/elastic/kibana/blob/main/x-pack/solutions/observability/plugins/inventory/e2e/cypress/e2e/alert_count/generate_data.ts#L82)\nused
to generate data.\n\n---------\n\nCo-authored-by: kibanamachine
<42973632+kibanamachine@users.noreply.github.com>","sha":"e21c5d0e9175ffd1bea0ad78ffe26cb973cc489f"}},{"branch":"8.x","label":"v8.19.0","branchLabelMappingKey":"^v8.19.0$","isSourceBranch":false,"state":"NOT_CREATED"}]}]
BACKPORT-->

Co-authored-by: Sergi Romeu <sergi.romeu@elastic.co>
@rmyz rmyz deleted the 210340-scout-add-synthtrace-fixture branch February 17, 2025 09:20
@dmlemeshko dmlemeshko added backport:version Backport to applied version labels and removed backport:version Backport to applied version labels labels Feb 18, 2025
@kibanamachine
Copy link
Contributor

Starting backport for target branches: 8.x, 9.0

https://github.com/elastic/kibana/actions/runs/13386246157

kibanamachine pushed a commit to kibanamachine/kibana that referenced this pull request Feb 18, 2025
## Summary

Closes elastic#210340

This PR adds synthtrace clients to scout as a test fixture, so you can
use it in your test to generate data.

The clients added were `apmSynthtraceEsClient`,
`infraSynthtraceEsClient` and `otelSynthtraceEsClient`.

## How to use them in parallel tests

As `synthtrace` ingests data into our indices, and sequential runs would
be the perfect way to introduce flakiness in our tests, there is a
better way to ingest data, using a hook, at the setup phase with
`globalSetup`.
We need to create a `global_setup.ts` file and link it into our
playwright config.
Then we can use something like
```
async function globalSetup(config: FullConfig) {
  const data = {
    apm: [
      opbeans({
        from: new Date(start).getTime(),
        to: new Date(end).getTime(),
      }),
    ],
    infra: [
      generateHosts({
        from: new Date(start).toISOString(),
        to: new Date(end).toISOString(),
      }),
    ],
    otel: [
      sendotlp({
        from: new Date(start).getTime(),
        to: new Date(end).getTime(),
      }),
    ],
  };

  return ingestSynthtraceDataHook(config, data);
}
```
Each key (apm, infra, otel) accepts an array of generators.

## How to use them in sequential tests
> [!WARNING]
> This should not be the standard behaviour, we should embrace
parallelism and use sequential testing when there is no other way.

### apmSynthtraceEsClient
```ts
 test.before(
    async ({ apmSynthtraceEsClient }) => {
      await apmSynthtraceEsClient.index(
        opbeans({
          from: new Date(start).getTime(),
          to: new Date(end).getTime(),
        })
      );
    }
  );
```
[opbeans
file](https://github.com/elastic/kibana/blob/main/x-pack/solutions/observability/plugins/apm/ftr_e2e/cypress/fixtures/synthtrace/opbeans.ts)
used in the example.

### otelSynthtraceEsClient
```ts
 test.before(
    async ({otelSynthtraceEsClient }) => {
      await otelSynthtraceEsClient.index(
        sendotlp({
          from: new Date(start).getTime(),
          to: new Date(end).getTime(),
        })
      );
    }
  );
```
[sendotlp
file](https://github.com/elastic/kibana/blob/main/x-pack/solutions/observability/plugins/apm/ftr_e2e/cypress/fixtures/synthtrace/sendotlp.ts)
which will create the data.

### infraSynthtraceEsClient
```ts
 test.before(
    async ({ infraSynthtraceEsClient }) => {
      await infraSynthtraceEsClient.index(
        generateHosts({
          from: new Date(start).toISOString(),
          to: new Date(end).toISOString(),
        })
      );
    }
  );
```
[generateHosts
file](https://github.com/elastic/kibana/blob/main/x-pack/solutions/observability/plugins/inventory/e2e/cypress/e2e/alert_count/generate_data.ts#L82)
used to generate data.

---------

Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com>
(cherry picked from commit e21c5d0)
@kibanamachine
Copy link
Contributor

💔 Some backports could not be created

Status Branch Result
8.x
9.0 Cherrypick failed because the selected commit (e21c5d0) is empty. It looks like the commit was already backported in #211351

Note: Successful backport PRs will be merged automatically after passing CI.

Manual backport

To create the backport manually run:

node scripts/backport --pr 210505

Questions ?

Please refer to the Backport tool documentation

kibanamachine added a commit that referenced this pull request Feb 18, 2025
# Backport

This will backport the following commits from `main` to `8.x`:
- [[kbn-scout] Add Synthtrace as a fixture
(#210505)](#210505)

<!--- Backport version: 9.6.5 -->

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

<!--BACKPORT [{"author":{"name":"Sergi
Romeu","email":"sergi.romeu@elastic.co"},"sourceCommit":{"committedDate":"2025-02-14T18:52:22Z","message":"[kbn-scout]
Add Synthtrace as a fixture (#210505)\n\n## Summary\n\nCloses
#210340\n\nThis PR adds synthtrace clients to scout as a test fixture,
so you can\nuse it in your test to generate data.\n\nThe clients added
were `apmSynthtraceEsClient`,\n`infraSynthtraceEsClient` and
`otelSynthtraceEsClient`.\n\n## How to use them in parallel tests\n\nAs
`synthtrace` ingests data into our indices, and sequential runs
would\nbe the perfect way to introduce flakiness in our tests, there is
a\nbetter way to ingest data, using a hook, at the setup phase
with\n`globalSetup`.\nWe need to create a `global_setup.ts` file and
link it into our\nplaywright config.\nThen we can use something
like\n```\nasync function globalSetup(config: FullConfig) {\n const data
= {\n apm: [\n opbeans({\n from: new Date(start).getTime(),\n to: new
Date(end).getTime(),\n }),\n ],\n infra: [\n generateHosts({\n from: new
Date(start).toISOString(),\n to: new Date(end).toISOString(),\n }),\n
],\n otel: [\n sendotlp({\n from: new Date(start).getTime(),\n to: new
Date(end).getTime(),\n }),\n ],\n };\n\n return
ingestSynthtraceDataHook(config, data);\n}\n```\nEach key (apm, infra,
otel) accepts an array of generators.\n\n## How to use them in
sequential tests\n> [!WARNING] \n> This should not be the standard
behaviour, we should embrace\nparallelism and use sequential testing
when there is no other way.\n\n### apmSynthtraceEsClient\n```ts\n
test.before(\n async ({ apmSynthtraceEsClient }) => {\n await
apmSynthtraceEsClient.index(\n opbeans({\n from: new
Date(start).getTime(),\n to: new Date(end).getTime(),\n })\n );\n }\n
);\n```\n[opbeans\nfile](https://github.com/elastic/kibana/blob/main/x-pack/solutions/observability/plugins/apm/ftr_e2e/cypress/fixtures/synthtrace/opbeans.ts)\nused
in the example.\n\n### otelSynthtraceEsClient\n```ts\n test.before(\n
async ({otelSynthtraceEsClient }) => {\n await
otelSynthtraceEsClient.index(\n sendotlp({\n from: new
Date(start).getTime(),\n to: new Date(end).getTime(),\n })\n );\n }\n
);\n```\n[sendotlp\nfile](https://github.com/elastic/kibana/blob/main/x-pack/solutions/observability/plugins/apm/ftr_e2e/cypress/fixtures/synthtrace/sendotlp.ts)\nwhich
will create the data.\n\n### infraSynthtraceEsClient\n```ts\n
test.before(\n async ({ infraSynthtraceEsClient }) => {\n await
infraSynthtraceEsClient.index(\n generateHosts({\n from: new
Date(start).toISOString(),\n to: new Date(end).toISOString(),\n })\n
);\n }\n
);\n```\n[generateHosts\nfile](https://github.com/elastic/kibana/blob/main/x-pack/solutions/observability/plugins/inventory/e2e/cypress/e2e/alert_count/generate_data.ts#L82)\nused
to generate data.\n\n---------\n\nCo-authored-by: kibanamachine
<42973632+kibanamachine@users.noreply.github.com>","sha":"e21c5d0e9175ffd1bea0ad78ffe26cb973cc489f","branchLabelMapping":{"^v9.1.0$":"main","^v8.19.0$":"8.x","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:skip","v9.0.0","apm:synthtrace","Team:obs-ux-infra_services","backport:version","test:scout","v9.1.0","v8.19.0"],"title":"[kbn-scout]
Add Synthtrace as a
fixture","number":210505,"url":"https://github.com/elastic/kibana/pull/210505","mergeCommit":{"message":"[kbn-scout]
Add Synthtrace as a fixture (#210505)\n\n## Summary\n\nCloses
#210340\n\nThis PR adds synthtrace clients to scout as a test fixture,
so you can\nuse it in your test to generate data.\n\nThe clients added
were `apmSynthtraceEsClient`,\n`infraSynthtraceEsClient` and
`otelSynthtraceEsClient`.\n\n## How to use them in parallel tests\n\nAs
`synthtrace` ingests data into our indices, and sequential runs
would\nbe the perfect way to introduce flakiness in our tests, there is
a\nbetter way to ingest data, using a hook, at the setup phase
with\n`globalSetup`.\nWe need to create a `global_setup.ts` file and
link it into our\nplaywright config.\nThen we can use something
like\n```\nasync function globalSetup(config: FullConfig) {\n const data
= {\n apm: [\n opbeans({\n from: new Date(start).getTime(),\n to: new
Date(end).getTime(),\n }),\n ],\n infra: [\n generateHosts({\n from: new
Date(start).toISOString(),\n to: new Date(end).toISOString(),\n }),\n
],\n otel: [\n sendotlp({\n from: new Date(start).getTime(),\n to: new
Date(end).getTime(),\n }),\n ],\n };\n\n return
ingestSynthtraceDataHook(config, data);\n}\n```\nEach key (apm, infra,
otel) accepts an array of generators.\n\n## How to use them in
sequential tests\n> [!WARNING] \n> This should not be the standard
behaviour, we should embrace\nparallelism and use sequential testing
when there is no other way.\n\n### apmSynthtraceEsClient\n```ts\n
test.before(\n async ({ apmSynthtraceEsClient }) => {\n await
apmSynthtraceEsClient.index(\n opbeans({\n from: new
Date(start).getTime(),\n to: new Date(end).getTime(),\n })\n );\n }\n
);\n```\n[opbeans\nfile](https://github.com/elastic/kibana/blob/main/x-pack/solutions/observability/plugins/apm/ftr_e2e/cypress/fixtures/synthtrace/opbeans.ts)\nused
in the example.\n\n### otelSynthtraceEsClient\n```ts\n test.before(\n
async ({otelSynthtraceEsClient }) => {\n await
otelSynthtraceEsClient.index(\n sendotlp({\n from: new
Date(start).getTime(),\n to: new Date(end).getTime(),\n })\n );\n }\n
);\n```\n[sendotlp\nfile](https://github.com/elastic/kibana/blob/main/x-pack/solutions/observability/plugins/apm/ftr_e2e/cypress/fixtures/synthtrace/sendotlp.ts)\nwhich
will create the data.\n\n### infraSynthtraceEsClient\n```ts\n
test.before(\n async ({ infraSynthtraceEsClient }) => {\n await
infraSynthtraceEsClient.index(\n generateHosts({\n from: new
Date(start).toISOString(),\n to: new Date(end).toISOString(),\n })\n
);\n }\n
);\n```\n[generateHosts\nfile](https://github.com/elastic/kibana/blob/main/x-pack/solutions/observability/plugins/inventory/e2e/cypress/e2e/alert_count/generate_data.ts#L82)\nused
to generate data.\n\n---------\n\nCo-authored-by: kibanamachine
<42973632+kibanamachine@users.noreply.github.com>","sha":"e21c5d0e9175ffd1bea0ad78ffe26cb973cc489f"}},"sourceBranch":"main","suggestedTargetBranches":["8.x"],"targetPullRequestStates":[{"branch":"9.0","label":"v9.0.0","branchLabelMappingKey":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"url":"https://github.com/elastic/kibana/pull/211351","number":211351,"state":"MERGED","mergeCommit":{"sha":"5b6ff1cd6e7cd703ed66337ee743a08abf0fa7a8","message":"[9.0]
[kbn-scout] Add Synthtrace as a fixture (#210505) (#211351)\n\n#
Backport\n\nThis will backport the following commits from `main` to
`9.0`:\n- [[kbn-scout] Add Synthtrace as a
fixture\n(#210505)](https://github.com/elastic/kibana/pull/210505)\n\n<!---
Backport version: 9.4.3 -->\n\n### Questions ?\nPlease refer to the
[Backport
tool\ndocumentation](https://github.com/sqren/backport)\n\n<!--BACKPORT
[{\"author\":{\"name\":\"Sergi\nRomeu\",\"email\":\"sergi.romeu@elastic.co\"},\"sourceCommit\":{\"committedDate\":\"2025-02-14T18:52:22Z\",\"message\":\"[kbn-scout]\nAdd
Synthtrace as a fixture (#210505)\\n\\n##
Summary\\n\\nCloses\n#210340\\n\\nThis PR adds synthtrace clients to
scout as a test fixture,\nso you can\\nuse it in your test to generate
data.\\n\\nThe clients added\nwere
`apmSynthtraceEsClient`,\\n`infraSynthtraceEsClient`
and\n`otelSynthtraceEsClient`.\\n\\n## How to use them in parallel
tests\\n\\nAs\n`synthtrace` ingests data into our indices, and
sequential runs\nwould\\nbe the perfect way to introduce flakiness in
our tests, there is\na\\nbetter way to ingest data, using a hook, at the
setup phase\nwith\\n`globalSetup`.\\nWe need to create a
`global_setup.ts` file and\nlink it into our\\nplaywright config.\\nThen
we can use something\nlike\\n```\\nasync function globalSetup(config:
FullConfig) {\\n const data\n= {\\n apm: [\\n opbeans({\\n from: new
Date(start).getTime(),\\n to: new\nDate(end).getTime(),\\n }),\\n ],\\n
infra: [\\n generateHosts({\\n from: new\nDate(start).toISOString(),\\n
to: new Date(end).toISOString(),\\n }),\\n\n],\\n otel: [\\n
sendotlp({\\n from: new Date(start).getTime(),\\n to:
new\nDate(end).getTime(),\\n }),\\n ],\\n };\\n\\n
return\ningestSynthtraceDataHook(config, data);\\n}\\n```\\nEach key
(apm, infra,\notel) accepts an array of generators.\\n\\n## How to use
them in\nsequential tests\\n> [!WARNING] \\n> This should not be the
standard\nbehaviour, we should embrace\\nparallelism and use sequential
testing\nwhen there is no other way.\\n\\n###
apmSynthtraceEsClient\\n```ts\\n\ntest.before(\\n async ({
apmSynthtraceEsClient }) => {\\n await\napmSynthtraceEsClient.index(\\n
opbeans({\\n from: new\nDate(start).getTime(),\\n to: new
Date(end).getTime(),\\n })\\n );\\n
}\\n\n);\\n```\\n[opbeans\\nfile](https://github.com/elastic/kibana/blob/main/x-pack/solutions/observability/plugins/apm/ftr_e2e/cypress/fixtures/synthtrace/opbeans.ts)\\nused\nin
the example.\\n\\n### otelSynthtraceEsClient\\n```ts\\n
test.before(\\n\nasync ({otelSynthtraceEsClient }) => {\\n
await\notelSynthtraceEsClient.index(\\n sendotlp({\\n from:
new\nDate(start).getTime(),\\n to: new Date(end).getTime(),\\n })\\n
);\\n
}\\n\n);\\n```\\n[sendotlp\\nfile](https://github.com/elastic/kibana/blob/main/x-pack/solutions/observability/plugins/apm/ftr_e2e/cypress/fixtures/synthtrace/sendotlp.ts)\\nwhich\nwill
create the data.\\n\\n###
infraSynthtraceEsClient\\n```ts\\n\ntest.before(\\n async ({
infraSynthtraceEsClient }) => {\\n
await\ninfraSynthtraceEsClient.index(\\n generateHosts({\\n from:
new\nDate(start).toISOString(),\\n to: new Date(end).toISOString(),\\n
})\\n\n);\\n
}\\n\n);\\n```\\n[generateHosts\\nfile](https://github.com/elastic/kibana/blob/main/x-pack/solutions/observability/plugins/inventory/e2e/cypress/e2e/alert_count/generate_data.ts#L82)\\nused\nto
generate data.\\n\\n---------\\n\\nCo-authored-by:
kibanamachine\n<42973632+kibanamachine@users.noreply.github.com>\",\"sha\":\"e21c5d0e9175ffd1bea0ad78ffe26cb973cc489f\",\"branchLabelMapping\":{\"^v9.1.0$\":\"main\",\"^v8.19.0$\":\"8.x\",\"^v(\\\\d+).(\\\\d+).\\\\d+$\":\"$1.$2\"}},\"sourcePullRequest\":{\"labels\":[\"release_note:skip\",\"v9.0.0\",\"apm:synthtrace\",\"Team:obs-ux-infra_services\",\"backport:version\",\"test:scout\",\"v9.1.0\",\"v8.19.0\"],\"title\":\"[kbn-scout]\nAdd
Synthtrace as
a\nfixture\",\"number\":210505,\"url\":\"https://github.com/elastic/kibana/pull/210505\",\"mergeCommit\":{\"message\":\"[kbn-scout]\nAdd
Synthtrace as a fixture (#210505)\\n\\n##
Summary\\n\\nCloses\n#210340\\n\\nThis PR adds synthtrace clients to
scout as a test fixture,\nso you can\\nuse it in your test to generate
data.\\n\\nThe clients added\nwere
`apmSynthtraceEsClient`,\\n`infraSynthtraceEsClient`
and\n`otelSynthtraceEsClient`.\\n\\n## How to use them in parallel
tests\\n\\nAs\n`synthtrace` ingests data into our indices, and
sequential runs\nwould\\nbe the perfect way to introduce flakiness in
our tests, there is\na\\nbetter way to ingest data, using a hook, at the
setup phase\nwith\\n`globalSetup`.\\nWe need to create a
`global_setup.ts` file and\nlink it into our\\nplaywright config.\\nThen
we can use something\nlike\\n```\\nasync function globalSetup(config:
FullConfig) {\\n const data\n= {\\n apm: [\\n opbeans({\\n from: new
Date(start).getTime(),\\n to: new\nDate(end).getTime(),\\n }),\\n ],\\n
infra: [\\n generateHosts({\\n from: new\nDate(start).toISOString(),\\n
to: new Date(end).toISOString(),\\n }),\\n\n],\\n otel: [\\n
sendotlp({\\n from: new Date(start).getTime(),\\n to:
new\nDate(end).getTime(),\\n }),\\n ],\\n };\\n\\n
return\ningestSynthtraceDataHook(config, data);\\n}\\n```\\nEach key
(apm, infra,\notel) accepts an array of generators.\\n\\n## How to use
them in\nsequential tests\\n> [!WARNING] \\n> This should not be the
standard\nbehaviour, we should embrace\\nparallelism and use sequential
testing\nwhen there is no other way.\\n\\n###
apmSynthtraceEsClient\\n```ts\\n\ntest.before(\\n async ({
apmSynthtraceEsClient }) => {\\n await\napmSynthtraceEsClient.index(\\n
opbeans({\\n from: new\nDate(start).getTime(),\\n to: new
Date(end).getTime(),\\n })\\n );\\n
}\\n\n);\\n```\\n[opbeans\\nfile](https://github.com/elastic/kibana/blob/main/x-pack/solutions/observability/plugins/apm/ftr_e2e/cypress/fixtures/synthtrace/opbeans.ts)\\nused\nin
the example.\\n\\n### otelSynthtraceEsClient\\n```ts\\n
test.before(\\n\nasync ({otelSynthtraceEsClient }) => {\\n
await\notelSynthtraceEsClient.index(\\n sendotlp({\\n from:
new\nDate(start).getTime(),\\n to: new Date(end).getTime(),\\n })\\n
);\\n
}\\n\n);\\n```\\n[sendotlp\\nfile](https://github.com/elastic/kibana/blob/main/x-pack/solutions/observability/plugins/apm/ftr_e2e/cypress/fixtures/synthtrace/sendotlp.ts)\\nwhich\nwill
create the data.\\n\\n###
infraSynthtraceEsClient\\n```ts\\n\ntest.before(\\n async ({
infraSynthtraceEsClient }) => {\\n
await\ninfraSynthtraceEsClient.index(\\n generateHosts({\\n from:
new\nDate(start).toISOString(),\\n to: new Date(end).toISOString(),\\n
})\\n\n);\\n
}\\n\n);\\n```\\n[generateHosts\\nfile](https://github.com/elastic/kibana/blob/main/x-pack/solutions/observability/plugins/inventory/e2e/cypress/e2e/alert_count/generate_data.ts#L82)\\nused\nto
generate data.\\n\\n---------\\n\\nCo-authored-by:
kibanamachine\n<42973632+kibanamachine@users.noreply.github.com>\",\"sha\":\"e21c5d0e9175ffd1bea0ad78ffe26cb973cc489f\"}},\"sourceBranch\":\"main\",\"suggestedTargetBranches\":[\"9.0\",\"8.x\"],\"targetPullRequestStates\":[{\"branch\":\"9.0\",\"label\":\"v9.0.0\",\"branchLabelMappingKey\":\"^v(\\\\d+).(\\\\d+).\\\\d+$\",\"isSourceBranch\":false,\"state\":\"NOT_CREATED\"},{\"branch\":\"main\",\"label\":\"v9.1.0\",\"branchLabelMappingKey\":\"^v9.1.0$\",\"isSourceBranch\":true,\"state\":\"MERGED\",\"url\":\"https://github.com/elastic/kibana/pull/210505\",\"number\":210505,\"mergeCommit\":{\"message\":\"[kbn-scout]\nAdd
Synthtrace as a fixture (#210505)\\n\\n##
Summary\\n\\nCloses\n#210340\\n\\nThis PR adds synthtrace clients to
scout as a test fixture,\nso you can\\nuse it in your test to generate
data.\\n\\nThe clients added\nwere
`apmSynthtraceEsClient`,\\n`infraSynthtraceEsClient`
and\n`otelSynthtraceEsClient`.\\n\\n## How to use them in parallel
tests\\n\\nAs\n`synthtrace` ingests data into our indices, and
sequential runs\nwould\\nbe the perfect way to introduce flakiness in
our tests, there is\na\\nbetter way to ingest data, using a hook, at the
setup phase\nwith\\n`globalSetup`.\\nWe need to create a
`global_setup.ts` file and\nlink it into our\\nplaywright config.\\nThen
we can use something\nlike\\n```\\nasync function globalSetup(config:
FullConfig) {\\n const data\n= {\\n apm: [\\n opbeans({\\n from: new
Date(start).getTime(),\\n to: new\nDate(end).getTime(),\\n }),\\n ],\\n
infra: [\\n generateHosts({\\n from: new\nDate(start).toISOString(),\\n
to: new Date(end).toISOString(),\\n }),\\n\n],\\n otel: [\\n
sendotlp({\\n from: new Date(start).getTime(),\\n to:
new\nDate(end).getTime(),\\n }),\\n ],\\n };\\n\\n
return\ningestSynthtraceDataHook(config, data);\\n}\\n```\\nEach key
(apm, infra,\notel) accepts an array of generators.\\n\\n## How to use
them in\nsequential tests\\n> [!WARNING] \\n> This should not be the
standard\nbehaviour, we should embrace\\nparallelism and use sequential
testing\nwhen there is no other way.\\n\\n###
apmSynthtraceEsClient\\n```ts\\n\ntest.before(\\n async ({
apmSynthtraceEsClient }) => {\\n await\napmSynthtraceEsClient.index(\\n
opbeans({\\n from: new\nDate(start).getTime(),\\n to: new
Date(end).getTime(),\\n })\\n );\\n
}\\n\n);\\n```\\n[opbeans\\nfile](https://github.com/elastic/kibana/blob/main/x-pack/solutions/observability/plugins/apm/ftr_e2e/cypress/fixtures/synthtrace/opbeans.ts)\\nused\nin
the example.\\n\\n### otelSynthtraceEsClient\\n```ts\\n
test.before(\\n\nasync ({otelSynthtraceEsClient }) => {\\n
await\notelSynthtraceEsClient.index(\\n sendotlp({\\n from:
new\nDate(start).getTime(),\\n to: new Date(end).getTime(),\\n })\\n
);\\n
}\\n\n);\\n```\\n[sendotlp\\nfile](https://github.com/elastic/kibana/blob/main/x-pack/solutions/observability/plugins/apm/ftr_e2e/cypress/fixtures/synthtrace/sendotlp.ts)\\nwhich\nwill
create the data.\\n\\n###
infraSynthtraceEsClient\\n```ts\\n\ntest.before(\\n async ({
infraSynthtraceEsClient }) => {\\n
await\ninfraSynthtraceEsClient.index(\\n generateHosts({\\n from:
new\nDate(start).toISOString(),\\n to: new Date(end).toISOString(),\\n
})\\n\n);\\n
}\\n\n);\\n```\\n[generateHosts\\nfile](https://github.com/elastic/kibana/blob/main/x-pack/solutions/observability/plugins/inventory/e2e/cypress/e2e/alert_count/generate_data.ts#L82)\\nused\nto
generate data.\\n\\n---------\\n\\nCo-authored-by:
kibanamachine\n<42973632+kibanamachine@users.noreply.github.com>\",\"sha\":\"e21c5d0e9175ffd1bea0ad78ffe26cb973cc489f\"}},{\"branch\":\"8.x\",\"label\":\"v8.19.0\",\"branchLabelMappingKey\":\"^v8.19.0$\",\"isSourceBranch\":false,\"state\":\"NOT_CREATED\"}]}]\nBACKPORT-->\n\nCo-authored-by:
Sergi Romeu
<sergi.romeu@elastic.co>"}},{"branch":"main","label":"v9.1.0","branchLabelMappingKey":"^v9.1.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/210505","number":210505,"mergeCommit":{"message":"[kbn-scout]
Add Synthtrace as a fixture (#210505)\n\n## Summary\n\nCloses
#210340\n\nThis PR adds synthtrace clients to scout as a test fixture,
so you can\nuse it in your test to generate data.\n\nThe clients added
were `apmSynthtraceEsClient`,\n`infraSynthtraceEsClient` and
`otelSynthtraceEsClient`.\n\n## How to use them in parallel tests\n\nAs
`synthtrace` ingests data into our indices, and sequential runs
would\nbe the perfect way to introduce flakiness in our tests, there is
a\nbetter way to ingest data, using a hook, at the setup phase
with\n`globalSetup`.\nWe need to create a `global_setup.ts` file and
link it into our\nplaywright config.\nThen we can use something
like\n```\nasync function globalSetup(config: FullConfig) {\n const data
= {\n apm: [\n opbeans({\n from: new Date(start).getTime(),\n to: new
Date(end).getTime(),\n }),\n ],\n infra: [\n generateHosts({\n from: new
Date(start).toISOString(),\n to: new Date(end).toISOString(),\n }),\n
],\n otel: [\n sendotlp({\n from: new Date(start).getTime(),\n to: new
Date(end).getTime(),\n }),\n ],\n };\n\n return
ingestSynthtraceDataHook(config, data);\n}\n```\nEach key (apm, infra,
otel) accepts an array of generators.\n\n## How to use them in
sequential tests\n> [!WARNING] \n> This should not be the standard
behaviour, we should embrace\nparallelism and use sequential testing
when there is no other way.\n\n### apmSynthtraceEsClient\n```ts\n
test.before(\n async ({ apmSynthtraceEsClient }) => {\n await
apmSynthtraceEsClient.index(\n opbeans({\n from: new
Date(start).getTime(),\n to: new Date(end).getTime(),\n })\n );\n }\n
);\n```\n[opbeans\nfile](https://github.com/elastic/kibana/blob/main/x-pack/solutions/observability/plugins/apm/ftr_e2e/cypress/fixtures/synthtrace/opbeans.ts)\nused
in the example.\n\n### otelSynthtraceEsClient\n```ts\n test.before(\n
async ({otelSynthtraceEsClient }) => {\n await
otelSynthtraceEsClient.index(\n sendotlp({\n from: new
Date(start).getTime(),\n to: new Date(end).getTime(),\n })\n );\n }\n
);\n```\n[sendotlp\nfile](https://github.com/elastic/kibana/blob/main/x-pack/solutions/observability/plugins/apm/ftr_e2e/cypress/fixtures/synthtrace/sendotlp.ts)\nwhich
will create the data.\n\n### infraSynthtraceEsClient\n```ts\n
test.before(\n async ({ infraSynthtraceEsClient }) => {\n await
infraSynthtraceEsClient.index(\n generateHosts({\n from: new
Date(start).toISOString(),\n to: new Date(end).toISOString(),\n })\n
);\n }\n
);\n```\n[generateHosts\nfile](https://github.com/elastic/kibana/blob/main/x-pack/solutions/observability/plugins/inventory/e2e/cypress/e2e/alert_count/generate_data.ts#L82)\nused
to generate data.\n\n---------\n\nCo-authored-by: kibanamachine
<42973632+kibanamachine@users.noreply.github.com>","sha":"e21c5d0e9175ffd1bea0ad78ffe26cb973cc489f"}},{"branch":"8.x","label":"v8.19.0","branchLabelMappingKey":"^v8.19.0$","isSourceBranch":false,"state":"NOT_CREATED"}]}]
BACKPORT-->

---------

Co-authored-by: Sergi Romeu <sergi.romeu@elastic.co>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
apm:synthtrace APM Synthtrace Topics backport:version Backport to applied version labels release_note:skip Skip the PR/issue when compiling release notes Team:obs-ux-infra_services Observability Infrastructure & Services User Experience Team test:scout v8.19.0 v9.0.0 v9.1.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Scout] Add synthtrace
7 participants