Skip to content

[8.x] [kbn-scout] Add Synthtrace as a fixture (#210505)#211524

Merged
kibanamachine merged 3 commits intoelastic:8.xfrom
kibanamachine:backport/8.x/pr-210505
Feb 18, 2025
Merged

[8.x] [kbn-scout] Add Synthtrace as a fixture (#210505)#211524
kibanamachine merged 3 commits intoelastic:8.xfrom
kibanamachine:backport/8.x/pr-210505

Conversation

@kibanamachine
Copy link
Copy Markdown
Contributor

Backport

This will backport the following commits from main to 8.x:

Questions ?

Please refer to the Backport tool documentation

\n\n### Questions ?\nPlease refer to the [Backport tool\ndocumentation](https://github.com/sqren/backport)\n\n\n\nCo-authored-by: Sergi Romeu "}},{"branch":"main","label":"v9.1.0","branchLabelMappingKey":"^v9.1.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com//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-->

## 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 kibanamachine added the backport This PR is a backport of another PR label Feb 18, 2025
@kibanamachine kibanamachine enabled auto-merge (squash) February 18, 2025 08:31
@rmyz
Copy link
Copy Markdown
Contributor

rmyz commented Feb 18, 2025

this depends on #211541 getting merged

@botelastic botelastic bot added ci:project-deploy-observability Create an Observability project Team:obs-ux-infra_services - DEPRECATED DEPRECATED - Use Team:obs-presentation. labels Feb 18, 2025
@elasticmachine
Copy link
Copy Markdown
Contributor

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

@github-actions
Copy link
Copy Markdown
Contributor

🤖 GitHub comments

Expand to view the GitHub comments

Just comment with:

  • /oblt-deploy : Deploy a Kibana instance using the Observability test environments.
  • run docs-build : Re-trigger the docs validation. (use unformatted text in the comment!)

@kibanamachine kibanamachine merged commit 52d5725 into elastic:8.x Feb 18, 2025
4 checks passed
@elasticmachine
Copy link
Copy Markdown
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/apm-synthtrace 94 97 +3
@kbn/scout 93 99 +6
total +9

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/apm-synthtrace 94 97 +3
@kbn/scout 383 389 +6
total +9

History

cc @rmyz

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport This PR is a backport of another PR ci:project-deploy-observability Create an Observability project Team:obs-ux-infra_services - DEPRECATED DEPRECATED - Use Team:obs-presentation.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants