elastic / kibana

Your window into the Elastic Stack
https://www.elastic.co/products/kibana
Other
19.61k stars 8.22k forks source link

[Synthetics] [Meta] Port API tests from stateful to serverless #179100

Open justinkambic opened 7 months ago

justinkambic commented 7 months ago

Some additional work that came out of https://github.com/elastic/kibana/pull/178897, we need to have some assurance that Synthetics will not catastrophically fail on Serverless when dependencies change. This is a visible risk that is illustrated in the linked issue for that PR.

As such, we should port at least a subset of the Synthetics API tests to the Serverless section of x-pack testing. This will give us at least assurance that our Kibana server is functioning nominally as more changes go in.

I've converted this task to a meta ticket with sub-issues stubbed out. ~I'll update each issue with links to the code in question, and add a guide to the meta for adapting tests that rely on features like roles and the ES security API that aren't available in Serverless. I'll also include links to the testing docs for Kibana's Serverless test suite.~

Prior art

You can see the initial implementation as part of https://github.com/elastic/kibana/pull/179861.

Key differences

When interacting via API endpoints, many of the Stateful tests utilize supertestWithAuth and make requests via users/roles they create using the security service:

          const username = 'admin';
          const roleName = `synthetics_admin-${privilege}`;
          const password = `${username}-password`;
          try {
            await security.role.create(roleName, {
              kibana: [
                {
                  feature: {
                    uptime: ['all'],
                  },
                  spaces: ['*'],
                },
              ],
              elasticsearch: {
                cluster: [privilege],
                indices: getServiceApiKeyPrivileges(false).indices,
              },
            });

In Serverless, there's a SAML simulator you can use to provide the necessary auth via supertestWithoutAuth:

note: at this time it's recommended to avoid using system_indices_superuser because this does not exist in MKI and will cause the test to fail and be skipped.

// `role` can be 'system_indices_superuser', 'admin', 'editor', 'viewer'
supertestWithoutAuth
  .put(SYNTHETICS_API_URLS.SYNTHETICS_ENABLEMENT)
  // internal request header is different from the typical kbn-xsrf header
  // implementation details are available in the PR linked above
  .set(internalRequestHeader)
  .set(await svlUserManager.getApiCredentialsForRole(role))
  .expect(expectedStatus);

Smells to look for are declarations like:

// custom user creation
const username = 'admin';
const roleName = `synthetics_admin-${privilege}`;

// calls to create custom roles
await security.role.create(roleName, ...)

The Serverless alternative is to choose the appropriate SAML role to utilize to replicate the spirit of the original test you're porting.

Guidance

You can learn more about writing and manipulating serverless tests in general and API tests specifically by reviewing the README for the test_serverless section of the Kibana repo.

elasticmachine commented 7 months ago

Pinging @elastic/unified-observability (Team:Observability)

elasticmachine commented 7 months ago

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

paulb-elastic commented 7 months ago

Removing from the Synthetics on serverless project board, as being tracked as part of Infra&Services work

paulb-elastic commented 5 months ago

Note that the Management UX team have been trying out having a unified set of API tests that are suitable for both stateful and serverless - see https://github.com/elastic/kibana/pull/183113.

This would be a more efficient implementation, rather than having duplicated API tests for each.

paulb-elastic commented 4 months ago

We should be hearing by the end of next week, the mechanism to allow stateful API tests to be run in a serverless configuration

elasticmachine commented 3 months ago

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

maryam-saeidi commented 20 hours ago

@justinkambic @dominiqueclarke Will this ticket be covered in https://github.com/elastic/kibana/issues/196229?