Skip to content
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
6 changes: 4 additions & 2 deletions .github/workflows/measure-disk-usage-master.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,14 @@ jobs:
- name: Measure disk usage (Uncompressed)
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: ddev -v size status --commit "${{ github.sha }}" --format json --to-dd-key ${{ steps.dd-sts.outputs.api_key }}
DD_API_KEY: ${{ steps.dd-sts.outputs.api_key }}
run: ddev -v size status --commit "${{ github.sha }}" --branch "${{ github.ref_name }}" --format json --to-dd-key "$DD_API_KEY"

- name: Measure disk usage (Compressed)
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: ddev -v size status --commit "${{ github.sha }}" --format json --to-dd-key ${{ steps.dd-sts.outputs.api_key }} --compressed
DD_API_KEY: ${{ steps.dd-sts.outputs.api_key }}
run: ddev -v size status --commit "${{ github.sha }}" --branch "${{ github.ref_name }}" --format json --to-dd-key "$DD_API_KEY" --compressed

- name: Upload JSON uncompressed sizes artifact
uses: actions/upload-artifact@bbbca2ddaa5d8feaa63e36b76fdaad77386f024f # v7.0.0
Expand Down
10 changes: 4 additions & 6 deletions .github/workflows/measure-disk-usage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ jobs:
steps:
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
with:
ref: ${{ github.event.workflow_run.head_sha }}
fetch-depth: 0

- name: Set up Python ${{ env.PYTHON_VERSION }}
Expand Down Expand Up @@ -49,27 +50,24 @@ jobs:
id: cmd
env:
HEAD_SHA: ${{ github.event.workflow_run.head_sha }}
EVENT_NAME: ${{ github.event.workflow_run.event }}
HEAD_BRANCH: ${{ github.event.workflow_run.head_branch }}
run: |
cmd="ddev -v size status --commit \"$HEAD_SHA\" --format json"

if [ "$EVENT_NAME" = "push" ] && [ "$HEAD_BRANCH" = "master" ]; then
cmd="$cmd --to-dd-key ${{ steps.dd-sts.outputs.api_key }}"
fi
cmd="ddev -v size status --commit \"$HEAD_SHA\" --branch \"$HEAD_BRANCH\" --format json --to-dd-key \"\$DD_API_KEY\""
echo "cmd=$cmd" >> $GITHUB_OUTPUT


- name: Measure disk usage (Uncompressed)
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
DD_API_KEY: ${{ steps.dd-sts.outputs.api_key }}
run: |
echo "Running for uncompressed sizes"
${{ steps.cmd.outputs.cmd }}

- name: Measure disk usage (Compressed)
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
DD_API_KEY: ${{ steps.dd-sts.outputs.api_key }}
run: |
echo "Running for compressed sizes"
${{ steps.cmd.outputs.cmd }} --compressed
Expand Down
1 change: 1 addition & 0 deletions ddev/changelog.d/23832.added
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add branch tags to `ddev size status` metrics sent to Datadog.
4 changes: 3 additions & 1 deletion ddev/src/ddev/cli/size/status.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
@click.option("--python", "version", help="Python version (e.g 3.12). If not specified, all versions will be analyzed")
@click.option("--dependency-sizes", type=click.Path(exists=True), help="Path to the dependency sizes file. If no")
@click.option("--commit", help="Commit hash to check the status of. It takes the commit's dependency sizes file.")
@click.option("--branch", help="Branch name used to tag metrics sent to Datadog.")
@common_params # platform, compressed, format, show_gui
@click.pass_obj
def status(
Expand All @@ -40,6 +41,7 @@ def status(
to_dd_key: str | None,
dependency_sizes: Path | None,
commit: str | None,
branch: str | None,
) -> None:
"""
Show the current size of all integrations and dependencies in your local repo.
Expand Down Expand Up @@ -108,7 +110,7 @@ def status(
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)
send_metrics_to_dd(app, commit, modules_plat_ver, to_dd_org, to_dd_key, compressed, branch or "unknown")
except Exception as e:
app.abort(str(e))

Expand Down
4 changes: 4 additions & 0 deletions ddev/src/ddev/cli/size/utils/common_funcs.py
Original file line number Diff line number Diff line change
Expand Up @@ -869,6 +869,7 @@ def send_metrics_to_dd(
org: str | None,
key: str | None,
compressed: bool,
branch: str,
) -> None:
metric_name = "datadog.agent_integrations"
size_type = "compressed" if compressed else "uncompressed"
Expand Down Expand Up @@ -907,6 +908,7 @@ def send_metrics_to_dd(
"team:agent-integrations",
f"compression:{size_type}",
f"metrics_version:{METRIC_VERSION}",
f"branch:{branch}",
f"jira_ticket:{tickets[0]}",
f"pr_number:{prs[-1]}",
f"commit_message:{message}",
Expand Down Expand Up @@ -943,6 +945,7 @@ def send_metrics_to_dd(
f"python_version:{py_version}",
"team:agent-integrations",
f"metrics_version:{METRIC_VERSION}",
f"branch:{branch}",
],
}
)
Expand All @@ -957,6 +960,7 @@ def send_metrics_to_dd(
f"python_version:{py_version}",
"team:agent-integrations",
f"metrics_version:{METRIC_VERSION}",
f"branch:{branch}",
],
}
)
Expand Down
2 changes: 2 additions & 0 deletions ddev/tests/cli/size/test_status.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ def mock_size_status():
(["--compressed"], False),
(["--format", "csv,markdown,json,png"], False),
(["--show-gui"], False),
(["--branch", "feature/branch"], False),
(["--platform", "linux-aarch64", "--python", "3.12"], False),
(["--platform", "linux-aarch64", "--python", "3.12", "--compressed"], False),
(["--platform", "linux-aarch64", "--python", "3.12", "--format", "csv,markdown,json,png"], False),
Expand All @@ -86,6 +87,7 @@ def mock_size_status():
"compressed",
"format",
"show_gui",
"branch",
"platform_and_version",
"platform_version_compressed",
"platform_version_format",
Expand Down
37 changes: 37 additions & 0 deletions ddev/tests/size/test_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
save_csv,
save_json,
save_markdown,
send_metrics_to_dd,
)
from ddev.utils.fs import Path

Expand Down Expand Up @@ -452,3 +453,39 @@ def test_get_dependencies_from_json():
mock_path.read_text.return_value = dep_size_dict
result = get_dependencies_from_json(mock_path, "linux-x86_64", "3.12", True)
assert result == expected


def test_send_metrics_to_dd_adds_branch_tag():
app = MagicMock()
app.config.orgs = {}
modules = [
{
"Name": "module1",
"Version": "1.2.3",
"Size_Bytes": 123,
"Size": "123 B",
"Type": "Integration",
"Platform": "linux-x86_64",
"Python_Version": "3.13",
},
{
"Name": "dep1",
"Version": "4.5.6",
"Size_Bytes": 456,
"Size": "456 B",
"Type": "Dependency",
"Platform": "linux-x86_64",
"Python_Version": "3.13",
},
]

with (
patch("ddev.cli.size.utils.common_funcs.get_commit_data", return_value=(1234567890, "message", [""], [""])),
patch("ddev.cli.size.utils.common_funcs.initialize"),
patch("ddev.cli.size.utils.common_funcs.api.Metric.send") as metric_send,
):
send_metrics_to_dd(app, "abcdef123", modules, None, "test-key", False, "feature/branch")

for call in metric_send.call_args_list:
for metric in call.kwargs["metrics"]:
assert "branch:feature/branch" in metric["tags"]
Loading