Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions ddev/changelog.d/21993.fixed
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Ensure correct commit attribution when sending size metrics by requiring an explicit commit in the ddev size status command.
7 changes: 5 additions & 2 deletions ddev/src/ddev/cli/size/status.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,10 +103,10 @@ 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, 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))

Expand Down Expand Up @@ -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))

Expand Down
24 changes: 14 additions & 10 deletions ddev/src/ddev/cli/size/utils/common_funcs.py
Original file line number Diff line number Diff line change
Expand Up @@ -837,6 +837,7 @@ def draw_treemap_rects_with_labels(

def send_metrics_to_dd(
app: Application,
commit: str,
modules: list[FileDataEntryPlatformVersion],
org: str | None,
key: str | None,
Expand All @@ -852,8 +853,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 = []
Expand Down Expand Up @@ -965,24 +965,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
Expand Down
Loading