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
8 changes: 5 additions & 3 deletions tasks/static_quality_gates/metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ def fetch_main_headroom(failing_gates: list[str]) -> dict[str, dict[str, int]]:
f"avg:datadog.agent.static_quality_gate.{m}{{git_ref:main AND ({gate_filter})}} by {{gate_name}}"
for m in metric_map
)
result = query_metrics(queries, from_time="now-1d", to_time="now")
result = query_metrics(queries, from_time="now-7d", to_time="now") # accounts for weekends

for series in result:
gate_name = _extract_gate_name_from_scope(series.get("scope", ""))
Expand All @@ -127,13 +127,15 @@ def fetch_main_headroom(failing_gates: list[str]) -> dict[str, dict[str, int]]:
main_metrics[gate_name][key] = int(latest_value)
break

from tasks.static_quality_gates.thresholds import BUFFER_SIZE # avoids a circular import

headroom: dict[str, dict[str, int]] = {}
for gate_name, metrics in main_metrics.items():
disk_headroom = metrics.get("max_disk", 0) - metrics.get("current_disk", 0)
wire_headroom = metrics.get("max_wire", 0) - metrics.get("current_wire", 0)
headroom[gate_name] = {
"disk_headroom": max(0, disk_headroom),
"wire_headroom": max(0, wire_headroom),
"disk_headroom": max(BUFFER_SIZE, disk_headroom),
"wire_headroom": max(BUFFER_SIZE, wire_headroom),
}

return headroom
9 changes: 5 additions & 4 deletions tasks/unit_tests/static_quality_gates/metrics_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
fetch_main_headroom,
fetch_pr_metrics,
)
from tasks.static_quality_gates.thresholds import BUFFER_SIZE


class MockPoint:
Expand Down Expand Up @@ -248,8 +249,8 @@ def test_calculates_headroom_correctly(self, mock_query):
self.assertEqual(headroom["wire_headroom"], 25 * 1024 * 1024)

@patch("tasks.static_quality_gates.metrics.query_metrics")
def test_headroom_never_negative(self, mock_query):
"""Headroom should never be negative (clamped to 0)."""
def test_headroom_floored_when_main_over_its_own_limit(self, mock_query):
"""Headroom should floor at BUFFER_SIZE, not 0-, when main is over its own limit."""
# Single API call with current > max
mock_query.return_value = [
{
Expand Down Expand Up @@ -277,8 +278,8 @@ def test_headroom_never_negative(self, mock_query):
result = fetch_main_headroom(["static_quality_gate_agent_deb_amd64"])

headroom = result["static_quality_gate_agent_deb_amd64"]
# disk_headroom = max(0, 150 - 200) = 0
self.assertEqual(headroom["disk_headroom"], 0)
# disk_headroom = max(BUFFER_SIZE, 150 - 200) = BUFFER_SIZE
self.assertEqual(headroom["disk_headroom"], BUFFER_SIZE)

def test_returns_empty_for_no_gates(self):
"""Should return empty dict when no gates provided."""
Expand Down
Loading