Skip to content

Add Metrics Upload to diff Command #20741

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 11 commits into
base: master
Choose a base branch
from
Draft
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
4 changes: 2 additions & 2 deletions .github/workflows/measure-disk-usage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ jobs:
run: |
BEFORE=$(git rev-parse HEAD^)
AFTER=$(git rev-parse HEAD)
ddev size diff $BEFORE $AFTER > diff-uncompressed.txt
ddev size diff $BEFORE $AFTER --to-dd-key ${{secrets.DD_API_KEY}} > diff-uncompressed.txt
ddev size diff $BEFORE $AFTER --format png,csv,markdown
cat diff-uncompressed.txt
echo "# Size diff (uncompressed)" >> $GITHUB_STEP_SUMMARY
Expand All @@ -61,7 +61,7 @@ jobs:
run: |
BEFORE=$(git rev-parse HEAD^)
AFTER=$(git rev-parse HEAD)
ddev size diff $BEFORE $AFTER --compressed > diff-compressed.txt
ddev size diff $BEFORE $AFTER --compressed --to-dd-key ${{secrets.DD_API_KEY}} > diff-compressed.txt
ddev size diff $BEFORE $AFTER --compressed --format png,csv,markdown
cat diff-compressed.txt
echo "# Size diff (compressed)" >> $GITHUB_STEP_SUMMARY
Expand Down
1 change: 1 addition & 0 deletions ddev/changelog.d/20741.added
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Adds support for sending metrics to Datadog using the `--to-dd-org` and `--to-dd-key` options in the `diff` command between two consecutive commits.
9 changes: 9 additions & 0 deletions ddev/src/ddev/cli/size/diff.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
get_valid_versions,
plot_treemap,
print_table,
send_metrics_to_dd,
)

console = Console(stderr=True)
Expand All @@ -38,6 +39,8 @@
@click.argument("first_commit")
@click.argument("second_commit")
@click.option("--python", "version", help="Python version (e.g 3.12). If not specified, all versions will be analyzed")
@click.option("--to-dd-org", type=str, help="Send metrics to Datadog using the specified organization name.")
@click.option("--to-dd-key", type=str, help="Send metrics to datadoghq.com using the specified API key.")
@common_params # platform, compressed, format, show_gui
@click.pass_obj
def diff(
Expand All @@ -49,6 +52,8 @@ def diff(
compressed: bool,
format: list[str],
show_gui: bool,
to_dd_org: str,
to_dd_key: str,
) -> None:
"""
Compare the size of integrations and dependencies between two commits.
Expand Down Expand Up @@ -119,6 +124,10 @@ def diff(
)
if format:
export_format(app, format, modules_plat_ver, "diff", platform, version, compressed)
if to_dd_org or to_dd_key:
send_metrics_to_dd(
app, modules_plat_ver, to_dd_org, to_dd_key, compressed, "diff", [first_commit, second_commit]
)
except Exception as e:
progress.stop()
app.abort(str(e))
Expand Down
39 changes: 35 additions & 4 deletions ddev/src/ddev/cli/size/historical_metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,10 @@ def upload_historical_metrics(date_from_str: str, org: str) -> None:
raise ValueError(f"Date ({date_from}) must be after 2024-09-18")
try:
console.print(f"[green]Processing repository: {repo_path}")

with GitRepo(repo_path) as gitRepo:
commits = gitRepo._run(f"git log --pretty=format:%H --since='{date_from}'")
gitRepo._run("git checkout master")
commits = gitRepo._run(f"git log --reverse --pretty=format:%H --since='{date_from}'")
console.print(f"Found {len(commits)} commits to process")
with Progress(
SpinnerColumn(),
Expand All @@ -32,12 +34,41 @@ def upload_historical_metrics(date_from_str: str, org: str) -> None:
) as progress:
commit_task = progress.add_task("[cyan]Processing commits...")

for i, commit in enumerate(commits, 1):
for i, commit in enumerate(commits, 0):
date, _, _ = gitRepo.get_commit_metadata(commit)
progress.update(
commit_task, description=f"Processing commit {i}/{len(commits)}: {commit[:8]} ({date})"
commit_task, description=f"Processing commit {i + 1}/{len(commits)}: {commit[:8]} ({date})"
)
print(f"Processing commit {i}/{len(commits)}: {commit[:8]} ({date})", flush=True)
print(f"Processing commit {i + 1}/{len(commits)}: {commit[:8]} ({date})", flush=True)
if i > 0:
result = subprocess.run(
["ddev", "--here", "size", "diff", "--to-dd-org", org, commits[i - 1], commit],
cwd=gitRepo.repo_dir,
text=True,
capture_output=True,
)
if result.returncode != 0:
console.print(f"[red]Error in commit {commit}: {result.stderr}")
continue
result = subprocess.run(
[
"ddev",
"--here",
"size",
"diff",
"--compressed",
"--to-dd-org",
org,
commits[i - 1],
commit,
],
cwd=gitRepo.repo_dir,
text=True,
capture_output=True,
)
if result.returncode != 0:
console.print(f"[red]Error in commit {commit}: {result.stderr}")
continue
gitRepo.checkout_commit(commit)
result = subprocess.run(
["ddev", "--here", "size", "status", "--to-dd-org", org],
Expand Down
5 changes: 3 additions & 2 deletions ddev/src/ddev/cli/size/status.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

import os
from pathlib import Path
from typing import Optional
from typing import Literal, Optional

import click
from rich.console import Console
Expand Down Expand Up @@ -84,7 +84,8 @@ def status(
if format:
export_format(app, format, modules_plat_ver, "status", platform, version, compressed)
if to_dd_org or to_dd_key:
send_metrics_to_dd(app, modules_plat_ver, to_dd_org, to_dd_key, compressed)
mode: Literal["status"] = "status"
send_metrics_to_dd(app, modules_plat_ver, to_dd_org, to_dd_key, compressed, mode, None)
except Exception as e:
app.abort(str(e))

Expand Down
Loading
Loading