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

chore(GAQ): [Merge 5.0] Breaking change: Remove GLOBAL_ASYNC_QUERIES_REDIS_CONFIG #30284

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
17 changes: 9 additions & 8 deletions superset/async_events/async_query_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,9 @@

import logging
import uuid
from typing import Any, Literal, Optional, Union
from typing import Any, Literal, Optional

import jwt
import redis
from flask import Flask, Request, request, Response, session
from flask_caching.backends.base import BaseCache

Expand All @@ -39,6 +38,10 @@
pass


class UnsupportedCacheBackendError(Exception):
pass


class AsyncQueryTokenException(Exception):
pass

Expand Down Expand Up @@ -77,7 +80,7 @@

def get_cache_backend(
config: dict[str, Any],
) -> Union[RedisCacheBackend, RedisSentinelCacheBackend, redis.Redis]: # type: ignore
) -> RedisCacheBackend | RedisSentinelCacheBackend:
cache_config = config.get("GLOBAL_ASYNC_QUERIES_CACHE_BACKEND", {})
cache_type = cache_config.get("CACHE_TYPE")

Expand All @@ -87,11 +90,9 @@
if cache_type == "RedisSentinelCache":
return RedisSentinelCacheBackend.from_config(cache_config)

# TODO: Deprecate hardcoded plain Redis code and expand cache backend options.
# Maintain backward compatibility with 'GLOBAL_ASYNC_QUERIES_REDIS_CONFIG' until it is deprecated.
return redis.Redis(
**config["GLOBAL_ASYNC_QUERIES_REDIS_CONFIG"], decode_responses=True
)
# TODO: Expand cache backend options.
# Removed support for deprecated 'GLOBAL_ASYNC_QUERIES_REDIS_CONFIG' as it is no longer needed.
raise UnsupportedCacheBackendError("Unsupported cache backend configuration")

Check warning on line 95 in superset/async_events/async_query_manager.py

View check run for this annotation

Codecov / codecov/patch

superset/async_events/async_query_manager.py#L95

Added line #L95 was not covered by tests


class AsyncQueryManager:
Expand Down
15 changes: 5 additions & 10 deletions superset/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -1672,13 +1672,7 @@ def EMAIL_HEADER_MUTATOR( # pylint: disable=invalid-name,unused-argument
GLOBAL_ASYNC_QUERY_MANAGER_CLASS = (
"superset.async_events.async_query_manager.AsyncQueryManager"
)
GLOBAL_ASYNC_QUERIES_REDIS_CONFIG = {
"port": 6379,
"host": "127.0.0.1",
"password": "",
"db": 0,
"ssl": False,
}

GLOBAL_ASYNC_QUERIES_REDIS_STREAM_PREFIX = "async-events-"
GLOBAL_ASYNC_QUERIES_REDIS_STREAM_LIMIT = 1000
GLOBAL_ASYNC_QUERIES_REDIS_STREAM_LIMIT_FIREHOSE = 1000000
Expand All @@ -1696,19 +1690,20 @@ def EMAIL_HEADER_MUTATOR( # pylint: disable=invalid-name,unused-argument
)
GLOBAL_ASYNC_QUERIES_WEBSOCKET_URL = "ws://127.0.0.1:8080/"

# The configuration 'GLOBAL_ASYNC_QUERIES_REDIS_CONFIG' has been deprecated and removed.
# Please use 'GLOBAL_ASYNC_QUERIES_CACHE_BACKEND' for cache configuration.
# Global async queries cache backend configuration options:
# - Set 'CACHE_TYPE' to 'RedisCache' for RedisCacheBackend.
# - Set 'CACHE_TYPE' to 'RedisSentinelCache' for RedisSentinelCacheBackend.
# - Set 'CACHE_TYPE' to 'None' to fall back on 'GLOBAL_ASYNC_QUERIES_REDIS_CONFIG'.
GLOBAL_ASYNC_QUERIES_CACHE_BACKEND = {
"CACHE_TYPE": "RedisCache",
"CACHE_REDIS_HOST": "localhost",
"CACHE_REDIS_HOST": "127.0.0.1",
"CACHE_REDIS_PORT": 6379,
"CACHE_REDIS_USER": "",
"CACHE_REDIS_PASSWORD": "",
"CACHE_REDIS_DB": 0,
"CACHE_DEFAULT_TIMEOUT": 300,
"CACHE_REDIS_SENTINELS": [("localhost", 26379)],
"CACHE_REDIS_SENTINELS": [("127.0.0.1", 26379)],
"CACHE_REDIS_SENTINEL_MASTER": "mymaster",
"CACHE_REDIS_SENTINEL_PASSWORD": None,
"CACHE_REDIS_SSL": False, # True or False
Expand Down
6 changes: 0 additions & 6 deletions tests/integration_tests/async_events/api_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@
from typing import Any, Optional, Type
from unittest import mock

import redis

from superset.async_events.cache_backend import (
RedisCacheBackend,
RedisSentinelCacheBackend,
Expand Down Expand Up @@ -127,10 +125,6 @@ def test_events_redis_sentinel_cache_backend(self, mock_uuid4):
RedisSentinelCacheBackend, self._test_events_logic
)

@mock.patch("uuid.uuid4", return_value=UUID)
def test_events_redis(self, mock_uuid4):
self.run_test_with_cache_backend(redis.Redis, self._test_events_logic)

def test_events_no_login(self):
app._got_first_request = False
async_query_manager.init_app(app)
Expand Down
1 change: 0 additions & 1 deletion tests/integration_tests/tasks/async_queries_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ class TestAsyncQueries(SupersetTestCase):
[
("RedisCacheBackend", mock.Mock(spec=RedisCacheBackend)),
("RedisSentinelCacheBackend", mock.Mock(spec=RedisSentinelCacheBackend)),
("redis.Redis", mock.Mock(spec=redis.Redis)),
]
)
@mock.patch("superset.tasks.async_queries.set_form_data")
Expand Down
3 changes: 0 additions & 3 deletions tests/unit_tests/async_events/async_query_manager_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
from unittest import mock
from unittest.mock import ANY, Mock

import redis
from flask import g
from jwt import encode
from pytest import fixture, mark, raises
Expand Down Expand Up @@ -84,7 +83,6 @@ def test_parse_channel_id_from_request_bad_jwt(async_query_manager):
[
("RedisCacheBackend", mock.Mock(spec=RedisCacheBackend)),
("RedisSentinelCacheBackend", mock.Mock(spec=RedisSentinelCacheBackend)),
("redis.Redis", mock.Mock(spec=redis.Redis)),
],
)
@mock.patch("superset.is_feature_enabled")
Expand Down Expand Up @@ -129,7 +127,6 @@ def test_submit_chart_data_job_as_guest_user(
[
("RedisCacheBackend", mock.Mock(spec=RedisCacheBackend)),
("RedisSentinelCacheBackend", mock.Mock(spec=RedisSentinelCacheBackend)),
("redis.Redis", mock.Mock(spec=redis.Redis)),
],
)
@mock.patch("superset.is_feature_enabled")
Expand Down
Loading