From 9a800b5c3fb1c514b2e49b1f9001a10d67307fe6 Mon Sep 17 00:00:00 2001 From: Riya Chakraborty <47572810+ayirr7@users.noreply.github.com> Date: Thu, 22 Feb 2024 08:26:50 -0800 Subject: [PATCH] fix(COGS): Fix cluster name in COGS accounting for Snuba API (#5570) * fix resource_id handling for cogs * add condiition for counters --- snuba/querylog/__init__.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/snuba/querylog/__init__.py b/snuba/querylog/__init__.py index a903fd7fb8..9d6614e564 100644 --- a/snuba/querylog/__init__.py +++ b/snuba/querylog/__init__.py @@ -121,7 +121,7 @@ def _record_cogs( cluster_name = query_metadata.query_list[0].stats.get("cluster_name", "") - if not cluster_name.startswith("snuba_gen_metrics"): + if not cluster_name.startswith("snuba-gen-metrics"): return # Only track shared clusters # Sanitize the cluster name to line up with the resource_id naming convention @@ -130,9 +130,10 @@ def _record_cogs( .replace("snuba_gen_metrics", "generic_metrics_clickhouse") .replace("_0", "") ) + if random() < (state.get_config("snuba_api_cogs_probability") or 0): record_cogs( - resource_id=f"{cluster_name}_snuba_api_bytes_scanned", + resource_id=f"{cluster_name}", app_feature=app_feature, amount=bytes_scanned, usage_type=UsageUnit.BYTES,