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

Refactor k6 development environment to prepare for regular runs in CD #4903

Merged
merged 4 commits into from
Sep 10, 2024

Conversation

sarayourfriend
Copy link
Collaborator

@sarayourfriend sarayourfriend commented Sep 10, 2024

Fixes

Part of https://github.com/WordPress/openverse-infrastructure/issues/1031

Description

This PR refactors the k6 development environment in preparation for running the k6 frontend suite after staging deployments.

This refactor (hopefully) does the following:

  1. Simplify k6 execution environment by running it in ov instead of using a Docker wrapper. This also includes simpler and more reusable just recipes.
    • This has the additional benefit of making it easier to use k6 login, as we would need to sort out volumes for k6 to store credentials or otherwise map credentials in.
  2. Improve k6 developer experience generally by adding TypeScript support, linting through ESLint (utilities directory is not linted by ESLint!).
  3. Refactoring the k6 frontend scripts to match k6's code organisation style. Check out this repository as an example: https://github.com/grafana/k6-template-typescript/tree/main/src. Using the file name to choose the scenario(s) rather than passing a new ENV leverages k6's run API, and simplifies scenario selection (makes it more static).
    • To avoid needing to do a lot more refactoring, I deleted the API scripts. We can and will add these back later, but it was easier to keep the scripts we actually have and plan to consistently use moving forward. Once we organise running the frontend scripts as part of CD, we can do the same for API scripts, which will prevent them from drifting or breaking.
    • This also got rid of the non-k6 based scripts, which I don't think we used in the last two years, and even if we did, would be better re-written in k6 following the better patterns
    • Includes using k6 options for user agent (which we weren't doing for the API scripts), and configuring options for scenario vus/iterations

There are probably lots of further improvements to be made that get this closer in line with typical k6 examples. Scenarios seem powerful, but also potentially get in the way of configurability, as they do not support cli options for configuration (see link in code explaining this). k6's docs also have information about grouping tests and such, which we aren't really following. See this section of their docs:

https://grafana.com/docs/k6/latest/using-k6/tags-and-groups/#discouraged-one-group-per-request

We might be able to simplify things a lot further by reading k6 docs and understanding its best practices better, before adding many more scenarios (like for the API). This PR gets us in a better place to do that, because it enhances the developer experience and lays some groundwork for improving the code organisation. In other words, this PR is not the end-all-be-all of k6 improvement, and is just a start!

Testing Instructions

Checkout the repository and run ov init to get the new k6 and words dependency.

Now run ov just k6 frontend static-en -e scenario_vus=1 -e scenario_iterations=1 and confirm it runs! You might get blocked by Cloudflare, but you should see at least the HTML output of the Cloudflare managed challenge page 😁

Checklist

  • My pull request has a descriptive title (not a vague title likeUpdate index.md).
  • My pull request targets the default branch of the repository (main) or a parent feature branch.
  • My commit messages follow best practices.
  • My code follows the established code style of the repository.
  • I added or updated tests for the changes I made (if applicable).
  • I added or updated documentation (if applicable).
  • I tried running the project locally and verified that there are no visible errors.
  • [N/A] I ran the DAG documentation generator (ov just catalog/generate-docs for catalog
    PRs) or the media properties generator (ov just catalog/generate-docs media-props
    for the catalog or ov just api/generate-docs for the API) where applicable.

Developer Certificate of Origin

Developer Certificate of Origin
Developer Certificate of Origin
Version 1.1

Copyright (C) 2004, 2006 The Linux Foundation and its contributors.
1 Letterman Drive
Suite D4700
San Francisco, CA, 94129

Everyone is permitted to copy and distribute verbatim copies of this
license document, but changing it is not allowed.


Developer's Certificate of Origin 1.1

By making a contribution to this project, I certify that:

(a) The contribution was created in whole or in part by me and I
    have the right to submit it under the open source license
    indicated in the file; or

(b) The contribution is based upon previous work that, to the best
    of my knowledge, is covered under an appropriate open source
    license and I have the right under that license to submit that
    work with modifications, whether created in whole or in part
    by me, under the same open source license (unless I am
    permitted to submit under a different license), as indicated
    in the file; or

(c) The contribution was provided directly to me by some other
    person who certified (a), (b) or (c) and I have not modified
    it.

(d) I understand and agree that this project and the contribution
    are public and that a record of the contribution (including all
    personal information I submit with it, including my sign-off) is
    maintained indefinitely and may be redistributed consistent with
    this project or the open source license(s) involved.

@sarayourfriend sarayourfriend added 🟨 priority: medium Not blocking but should be addressed soon ✨ goal: improvement Improvement to an existing user-facing feature 💻 aspect: code Concerns the software code in the repository 🤖 aspect: dx Concerns developers' experience with the codebase 🧱 stack: mgmt Related to repo management and automations labels Sep 10, 2024
@sarayourfriend sarayourfriend requested review from a team as code owners September 10, 2024 05:13
@sarayourfriend sarayourfriend requested review from zackkrida and dhruvkb and removed request for a team September 10, 2024 05:13
@openverse-bot openverse-bot added the 🧱 stack: frontend Related to the Nuxt frontend label Sep 10, 2024
Copy link
Member

@zackkrida zackkrida left a comment

Choose a reason for hiding this comment

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

Awesome, works great. I made sure to test overriding the frontend url as well, for example: ov env FRONTEND_URL=http://172.17.0.1:8443/ just k6 frontend all

@sarayourfriend
Copy link
Collaborator Author

Oh, of course, I should have been testing that way to begin with! 🤦

@sarayourfriend sarayourfriend merged commit f54612d into main Sep 10, 2024
46 checks passed
@sarayourfriend sarayourfriend deleted the refactor/k6-dev-env branch September 10, 2024 20:53
@d3jawu d3jawu mentioned this pull request Sep 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
💻 aspect: code Concerns the software code in the repository 🤖 aspect: dx Concerns developers' experience with the codebase ✨ goal: improvement Improvement to an existing user-facing feature 🟨 priority: medium Not blocking but should be addressed soon 🧱 stack: frontend Related to the Nuxt frontend 🧱 stack: mgmt Related to repo management and automations
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

3 participants