Browse Source

fix(tsdb) Pass through consistent flag correctly with SnQL (#43927)

The SnQL code path wasn't correctly passing through the consistent flag
in the
Request. Start reading that flag out in the SnQL code path as well.
Evan Hicks 2 years ago
parent
commit
37b57997ca
2 changed files with 16 additions and 0 deletions
  1. 6 0
      src/sentry/utils/snuba.py
  2. 10 0
      tests/snuba/tsdb/test_tsdb_backend.py

+ 6 - 0
src/sentry/utils/snuba.py

@@ -740,6 +740,9 @@ def raw_snql_query(
     # other functions do here. It does not add any automatic conditions, format
     # results, nothing. Use at your own risk.
     metrics.incr("snql.sdk.api", tags={"referrer": referrer or "unknown"})
+    if "consistent" in OVERRIDE_OPTIONS:
+        request.flags.consistent = OVERRIDE_OPTIONS["consistent"]
+
     params: SnubaQueryBody = (request, lambda x: x, lambda x: x)
     return _apply_cache_and_build_results([params], referrer=referrer, use_cache=use_cache)[0]
 
@@ -753,6 +756,9 @@ def bulk_snql_query(
     # other functions do here. It does not add any automatic conditions, format
     # results, nothing. Use at your own risk.
     metrics.incr("snql.sdk.api", tags={"referrer": referrer or "unknown"})
+    if "consistent" in OVERRIDE_OPTIONS:
+        for request in requests:
+            request.flags.consistent = OVERRIDE_OPTIONS["consistent"]
     params: SnubaQuery = [(request, lambda x: x, lambda x: x) for request in requests]
     return _apply_cache_and_build_results(params, referrer=referrer, use_cache=use_cache)
 

+ 10 - 0
tests/snuba/tsdb/test_tsdb_backend.py

@@ -507,6 +507,16 @@ class SnubaTSDBTest(TestCase, SnubaTestCase):
             self.db.get_data(TSDBModel.group, [1, 2, 3, 4, 5], start, end, rollup=rollup)
             assert snuba.call_args.args[0].query.limit == Limit(5)
 
+    @patch("sentry.utils.snuba.OVERRIDE_OPTIONS", new={"consistent": True})
+    def test_tsdb_with_consistent(self):
+        with patch("sentry.utils.snuba._apply_cache_and_build_results") as snuba:
+            rollup = 3600
+            end = self.now
+            start = end + timedelta(days=-1, seconds=rollup)
+            self.db.get_data(TSDBModel.group, [1, 2, 3, 4, 5], start, end, rollup=rollup)
+            assert snuba.call_args.args[0][0][0].query.limit == Limit(120)
+            assert snuba.call_args.args[0][0][0].flags.consistent is True
+
 
 @region_silo_test
 class SnubaTSDBGroupPerformanceTest(TestCase, SnubaTestCase, PerfIssueTransactionTestMixin):