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: add e2e playwright tests for grafana #844

Merged
merged 47 commits into from
Oct 18, 2024
Merged
Show file tree
Hide file tree
Changes from 41 commits
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
8765b88
chore: add e2e playwright tests for grafana
mjnagel Sep 30, 2024
e481066
Merge branch 'main' into grafana-e2e-test
mjnagel Sep 30, 2024
b52e722
chore: add e2e tests to upgrade
mjnagel Sep 30, 2024
d6cd73e
fix: override path
mjnagel Sep 30, 2024
61321df
Update values.schema.json
mjnagel Sep 30, 2024
67c19d2
chore: template update for kc
mjnagel Sep 30, 2024
aa9bcf8
fix: upgrade test logic and bundle deploy
mjnagel Sep 30, 2024
61d170d
Merge branch 'main' into grafana-e2e-test
mjnagel Sep 30, 2024
7ce5f88
chore: rebase
mjnagel Oct 1, 2024
6f87a6b
chore: rebase
mjnagel Oct 7, 2024
aa68212
wip: single layer test, video
mjnagel Oct 8, 2024
5e48738
Merge branch 'main' into grafana-e2e-test
mjnagel Oct 8, 2024
22641e5
wip: working func layers test
mjnagel Oct 8, 2024
dce3745
Merge branch 'main' into grafana-e2e-test
mjnagel Oct 9, 2024
66d751a
chore: rebase
mjnagel Oct 10, 2024
251fc1b
chore: password for kc admin
mjnagel Oct 10, 2024
44d6b4c
chore: password for kc admin
mjnagel Oct 10, 2024
8a7d006
chore: add license
mjnagel Oct 10, 2024
e5274a1
layer doc fix
mjnagel Oct 10, 2024
7e6b9ba
remove extra
mjnagel Oct 10, 2024
2f39a15
relocate playwright artifacts
mjnagel Oct 11, 2024
fb5f673
chore: increase timeout
mjnagel Oct 11, 2024
530eb11
Merge branch 'main' into grafana-e2e-test
mjnagel Oct 11, 2024
e723936
Merge branch 'main' into grafana-e2e-test
mjnagel Oct 11, 2024
bb2e8e0
sudo time
mjnagel Oct 11, 2024
04af744
chore: rebase
mjnagel Oct 15, 2024
d2efc02
Merge branch 'main' into grafana-e2e-test
mjnagel Oct 15, 2024
3c8d2d9
chore: align upgrade deploys
mjnagel Oct 15, 2024
50e95e6
Merge branch 'main' into grafana-e2e-test
mjnagel Oct 15, 2024
fb0d203
Merge branch 'main' into grafana-e2e-test
mjnagel Oct 15, 2024
384aef4
Merge branch 'main' into grafana-e2e-test
mjnagel Oct 15, 2024
c24525d
fix: cyclic
mjnagel Oct 15, 2024
3aa0f82
fix: gitignore
mjnagel Oct 15, 2024
8934ca0
chore: folders
mjnagel Oct 15, 2024
fb8897b
Merge branch 'main' into grafana-e2e-test
mjnagel Oct 16, 2024
2d9c63d
add service patch for loki
mjnagel Oct 16, 2024
5a6458c
fix weird import things
mjnagel Oct 17, 2024
86f895f
Merge branch 'main' into grafana-e2e-test
mjnagel Oct 17, 2024
4953590
Merge branch 'main' into grafana-e2e-test
mjnagel Oct 17, 2024
dc791fc
chore: update playwright version
mjnagel Oct 17, 2024
df1b254
chore: update playwright version
mjnagel Oct 17, 2024
e33fad5
align es version, scale up backend
mjnagel Oct 17, 2024
173d266
chore: tweaks
mjnagel Oct 17, 2024
61f27cb
chore: change
mjnagel Oct 17, 2024
cc377a6
Merge branch 'main' into grafana-e2e-test
mjnagel Oct 17, 2024
13bc88d
Merge branch 'main' into grafana-e2e-test
mjnagel Oct 17, 2024
5b4e211
chore: rebase
mjnagel Oct 18, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 23 additions & 6 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,38 @@
"browser": false,
"es2021": true
},
"extends": ["eslint:recommended", "plugin:@typescript-eslint/recommended"],
"extends": [
"eslint:recommended",
"plugin:@typescript-eslint/recommended"
],
"parser": "@typescript-eslint/parser",
"parserOptions": {
"project": ["./tsconfig.json"],
"project": [
"./tsconfig.json"
],
"ecmaVersion": 2022
},
"plugins": ["@typescript-eslint"],
"ignorePatterns": ["node_modules", "dist", "jest.*.js"],
"plugins": [
"@typescript-eslint"
],
"ignorePatterns": [
"node_modules",
"dist",
"jest.*.js",
"e2e/"
],
"root": true,
"rules": {
"@typescript-eslint/no-floating-promises": ["error"]
"@typescript-eslint/no-floating-promises": [
"error"
]
},
"overrides": [
{
"files": [ "src/pepr/operator/crd/generated/**/*.ts", "src/pepr/operator/crd/generated/*.ts" ],
"files": [
"src/pepr/operator/crd/generated/**/*.ts",
"src/pepr/operator/crd/generated/*.ts"
],
"rules": {
"@typescript-eslint/no-explicit-any": "off"
}
Expand Down
8 changes: 8 additions & 0 deletions .github/actions/save-logs/action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,12 @@ runs:
sudo chown $USER /tmp/uds-*.log || echo ""
shell: bash

- name: Move Playwright Artifacts
run: |
sudo mkdir -p /tmp/playwright
sudo mv e2e/playwright/.playwright/* /tmp/playwright || true
shell: bash

- uses: actions/upload-artifact@b4b15b8c7c6ac21ea08fcf65892d2ee8f75cf882 # v4.4.3
with:
name: debug-log${{ inputs.suffix }}
Expand All @@ -47,3 +53,5 @@ runs:
/tmp/debug-*.log
/tmp/uds-containerd-logs
/tmp/k3d-uds-*.log
/tmp/playwright/output
/tmp/playwright/reports
2 changes: 1 addition & 1 deletion .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ jobs:

- name: Test UDS Core Install
if: ${{ inputs.package == 'all' && inputs.test_type == 'install' }}
run: uds run test-uds-core --set FLAVOR=${{ inputs.flavor }} --no-progress
run: uds run test:uds-core-e2e --set FLAVOR=${{ inputs.flavor }} --no-progress

- name: Validate UDS Core Compliance
if: ${{ inputs.package == 'all' && inputs.test_type == 'install' }}
Expand Down
7 changes: 6 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,13 @@ build/
.DS_Store
*.tar.zst
zarf-sbom
zarf-sbom/**
tmp/
env.ts
node_modules/**
**/node_modules
**/node_modules/**
dist
dist/**
insecure*
.env
zarf
Expand All @@ -19,3 +22,5 @@ extract-terraform.sh
cluster-config.yaml
**.tfstate
**.backup
**/.playwright/**
**/.playwright
98 changes: 79 additions & 19 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
# Welcome to UDS Core

Thank you for your interest in Defense Unicorns UDS Core!

This document describes the process and requirements for contributing to this UDS Core repo.
Thank you for your interest in contributing to Defense Unicorns UDS Core! This document will guide you through the contribution process.

## Table of Contents

Expand All @@ -20,35 +18,97 @@ Continuous Delivery is core to our development philosophy. Check out [https://mi

Specifically:

* We do trunk-based development (main) with short-lived feature branches that originate from the trunk, get merged into the trunk, and are deleted after the merge
* We don't merge code into main that isn't releasable
* We perform automated testing on all changes before they get merged to main
* Continuous integration (CI) pipeline tests are definitive
* We create immutable release artifacts
- We practice trunk-based development (main) with short-lived feature branches that are merged and deleted after the merge.
- We don't merge code into main that isn't releasable.
- All changes are tested automatically before being merged into main.
- Continuous integration (CI) pipeline tests are the source of truth.
- We produce immutable release artifacts.

### Pre-Commit Checks

Commits:
We use [codespell](https://github.com/codespell-project/codespell) and [yamllint](https://yamllint.readthedocs.io/en/stable/) for pre-commit checks. Please install these before committing, or your commit may fail.

We use [codespell](https://github.com/codespell-project/codespell) and [yamllint](https://yamllint.readthedocs.io/en/stable/) for our precommit checking. It is recommended to have these installed before attempting to commit to the a branch otherwise your commit will not finalize and you will be shown an error.
To install these tools, run:

```console
uds run lint-check
```

To install both of these tools you can run `uds run lint-check` to install them or utilize `pip` to install them manually.
Alternatively, you can install them with `pip`:

```bash
```console
pip install yamllint codespell
```

## Definition of Done

We apply these general principles to all User Stories and activities contributing to the UDS.
We apply these principles to all User Stories and contributions:

- Automated continuous integration (CI) pipeline tests pass
- CI tests are updated to cover new system changes
- Changes are peer-reviewed
- Acceptance criteria is met
- Documentation is updated to reflect changes

### Testing

Each individual component of UDS Core contains lightweight validations in its own `src/<component>/tasks.yaml` file. These validations focus on the bare minimum functionality, typically covering pod health and endpoint accessibility.

We also place end-to-end tests under the `e2e` folder. In particular we use [Playwright](https://playwright.dev/) for browser based testing and have authentication setup to login to applications with a shared SSO session. Playwright provides a [test recorder](https://playwright.dev/docs/codegen#generate-tests-with-the-playwright-inspector) which can be beneficial to get a quickstart on new tests.

* Automated continuous integration (CI) pipeline tests pass
* CI pipeline tests have been updated to meet system changes
* Changes are peer reviewed
* Acceptance criteria is met
* Documentation is updated to reflect what changed
In general our testing focuses on the unique configuration and setup provided by UDS Core, rather than exhaustive functionality testing. We take this approach since each of the opensource applications we package and configure also have extensive end-to-end testing in their upstream repositories.

## Getting Started

TBD
This section will help you get set up and ready to contribute to UDS Core.

### 1. Prerequisites

Before starting, ensure that you have the following installed:

- **Git**: [Install Git](https://git-scm.com/book/en/v2/Getting-Started-Installing-Git)
- **K3d**: [Install K3d](https://k3d.io/#installation)
- **Node.js** (for building and running Pepr): [Install Node.js](https://nodejs.org/en/download/)
- **UDS CLI** (for running tasks and deploying): [Install UDS](https://uds.defenseunicorns.com/cli/quickstart-and-usage/)

### 2. Clone the Repository and Make a Branch

Clone the UDS Core repository to your local machine using Git (note that you may want to [fork](https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/working-with-forks/fork-a-repo) this repository):

```console
git clone https://github.com/DefenseUnicorns/uds-core.git
cd uds-core
```

Then make a branch for your changes:

```console
git checkout -b my-feature-branch
```

### 3. Make Changes and Test Locally

Make the changes to add the new feature, bug fix, or other change necessary. Keep in mind any documentation or testing changes that are relevant while making code changes.

When you are ready to test locally you can run the same tests as CI using the below UDS commands:

```console
# Lightweight validations
uds run test-uds-core

# Full e2e tests (run in CI)
uds run test:uds-core-e2e
```

Each of these tasks will create a local k3d cluster, install UDS Core, and run a series of tests against it, the same tests that are run in CI.

If you want to run a subset of core for faster iterations against a specific package, you can use the `LAYER` variable with the below task (example for metrics-server):

```console
uds run test-single-layer --set LAYER=metrics-server
```

Note you can also specify the `--set FLAVOR=<registry1/unicorn>` flag to test using with either the Iron Bank or Unicorn sourced images instead of the upstream ones.

## Submitting a Pull Request

Expand Down
32 changes: 32 additions & 0 deletions e2e/playwright/auth.setup.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/**
* Copyright 2024 Defense Unicorns
* SPDX-License-Identifier: AGPL-3.0-or-later OR LicenseRef-Defense-Unicorns-Commercial
*/

import { expect, test as setup } from "@playwright/test";
import { authFile } from "./playwright.config";
import { domain } from "./uds.config";

const baseURL = `https://sso.${domain}`;

setup("authenticate", async ({ page, context }) => {
await page.goto(baseURL);

await page.getByLabel("Username or email").fill("doug");
await page.getByLabel("Password").fill("unicorn123!@#UN");
await page.getByRole("button", { name: "Log In" }).click();

await page.waitForURL(`${baseURL}/realms/uds/account`); // successful redirect

// ensure auth cookies were set
const cookies = await context.cookies();
const keycloakCookie = cookies.find(
(cookie) => cookie.name === "KEYCLOAK_SESSION",
);

expect(keycloakCookie).toBeDefined();
expect(keycloakCookie?.value).not.toBe("");
expect(keycloakCookie?.domain).toContain("sso.");

await page.context().storageState({ path: authFile });
});
54 changes: 54 additions & 0 deletions e2e/playwright/grafana.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/**
* Copyright 2024 Defense Unicorns
* SPDX-License-Identifier: AGPL-3.0-or-later OR LicenseRef-Defense-Unicorns-Commercial
*/

import { expect, test } from "@playwright/test";
import { domain, fullCore } from "./uds.config";

test.use({ baseURL: `https://grafana.admin.${domain}` });
test.describe.configure({ mode: 'serial' });

test("validate loki datasource", async ({ page }) => {
test.skip(!fullCore, "Loki is only present on full core deploys");
await test.step("check loki", async () => {
await page.goto(`/connections/datasources`);
await page.getByRole('link', { name: 'Loki' }).click();
await page.click('text=Save & test');
// Allow 40 second timeout for datasource validation
await expect(page.locator('[data-testid="data-testid Alert success"]')).toBeVisible({ timeout: 40000 });
});
});

test("validate prometheus datasource", async ({ page }) => {
await test.step("check prometheus", async () => {
await page.goto(`/connections/datasources`);
await page.getByRole('link', { name: 'Prometheus' }).click();
await page.click('text=Save & test');
// Allow 20 second timeout for datasource validation
await expect(page.locator('[data-testid="data-testid Alert success"]')).toBeVisible({ timeout: 20000 });
});
});

// This dashboard is added by the upstream kube-prometheus-stack
test("validate namespace dashboard", async ({ page }) => {
await test.step("check dashboard", async () => {
await page.goto(`/dashboards`);
await page.click('text="Kubernetes / Compute Resources / Namespace (Pods)"');
await page.getByTestId('data-testid Dashboard template variables Variable Value DropDown value link text authservice').click();
await page.getByRole('checkbox', { name: 'grafana' }).click();
});
});

// This dashboard is deployed "custom" by our uds config chart
test("validate loki dashboard", async ({ page }) => {
test.skip(!fullCore, "Loki is only present on full core deploys");
await test.step("check dashboard", async () => {
await page.goto(`/dashboards`);
await page.getByPlaceholder('Search for dashboards and folders').fill('Loki');
await page.click('text="Loki Dashboard quick search"');
await page.getByTestId('data-testid Dashboard template variables Variable Value DropDown value link text authservice').click();
await page.getByRole('checkbox', { name: 'grafana' }).click();
await expect(page.getByTestId('data-testid Panel header Logs Panel').getByTestId('data-testid panel content')).toBeVisible();
});
});
Loading
Loading