Skip to content

Commit e932cc7

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

File tree

4 files changed

+73
-3
lines changed

4 files changed

+73
-3
lines changed

.github/workflows/ci.yml

Lines changed: 20 additions & 0 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:
@@ -433,6 +446,13 @@ jobs:
433446
./packages/e2e-tests/reports
434447
retention-days: 5
435448

449+
- name: Push performance metrics to Datadog
450+
working-directory: ./packages/e2e-tests/tools
451+
env:
452+
DATADOG_API_KEY: ${{ secrets.DATADOG_API_KEY }}
453+
DD_SITE: us5.datadoghq.com
454+
run: python push_to_datadog.py
455+
436456
- run: |
437457
if [[ ${{ needs.smokeTests.result }} == "success" ]]; then
438458
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: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
import os
2+
import json
3+
import time
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+
METRICS_DIR = "../metrics"
14+
15+
def send_to_datadog(series_batch):
16+
url = f"https://api.{DD_SITE}/api/v1/series"
17+
res = requests.post(url, headers=headers, data=json.dumps({"series": series_batch}))
18+
print(f"→ Sent {len(series_batch)} points. Status: {res.status_code}")
19+
if res.status_code >= 300:
20+
print(res.text)
21+
22+
series = []
23+
24+
for filename in os.listdir(METRICS_DIR):
25+
if filename.endswith(".json"):
26+
path = os.path.join(METRICS_DIR, filename)
27+
with open(path) as f:
28+
content = json.load(f)
29+
scenario = content["scenarioName"]
30+
for point in content["data"]:
31+
ts = int(point["timestamp"] / 1000)
32+
series.append({
33+
"metric": "e2e.cpu_seconds_total",
34+
"points": [[ts, point["cpu"]]],
35+
"tags": [f"scenario:{scenario}", f"source_file:{filename}"],
36+
"type": "gauge"
37+
})
38+
series.append({
39+
"metric": "e2e.memory_rss_bytes",
40+
"points": [[ts, point["memory"]]],
41+
"tags": [f"scenario:{scenario}", f"source_file:{filename}"],
42+
"type": "gauge"
43+
})
44+
45+
print(f"Uploading {len(series)} points to Datadog in chunks...")
46+
47+
CHUNK_SIZE = 400
48+
for i in range(0, len(series), CHUNK_SIZE):
49+
chunk = series[i:i + CHUNK_SIZE]
50+
send_to_datadog(chunk)

0 commit comments

Comments
 (0)