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 prometheus, loki, and vector e2e testing #939

Merged
merged 45 commits into from
Nov 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
45b8482
chore: loki e2e testing
UnicornChance Oct 18, 2024
31653ef
fix: zarf package for flavors
UnicornChance Oct 18, 2024
cf7085f
Merge branch 'main' into loki-e2e
UnicornChance Oct 18, 2024
043b148
fix: vendor zarf
UnicornChance Oct 18, 2024
1ba033e
Merge branch 'main' into loki-e2e
UnicornChance Oct 18, 2024
8acc758
Merge branch 'main' into loki-e2e
UnicornChance Oct 18, 2024
6e6cf12
Merge branch 'main' into loki-e2e
UnicornChance Oct 21, 2024
260d4cb
fix: increase retry delay
UnicornChance Oct 21, 2024
3cb4b17
Merge branch 'main' into loki-e2e
UnicornChance Oct 21, 2024
75578c7
fix: overlapping testing
UnicornChance Oct 22, 2024
a17635f
wip: jest testing
UnicornChance Oct 24, 2024
ead0e0a
fix: linting
UnicornChance Oct 24, 2024
25d8f60
fix: working jest tests
UnicornChance Oct 24, 2024
68d8bca
add prometheus tests to chances branch
rjferguson21 Oct 24, 2024
39c5bdb
fix: working e2e tasks
UnicornChance Oct 24, 2024
df0b0c0
fix: merge conflicts
UnicornChance Oct 24, 2024
1954b28
Merge branch 'main' into loki-e2e
UnicornChance Oct 24, 2024
18a888e
Vector e2e test (#960)
noahpb Oct 24, 2024
db602d2
fix: lint and rename to spec.ts
UnicornChance Oct 24, 2024
576d129
fix: vector test directory name
UnicornChance Oct 24, 2024
ae64b9a
add node log generate for vector e2e test
noahpb Oct 25, 2024
12a4355
add echo to generate some pod logs
noahpb Oct 25, 2024
65c74fa
add a 30 second sleep
noahpb Oct 25, 2024
4c53279
increase sleep to 60s
noahpb Oct 25, 2024
a54674f
add retry and sleep task
noahpb Oct 25, 2024
7da65bc
rn vector e2e test, query from loki
noahpb Oct 28, 2024
889fff2
rm e2e test from src/vector/tasks.yaml
noahpb Oct 28, 2024
2553ead
skip if no tests defined
noahpb Oct 28, 2024
16d6e2b
lint
noahpb Oct 28, 2024
8e1432a
Merge branch 'main' into loki-e2e
noahpb Oct 28, 2024
57109f8
Merge branch 'main' into loki-e2e
rjferguson21 Oct 28, 2024
6d082d0
Merge branch 'main' into loki-e2e
noahpb Oct 29, 2024
e1b4b00
Merge branch 'main' into loki-e2e
noahpb Oct 31, 2024
6e03d38
Merge branch 'main' into loki-e2e
noahpb Nov 4, 2024
ecc8e74
chore: update renovate support deps
UnicornChance Nov 4, 2024
b194124
Merge branch 'main' into loki-e2e
UnicornChance Nov 4, 2024
f9a9bea
Update tasks/test.yaml
noahpb Nov 5, 2024
75d8e36
fix: move e2e tests to test dir, pr comments
UnicornChance Nov 5, 2024
2478ede
Merge branch 'main' into loki-e2e
UnicornChance Nov 5, 2024
d944b48
fix: tsconfig issues
UnicornChance Nov 5, 2024
bd7d80f
fix: merge conflicts
UnicornChance Nov 5, 2024
c608a5f
fix: conflicts again?
UnicornChance Nov 5, 2024
c2677f8
chore(deps): update support-deps (#928)
renovate[bot] Nov 5, 2024
22f039f
Merge remote-tracking branch 'origin/main' into loki-e2e
UnicornChance Nov 5, 2024
c6a7f2a
update test to warn if targets are unknown
rjferguson21 Nov 5, 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
2 changes: 1 addition & 1 deletion .codespellrc
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Lint Codespell configurations
[codespell]
skip = .codespellrc,.git,node_modules,build,dist,*.zst,CHANGELOG.md,.playwright,.terraform
ignore-words-list = NotIn,AKS,LICENS,aks
ignore-words-list = NotIn,AKS,LICENS,aks,afterAll
enable-colors =
check-hidden =
2 changes: 1 addition & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"node_modules",
"dist",
"jest.*.js",
"e2e/"
"test/playwright/"
],
"root": true,
"rules": {
Expand Down
2 changes: 1 addition & 1 deletion .github/actions/save-logs/action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ runs:
- name: Move Playwright Artifacts
run: |
sudo mkdir -p /tmp/playwright
sudo mv e2e/playwright/.playwright/* /tmp/playwright || true
sudo mv test/playwright/.playwright/* /tmp/playwright || true
shell: bash

- uses: actions/upload-artifact@b4b15b8c7c6ac21ea08fcf65892d2ee8f75cf882 # v4.4.3
Expand Down
2 changes: 1 addition & 1 deletion .yamllint
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ ignore:
- 'k3d/local/manifests/metallb/metallb-native.yaml'
- '**/.terraform/**'
- '**/chart/templates/**'
- 'node_modules/**'
- '**/node_modules/**'
- 'dist/**'
- 'src/pepr/uds-operator-config/templates/**'
- '.codespellrc'
Expand Down
1 change: 1 addition & 0 deletions packages/logging/tasks.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@ tasks:
actions:
- task: loki:validate
- task: vector:validate
- task: loki:e2e-test
1 change: 1 addition & 0 deletions packages/monitoring/tasks.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@ tasks:
- task: prometheus:validate
- task: grafana:validate
- task: grafana:e2e-test
- task: prometheus:e2e-test
2 changes: 1 addition & 1 deletion renovate.json
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@
"commitMessageTopic": "grafana"
},
{
"matchFileNames": ["e2e/playwright/**", ".github/**", "bundles/**", "tasks/*.yaml", ".vscode/settings.json", "src/test/**"],
"matchFileNames": ["test/**", ".github/**", "bundles/**", "tasks/*.yaml", ".vscode/settings.json", "src/test/**"],
"groupName": "support-deps",
"commitMessageTopic": "support dependencies"
},
Expand Down
4 changes: 4 additions & 0 deletions src/authservice/tasks.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,7 @@ tasks:
name: "app.kubernetes.io/name=authservice"
namespace: authservice
condition: Ready

- name: e2e-test
actions:
- description: "Run Authservice E2E tests"
2 changes: 1 addition & 1 deletion src/grafana/tasks.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,4 @@ tasks:
npm ci && \
npx playwright test grafana.test.ts \
"
dir: e2e/playwright
dir: test/playwright
4 changes: 4 additions & 0 deletions src/istio/tasks.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,7 @@ tasks:
kind: Gateway
name: tenant-gateway
namespace: istio-tenant-gateway

- name: e2e-test
actions:
- description: "Run Istio E2E tests"
4 changes: 4 additions & 0 deletions src/keycloak/tasks.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,7 @@ tasks:
- name: regenerate-test-pki
actions:
- task: config:regenerate-test-pki

- name: e2e-test
actions:
- description: "Run Keycloak E2E tests"
4 changes: 4 additions & 0 deletions src/kiali/tasks.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,7 @@ tasks:
cmd: "echo Replace Me"
# wait:
# cluster:

- name: e2e-test
actions:
- description: "Run Kiali E2E tests"
7 changes: 7 additions & 0 deletions src/loki/tasks.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,10 @@ tasks:
name: app.kubernetes.io/component=gateway
namespace: loki
condition: Ready

- name: e2e-test
actions:
- description: "Run Loki E2E tests"
cmd: |
npm ci && npx jest --testPathPattern loki*
dir: test/jest
4 changes: 4 additions & 0 deletions src/metrics-server/tasks.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,7 @@ tasks:
kind: APIService
name: v1beta1.metrics.k8s.io
condition: available

- name: e2e-test
actions:
- description: "Run Metrics-Server E2E tests"
4 changes: 4 additions & 0 deletions src/neuvector/tasks.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,7 @@ tasks:
protocol: https
address: neuvector.admin.uds.dev
code: 200

- name: e2e-test
actions:
- description: "Run Neuvector E2E tests"
2 changes: 1 addition & 1 deletion src/pepr/istio/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ When(a.Pod)
log.info(`Terminated sidecar for ${key}`);
} catch (err) {
log.error({ err }, `Failed to terminate the sidecar for ${key}`);

} finally {
// Remove the pod from the seen list
inProgress.delete(key);
}
Expand Down
4 changes: 4 additions & 0 deletions src/pepr/tasks.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -50,3 +50,7 @@ tasks:
# Remove the json and go files
rm -f "$CRD-crd.json"
done

- name: e2e-test
actions:
- description: "Run Pepr E2E tests"
7 changes: 7 additions & 0 deletions src/prometheus-stack/tasks.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,10 @@ tasks:
# cmd: "npx kubernetes-fluent-client crd https://raw.githubusercontent.com/prometheus-operator/prometheus-operator/v0.77.1/example/prometheus-operator-crd/monitoring.coreos.com_podmonitors.yaml src/pepr/operator/crd/generated/prometheus"
# - description: Pepr Format
# cmd: "npx pepr format"

- name: e2e-test
actions:
- description: "Run Prometheus-Stack E2E tests"
cmd: |
npm ci && npx jest --testPathPattern prometheus*
dir: test/jest
4 changes: 4 additions & 0 deletions src/tempo/tasks.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,7 @@ tasks:
cmd: "echo Replace Me"
# wait:
# cluster:

- name: e2e-test
actions:
- description: "Run Tempo E2E tests"
4 changes: 4 additions & 0 deletions src/test/tasks.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -148,3 +148,7 @@ tasks:

- description: Remove the test resources
cmd: "uds zarf package remove build/zarf-package-uds-core-test-apps-*.zst --confirm --no-progress"

- name: e2e-test
actions:
- description: "Run Test Apps E2E tests"
3 changes: 3 additions & 0 deletions src/vector/tasks.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,6 @@ tasks:
name: app.kubernetes.io/name=vector
namespace: vector
condition: Ready
- name: e2e-test
actions:
- description: "Run Vector E2E tests"
4 changes: 4 additions & 0 deletions src/vector/values/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@
role: "Agent"

customConfig:
api:
enabled: false
address: 0.0.0.0:8686
playground: false
data_dir: /var/lib/vector
# Ensure e2e delivery of events
acknowledgements:
Expand Down
4 changes: 4 additions & 0 deletions src/velero/tasks.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -83,3 +83,7 @@ tasks:
fi
fi
echo "Status is Complete! Great success!"

- name: e2e-test
actions:
- description: "Run Velero E2E tests"
6 changes: 5 additions & 1 deletion tasks/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -62,14 +62,18 @@ tasks:
# Self-reference this task file to avoid https://github.com/defenseunicorns/maru-runner/issues/144
cmd: uds run -f tasks/test.yaml common-setup:create-doug-user --set KEYCLOAK_GROUP="/UDS Core/Admin" # Adds the test doug user
- description: "Run Playwright E2E tests for all packages"
dir: e2e/playwright
dir: test/playwright
cmd: |
# renovate: datasource=docker depName=mcr.microsoft.com/playwright versioning=docker
docker run --rm --ipc=host --net=host -e FULL_CORE="true" --mount type=bind,source="$(pwd)",target=/app mcr.microsoft.com/playwright:v1.48.2-noble sh -c " \
cd app && \
npm ci && \
npx playwright test \
"
- description: "Run E2E Tests"
cmd: |
npm ci
npx jest test/jest/

- name: uds-core
description: "Build and test UDS Core"
Expand Down
122 changes: 122 additions & 0 deletions test/jest/forward.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
/**
* Copyright 2024 Defense Unicorns
* SPDX-License-Identifier: AGPL-3.0-or-later OR LicenseRef-Defense-Unicorns-Commercial
*/

import * as k8s from "@kubernetes/client-node";
import { K8s, kind } from "kubernetes-fluent-client";
import * as net from "net";

const kc = new k8s.KubeConfig();
const forward = new k8s.PortForward(kc);
kc.loadFromDefault();

interface ForwardResult {
server: net.Server;
url: string;
}

// Utility function to get an available random port within a range
async function getAvailablePort(min = 1024, max = 65535): Promise<number> {
let port: number;
let isAvailable = false;

while (!isAvailable) {
port = Math.floor(Math.random() * (max - min + 1)) + min;
isAvailable = await new Promise<boolean>(resolve => {
const server = net.createServer();

server.once("error", () => resolve(false)); // Port is in use
server.once("listening", () => {
server.close(() => resolve(true)); // Port is available
});

server.listen(port, "127.0.0.1");
});
}

return port!;
}

export async function getPodFromService(svc: string, namespace: string): Promise<string> {
try {
const service = await K8s(kind.Service).InNamespace(namespace).Get(svc);
const labelSelector = service.spec?.selector;

if (!labelSelector) {
throw new Error(`No label selectors found for service: ${svc}`);
}

let podsQuery = K8s(kind.Pod).InNamespace(namespace);
for (const key in labelSelector) {
podsQuery = podsQuery.WithLabel(key, labelSelector[key]);
}

const pods = await podsQuery.Get();
if (pods.items.length === 0) {
throw new Error(`No pods found for service: ${svc}`);
}

return pods.items[0].metadata!.name!;
} catch (err) {
// Type guard to check if `err` is an instance of `Error`
if (err instanceof Error) {
throw new Error(`Failed to get pod from service ${svc}: ${err.message}`);
} else {
throw new Error(`Unknown error occurred while fetching pod from service ${svc}`);
}
}
}

export async function getForward(
service: string,
namespace: string,
port: number,
): Promise<ForwardResult> {
try {
const podName = await getPodFromService(service, namespace);
const randomPort = await getAvailablePort(3000, 65535);

return await new Promise<ForwardResult>((resolve, reject) => {
const server = net.createServer(socket => {
// Explicitly ignore the promise with `void` to avoid eslint no-floating-promises error
void forward.portForward(namespace, podName, [port], socket, null, socket);
});

server.listen(randomPort, "127.0.0.1", () => {
resolve({ server, url: `http://localhost:${randomPort}` });
});

server.on("error", err => {
if (err instanceof Error) {
reject(new Error(`Error binding to port ${randomPort}: ${err.message}`));
} else {
reject(new Error(`Unknown error occurred while binding to port ${randomPort}`));
}
});
});
} catch (err) {
if (err instanceof Error) {
throw new Error(`Failed to setup port forwarding for service ${service}: ${err.message}`);
} else {
throw new Error(
`Unknown error occurred while setting up port forwarding for service ${service}`,
);
}
}
}

export function closeForward(server: net.Server): Promise<void> {
return new Promise((resolve, reject) => {
server.close(err => {
// Type guard to check if `err` is an instance of `Error`
if (err instanceof Error) {
reject(new Error(`Failed to close server: ${err.message}`));
} else if (err) {
reject(new Error("Unknown error occurred while closing the server"));
} else {
resolve();
}
});
});
}
Loading