Skip to content
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

fix(ci): Reduce the amount of test data that's stored #60197

Merged
merged 1 commit into from
Nov 21, 2023
Merged
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
64 changes: 26 additions & 38 deletions tests/snuba/test_metrics_layer.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def setUp(self) -> None:
self.org_id = self.project.organization_id
for mri, metric_type in self.metrics.items():
assert metric_type in {"counter", "distribution", "set", "gauge"}
for i in range(360):
for i in range(10):
value: int | dict[str, int]
if metric_type == "gauge":
value = {
Expand All @@ -66,8 +66,8 @@ def setUp(self) -> None:
mri,
{
"transaction": f"transaction_{i % 2}",
"status_code": "500" if i % 10 == 0 else "200",
"device": "BlackBerry" if i % 3 == 0 else "Nokia",
"status_code": "500" if i % 3 == 0 else "200",
"device": "BlackBerry" if i % 2 == 0 else "Nokia",
},
self.ts(self.hour_ago + timedelta(minutes=1 * i)),
value,
Expand Down Expand Up @@ -100,9 +100,9 @@ def test_basic(self) -> None:
tenant_ids={"referrer": "metrics.testing.test", "organization_id": self.org_id},
)
result = run_query(request)
assert len(result["data"]) == 61
assert len(result["data"]) == 10
rows = result["data"]
for i in range(61):
for i in range(10):
assert rows[i]["aggregate_value"] == i
assert (
rows[i]["time"]
Expand Down Expand Up @@ -139,9 +139,9 @@ def test_groupby(self) -> None:
tenant_ids={"referrer": "metrics.testing.test", "organization_id": self.org_id},
)
result = run_query(request)
assert len(result["data"]) == 61
assert len(result["data"]) == 10
rows = result["data"]
for i in range(61):
for i in range(10):
assert rows[i]["aggregate_value"] == [i, i]
assert rows[i]["transaction"] == f"transaction_{i % 2}"
assert (
Expand Down Expand Up @@ -182,16 +182,10 @@ def test_filters(self) -> None:
tenant_ids={"referrer": "metrics.testing.test", "organization_id": self.org_id},
)
result = run_query(request)
assert len(result["data"]) == 3
assert len(result["data"]) == 2
rows = result["data"]
for i in range(3): # 500 status codes on Blackberry are sparse
assert rows[i]["aggregate_value"] == [i * 30]
assert (
rows[i]["time"]
== (
self.hour_ago.replace(second=0, microsecond=0) + timedelta(minutes=30 * i)
).isoformat()
)
assert rows[0]["aggregate_value"] == [0]
assert rows[1]["aggregate_value"] == [6.0]

def test_complex(self) -> None:
query = MetricsQuery(
Expand Down Expand Up @@ -225,17 +219,12 @@ def test_complex(self) -> None:
tenant_ids={"referrer": "metrics.testing.test", "organization_id": self.org_id},
)
result = run_query(request)
assert len(result["data"]) == 3
assert len(result["data"]) == 2
rows = result["data"]
for i in range(3): # 500 status codes on BB are sparse
assert rows[i]["aggregate_value"] == [i * 30]
assert rows[i]["transaction"] == "transaction_0"
assert (
rows[i]["time"]
== (
self.hour_ago.replace(second=0, microsecond=0) + timedelta(minutes=30 * i)
).isoformat()
)
assert rows[0]["aggregate_value"] == [0]
assert rows[0]["transaction"] == "transaction_0"
assert rows[1]["aggregate_value"] == [6.0]
assert rows[1]["transaction"] == "transaction_0"

def test_totals(self) -> None:
query = MetricsQuery(
Expand Down Expand Up @@ -268,10 +257,8 @@ def test_totals(self) -> None:
assert len(result["data"]) == 2
rows = result["data"]

assert rows[0]["aggregate_value"] == 58
assert rows[0]["transaction"] == "transaction_0"
assert rows[1]["aggregate_value"] == 59
assert rows[1]["transaction"] == "transaction_1"
assert rows[0]["aggregate_value"] == 7.0
assert rows[1]["aggregate_value"] == 8.0

def test_meta_data_in_response(self) -> None:
query = MetricsQuery(
Expand Down Expand Up @@ -364,8 +351,8 @@ def test_interval_with_totals(self) -> None:
tenant_ids={"referrer": "metrics.testing.test", "organization_id": self.org_id},
)
result = run_query(request)
assert len(result["data"]) == 54
assert result["totals"]["aggregate_value"] == 59
assert len(result["data"]) == 6
assert result["totals"]["aggregate_value"] == 8.0

def test_automatic_granularity(self) -> None:
query = MetricsQuery(
Expand All @@ -392,9 +379,10 @@ def test_automatic_granularity(self) -> None:
tenant_ids={"referrer": "metrics.testing.test", "organization_id": self.org_id},
)
result = run_query(request)
# 30 since it's every 2 minutes.
# # TODO(evanh): There's a flaky off by one error that comes from the interval rounding I don't care to fix right now, hence the 31 option.
assert len(result["data"]) in [30, 31]

# There's a flaky off by one error here that is very difficult to track down
# TODO: figure out why this is flaky and assert to one specific value
assert len(result["data"]) in [5, 6]

def test_automatic_dataset(self) -> None:
query = MetricsQuery(
Expand Down Expand Up @@ -451,8 +439,8 @@ def test_gauges(self) -> None:
)
result = run_query(request)

assert len(result["data"]) == 61
assert result["totals"]["aggregate_value"] == 60
assert len(result["data"]) == 10
assert result["totals"]["aggregate_value"] == 9.0

def test_failure_rate(self) -> None:
query = MetricsQuery(
Expand Down Expand Up @@ -501,5 +489,5 @@ def test_failure_rate(self) -> None:
)
result = run_query(request)

assert len(result["data"]) == 61
assert len(result["data"]) == 10
assert result["totals"]["aggregate_value"] == 1.0