Skip to content

Commit b255490

Browse files
committed
test: datadog performance tracking poc
1 parent e391c42 commit b255490

File tree

4 files changed

+81
-6
lines changed

4 files changed

+81
-6
lines changed

.github/workflows/ci.yml

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -386,6 +386,19 @@ jobs:
386386
needs: smokeTests
387387
if: always()
388388
steps:
389+
- name: Checkout repository
390+
uses: actions/checkout@v4
391+
392+
- name: Set up Python
393+
uses: actions/setup-python@v5
394+
with:
395+
python-version: '3.11'
396+
397+
- name: Install dependencies
398+
run: |
399+
python -m pip install --upgrade pip
400+
pip install requests
401+
389402
- name: Download all smoke tests artifacts
390403
uses: actions/download-artifact@v4
391404
with:
@@ -428,11 +441,19 @@ jobs:
428441
with:
429442
name: test-artifacts
430443
path: |
431-
./packages/e2e-tests/screenshots
432-
./packages/e2e-tests/logs
433-
./packages/e2e-tests/reports
444+
./screenshots
445+
./logs
446+
./reports
447+
./metrics
434448
retention-days: 5
435449

450+
- name: Push performance metrics to Datadog
451+
working-directory: ./packages/e2e-tests/tools
452+
env:
453+
DATADOG_API_KEY: ${{ secrets.DATADOG_API_KEY }}
454+
DD_SITE: us5.datadoghq.com
455+
run: python push_to_datadog.py ../../../metrics
456+
436457
- run: |
437458
if [[ ${{ needs.smokeTests.result }} == "success" ]]; then
438459
exit 0

packages/e2e-tests/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
"allure:generate": "yarn allure generate -c ./reports/allure/results -o ./reports/allure/report",
1111
"allure:open": "allure open ./reports/allure/report/",
1212
"build": "yarn exec echo 'No build required'",
13-
"cleanup": "rm -rf logs node_modules reports screenshots",
13+
"cleanup": "rm -rf logs node_modules reports screenshots metrics",
1414
"lint": "run -T eslint -c .eslintrc.cjs .",
1515
"lint:fix": "run -T eslint -c .eslintrc.cjs . --fix",
1616
"pack-chrome-extension": "node ./src/utils/packExtension.ts",

packages/e2e-tests/src/support/PidMonitor.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import { Logger } from './logger';
99
const execAsync = promisify(exec);
1010

1111
interface UsageData {
12-
timestamp: string;
12+
timestamp: number;
1313
cpu: number;
1414
memory: number;
1515
}
@@ -81,7 +81,7 @@ class PidMonitor {
8181
try {
8282
const stats = await pidusage(this.pid);
8383
this._data.push({
84-
timestamp: new Date().toISOString(),
84+
timestamp: Date.now(),
8585
cpu: stats.cpu,
8686
memory: stats.memory
8787
});
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
import os
2+
import json
3+
import sys
4+
import requests
5+
6+
DD_API_KEY = os.getenv("DD_API_KEY")
7+
DD_SITE = os.getenv("DD_SITE", "us5.datadoghq.com")
8+
headers = {
9+
"Content-Type": "application/json",
10+
"DD-API-KEY": DD_API_KEY
11+
}
12+
13+
if len(sys.argv) < 2:
14+
print("Usage: python push_to_datadog.py <metrics_dir>")
15+
sys.exit(1)
16+
17+
METRICS_DIR = sys.argv[1]
18+
19+
def send_to_datadog(series_batch):
20+
url = f"https://api.{DD_SITE}/api/v1/series"
21+
res = requests.post(url, headers=headers, data=json.dumps({"series": series_batch}))
22+
print(f"→ Sent {len(series_batch)} points. Status: {res.status_code}")
23+
if res.status_code >= 300:
24+
print(res.text)
25+
26+
series = []
27+
28+
for filename in os.listdir(METRICS_DIR):
29+
if filename.endswith(".json"):
30+
path = os.path.join(METRICS_DIR, filename)
31+
with open(path) as f:
32+
content = json.load(f)
33+
scenario = content["scenarioName"]
34+
for point in content["data"]:
35+
ts = int(point["timestamp"] / 1000)
36+
series.append({
37+
"metric": "e2e.cpu_seconds_total",
38+
"points": [[ts, point["cpu"]]],
39+
"tags": [f"scenario:{scenario}", f"source_file:{filename}"],
40+
"type": "gauge"
41+
})
42+
series.append({
43+
"metric": "e2e.memory_rss_bytes",
44+
"points": [[ts, point["memory"]]],
45+
"tags": [f"scenario:{scenario}", f"source_file:{filename}"],
46+
"type": "gauge"
47+
})
48+
49+
print(f"Uploading {len(series)} points to Datadog in chunks...")
50+
51+
CHUNK_SIZE = 400
52+
for i in range(0, len(series), CHUNK_SIZE):
53+
chunk = series[i:i + CHUNK_SIZE]
54+
send_to_datadog(chunk)

0 commit comments

Comments
 (0)