Skip to content
This repository has been archived by the owner on Nov 30, 2022. It is now read-only.

Update Celery config defaults #808

Merged
merged 9 commits into from
Jul 7, 2022
Merged
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
4 changes: 3 additions & 1 deletion docs/fidesops/docs/guides/configuration_reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,10 @@ The `fidesops.toml` file should specify the following variables:
| Redis Variables |---|---|---|---|---|
| `HOST` | `FIDESOPS__REDIS__HOST` | string | redis.internal | N/A | The networking address for the Fidesops application Redis cache |
| `PORT` | `FIDESOPS__REDIS__PORT` | int | 6379 | 6379 | The port at which the Fidesops application cache will be accessible |
| `USER` | `FIDESOPS__REDIS__USER` | string | testuser | N/A | The user with which to login to the Redis cache |
| `PASSWORD` | `FIDESOPS__REDIS__PASSWORD` | string | anotherpassword | N/A | The password with which to login to the Fidesops application cache |
| `DB_INDEX` | `FIDESOPS__REDIS__DB_INDEX` | int | 0 | 0 | The Fidesops application will use this index in the Redis cache to cache data |
| `DB_INDEX` | `FIDESOPS__REDIS__DB_INDEX` | int | 0 | N/A | The Fidesops application will use this index in the Redis cache to cache data |
| `CONNECTION_URL` | `FIDESOPS__REDIS__CONNECTION_URL` | string | redis://:testpassword@redis:6379/0 | N/A | If not specified this URL is automatically assembled from the `HOST`, `PORT`, `PASSWORD` and `DB_INDEX` specified above |
| `DEFAULT_TTL_SECONDS` | `FIDESOPS__REDIS__DEFAULT_TTL_SECONDS` | int | 3600 | 604800 | The number of seconds for which data will live in Redis before automatically expiring |
| `ENABLED` | `FIDESOPS__REDIS__ENABLED` | bool | True | True | Whether the application's redis cache should be enabled. Only set to false for certain narrow uses of the application that do not require a backing redis cache. |
| Security Variables |---|---|---|---|---|
Expand Down
22 changes: 19 additions & 3 deletions src/fidesops/core/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ class ExecutionSettings(FidesSettings):
TASK_RETRY_BACKOFF: int
REQUIRE_MANUAL_REQUEST_APPROVAL: bool = False
MASKING_STRICT: bool = True
CELERY_BROKER_URL: str = "redis://:testpassword@redis:6379/1"
CELERY_RESULT_BACKEND: str = "redis://:testpassword@redis:6379/1"
CELERY_BROKER_URL: Optional[str] = None
CELERY_RESULT_BACKEND: Optional[str] = None
WORKER_ENABLED: bool = True

class Config:
Expand All @@ -52,14 +52,30 @@ class RedisSettings(FidesSettings):

HOST: str
PORT: int = 6379
USER: Optional[str] = ""
PASSWORD: str
CHARSET: str = "utf8"
DECODE_RESPONSES: bool = True
DEFAULT_TTL_SECONDS: int = 604800
DB_INDEX: int
DB_INDEX: Optional[int]
ENABLED: bool = True
SSL: bool = False
SSL_CERT_REQS: Optional[str] = "required"
CONNECTION_URL: Optional[str] = None

@validator("CONNECTION_URL", pre=True)
@classmethod
def assemble_connection_url(
cls,
v: Optional[str],
values: Dict[str, str],
) -> str:
"""Join Redis connection credentials into a connection string"""
if isinstance(v, str):
# If the whole URL is provided via the config, preference that
return v
seanpreston marked this conversation as resolved.
Show resolved Hide resolved

return f"redis://{values.get('USER', '')}:{values['PASSWORD']}@{values['HOST']}:{values['PORT']}/{values.get('DB_INDEX', '')}"

class Config:
env_prefix = "FIDESOPS__REDIS__"
Expand Down
10 changes: 8 additions & 2 deletions src/fidesops/tasks/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,14 @@ def _create_celery() -> Celery:
"""
logger.info("Creating Celery app...")
app = Celery(__name__)
app.conf.update(broker_url=config.execution.CELERY_BROKER_URL)
app.conf.update(result_backend=config.execution.CELERY_RESULT_BACKEND)

broker_url = config.execution.CELERY_BROKER_URL or config.redis.CONNECTION_URL
app.conf.update(broker_url=broker_url)

result_backend = (
config.execution.CELERY_RESULT_BACKEND or config.redis.CONNECTION_URL
)
app.conf.update(result_backend=result_backend)
logger.info("Autodiscovering tasks...")
app.autodiscover_tasks(
[
Expand Down