feat(GAQ): Add Redis Sentinel Support for Global Async Queries (#29912)

Co-authored-by: Sivarajan Narayanan <narayanan_sivarajan@apple.com>
This commit is contained in:
nsivarajan
2024-08-30 23:12:29 +05:30
committed by GitHub
parent cd6b8b2f6d
commit 103cd3d6f3
6 changed files with 450 additions and 45 deletions

View File

@@ -17,15 +17,20 @@
from unittest import mock
from unittest.mock import ANY, Mock
import redis
from flask import g
from jwt import encode
from pytest import fixture, raises
from pytest import fixture, mark, raises
from superset import security_manager
from superset.async_events.async_query_manager import (
AsyncQueryManager,
AsyncQueryTokenException,
)
from superset.async_events.cache_backend import (
RedisCacheBackend,
RedisSentinelCacheBackend,
)
JWT_TOKEN_SECRET = "some_secret"
JWT_TOKEN_COOKIE_NAME = "superset_async_jwt"
@@ -36,7 +41,6 @@ def async_query_manager():
query_manager = AsyncQueryManager()
query_manager._jwt_secret = JWT_TOKEN_SECRET
query_manager._jwt_cookie_name = JWT_TOKEN_COOKIE_NAME
return query_manager
@@ -75,12 +79,24 @@ def test_parse_channel_id_from_request_bad_jwt(async_query_manager):
async_query_manager.parse_channel_id_from_request(request)
@mark.parametrize(
"cache_type, cache_backend",
[
("RedisCacheBackend", mock.Mock(spec=RedisCacheBackend)),
("RedisSentinelCacheBackend", mock.Mock(spec=RedisSentinelCacheBackend)),
("redis.Redis", mock.Mock(spec=redis.Redis)),
],
)
@mock.patch("superset.is_feature_enabled")
def test_submit_chart_data_job_as_guest_user(
is_feature_enabled_mock, async_query_manager
is_feature_enabled_mock, async_query_manager, cache_type, cache_backend
):
is_feature_enabled_mock.return_value = True
set_current_as_guest_user()
# Mock the get_cache_backend method to return the current cache backend
async_query_manager.get_cache_backend = mock.Mock(return_value=cache_backend)
job_mock = Mock()
async_query_manager._load_chart_data_into_cache_job = job_mock
job_meta = async_query_manager.submit_chart_data_job(
@@ -105,14 +121,27 @@ def test_submit_chart_data_job_as_guest_user(
)
assert "guest_token" not in job_meta
job_mock.reset_mock() # Reset the mock for the next iteration
@mark.parametrize(
"cache_type, cache_backend",
[
("RedisCacheBackend", mock.Mock(spec=RedisCacheBackend)),
("RedisSentinelCacheBackend", mock.Mock(spec=RedisSentinelCacheBackend)),
("redis.Redis", mock.Mock(spec=redis.Redis)),
],
)
@mock.patch("superset.is_feature_enabled")
def test_submit_explore_json_job_as_guest_user(
is_feature_enabled_mock, async_query_manager
is_feature_enabled_mock, async_query_manager, cache_type, cache_backend
):
is_feature_enabled_mock.return_value = True
set_current_as_guest_user()
# Mock the get_cache_backend method to return the current cache backend
async_query_manager.get_cache_backend = mock.Mock(return_value=cache_backend)
job_mock = Mock()
async_query_manager._load_explore_json_into_cache_job = job_mock
job_meta = async_query_manager.submit_explore_json_job(