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

PROD-2709 Fix Email Connector logs so they use configuration key instead of name #5286

Merged
merged 5 commits into from
Sep 23, 2024
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ The types of changes are:

### Fixed
- Ignore `400` errors from Talkable's `person` endpoint. [#5317](https://github.com/ethyca/fides/pull/5317)
- Fix Email Connector logs so they use configuration key instead of name [#5286](https://github.com/ethyca/fides/pull/5286)

## [2.45.2](https://github.com/ethyca/fides/compare/2.45.1...2.45.2)

Expand Down
5 changes: 5 additions & 0 deletions src/fides/api/models/connectionconfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,11 @@ def authorized(self) -> bool:

return bool(self.secrets and self.secrets.get("access_token"))

@property
def name_or_key(self) -> str:
"""Returns the ConnectionConfig name if it exists, or its key otherwise."""
return self.name or self.key

@classmethod
def create_without_saving(
cls: Type[ConnectionConfig], db: Session, *, data: dict[str, Any]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,12 +73,12 @@ def add_skipped_log(self, db: Session, privacy_request: PrivacyRequest) -> None:
db=db,
data={
"connection_key": self.configuration.key,
"dataset_name": self.configuration.name,
"collection_name": self.configuration.name,
"dataset_name": self.configuration.name_or_key,
"collection_name": self.configuration.name_or_key,
"privacy_request_id": privacy_request.id,
"action_type": ActionType.erasure,
"status": ExecutionLogStatus.skipped,
"message": f"Erasure email skipped for '{self.configuration.name}'",
"message": f"Erasure email skipped for '{self.configuration.name_or_key}'",
},
)

Expand Down
36 changes: 22 additions & 14 deletions src/fides/api/service/connectors/consent_email_connector.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ def test_connection(self) -> Optional[ConnectionTestStatus]:
try:
if not self.config.test_email_address:
raise MessageDispatchException(
f"Cannot test connection. No test email defined for {self.configuration.name}"
f"Cannot test connection. No test email defined for {self.configuration.key}"
)

logger.info("Starting test connection to {}", self.configuration.key)
Expand Down Expand Up @@ -137,7 +137,11 @@ def test_connection(self) -> Optional[ConnectionTestStatus]:
)

except MessageDispatchException as exc:
logger.info("Email consent connector test failed with exception {}", exc)
logger.info(
"Email consent connector test for {} failed with exception {}",
self.configuration.key,
exc,
)
return ConnectionTestStatus.failed
return ConnectionTestStatus.succeeded

Expand Down Expand Up @@ -177,12 +181,12 @@ def add_skipped_log(self, db: Session, privacy_request: PrivacyRequest) -> None:
db=db,
data={
"connection_key": self.configuration.key,
"dataset_name": self.configuration.name,
"collection_name": self.configuration.name,
"dataset_name": self.configuration.name_or_key,
"collection_name": self.configuration.name_or_key,
"privacy_request_id": privacy_request.id,
"action_type": ActionType.consent,
"status": ExecutionLogStatus.skipped,
"message": f"Consent email skipped for '{self.configuration.name}'",
"message": f"Consent email skipped for '{self.configuration.name_or_key}'",
},
)
for pref in privacy_request.privacy_preferences: # type: ignore[attr-defined]
Expand All @@ -197,12 +201,12 @@ def add_errored_log(self, db: Session, privacy_request: PrivacyRequest) -> None:
db=db,
data={
"connection_key": self.configuration.key,
"dataset_name": self.configuration.name,
"collection_name": self.configuration.name,
"dataset_name": self.configuration.name_or_key,
"collection_name": self.configuration.name_or_key,
"privacy_request_id": privacy_request.id,
"action_type": ActionType.consent,
"status": ExecutionLogStatus.error,
"message": f"Consent email send error for '{self.configuration.name}'",
"message": f"Consent email send error for '{self.configuration.name_or_key}'",
},
)
add_errored_system_status_for_consent_reporting(
Expand Down Expand Up @@ -265,13 +269,13 @@ def batch_email_send(self, privacy_requests: Query) -> None:
logger.info(
"Skipping consent email send for connector: '{}'. "
"No corresponding user identities found for pending privacy requests.",
self.configuration.name,
self.configuration.key,
)
return

logger.info(
"Sending batched consent email for connector {}...",
self.configuration.name,
self.configuration.key,
)

db = Session.object_session(self.configuration)
Expand All @@ -286,7 +290,11 @@ def batch_email_send(self, privacy_requests: Query) -> None:
test_mode=False,
)
except MessageDispatchException as exc:
logger.info("Consent email failed with exception {}", exc)
logger.info(
"Consent email for connector {} failed with exception {}",
self.configuration.key,
exc,
)
for privacy_request in privacy_requests:
if privacy_request.id not in skipped_privacy_requests:
self.add_errored_log(db, privacy_request)
Expand All @@ -298,12 +306,12 @@ def batch_email_send(self, privacy_requests: Query) -> None:
db=db,
data={
"connection_key": self.configuration.key,
"dataset_name": self.configuration.name,
"dataset_name": self.configuration.name_or_key,
"privacy_request_id": privacy_request.id,
"collection_name": self.configuration.name,
"collection_name": self.configuration.name_or_key,
"action_type": ActionType.consent,
"status": ExecutionLogStatus.complete,
"message": f"Consent email instructions dispatched for '{self.configuration.name}'",
"message": f"Consent email instructions dispatched for '{self.configuration.name_or_key}'",
},
)
add_complete_system_status_for_consent_reporting(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -174,14 +174,12 @@ def batch_email_send(self, privacy_requests: Query) -> None:
db=db,
data={
"connection_key": self.configuration.key,
"dataset_name": self.configuration.name
or self.configuration.key,
"collection_name": self.configuration.name
or self.configuration.key,
"dataset_name": self.configuration.name_or_key,
"collection_name": self.configuration.name_or_key,
"privacy_request_id": privacy_request.id,
"action_type": ActionType.erasure,
"status": ExecutionLogStatus.complete,
"message": f"Erasure email instructions dispatched for '{self.configuration.name or self.configuration.key}'",
"message": f"Erasure email instructions dispatched for '{self.configuration.name_or_key}'",
},
)

