From fd77fe18fb4a02f7a5641277f0aeff6da8e5b580 Mon Sep 17 00:00:00 2001 From: Lucia Sanchez Bella Date: Thu, 27 Nov 2025 11:32:01 +0100 Subject: [PATCH 1/6] Specify commit for the timestamp --- ddev/src/ddev/cli/size/status.py | 2 +- ddev/src/ddev/cli/size/utils/common_funcs.py | 29 +++++++++++++------- 2 files changed, 20 insertions(+), 11 deletions(-) diff --git a/ddev/src/ddev/cli/size/status.py b/ddev/src/ddev/cli/size/status.py index 2e88b08ae3436..ba29e1984656e 100644 --- a/ddev/src/ddev/cli/size/status.py +++ b/ddev/src/ddev/cli/size/status.py @@ -106,7 +106,7 @@ def status( if to_dd_org or to_dd_key: from ddev.cli.size.utils.common_funcs import send_metrics_to_dd - send_metrics_to_dd(app, modules_plat_ver, to_dd_org, to_dd_key, compressed) + send_metrics_to_dd(app, commit, modules_plat_ver, to_dd_org, to_dd_key, compressed) except Exception as e: app.abort(str(e)) diff --git a/ddev/src/ddev/cli/size/utils/common_funcs.py b/ddev/src/ddev/cli/size/utils/common_funcs.py index 9e33a4562c1c3..ceaa68fd71e45 100644 --- a/ddev/src/ddev/cli/size/utils/common_funcs.py +++ b/ddev/src/ddev/cli/size/utils/common_funcs.py @@ -837,11 +837,17 @@ def draw_treemap_rects_with_labels( def send_metrics_to_dd( app: Application, + commit: str | None, modules: list[FileDataEntryPlatformVersion], org: str | None, key: str | None, compressed: bool, ) -> None: + + if not commit: + app.display_error("In order to send metrics to Datadog, you need to provide a commit hash") + return + metric_name = "datadog.agent_integrations" size_type = "compressed" if compressed else "uncompressed" @@ -852,8 +858,7 @@ def send_metrics_to_dd( if "site" not in config_file_info: raise RuntimeError("No site found in config file") - message, tickets, prs = get_last_commit_data() - timestamp = get_last_commit_timestamp() + timestamp, message, tickets, prs = get_commit_data(commit) metrics = [] n_integrations_metrics = [] @@ -965,24 +970,28 @@ def send_metrics_to_dd( api.Metric.send(metrics=n_dependencies_metrics) -def get_last_commit_timestamp() -> int: - result = subprocess.run(["git", "log", "-1", "--format=%ct"], capture_output=True, text=True, check=True) - return int(result.stdout.strip()) - +def get_commit_data(commit: str) -> tuple[int, str, list[str], list[str]]: + ''' + Gets the timestamp, message, tickets and PRs of a given commit. If no commit is provided, it uses the last commit. + ''' + result = subprocess.run( + ["git", "show", "-s", "--format=%ct,%s", commit], + capture_output=True, + text=True, + check=True, + ) -def get_last_commit_data() -> tuple[str, list[str], list[str]]: - result = subprocess.run(["git", "log", "-1", "--format=%s"], capture_output=True, text=True, check=True) + timestamp, message = result.stdout.strip().split(',', 1) ticket_pattern = r'\b(?:DBMON|SAASINT|AGENT|AI)-\d+\b' pr_pattern = r'#(\d+)' - message = result.stdout.strip() tickets = re.findall(ticket_pattern, message) prs = re.findall(pr_pattern, message) if not tickets: tickets = [""] if not prs: prs = [""] - return message, tickets, prs + return int(timestamp), message, tickets, prs @cache From dd7e7452a88317106d6ab1f38991a7f631d64b19 Mon Sep 17 00:00:00 2001 From: Lucia Sanchez Bella Date: Thu, 27 Nov 2025 12:05:30 +0100 Subject: [PATCH 2/6] Add changelog --- ddev/changelog.d/21993.fixed | 1 + 1 file changed, 1 insertion(+) create mode 100644 ddev/changelog.d/21993.fixed diff --git a/ddev/changelog.d/21993.fixed b/ddev/changelog.d/21993.fixed new file mode 100644 index 0000000000000..0d9c818e48767 --- /dev/null +++ b/ddev/changelog.d/21993.fixed @@ -0,0 +1 @@ +Ensured correct commit attribution when sending size metrics by requiring an explicit commit in the ddev size status command. \ No newline at end of file From ce7ec55bc4501a800a256369d6f43512b0744bb6 Mon Sep 17 00:00:00 2001 From: Lucia Sanchez Bella Date: Thu, 27 Nov 2025 12:29:03 +0100 Subject: [PATCH 3/6] Fix Lint --- ddev/src/ddev/cli/size/utils/common_funcs.py | 1 - 1 file changed, 1 deletion(-) diff --git a/ddev/src/ddev/cli/size/utils/common_funcs.py b/ddev/src/ddev/cli/size/utils/common_funcs.py index ceaa68fd71e45..1b0d95ed3f3b3 100644 --- a/ddev/src/ddev/cli/size/utils/common_funcs.py +++ b/ddev/src/ddev/cli/size/utils/common_funcs.py @@ -843,7 +843,6 @@ def send_metrics_to_dd( key: str | None, compressed: bool, ) -> None: - if not commit: app.display_error("In order to send metrics to Datadog, you need to provide a commit hash") return From 8e5815dddb1471060d73d2d4eef3fb5547346eff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luc=C3=ADa?= Date: Fri, 28 Nov 2025 09:51:40 +0100 Subject: [PATCH 4/6] Update ddev/changelog.d/21993.fixed Co-authored-by: Juanpe Araque --- ddev/changelog.d/21993.fixed | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ddev/changelog.d/21993.fixed b/ddev/changelog.d/21993.fixed index 0d9c818e48767..072abe62da962 100644 --- a/ddev/changelog.d/21993.fixed +++ b/ddev/changelog.d/21993.fixed @@ -1 +1 @@ -Ensured correct commit attribution when sending size metrics by requiring an explicit commit in the ddev size status command. \ No newline at end of file +Ensure correct commit attribution when sending size metrics by requiring an explicit commit in the ddev size status command. \ No newline at end of file From 723693551dd96b2716c26052a0a0001b01977ad6 Mon Sep 17 00:00:00 2001 From: Lucia Sanchez Bella Date: Tue, 2 Dec 2025 12:54:48 +0100 Subject: [PATCH 5/6] move commit validation to the start of the command --- ddev/src/ddev/cli/size/status.py | 3 +++ ddev/src/ddev/cli/size/utils/common_funcs.py | 6 +----- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/ddev/src/ddev/cli/size/status.py b/ddev/src/ddev/cli/size/status.py index ba29e1984656e..aac5dbf55a9b1 100644 --- a/ddev/src/ddev/cli/size/status.py +++ b/ddev/src/ddev/cli/size/status.py @@ -144,6 +144,9 @@ def validate_parameters( if to_dd_org and to_dd_key: errors.append("Specify either --to-dd-org or --to-dd-key, not both") + if (to_dd_org or to_dd_key) and not commit: + errors.append("In order to send metrics to Datadog, you need to provide a commit hash") + if errors: app.abort("\n".join(errors)) diff --git a/ddev/src/ddev/cli/size/utils/common_funcs.py b/ddev/src/ddev/cli/size/utils/common_funcs.py index 1b0d95ed3f3b3..5d64d752cf7f5 100644 --- a/ddev/src/ddev/cli/size/utils/common_funcs.py +++ b/ddev/src/ddev/cli/size/utils/common_funcs.py @@ -837,16 +837,12 @@ def draw_treemap_rects_with_labels( def send_metrics_to_dd( app: Application, - commit: str | None, + commit: str, modules: list[FileDataEntryPlatformVersion], org: str | None, key: str | None, compressed: bool, ) -> None: - if not commit: - app.display_error("In order to send metrics to Datadog, you need to provide a commit hash") - return - metric_name = "datadog.agent_integrations" size_type = "compressed" if compressed else "uncompressed" From c625b523371ea16493d6b8d08c1e93f497646be0 Mon Sep 17 00:00:00 2001 From: Lucia Sanchez Bella Date: Tue, 2 Dec 2025 14:39:01 +0100 Subject: [PATCH 6/6] Fix lint --- ddev/src/ddev/cli/size/status.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ddev/src/ddev/cli/size/status.py b/ddev/src/ddev/cli/size/status.py index aac5dbf55a9b1..b487b19f25b69 100644 --- a/ddev/src/ddev/cli/size/status.py +++ b/ddev/src/ddev/cli/size/status.py @@ -103,7 +103,7 @@ def status( from ddev.cli.size.utils.common_funcs import export_format export_format(app, format, modules_plat_ver, "status", platform, version, compressed) - if to_dd_org or to_dd_key: + if (to_dd_org or to_dd_key) and commit: from ddev.cli.size.utils.common_funcs import send_metrics_to_dd send_metrics_to_dd(app, commit, modules_plat_ver, to_dd_org, to_dd_key, compressed)