[GH-1420] Notification Improvements Stage 1#1748
[GH-1420] Notification Improvements Stage 1#1748TejasRGitHub wants to merge 27 commits intodata-dot-all:mainfrom
Conversation
noah-paige
left a comment
There was a problem hiding this comment.
part 1 Review - still have a couple more files on Dataset Table notifications and weekly digest
backend/dataall/modules/notifications/services/admin_notifications.py
Outdated
Show resolved
Hide resolved
backend/dataall/modules/notifications/services/ses_email_notification_service.py
Show resolved
Hide resolved
backend/dataall/modules/notifications/services/ses_email_notification_service.py
Outdated
Show resolved
Hide resolved
backend/dataall/modules/shares_base/services/share_notification_service.py
Outdated
Show resolved
Hide resolved
backend/dataall/modules/shares_base/services/sharing_service.py
Outdated
Show resolved
Hide resolved
backend/dataall/modules/shares_base/services/share_notification_service.py
Outdated
Show resolved
Hide resolved
| def find_share_by_dataset_attributes(session, dataset_uri, dataset_owner, groups = None): | ||
| if groups is None: | ||
| groups = [] |
There was a problem hiding this comment.
I am guessing there is an edge case where groups could be passed in explicitly as None before and not being set to [] so the query failed?
There was a problem hiding this comment.
tbh, I added it because my editor was suggesting an improvement. I think this article does a fine job at explaining why - https://nikos7am.com/posts/mutable-default-arguments/
backend/dataall/modules/notifications/tasks/weekly_digest_reminder.py
Outdated
Show resolved
Hide resolved
backend/dataall/modules/notifications/tasks/weekly_digest_reminder.py
Outdated
Show resolved
Hide resolved
backend/dataall/modules/notifications/tasks/weekly_digest_reminder.py
Outdated
Show resolved
Hide resolved
noah-paige
left a comment
There was a problem hiding this comment.
some additional comments from pending file review
backend/dataall/modules/notifications/tasks/weekly_digest_reminder.py
Outdated
Show resolved
Hide resolved
backend/dataall/modules/notifications/tasks/weekly_digest_reminder.py
Outdated
Show resolved
Hide resolved
| if table_status_map: | ||
| log.info('Sending email notification after dataset table updates were found') | ||
| try: | ||
| DatasetTableNotifications(dataset=dataset).notify_dataset_table_updates(session=session, table_status_map=table_status_map) | ||
| except Exception as e: | ||
| error_log = f"Error occurred while sending email to notify about changes to the glue tables for dataset with uri: {dataset.datasetUri} due to: {e}" | ||
| task_exceptions.append(error_log) |
There was a problem hiding this comment.
table_status_map will always be defined so this will always execute right?
There was a problem hiding this comment.
also should there be a try catch here or only on the loop over datasets?
There was a problem hiding this comment.
table_status_map will always be defined so this will always execute right?
The table_status_map will be empty when there are no newly added tables, no table has been deleted , no table which was deleted previously has been added. And thus when it is empty the if part won't execute.
also should there be a try catch here or only on the loop over datasets?
I have added this try catch explicitly so that that any email sending failures are caught. Also with this , the rest of the code deosn't get affected and I don't want it to get affected
|
Hi @noah-paige , I have updated the PR. Please let me know if you have any additional code comments. Let me know if you need any clarification / discussion on few of my replies on your comments . Few additional things which I noticed and added as a part of new updated PR,
|
There was a problem hiding this comment.
nit: should we also explicitly import db in the __init__ file? (at dataall/backend/dataall/core/groups/__init__.py) -- think right now it is implicitly imported via api
There was a problem hiding this comment.
I wouldn't mind it getting imported implicitly. With a blank init all the group_models and constants file will be imported.
backend/dataall/modules/notifications/services/admin_notifications.py
Outdated
Show resolved
Hide resolved
backend/dataall/modules/notifications/services/admin_notifications.py
Outdated
Show resolved
Hide resolved
backend/dataall/modules/notifications/services/admin_notifications.py
Outdated
Show resolved
Hide resolved
backend/dataall/modules/notifications/services/ses_email_notification_service.py
Show resolved
Hide resolved
backend/dataall/modules/notifications/services/ses_email_notification_service.py
Outdated
Show resolved
Hide resolved
backend/dataall/modules/shares_base/services/sharing_service.py
Outdated
Show resolved
Hide resolved
backend/dataall/modules/shares_base/services/sharing_service.py
Outdated
Show resolved
Hide resolved
| @staticmethod | ||
| def find_dataset_shares(session, dataset_uri): | ||
| return session.query(ShareObject).filter(ShareObject.datasetUri == dataset_uri).all() | ||
| def find_dataset_shares(session, dataset_uri: str): |
There was a problem hiding this comment.
Nothing has changed here. Only returning via query.allI() instead of on the same line
| log.info(f'Notification type : {share_notification_config_type} is not active') | ||
| else: | ||
| log.info('Notifications are not active') | ||
|
|
There was a problem hiding this comment.
Removing this function from here and moving it to ses_email_notification_service.py
| "parameters": { | ||
| "group_notifications": true | ||
| "group_notifications": true, | ||
| "admin_notifications": true |
There was a problem hiding this comment.
Adding this new parameter to switch on/off admin notifications. This can be later removed and admin notifications can be enabled by default when email notifications are enabled. Keeping this for now, to test and see how many notifications an admin might get with the current code change. There is a chance in which admins can be bombarded with a lot of notifications in which this will serve as a good way to stop creating admin notifications
| container_id='container', | ||
| ecr_repository=ecr_repository, | ||
| environment=self._create_env(), | ||
| environment=self.env_vars, |
There was a problem hiding this comment.
Switching to env_vars as those contains the same as self._create_env()
|
Hi @petrkalos , @noah-paige , I have made code changes after taking a look at the review comments. Can you please take a look and let me if this PR looks good now I have re-tested after code changes
|
backend/dataall/modules/shares_base/tasks/share_reapplier_task.py
Outdated
Show resolved
Hide resolved
...nd/dataall/modules/s3_datasets_shares/services/share_processors/s3_bucket_share_processor.py
Outdated
Show resolved
Hide resolved
...aall/modules/s3_datasets_shares/services/share_processors/s3_access_point_share_processor.py
Outdated
Show resolved
Hide resolved
...d/dataall/modules/s3_datasets_shares/services/share_processors/glue_table_share_processor.py
Outdated
Show resolved
Hide resolved
backend/dataall/modules/s3_datasets/services/dataset_table_notifications.py
Outdated
Show resolved
Hide resolved
|
@noah-paige, Updated PR and made minor changes as per the review comments |
|
@TejasRGitHub - looks like a test is failing and need to format with ruff |
Updated PR . Now the ruff tests and the unit test should pass |
noah-paige
left a comment
There was a problem hiding this comment.
Thanks for resolving ruff issues - looks like latest version of ruff had updated the way it formats f-strings causing a number of files to be updated for formatting outside the scope of this PR
| """ | ||
|
|
||
| import functools | ||
| import logging |
There was a problem hiding this comment.
This file is a part of PR
| @@ -0,0 +1,2 @@ | |||
| class DataallGroups: | |||
There was a problem hiding this comment.
This file is a part of PR
| from dataall.base.db import get_engine | ||
| from dataall.base.loader import load_modules, ImportMode | ||
| from dataall.base.utils.alarm_service import AlarmService | ||
| from dataall.modules.notifications.services.admin_notifications import AdminNotificationService |
There was a problem hiding this comment.
This file is a part of PR
| @@ -0,0 +1,35 @@ | |||
| import logging | |||
There was a problem hiding this comment.
This file is a part of PR
| email_provider = SESEmailNotificationService.get_email_provider_instance( | ||
| recipient_groups_list, recipient_email_list | ||
| ) | ||
| identityProvider = ServiceProviderFactory.get_service_provider_instance() |
There was a problem hiding this comment.
This file is a part of PR
| import os | ||
| from dataclasses import dataclass, field | ||
| from typing import List, Dict, Any, Tuple, Set | ||
|
|
There was a problem hiding this comment.
This file is a part of PR
| dataset = DatasetBaseRepository.get_dataset_by_uri(session, share.datasetUri) | ||
| ShareNotificationService(session=session, dataset=dataset, share=share).notify_persistent_email_reminder( | ||
| email_id=share.owner | ||
| task_exceptions = [] |
There was a problem hiding this comment.
This file is a part of PR
| revoked_items_states = ShareStatusRepository.get_share_items_states( | ||
| session, share.shareUri, item_uris | ||
| ) | ||
| task_exceptions = [] |
There was a problem hiding this comment.
This file is a part of PR
| import os | ||
| import sys | ||
|
|
||
| from dataall.modules.notifications.services.admin_notifications import AdminNotificationService |
There was a problem hiding this comment.
This file is a part of PR
| import sys | ||
| from typing import List | ||
|
|
||
| from dataall.modules.notifications.services.admin_notifications import AdminNotificationService |
There was a problem hiding this comment.
This file is a part of PR
| processed_share_objects.append(share_object.shareUri) | ||
| SharingService.verify_share( | ||
| engine, share_uri=share_object.shareUri, status=ShareItemStatus.Share_Succeeded.value, healthStatus=None | ||
| task_exceptions = [] |
There was a problem hiding this comment.
This file is a part of PR
Yes there are abut 60 - 70 files which got formatted 😢 . @petrkalos I have commented on the files which are a part of this PR . You can also view the changes made in the PR update prior to the formatting changes |
Feature or Bugfix
Detail
Stage 1 as described in the Gh issue 1420 ( #1420 (comment))
Table on information about when notifications are sent to whom they are sent. I will add this as a part of documentation as well.
Tests
Relates
Security
Please answer the questions below briefly where applicable, or write
N/A. Based onOWASP 10.
fetching data from storage outside the application (e.g. a database, an S3 bucket)?
evalor similar functions are used?By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.