Expand Down Expand Up @@ -496,8 +494,8 @@ def error_privacy_request(
db=db,
data={
"connection_key": self.configuration.key,
"dataset_name": self.configuration.name or self.configuration.key,
"collection_name": self.configuration.name or self.configuration.key,
"dataset_name": self.configuration.name_or_key,
"collection_name": self.configuration.name_or_key,
"privacy_request_id": privacy_request.id,
"action_type": ActionType.erasure,
"status": ExecutionLogStatus.error,
Expand Down
24 changes: 16 additions & 8 deletions src/fides/api/service/connectors/erasure_email_connector.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def test_connection(self) -> Optional[ConnectionTestStatus]:
try:
if not self.config.test_email_address:
raise MessageDispatchException(
f"Cannot test connection. No test email defined for {self.configuration.name}"
f"Cannot test connection. No test email defined for {self.configuration.key}"
)
# synchronous for now since failure to send is considered a connection test failure
send_single_erasure_email(
Expand All @@ -58,7 +58,11 @@ def test_connection(self) -> Optional[ConnectionTestStatus]:
test_mode=True,
)
except MessageDispatchException as exc:
logger.info("Email connector test failed with exception {}", exc)
logger.info(
"Email connector test for {} failed with exception {}",
self.configuration.key,
exc,
)
return ConnectionTestStatus.failed
return ConnectionTestStatus.succeeded

Expand All @@ -82,13 +86,13 @@ def batch_email_send(self, privacy_requests: Query) -> None:
logger.info(
"Skipping erasure email send for connector: '{}'. "
"No corresponding user identities found for pending privacy requests.",
self.configuration.name,
self.configuration.key,
)
return

logger.info(
"Sending batched erasure email for connector {}...",
self.configuration.name,
self.configuration.key,
)

try:
Expand All @@ -100,7 +104,11 @@ def batch_email_send(self, privacy_requests: Query) -> None:
test_mode=False,
)
except MessageDispatchException as exc:
logger.info("Erasure email failed with exception {}", exc)
logger.info(
"Erasure email for connector {} failed with exception {}",
self.configuration.key,
exc,
)
raise

# create an audit event for each privacy request ID
Expand All @@ -110,11 +118,11 @@ def batch_email_send(self, privacy_requests: Query) -> None:
db=db,
data={
"connection_key": self.configuration.key,
"dataset_name": self.configuration.name,
"collection_name": self.configuration.name,
"dataset_name": self.configuration.name_or_key,
"collection_name": self.configuration.name_or_key,
"privacy_request_id": privacy_request.id,
"action_type": ActionType.erasure,
"status": ExecutionLogStatus.complete,
"message": f"Erasure email instructions dispatched for '{self.configuration.name}'",
"message": f"Erasure email instructions dispatched for '{self.configuration.name_or_key}'",
},
)
Loading