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

chore(slo): add api integration tests for main services #195316

Closed
wants to merge 6 commits into from

Conversation

kdelemme
Copy link
Contributor

@kdelemme kdelemme commented Oct 7, 2024

resolves #187077

🌮 Summary

This PR adds the missing api integration tests on serverless for the update and reset SLO services.

@reakaleek
Copy link
Member

🤖 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!)

@kdelemme kdelemme added v9.0.0 backport:prev-minor Backport to (8.x) the previous minor version (i.e. one version back from main) Team:obs-ux-management Observability Management User Experience Team release_note:skip Skip the PR/issue when compiling release notes labels Oct 7, 2024
@kdelemme kdelemme marked this pull request as ready for review October 8, 2024 13:32
@kdelemme kdelemme requested review from a team as code owners October 8, 2024 13:32
@elasticmachine
Copy link
Contributor

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

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.

Please don't use supertest service to test API calls, as it will make API calls with operator privileges instead of native realm roles (viewer, editor, etc.)

{ sloId, slo }: { sloId: string; slo: UpdateSLOInput },
roleAuthc: RoleCredentials
) {
const { body } = await supertest
Copy link
Member

Choose a reason for hiding this comment

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

I just noticed that SloApiProvider is using supertest service. This service is authenticated with operator user and will use it to run API calls (ignoring roleAuthc.apiKeyHeader). It is not a right approach, please update the service to supertestWithoutAuth. This one has no authentication cached and will use provided API key / Cookie header to make API calls.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks, will do

Copy link
Contributor Author

Choose a reason for hiding this comment

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

resolved in d23a04e

Copy link
Contributor

Choose a reason for hiding this comment

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

@kdelemme We are actively working on migrating our current tests to the deployment agnostic framework. slo_api service in serverless folder will soon be removed. The slo_api service has already been migrated to the deployment agnostic folder and @dominiqueclarke is working into migrating the slo tests to the new framework.

.post(`/api/observability/slos/${sloId}/_reset`)
.set(svlCommonApi.getInternalRequestHeader())
.set(roleAuthc.apiKeyHeader)
.timeout(requestTimeout);
Copy link
Member

Choose a reason for hiding this comment

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

Feel free to ignore, just sharing another way to handle the wait:

If it makes sense to "fail fast" and not slow the test because of high request timeout (30s), the alternative is to set request retry count and decrease timeout. E.g. 10s request timeout and 2s delay before the next attempt

      return await retry.tryWithRetries(
        `Wait for SLO to be created`,
        async () => {
          const response = await supertestWithoutAuth
            .get(`/api/observability/slos/${sloId}`)
            .set(svlCommonApi.getInternalRequestHeader())
            .set(roleAuthc.apiKeyHeader)
            .timeout(10000);
          if (response.body.id === undefined) {
            throw new Error(`No slo with id ${sloId} found`);
          }
          return response.body;
        },
        { retryCount: 5, retryDelay: 2000 }
      );

Alerting API services uses it https://github.com/elastic/kibana/blob/main/x-pack/test/api_integration/deployment_agnostic/services/alerting_api.ts#L97-L130

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.

x-pack/test_serverless/api_integration/services changes LGTM

@elasticmachine
Copy link
Contributor

💚 Build Succeeded

Metrics [docs]

✅ unchanged

History

@kdelemme
Copy link
Contributor Author

Closing as outdated by #195927

@kdelemme kdelemme closed this Oct 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport:prev-minor Backport to (8.x) the previous minor version (i.e. one version back from main) release_note:skip Skip the PR/issue when compiling release notes Team:obs-ux-management Observability Management User Experience Team v9.0.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[SLO] API integration test coverage for SLO API usage
5 participants