-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: add prometheus, loki, and vector e2e testing (#939)
## Description Add E2E prometheus, loki, and vector testing. ## Related Issues Fixes #824 #823 #822 ## Type of change - [ ] Bug fix (non-breaking change which fixes an issue) - [ ] New feature (non-breaking change which adds functionality) - [x] Other (security config, docs update, etc) ## Checklist before merging - [x] Test, docs, adr added or updated as needed - [x] [Contributor Guide](https://github.com/defenseunicorns/uds-template-capability/blob/main/CONTRIBUTING.md) followed --------- Co-authored-by: Rob Ferguson <rjferguson21@gmail.com> Co-authored-by: Noah <40781376+noahpb@users.noreply.github.com> Co-authored-by: Noah Birrer <noah@defenseunicorns.com> Co-authored-by: Micah Nagel <micah.nagel@defenseunicorns.com> Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
- Loading branch information
1 parent
a9cf1f2
commit f271ce2
Showing
38 changed files
with
5,353 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 = |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,7 +21,7 @@ | |
"node_modules", | ||
"dist", | ||
"jest.*.js", | ||
"e2e/" | ||
"test/playwright/" | ||
], | ||
"root": true, | ||
"rules": { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,3 +10,4 @@ tasks: | |
actions: | ||
- task: loki:validate | ||
- task: vector:validate | ||
- task: loki:e2e-test |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -45,4 +45,4 @@ tasks: | |
npm ci && \ | ||
npx playwright test grafana.test.ts \ | ||
" | ||
dir: e2e/playwright | ||
dir: test/playwright |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,3 +8,7 @@ tasks: | |
cmd: "echo Replace Me" | ||
# wait: | ||
# cluster: | ||
|
||
- name: e2e-test | ||
actions: | ||
- description: "Run Kiali E2E tests" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,3 +8,7 @@ tasks: | |
cmd: "echo Replace Me" | ||
# wait: | ||
# cluster: | ||
|
||
- name: e2e-test | ||
actions: | ||
- description: "Run Tempo E2E tests" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
}); | ||
}); | ||
} |
Oops, something went wrong.