k6lab-agent 1.0.0 โ 1.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +97 -0
- package/package.json +1 -1
- package/src/commands/start.js +18 -1
package/README.md
ADDED
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
# ๐ k6lab-agent
|
|
2
|
+
|
|
3
|
+
> The high-performance, local load-testing execution runner for the **K6 Lab** platform.
|
|
4
|
+
|
|
5
|
+
`k6lab-agent` is a lightweight, globally linked command-line utility that bridges your local environment with the K6 Lab dashboard. By utilizing this local agent, K6 Lab runs in **Agent-Only Mode**, running heavy stress tests directly on your laptop with zero-overhead server processing, while synchronizing live telemetry and logs in real-time.
|
|
6
|
+
|
|
7
|
+
---
|
|
8
|
+
|
|
9
|
+
## ๐ฆ Features
|
|
10
|
+
|
|
11
|
+
* **Local k6 Execution**: Spawns native, lightning-fast `k6` binaries directly on your machine.
|
|
12
|
+
* **Real-Time Log Streaming**: Streams terminal output (`stdout`/`stderr`) live to your K6 Lab dashboard cockpit.
|
|
13
|
+
* **Atomically Queued Runs**: Automatically polls your MongoDB backend queues and executes runs chronologically.
|
|
14
|
+
* **Heartbeat Synchronizer**: Periodically signals connection status (online/offline) to prevent diagnostic dropouts.
|
|
15
|
+
* **Zero Secrets Exposure**: Kept completely safeโno database credentials or private environment variables are stored in the agent.
|
|
16
|
+
|
|
17
|
+
---
|
|
18
|
+
|
|
19
|
+
## ๐ ๏ธ Installation
|
|
20
|
+
|
|
21
|
+
Ensure you have [Node.js](https://nodejs.org/) (v16+) and the [k6 load testing tool](https://k6.io/docs/get-started/installation/) installed locally.
|
|
22
|
+
|
|
23
|
+
### 1. Install k6 (Native Binary)
|
|
24
|
+
* **macOS** (via Homebrew):
|
|
25
|
+
```bash
|
|
26
|
+
brew install k6
|
|
27
|
+
```
|
|
28
|
+
* **Windows** (via Chocolatey):
|
|
29
|
+
```powershell
|
|
30
|
+
choco install k6
|
|
31
|
+
```
|
|
32
|
+
* **Linux** (via Debian/Ubuntu):
|
|
33
|
+
```bash
|
|
34
|
+
sudo gpg --no-default-keyring --keyring /usr/share/keyrings/k6-archive-keyring.gpg --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys C5D53F5675C117B8
|
|
35
|
+
echo "deb [signed-by=/usr/share/keyrings/k6-archive-keyring.gpg] https://dl.k6.io/deb stable main" | sudo tee /etc/apt/sources.list.d/k6.list
|
|
36
|
+
sudo apt-get update
|
|
37
|
+
sudo apt-get install k6
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
### 2. Install the Agent CLI Globally
|
|
41
|
+
Install the package directly from the public npm registry:
|
|
42
|
+
```bash
|
|
43
|
+
npm install -g k6lab-agent
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
---
|
|
47
|
+
|
|
48
|
+
## ๐ Getting Started
|
|
49
|
+
|
|
50
|
+
To link and run your agent, follow these quick steps:
|
|
51
|
+
|
|
52
|
+
### Step 1: Login with your API Token
|
|
53
|
+
Retrieve your unique agent login token from your K6 Lab dashboard panel, and authenticate:
|
|
54
|
+
```bash
|
|
55
|
+
k6lab-agent login k6lab_agent_your_unique_dashboard_token
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
### Step 2: Start the Agent runner
|
|
59
|
+
Start the runner loop. The agent will connect, start emitting 5-second heartbeats to display as "Online" on your dashboard, and listen for new stress tests:
|
|
60
|
+
```bash
|
|
61
|
+
k6lab-agent start
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
*Leave this terminal window open. As soon as you click **"Dispatch Load Test Run"** on the K6 Lab configurator, the agent will instantly catch the job, execute k6, and feed live console logs back to your screen!*
|
|
65
|
+
|
|
66
|
+
---
|
|
67
|
+
|
|
68
|
+
## ๐ป CLI Command Reference
|
|
69
|
+
|
|
70
|
+
| Command | Description |
|
|
71
|
+
| :--- | :--- |
|
|
72
|
+
| `k6lab-agent login <token>` | Saves your API credentials and registers your Mac/PC with the backend server. |
|
|
73
|
+
| `k6lab-agent start` | Connects the active agent, initiates heartbeats, and polls for pending dashboard runs. |
|
|
74
|
+
| `k6lab-agent status` | Displays the current connection and login configurations. |
|
|
75
|
+
| `k6lab-agent logout` | Revokes the current agent token and clears credentials from your machine. |
|
|
76
|
+
|
|
77
|
+
---
|
|
78
|
+
|
|
79
|
+
## ๐ Configuration Storage
|
|
80
|
+
|
|
81
|
+
The agent securely stores local configuration parameters inside a hidden directory in your user home folder:
|
|
82
|
+
* **Storage Location**: `~/.k6lab/config.json`
|
|
83
|
+
* **Contents**:
|
|
84
|
+
```json
|
|
85
|
+
{
|
|
86
|
+
"token": "k6lab_agent_your_token_hash",
|
|
87
|
+
"apiUrl": "http://localhost:8000/api"
|
|
88
|
+
}
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
---
|
|
92
|
+
|
|
93
|
+
## ๐ Security & Privacy
|
|
94
|
+
|
|
95
|
+
* **Strict Encryption**: Tokens are cryptographically matched on the Mongoose backend using one-way SHA-256 hashes.
|
|
96
|
+
* **Target URLs**: All network traffic generated during stress runs goes directly from your local machine to the target URL.
|
|
97
|
+
* **Self-Contained**: The agent only reads the dynamically generated temporary k6 test scripts in `~/.k6lab/jobs/` and has no access to other filesystem paths.
|
package/package.json
CHANGED
package/src/commands/start.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import fs from "fs-extra";
|
|
2
|
+
import path from "path";
|
|
2
3
|
import { checkK6Installed } from "../services/k6Checker.js";
|
|
3
4
|
import {
|
|
4
5
|
sendHeartbeat,
|
|
@@ -86,8 +87,11 @@ export async function start() {
|
|
|
86
87
|
}
|
|
87
88
|
}, 2000);
|
|
88
89
|
|
|
90
|
+
let scriptPath = null;
|
|
89
91
|
try {
|
|
90
|
-
const
|
|
92
|
+
const scriptDetails = await createK6Script(job);
|
|
93
|
+
scriptPath = scriptDetails.scriptPath;
|
|
94
|
+
const { summaryPath, logsPath } = scriptDetails;
|
|
91
95
|
|
|
92
96
|
const runResult = await runK6(scriptPath, job, logsPath);
|
|
93
97
|
|
|
@@ -133,6 +137,12 @@ export async function start() {
|
|
|
133
137
|
console.log("");
|
|
134
138
|
console.log("Waiting for jobs...");
|
|
135
139
|
console.log("");
|
|
140
|
+
|
|
141
|
+
if (scriptPath) {
|
|
142
|
+
try {
|
|
143
|
+
await fs.remove(path.dirname(scriptPath));
|
|
144
|
+
} catch (cleanErr) {}
|
|
145
|
+
}
|
|
136
146
|
continue;
|
|
137
147
|
}
|
|
138
148
|
} catch (statusErr) {
|
|
@@ -154,6 +164,13 @@ export async function start() {
|
|
|
154
164
|
|
|
155
165
|
console.log("Waiting for jobs...");
|
|
156
166
|
console.log("");
|
|
167
|
+
} finally {
|
|
168
|
+
// ๐งน Clean up local job folder on success or error
|
|
169
|
+
if (scriptPath) {
|
|
170
|
+
try {
|
|
171
|
+
await fs.remove(path.dirname(scriptPath));
|
|
172
|
+
} catch (cleanErr) {}
|
|
173
|
+
}
|
|
157
174
|
}
|
|
158
175
|
} catch (err) {
|
|
159
176
|
console.error("Agent connection error:", err.message);
|