Skip to content

Commit 6d5a319

Browse files
Upload historical data
1 parent 44be19d commit 6d5a319

File tree

3 files changed

+62
-9
lines changed

3 files changed

+62
-9
lines changed

ddev/src/ddev/cli/size/common.py

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -644,20 +644,25 @@ def draw_treemap_rects_with_labels(
644644

645645

646646
def send_metrics_to_dd(
647-
app: Application, modules: list[FileDataEntryPlatformVersion], org: str, compressed: bool
647+
app: Application, modules: list[FileDataEntryPlatformVersion], org: str, compressed: bool, timestamp: int
648648
) -> None:
649649
metric_name = (
650650
"datadog.agent_integrations.size_analyzer.compressed"
651651
if compressed
652652
else "datadog.agent_integrations.size_analyzer.uncompressed"
653653
)
654-
config_file_info = get_org(app, org)
655-
656-
if not is_everything_committed():
657-
raise RuntimeError("All files have to be committed in order to send the metrics to Datadog")
654+
config_file_info = {
655+
"api_key": "",
656+
"app_key": "",
657+
"site": "datadoghq.eu",
658+
}
659+
# get_org(app, org)
658660

659-
timestamp = get_last_commit_timestamp()
661+
# if not is_everything_committed():
662+
# raise RuntimeError("All files have to be committed in order to send the metrics to Datadog")
660663

664+
# timestamp = get_last_commit_timestamp()
665+
print(f"Sending metrics for commit timestamp: {date.fromtimestamp(timestamp)}")
661666
metrics = []
662667

663668
for item in modules:
@@ -682,8 +687,8 @@ def send_metrics_to_dd(
682687
app_key=config_file_info["app_key"],
683688
api_host=f"https://api.{config_file_info['site']}",
684689
)
685-
686-
api.Metric.send(metrics=metrics)
690+
response = api.Metric.send(metrics=metrics)
691+
print(f"Metrics sent successfully: {response}")
687692

688693

689694
def get_org(app: Application, org: Optional[str] = "default") -> dict[str, str]:
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
import subprocess
2+
3+
from ddev.cli.size.common import GitRepo
4+
import os
5+
6+
def upload_historical_metrics():
7+
url = "/Users/lucia.sanchezbella/dd/integrations-core"
8+
print(f"Processing repository: {url}")
9+
with GitRepo(url) as gitRepo:
10+
11+
commits = gitRepo._run("git log --reverse --pretty=format:%H --since=2025-04-05")
12+
print(f"Found {len(commits)} commits to process")
13+
14+
for i, commit in enumerate(commits, 1):
15+
date, _, _ = gitRepo.get_commit_metadata(commit)
16+
print(f"Processing commit {i}/{len(commits)}: {commit} ({date})")
17+
gitRepo.checkout_commit(commit)
18+
timestamp = get_last_commit_timestamp(gitRepo.repo_dir)
19+
print("Running uncompressed size metrics...")
20+
result = subprocess.run(
21+
["ddev", "size", "status", "--send-metrics-dd-org", "default", "--timestamp", str(timestamp)],
22+
cwd=gitRepo.repo_dir,
23+
text=True,
24+
capture_output=True,
25+
)
26+
print("[UNCOMP STDOUT]", result.stdout)
27+
print("[UNCOMP STDERR]", result.stderr)
28+
29+
print("Running compressed size metrics...")
30+
result = subprocess.run(
31+
["ddev", "size", "status", "--compressed", "--send-metrics-dd-org", "default", "--timestamp", str(timestamp)],
32+
cwd=gitRepo.repo_dir,
33+
text=True,
34+
capture_output=True,
35+
)
36+
print("[COMP STDOUT]", result.stdout)
37+
print("[COMP STDERR]", result.stderr)
38+
39+
print(f"Finished processing commit {i}\n")
40+
41+
def get_last_commit_timestamp(cwd: str) -> int:
42+
result = subprocess.run(["git", "log", "-1", "--format=%ct"], capture_output=True, text=True, check=True, cwd=cwd)
43+
return int(result.stdout.strip())
44+
45+
if __name__ == "__main__":
46+
upload_historical_metrics()

ddev/src/ddev/cli/size/status.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
help="Display a pop-up window with a treemap showing the current size distribution of modules.",
4747
)
4848
@click.option("--send-metrics-dd-org", type=str, help="Send metrics to Datadog using the specified organization name.")
49+
@click.option("--timestamp", type=int, help="Timestamp of the commit to send metrics for.")
4950
@click.pass_obj
5051
def status(
5152
app: Application,
@@ -58,6 +59,7 @@ def status(
5859
save_to_png_path: Optional[str],
5960
show_gui: bool,
6061
send_metrics_dd_org: str,
62+
timestamp: Optional[int],
6163
) -> None:
6264
"""
6365
Show the current size of all integrations and dependencies.
@@ -104,7 +106,7 @@ def status(
104106
elif json:
105107
print_json(app, modules_plat_ver)
106108
if send_metrics_dd_org:
107-
send_metrics_to_dd(app, modules_plat_ver, send_metrics_dd_org, compressed)
109+
send_metrics_to_dd(app, modules_plat_ver, send_metrics_dd_org, compressed, timestamp)
108110
except Exception as e:
109111
app.abort(str(e))
110112

0 commit comments

Comments
 (0)