ethyca-fides 2.67.0rc1__py2.py3-none-any.whl → 2.67.1b0__py2.py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of ethyca-fides might be problematic. Click here for more details.
- {ethyca_fides-2.67.0rc1.dist-info → ethyca_fides-2.67.1b0.dist-info}/METADATA +1 -1
- {ethyca_fides-2.67.0rc1.dist-info → ethyca_fides-2.67.1b0.dist-info}/RECORD +110 -109
- fides/_version.py +3 -3
- fides/api/common_exceptions.py +4 -0
- fides/api/graph/execution.py +16 -0
- fides/api/models/privacy_request/privacy_request.py +33 -13
- fides/api/schemas/application_config.py +1 -0
- fides/api/schemas/connection_configuration/connection_secrets_datahub.py +10 -1
- fides/api/service/connectors/base_connector.py +14 -0
- fides/api/service/connectors/bigquery_connector.py +5 -0
- fides/api/service/connectors/query_configs/bigquery_query_config.py +4 -4
- fides/api/service/connectors/query_configs/snowflake_query_config.py +3 -3
- fides/api/service/connectors/snowflake_connector.py +55 -2
- fides/api/service/connectors/sql_connector.py +107 -9
- fides/api/service/privacy_request/request_runner_service.py +3 -2
- fides/api/service/privacy_request/request_service.py +173 -32
- fides/api/task/execute_request_tasks.py +4 -0
- fides/api/task/graph_task.py +48 -2
- fides/api/util/cache.py +56 -0
- fides/api/util/memory_watchdog.py +286 -0
- fides/config/execution_settings.py +8 -0
- fides/config/utils.py +1 -0
- fides/ui-build/static/admin/404.html +1 -1
- fides/ui-build/static/admin/_next/static/chunks/pages/{_app-5c3a63bb1697f34c.js → _app-750d6bd16c971bb9.js} +1 -1
- fides/ui-build/static/admin/add-systems/manual.html +1 -1
- fides/ui-build/static/admin/add-systems/multiple.html +1 -1
- fides/ui-build/static/admin/add-systems.html +1 -1
- fides/ui-build/static/admin/consent/configure/add-vendors.html +1 -1
- fides/ui-build/static/admin/consent/configure.html +1 -1
- fides/ui-build/static/admin/consent/privacy-experience/[id].html +1 -1
- fides/ui-build/static/admin/consent/privacy-experience/new.html +1 -1
- fides/ui-build/static/admin/consent/privacy-experience.html +1 -1
- fides/ui-build/static/admin/consent/privacy-notices/[id].html +1 -1
- fides/ui-build/static/admin/consent/privacy-notices/new.html +1 -1
- fides/ui-build/static/admin/consent/privacy-notices.html +1 -1
- fides/ui-build/static/admin/consent/properties.html +1 -1
- fides/ui-build/static/admin/consent/reporting.html +1 -1
- fides/ui-build/static/admin/consent.html +1 -1
- fides/ui-build/static/admin/data-catalog/[systemId]/projects/[projectUrn]/[resourceUrn].html +1 -1
- fides/ui-build/static/admin/data-catalog/[systemId]/projects/[projectUrn].html +1 -1
- fides/ui-build/static/admin/data-catalog/[systemId]/projects.html +1 -1
- fides/ui-build/static/admin/data-catalog/[systemId]/resources/[resourceUrn].html +1 -1
- fides/ui-build/static/admin/data-catalog/[systemId]/resources.html +1 -1
- fides/ui-build/static/admin/data-catalog.html +1 -1
- fides/ui-build/static/admin/data-discovery/action-center/[monitorId]/[systemId].html +1 -1
- fides/ui-build/static/admin/data-discovery/action-center/[monitorId].html +1 -1
- fides/ui-build/static/admin/data-discovery/action-center.html +1 -1
- fides/ui-build/static/admin/data-discovery/activity.html +1 -1
- fides/ui-build/static/admin/data-discovery/detection/[resourceUrn].html +1 -1
- fides/ui-build/static/admin/data-discovery/detection.html +1 -1
- fides/ui-build/static/admin/data-discovery/discovery/[resourceUrn].html +1 -1
- fides/ui-build/static/admin/data-discovery/discovery.html +1 -1
- fides/ui-build/static/admin/datamap.html +1 -1
- fides/ui-build/static/admin/dataset/[datasetId]/[collectionName]/[...subfieldNames].html +1 -1
- fides/ui-build/static/admin/dataset/[datasetId]/[collectionName].html +1 -1
- fides/ui-build/static/admin/dataset/[datasetId].html +1 -1
- fides/ui-build/static/admin/dataset/new.html +1 -1
- fides/ui-build/static/admin/dataset.html +1 -1
- fides/ui-build/static/admin/datastore-connection/[id].html +1 -1
- fides/ui-build/static/admin/datastore-connection/new.html +1 -1
- fides/ui-build/static/admin/datastore-connection.html +1 -1
- fides/ui-build/static/admin/index.html +1 -1
- fides/ui-build/static/admin/integrations/[id].html +1 -1
- fides/ui-build/static/admin/integrations.html +1 -1
- fides/ui-build/static/admin/login/[provider].html +1 -1
- fides/ui-build/static/admin/login.html +1 -1
- fides/ui-build/static/admin/messaging/[id].html +1 -1
- fides/ui-build/static/admin/messaging/add-template.html +1 -1
- fides/ui-build/static/admin/messaging.html +1 -1
- fides/ui-build/static/admin/poc/ant-components.html +1 -1
- fides/ui-build/static/admin/poc/form-experiments/AntForm.html +1 -1
- fides/ui-build/static/admin/poc/form-experiments/FormikAntFormItem.html +1 -1
- fides/ui-build/static/admin/poc/form-experiments/FormikControlled.html +1 -1
- fides/ui-build/static/admin/poc/form-experiments/FormikField.html +1 -1
- fides/ui-build/static/admin/poc/form-experiments/FormikSpreadField.html +1 -1
- fides/ui-build/static/admin/poc/forms.html +1 -1
- fides/ui-build/static/admin/poc/table-migration.html +1 -1
- fides/ui-build/static/admin/privacy-requests/[id].html +1 -1
- fides/ui-build/static/admin/privacy-requests/configure/messaging.html +1 -1
- fides/ui-build/static/admin/privacy-requests/configure/storage.html +1 -1
- fides/ui-build/static/admin/privacy-requests/configure.html +1 -1
- fides/ui-build/static/admin/privacy-requests.html +1 -1
- fides/ui-build/static/admin/properties/[id].html +1 -1
- fides/ui-build/static/admin/properties/add-property.html +1 -1
- fides/ui-build/static/admin/properties.html +1 -1
- fides/ui-build/static/admin/reporting/datamap.html +1 -1
- fides/ui-build/static/admin/settings/about/alpha.html +1 -1
- fides/ui-build/static/admin/settings/about.html +1 -1
- fides/ui-build/static/admin/settings/consent/[configuration_id]/[purpose_id].html +1 -1
- fides/ui-build/static/admin/settings/consent.html +1 -1
- fides/ui-build/static/admin/settings/custom-fields.html +1 -1
- fides/ui-build/static/admin/settings/domain-records.html +1 -1
- fides/ui-build/static/admin/settings/domains.html +1 -1
- fides/ui-build/static/admin/settings/email-templates.html +1 -1
- fides/ui-build/static/admin/settings/locations.html +1 -1
- fides/ui-build/static/admin/settings/organization.html +1 -1
- fides/ui-build/static/admin/settings/regulations.html +1 -1
- fides/ui-build/static/admin/systems/configure/[id]/test-datasets.html +1 -1
- fides/ui-build/static/admin/systems/configure/[id].html +1 -1
- fides/ui-build/static/admin/systems.html +1 -1
- fides/ui-build/static/admin/taxonomy.html +1 -1
- fides/ui-build/static/admin/user-management/new.html +1 -1
- fides/ui-build/static/admin/user-management/profile/[id].html +1 -1
- fides/ui-build/static/admin/user-management.html +1 -1
- {ethyca_fides-2.67.0rc1.dist-info → ethyca_fides-2.67.1b0.dist-info}/WHEEL +0 -0
- {ethyca_fides-2.67.0rc1.dist-info → ethyca_fides-2.67.1b0.dist-info}/entry_points.txt +0 -0
- {ethyca_fides-2.67.0rc1.dist-info → ethyca_fides-2.67.1b0.dist-info}/licenses/LICENSE +0 -0
- {ethyca_fides-2.67.0rc1.dist-info → ethyca_fides-2.67.1b0.dist-info}/top_level.txt +0 -0
- /fides/ui-build/static/admin/_next/static/{ZIM71ZcqBBeTYHc-MN9_n → v1eqRIfzld3di00TTnVM9}/_buildManifest.js +0 -0
- /fides/ui-build/static/admin/_next/static/{ZIM71ZcqBBeTYHc-MN9_n → v1eqRIfzld3di00TTnVM9}/_ssgManifest.js +0 -0
fides/api/task/graph_task.py
CHANGED
|
@@ -18,6 +18,7 @@ from fides.api.common_exceptions import (
|
|
|
18
18
|
NotSupportedForCollection,
|
|
19
19
|
PrivacyRequestErasureEmailSendRequired,
|
|
20
20
|
SkippingConsentPropagation,
|
|
21
|
+
TableNotFound,
|
|
21
22
|
)
|
|
22
23
|
from fides.api.graph.config import (
|
|
23
24
|
ROOT_COLLECTION_ADDRESS,
|
|
@@ -61,6 +62,7 @@ from fides.api.util.consent_util import (
|
|
|
61
62
|
)
|
|
62
63
|
from fides.api.util.logger import Pii
|
|
63
64
|
from fides.api.util.logger_context_utils import LoggerContextKeys
|
|
65
|
+
from fides.api.util.memory_watchdog import MemoryLimitExceeded
|
|
64
66
|
from fides.api.util.saas_util import FIDESOPS_GROUPED_INPUTS
|
|
65
67
|
from fides.config import CONFIG
|
|
66
68
|
|
|
@@ -70,6 +72,16 @@ EMPTY_REQUEST = PrivacyRequest()
|
|
|
70
72
|
EMPTY_REQUEST_TASK = RequestTask()
|
|
71
73
|
|
|
72
74
|
|
|
75
|
+
def _is_memory_limit_exceeded(exception: BaseException) -> bool:
|
|
76
|
+
"""Check if the exception or any exception in its chain is a MemoryLimitExceeded."""
|
|
77
|
+
current_exception: Optional[BaseException] = exception
|
|
78
|
+
while current_exception:
|
|
79
|
+
if isinstance(current_exception, MemoryLimitExceeded):
|
|
80
|
+
return True
|
|
81
|
+
current_exception = current_exception.__cause__ or current_exception.__context__
|
|
82
|
+
return False
|
|
83
|
+
|
|
84
|
+
|
|
73
85
|
def retry(
|
|
74
86
|
action_type: ActionType,
|
|
75
87
|
default_return: Any,
|
|
@@ -126,6 +138,7 @@ def retry(
|
|
|
126
138
|
CollectionDisabled,
|
|
127
139
|
ActionDisabled,
|
|
128
140
|
NotSupportedForCollection,
|
|
141
|
+
TableNotFound,
|
|
129
142
|
) as exc:
|
|
130
143
|
logger.warning(
|
|
131
144
|
"{} - Skipping collection {} for privacy_request: {}",
|
|
@@ -144,7 +157,31 @@ def retry(
|
|
|
144
157
|
self.log_skipped(action_type, exc)
|
|
145
158
|
self.cache_system_status_for_preferences()
|
|
146
159
|
return default_return
|
|
160
|
+
except MemoryLimitExceeded as ex:
|
|
161
|
+
# Hard failure – mark task & downstream as errored and abort.
|
|
162
|
+
logger.error(
|
|
163
|
+
"Memory watchdog exceeded ({}%). Aborting {} {} without retry.",
|
|
164
|
+
ex.memory_percent,
|
|
165
|
+
method_name,
|
|
166
|
+
self.execution_node.address,
|
|
167
|
+
)
|
|
168
|
+
# Persist error status and create execution logs before raising
|
|
169
|
+
self.log_end(action_type, ex)
|
|
170
|
+
self.add_error_status_for_consent_reporting()
|
|
171
|
+
raise
|
|
147
172
|
except BaseException as ex: # pylint: disable=W0703
|
|
173
|
+
# Check if this exception was caused by memory limit exceeded
|
|
174
|
+
if _is_memory_limit_exceeded(ex):
|
|
175
|
+
logger.error(
|
|
176
|
+
"Memory watchdog exceeded (wrapped exception). Aborting {} {} without retry.",
|
|
177
|
+
method_name,
|
|
178
|
+
self.execution_node.address,
|
|
179
|
+
)
|
|
180
|
+
# Persist error status and create execution logs before raising
|
|
181
|
+
self.log_end(action_type, ex)
|
|
182
|
+
self.add_error_status_for_consent_reporting()
|
|
183
|
+
raise
|
|
184
|
+
|
|
148
185
|
traceback.print_exc()
|
|
149
186
|
func_delay *= CONFIG.execution.task_retry_backoff
|
|
150
187
|
logger.warning(
|
|
@@ -553,12 +590,21 @@ class GraphTask(ABC): # pylint: disable=too-many-instance-attributes
|
|
|
553
590
|
# For access request results, mutate rows in-place to remove non-matching
|
|
554
591
|
# array elements. We already iterated over `output` above, so reuse the same
|
|
555
592
|
# loop structure to keep cache locality.
|
|
593
|
+
logger.info(
|
|
594
|
+
"Filtering {} rows in {} for matching array elements.",
|
|
595
|
+
len(output),
|
|
596
|
+
self.execution_node.address,
|
|
597
|
+
)
|
|
556
598
|
for row in output:
|
|
599
|
+
filter_element_match(row, post_processed_node_input_data)
|
|
600
|
+
|
|
601
|
+
if len(output) > 0:
|
|
557
602
|
logger.info(
|
|
558
|
-
"Filtering
|
|
603
|
+
"Filtering completed for {} rows in {}. Post-processed node size: {}",
|
|
604
|
+
len(output),
|
|
559
605
|
self.execution_node.address,
|
|
606
|
+
len(post_processed_node_input_data),
|
|
560
607
|
)
|
|
561
|
-
filter_element_match(row, post_processed_node_input_data)
|
|
562
608
|
|
|
563
609
|
if self.request_task.id:
|
|
564
610
|
# Saves intermediate access results for DSR 3.0 directly on the Request Task
|
fides/api/util/cache.py
CHANGED
|
@@ -334,6 +334,62 @@ def cache_task_tracking_key(request_id: str, celery_task_id: str) -> None:
|
|
|
334
334
|
)
|
|
335
335
|
|
|
336
336
|
|
|
337
|
+
def get_privacy_request_retry_cache_key(privacy_request_id: str) -> str:
|
|
338
|
+
"""Get cache key for tracking privacy request requeue retry attempts."""
|
|
339
|
+
return f"id-{privacy_request_id}-privacy-request-retry-count"
|
|
340
|
+
|
|
341
|
+
|
|
342
|
+
def get_privacy_request_retry_count(privacy_request_id: str) -> int:
|
|
343
|
+
"""Get the current retry count for a privacy request requeue attempts.
|
|
344
|
+
|
|
345
|
+
Raises Exception if cache operations fail, allowing callers to handle cache failures appropriately.
|
|
346
|
+
"""
|
|
347
|
+
cache: FidesopsRedis = get_cache()
|
|
348
|
+
try:
|
|
349
|
+
retry_count = cache.get(get_privacy_request_retry_cache_key(privacy_request_id))
|
|
350
|
+
return int(retry_count) if retry_count else 0
|
|
351
|
+
except Exception as exc:
|
|
352
|
+
logger.error(
|
|
353
|
+
f"Failed to get retry count for privacy request {privacy_request_id}: {exc}"
|
|
354
|
+
)
|
|
355
|
+
raise
|
|
356
|
+
|
|
357
|
+
|
|
358
|
+
def increment_privacy_request_retry_count(privacy_request_id: str) -> int:
|
|
359
|
+
"""Increment and return the retry count for a privacy request requeue attempts.
|
|
360
|
+
|
|
361
|
+
Raises Exception if cache operations fail, allowing callers to handle cache failures appropriately.
|
|
362
|
+
"""
|
|
363
|
+
cache: FidesopsRedis = get_cache()
|
|
364
|
+
cache_key = get_privacy_request_retry_cache_key(privacy_request_id)
|
|
365
|
+
|
|
366
|
+
try:
|
|
367
|
+
# Increment the counter, will be 1 if key doesn't exist
|
|
368
|
+
new_count = cache.incr(cache_key)
|
|
369
|
+
# Set expiry to prevent cache buildup (24 hours)
|
|
370
|
+
cache.expire(cache_key, 86400)
|
|
371
|
+
return new_count
|
|
372
|
+
except Exception as exc:
|
|
373
|
+
logger.error(
|
|
374
|
+
f"Failed to increment retry count for privacy request {privacy_request_id}: {exc}"
|
|
375
|
+
)
|
|
376
|
+
raise
|
|
377
|
+
|
|
378
|
+
|
|
379
|
+
def reset_privacy_request_retry_count(privacy_request_id: str) -> None:
|
|
380
|
+
"""Reset the retry count for a privacy request requeue attempts.
|
|
381
|
+
|
|
382
|
+
Silently fails if cache operations fail since this is cleanup.
|
|
383
|
+
"""
|
|
384
|
+
cache: FidesopsRedis = get_cache()
|
|
385
|
+
try:
|
|
386
|
+
cache.delete(get_privacy_request_retry_cache_key(privacy_request_id))
|
|
387
|
+
except Exception as exc:
|
|
388
|
+
logger.warning(
|
|
389
|
+
f"Failed to reset retry count for privacy request {privacy_request_id}: {exc}"
|
|
390
|
+
)
|
|
391
|
+
|
|
392
|
+
|
|
337
393
|
def celery_tasks_in_flight(celery_task_ids: List[str]) -> bool:
|
|
338
394
|
"""Returns True if supplied Celery Tasks appear to be in-flight"""
|
|
339
395
|
if not celery_task_ids:
|
|
@@ -0,0 +1,286 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Memory watchdog utilities used to proactively interrupt long-running Celery tasks that approach the
|
|
3
|
+
container's memory limits.
|
|
4
|
+
|
|
5
|
+
The watchdog runs in a background thread and periodically samples the overall system memory usage
|
|
6
|
+
(using `psutil`). When usage exceeds the configured threshold, it immediately sends `SIGUSR1` to
|
|
7
|
+
the current process. The signal handler raises `MemoryLimitExceeded` which can be caught by the
|
|
8
|
+
calling code to perform clean-up and let Celery record the task as failed.
|
|
9
|
+
|
|
10
|
+
This allows tasks to terminate gracefully with proper error logging, rather than being forcefully
|
|
11
|
+
killed by the system's OOM killer which would result in a WorkerLostError and incomplete cleanup.
|
|
12
|
+
"""
|
|
13
|
+
|
|
14
|
+
from __future__ import annotations
|
|
15
|
+
|
|
16
|
+
import os
|
|
17
|
+
import signal
|
|
18
|
+
import threading
|
|
19
|
+
import time
|
|
20
|
+
from functools import wraps
|
|
21
|
+
from types import FrameType, TracebackType
|
|
22
|
+
from typing import Any, Callable, Literal, Optional, Type, TypeVar, Union
|
|
23
|
+
|
|
24
|
+
import psutil # type: ignore
|
|
25
|
+
from loguru import logger
|
|
26
|
+
|
|
27
|
+
F = TypeVar("F", bound=Callable[..., Any])
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
def get_memory_watchdog_enabled() -> bool:
|
|
31
|
+
"""
|
|
32
|
+
Get the memory_watchdog_enabled setting from the application configuration.
|
|
33
|
+
|
|
34
|
+
Returns:
|
|
35
|
+
bool: True if memory_watchdog_enabled is enabled, False otherwise (defaults to False)
|
|
36
|
+
"""
|
|
37
|
+
try:
|
|
38
|
+
from fides.api.api.deps import get_autoclose_db_session as get_db
|
|
39
|
+
from fides.config.config_proxy import ConfigProxy
|
|
40
|
+
|
|
41
|
+
with get_db() as db:
|
|
42
|
+
config_proxy = ConfigProxy(db)
|
|
43
|
+
# ConfigProxy returns None when no config record exists, so we must handle None explicitly
|
|
44
|
+
value = getattr(config_proxy.execution, "memory_watchdog_enabled")
|
|
45
|
+
return value if value is not None else False
|
|
46
|
+
except Exception: # pragma: no cover
|
|
47
|
+
# default to disabled for backward compatibility
|
|
48
|
+
return False
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
class MemoryLimitExceeded(RuntimeError):
|
|
52
|
+
"""Raised when the watchdog detects sustained memory usage above the threshold."""
|
|
53
|
+
|
|
54
|
+
def __init__(self, message: str, *, memory_percent: Optional[float] = None) -> None:
|
|
55
|
+
super().__init__(message)
|
|
56
|
+
self.memory_percent: Optional[float] = memory_percent
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
class MemoryWatchdog:
|
|
60
|
+
"""Background memory monitor that enables graceful task termination.
|
|
61
|
+
|
|
62
|
+
Monitors system memory usage and triggers controlled shutdown when usage exceeds the threshold,
|
|
63
|
+
preventing forceful termination by the system's OOM killer.
|
|
64
|
+
|
|
65
|
+
Parameters
|
|
66
|
+
----------
|
|
67
|
+
threshold:
|
|
68
|
+
Percentage of *overall* system memory usage at which the watchdog triggers.
|
|
69
|
+
check_interval:
|
|
70
|
+
How often (in seconds) to sample ``psutil.virtual_memory()``.
|
|
71
|
+
grace_period:
|
|
72
|
+
Deprecated - kept for compatibility but defaults to 0 for immediate action.
|
|
73
|
+
"""
|
|
74
|
+
|
|
75
|
+
def __init__(
|
|
76
|
+
self, *, threshold: int = 90, check_interval: float = 0.5, grace_period: int = 0
|
|
77
|
+
) -> None:
|
|
78
|
+
self.threshold = threshold
|
|
79
|
+
self.check_interval = check_interval
|
|
80
|
+
self.grace_period = grace_period
|
|
81
|
+
|
|
82
|
+
self._thread: Optional[threading.Thread] = None
|
|
83
|
+
self._monitoring = threading.Event()
|
|
84
|
+
self._original_handler: Union[
|
|
85
|
+
Callable[[int, Optional[FrameType]], Any], int, signal.Handlers, None
|
|
86
|
+
] = None
|
|
87
|
+
|
|
88
|
+
# ---------------------------------------------------------------------
|
|
89
|
+
# Public helpers
|
|
90
|
+
# ---------------------------------------------------------------------
|
|
91
|
+
def start(self) -> None:
|
|
92
|
+
"""Start the background monitoring thread and register the signal handler."""
|
|
93
|
+
logger.debug(
|
|
94
|
+
"Starting memory watchdog - threshold={}%, check_interval={}s",
|
|
95
|
+
self.threshold,
|
|
96
|
+
self.check_interval,
|
|
97
|
+
)
|
|
98
|
+
self._original_handler = signal.signal(signal.SIGUSR1, self._signal_handler)
|
|
99
|
+
self._monitoring.set()
|
|
100
|
+
self._thread = threading.Thread(
|
|
101
|
+
target=self._run, name="memory-watchdog", daemon=True
|
|
102
|
+
)
|
|
103
|
+
self._thread.start()
|
|
104
|
+
|
|
105
|
+
def stop(self) -> None:
|
|
106
|
+
"""Stop the monitoring thread and restore the previous signal handler."""
|
|
107
|
+
logger.debug("Stopping memory watchdog")
|
|
108
|
+
self._monitoring.clear()
|
|
109
|
+
if self._thread and self._thread.is_alive():
|
|
110
|
+
self._thread.join(timeout=2)
|
|
111
|
+
if self._original_handler is not None:
|
|
112
|
+
signal.signal(signal.SIGUSR1, self._original_handler)
|
|
113
|
+
self._original_handler = None
|
|
114
|
+
|
|
115
|
+
# ------------------------------------------------------------------
|
|
116
|
+
# Context-manager support
|
|
117
|
+
# ------------------------------------------------------------------
|
|
118
|
+
def __enter__(self) -> "MemoryWatchdog":
|
|
119
|
+
self.start()
|
|
120
|
+
return self
|
|
121
|
+
|
|
122
|
+
def __exit__(
|
|
123
|
+
self,
|
|
124
|
+
exc_type: Optional[Type[BaseException]],
|
|
125
|
+
exc_value: Optional[BaseException],
|
|
126
|
+
traceback: Optional[TracebackType],
|
|
127
|
+
) -> Literal[False]:
|
|
128
|
+
self.stop()
|
|
129
|
+
# Do not suppress exceptions
|
|
130
|
+
return False
|
|
131
|
+
|
|
132
|
+
# ------------------------------------------------------------------
|
|
133
|
+
# Internal helpers
|
|
134
|
+
# ------------------------------------------------------------------
|
|
135
|
+
def _signal_handler(
|
|
136
|
+
self, signum: int, frame: Optional[FrameType]
|
|
137
|
+
) -> None: # noqa: D401 – Celery uses signal handlers
|
|
138
|
+
"""Convert the signal into an exception on the main thread."""
|
|
139
|
+
current_percent = _system_memory_percent()
|
|
140
|
+
logger.error("Memory limit exceeded: {}%", current_percent)
|
|
141
|
+
self.stop()
|
|
142
|
+
raise MemoryLimitExceeded(
|
|
143
|
+
"Memory usage exceeded threshold", memory_percent=current_percent
|
|
144
|
+
)
|
|
145
|
+
|
|
146
|
+
def _run(self) -> None:
|
|
147
|
+
"""Background thread body."""
|
|
148
|
+
while self._monitoring.is_set():
|
|
149
|
+
try:
|
|
150
|
+
mem_percent = _system_memory_percent()
|
|
151
|
+
|
|
152
|
+
if mem_percent > self.threshold:
|
|
153
|
+
# Trigger graceful termination before the system OOM killer can intervene
|
|
154
|
+
logger.error(
|
|
155
|
+
"Memory usage {}% above threshold {}% - sending SIGUSR1 to terminate task gracefully (prevents OOM kill)",
|
|
156
|
+
mem_percent,
|
|
157
|
+
self.threshold,
|
|
158
|
+
)
|
|
159
|
+
os.kill(os.getpid(), signal.SIGUSR1)
|
|
160
|
+
return # stop monitoring after signal
|
|
161
|
+
|
|
162
|
+
time.sleep(self.check_interval)
|
|
163
|
+
except Exception as exc: # pragma: no cover – best-effort logging
|
|
164
|
+
logger.exception("Uncaught error in memory watchdog: {}", exc)
|
|
165
|
+
break
|
|
166
|
+
|
|
167
|
+
|
|
168
|
+
# -----------------------------------------------------------------------------
|
|
169
|
+
# Decorator for Celery tasks (or any function)
|
|
170
|
+
# -----------------------------------------------------------------------------
|
|
171
|
+
|
|
172
|
+
|
|
173
|
+
def memory_limiter(
|
|
174
|
+
_func: Optional[F] = None,
|
|
175
|
+
*,
|
|
176
|
+
threshold: int = 90,
|
|
177
|
+
check_interval: float = 0.5,
|
|
178
|
+
grace_period: int = 0,
|
|
179
|
+
) -> Union[F, Callable[[F], F]]:
|
|
180
|
+
"""Decorator that runs the wrapped callable under a :class:`MemoryWatchdog`.
|
|
181
|
+
|
|
182
|
+
Enables graceful task termination when memory usage is high, preventing WorkerLostError
|
|
183
|
+
from system OOM killer intervention.
|
|
184
|
+
|
|
185
|
+
Can be applied **with or without arguments**::
|
|
186
|
+
|
|
187
|
+
@memory_limiter
|
|
188
|
+
def task_a():
|
|
189
|
+
...
|
|
190
|
+
|
|
191
|
+
@memory_limiter(threshold=85)
|
|
192
|
+
def task_b():
|
|
193
|
+
...
|
|
194
|
+
"""
|
|
195
|
+
|
|
196
|
+
def decorator(func: F) -> F:
|
|
197
|
+
@wraps(func)
|
|
198
|
+
def wrapper(*args: Any, **kwargs: Any) -> Any:
|
|
199
|
+
# Check if memory watchdog is enabled
|
|
200
|
+
if not get_memory_watchdog_enabled():
|
|
201
|
+
logger.debug(
|
|
202
|
+
"Memory watchdog disabled by configuration - running task without monitoring"
|
|
203
|
+
)
|
|
204
|
+
return func(*args, **kwargs)
|
|
205
|
+
|
|
206
|
+
watchdog = MemoryWatchdog(
|
|
207
|
+
threshold=threshold,
|
|
208
|
+
check_interval=check_interval,
|
|
209
|
+
grace_period=grace_period,
|
|
210
|
+
)
|
|
211
|
+
watchdog.start()
|
|
212
|
+
try:
|
|
213
|
+
return func(*args, **kwargs)
|
|
214
|
+
except MemoryLimitExceeded as exc:
|
|
215
|
+
logger.error(
|
|
216
|
+
"Task terminated gracefully due to memory pressure: {}%",
|
|
217
|
+
exc.memory_percent,
|
|
218
|
+
)
|
|
219
|
+
raise
|
|
220
|
+
finally:
|
|
221
|
+
watchdog.stop()
|
|
222
|
+
|
|
223
|
+
return wrapper # type: ignore[return-value]
|
|
224
|
+
|
|
225
|
+
# If called without arguments, the first positional argument is the function
|
|
226
|
+
if _func is not None and callable(_func):
|
|
227
|
+
return decorator(_func)
|
|
228
|
+
|
|
229
|
+
return decorator
|
|
230
|
+
|
|
231
|
+
|
|
232
|
+
# -----------------------------------------------------------------------------
|
|
233
|
+
# Platform helpers – cgroup-aware memory measurement
|
|
234
|
+
# -----------------------------------------------------------------------------
|
|
235
|
+
|
|
236
|
+
# Docker / Kubernetes containers are usually memory-constrained via cgroups. If we only look at
|
|
237
|
+
# host-wide memory usage the watchdog will never fire, because the host may still have plenty of
|
|
238
|
+
# free RAM even though the container is about to be OOM-killed. The helpers below read the
|
|
239
|
+
# relevant cgroup files (v2 first, then v1) and compute the percentage of the *container limit* in
|
|
240
|
+
# use. When cgroup information is unavailable (e.g. running directly on the host) we return
|
|
241
|
+
# `None` and fall back to `psutil`.
|
|
242
|
+
|
|
243
|
+
|
|
244
|
+
def _cgroup_memory_percent() -> Optional[float]:
|
|
245
|
+
"""Return container memory usage as *percentage* of the cgroup limit or `None` when not
|
|
246
|
+
running inside a memory-limited cgroup."""
|
|
247
|
+
|
|
248
|
+
def _read(path: str) -> Optional[int]:
|
|
249
|
+
try:
|
|
250
|
+
with open(path, "r", encoding="utf-8") as fh:
|
|
251
|
+
raw = fh.read().strip()
|
|
252
|
+
if raw == "" or raw.lower() == "max": # v2 "max" means unlimited
|
|
253
|
+
return None
|
|
254
|
+
return int(raw)
|
|
255
|
+
except (FileNotFoundError, PermissionError, ValueError): # pragma: no cover
|
|
256
|
+
return None
|
|
257
|
+
|
|
258
|
+
# cgroups v2 (unified)
|
|
259
|
+
usage = _read("/sys/fs/cgroup/memory.current")
|
|
260
|
+
limit = _read("/sys/fs/cgroup/memory.max")
|
|
261
|
+
if usage is not None and limit and limit > 0:
|
|
262
|
+
return usage / limit * 100
|
|
263
|
+
|
|
264
|
+
# cgroups v1
|
|
265
|
+
usage = _read("/sys/fs/cgroup/memory/memory.usage_in_bytes")
|
|
266
|
+
limit = _read("/sys/fs/cgroup/memory/memory.limit_in_bytes")
|
|
267
|
+
if (
|
|
268
|
+
usage is not None and limit and 0 < limit < (1 << 60)
|
|
269
|
+
): # ignore enormous "unlimited" value
|
|
270
|
+
return usage / limit * 100
|
|
271
|
+
|
|
272
|
+
return None
|
|
273
|
+
|
|
274
|
+
|
|
275
|
+
def _system_memory_percent() -> float:
|
|
276
|
+
"""Best-effort *current* memory usage percentage for the running worker.
|
|
277
|
+
|
|
278
|
+
1. Use cgroup metrics when they are available and meaningful.
|
|
279
|
+
2. Fall back to host-wide `psutil.virtual_memory().percent` otherwise."""
|
|
280
|
+
|
|
281
|
+
cgroup_percent = _cgroup_memory_percent()
|
|
282
|
+
if cgroup_percent is not None:
|
|
283
|
+
return cgroup_percent
|
|
284
|
+
|
|
285
|
+
# Fall back to host memory usage
|
|
286
|
+
return psutil.virtual_memory().percent
|
|
@@ -57,6 +57,10 @@ class ExecutionSettings(FidesSettings):
|
|
|
57
57
|
default=300,
|
|
58
58
|
description="Seconds between polling for interrupted tasks to requeue",
|
|
59
59
|
)
|
|
60
|
+
privacy_request_requeue_retry_count: int = Field(
|
|
61
|
+
default=3,
|
|
62
|
+
description="The number of times a privacy request will be requeued when its tasks are interrupted before being marked as error",
|
|
63
|
+
)
|
|
60
64
|
use_dsr_3_0: bool = Field(
|
|
61
65
|
default=False,
|
|
62
66
|
description="Temporary flag to switch to using DSR 3.0 to process your tasks.",
|
|
@@ -77,4 +81,8 @@ class ExecutionSettings(FidesSettings):
|
|
|
77
81
|
default="US/Eastern",
|
|
78
82
|
description="The timezone to send batch emails for DSR email integration.",
|
|
79
83
|
)
|
|
84
|
+
memory_watchdog_enabled: bool = Field(
|
|
85
|
+
default=False,
|
|
86
|
+
description="Whether the memory watchdog is enabled to monitor and gracefully terminate tasks that approach memory limits.",
|
|
87
|
+
)
|
|
80
88
|
model_config = SettingsConfigDict(env_prefix=ENV_PREFIX)
|
fides/config/utils.py
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
<!DOCTYPE html><html lang="en"><head><meta charSet="utf-8"/><meta name="viewport" content="width=device-width"/><meta name="next-head-count" content="2"/><link data-next-font="" rel="preconnect" href="/" crossorigin="anonymous"/><link rel="preload" href="/_next/static/css/d9924caa849931b3.css" as="style"/><link rel="stylesheet" href="/_next/static/css/d9924caa849931b3.css" data-n-g=""/><noscript data-n-css=""></noscript><script defer="" nomodule="" src="/_next/static/chunks/polyfills-42372ed130431b0a.js"></script><script src="/_next/static/chunks/webpack-90e8ec1fc5c6455b.js" defer=""></script><script src="/_next/static/chunks/framework-c92fc3344e6fd165.js" defer=""></script><script src="/_next/static/chunks/main-090643377c8254e6.js" defer=""></script><script src="/_next/static/chunks/pages/_app-
|
|
1
|
+
<!DOCTYPE html><html lang="en"><head><meta charSet="utf-8"/><meta name="viewport" content="width=device-width"/><meta name="next-head-count" content="2"/><link data-next-font="" rel="preconnect" href="/" crossorigin="anonymous"/><link rel="preload" href="/_next/static/css/d9924caa849931b3.css" as="style"/><link rel="stylesheet" href="/_next/static/css/d9924caa849931b3.css" data-n-g=""/><noscript data-n-css=""></noscript><script defer="" nomodule="" src="/_next/static/chunks/polyfills-42372ed130431b0a.js"></script><script src="/_next/static/chunks/webpack-90e8ec1fc5c6455b.js" defer=""></script><script src="/_next/static/chunks/framework-c92fc3344e6fd165.js" defer=""></script><script src="/_next/static/chunks/main-090643377c8254e6.js" defer=""></script><script src="/_next/static/chunks/pages/_app-750d6bd16c971bb9.js" defer=""></script><script src="/_next/static/chunks/pages/404-2d803dab6a00f353.js" defer=""></script><script src="/_next/static/v1eqRIfzld3di00TTnVM9/_buildManifest.js" defer=""></script><script src="/_next/static/v1eqRIfzld3di00TTnVM9/_ssgManifest.js" defer=""></script><style>.data-ant-cssinjs-cache-path{content:"";}</style></head><body><div id="__next"><div style="height:100%;display:flex"></div></div><script id="__NEXT_DATA__" type="application/json">{"props":{"pageProps":{}},"page":"/404","query":{},"buildId":"v1eqRIfzld3di00TTnVM9","nextExport":true,"autoExport":true,"isFallback":false,"scriptLoader":[]}</script></body></html>
|