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

[GH-1420] Notification Improvements Stage 1 #1748

Open
wants to merge 23 commits into
base: main
Choose a base branch
from

Conversation

TejasRGitHub
Copy link
Contributor

@TejasRGitHub TejasRGitHub commented Dec 26, 2024

Feature or Bugfix

  • Feature [Enhancements]

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.

Data.all Resource Notification Recipient
Share Share Object Submitted Dataset owner, steward and share owner ( requestor )
Share Share Object Approved Dataset owner, steward and share owner ( requestor )
Share Share Object Failed Dataset owner, steward and share owner ( requestor )
Share Share Object Revoked / Rejected Dataset owner, steward and share owner ( requestor )
Share Share verifier finds share is unhealthy Share requestor team
Share Share reapplier finds share is unhealthy Share requestor team
Share Share reapplier finds share is healthy Share requestor team
Weekly reminders (Share Objects ) Submitted shares and unhealthy shares Share requestor team
Weekly reminders (Dataset Objects ) Unhealthy dataset Dataset owner and stewards team
Weekly reminders (Environment Objects ) Unhealthy environments Environment owner team
ECS task Any failures in ECS task Data.all admin team ( DAAdministrators )
Dataset Table Dataset table is removed Dataset owners and stewards and if any shares exist on that table then notify all share object requestor teams
Dataset Table Dataset table is added Dataset owners and stewards
Dataset Table Dataset table which was previously deleted was added back again Dataset owners and stewards

Tests

  1. Email Sent when something fails in ECS tasks ✅ Sample email -
image 2. Weekly Reminder email ✅ - image 3. Email sent when shares are reapplied ✅ - image 4. Email sent when share verifier finds share in unhealthy state ✅ image 5. Email sent when a glue table is deleted / resynced / added Email sent to dataset owners and dataset stewards when a table is deleted image Email sent to the share owner group when a table is deleted and there are active shares on that table image
  1. Email sent incase of share failure -
image

Relates

Security

Please answer the questions below briefly where applicable, or write N/A. Based on
OWASP 10.

  • Does this PR introduce or modify any input fields or queries - this includes
    fetching data from storage outside the application (e.g. a database, an S3 bucket)?
    • Is the input sanitized?
    • What precautions are you taking before deserializing the data you consume?
    • Is injection prevented by parametrizing queries?
    • Have you ensured no eval or similar functions are used?
  • Does this PR introduce any functionality or component that requires authorization?
    • How have you ensured it respects the existing AuthN/AuthZ mechanisms?
    • Are you logging failed auth attempts?
  • Are you using or adding any cryptographic features?
    • Do you use a standard proven implementations?
    • Are the used keys controlled by the customer? Where are they stored?
  • Are you introducing any new policies/roles/users?
    • Have you used the least-privilege principle? How?

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

@TejasRGitHub TejasRGitHub marked this pull request as ready for review January 3, 2025 00:27
@noah-paige noah-paige linked an issue Jan 10, 2025 that may be closed by this pull request
Copy link
Contributor

@noah-paige noah-paige left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

part 1 Review - still have a couple more files on Dataset Table notifications and weekly digest

Comment on lines 54 to 56
def find_share_by_dataset_attributes(session, dataset_uri, dataset_owner, groups = None):
if groups is None:
groups = []
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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/

Copy link
Contributor

@noah-paige noah-paige left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

some additional comments from pending file review

Comment on lines 57 to 63
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)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

table_status_map will always be defined so this will always execute right?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also should there be a try catch here or only on the loop over datasets?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

@TejasRGitHub
Copy link
Contributor Author

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,

  1. Admin group config ( admin_notifications ) in config.json to enable/disable admin email notifications. I am only keeping email admin notifications and not creating UI notifications - as UI notifications will look bloated with a lot of content.
  2. Added try..catch in sharing_services file where missing and reformatted to have the same pattern of try except finally block across the file

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wouldn't mind it getting imported implicitly. With a blank init all the group_models and constants file will be imported.

@@ -42,11 +42,15 @@ def find_share(session, dataset: DatasetBase, env, principal_id, principal_role_
)

@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):
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nothing has changed here. Only returning via query.allI() instead of on the same line

@@ -332,30 +437,3 @@ def _create_notification_task(self, subject, msg):
log.info(f'Notification type : {share_notification_config_type} is not active')
else:
log.info('Notifications are not active')

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removing this function from here and moving it to ses_email_notification_service.py

@@ -32,7 +32,8 @@
"active": false,
"persistent_reminders": false,
"parameters": {
"group_notifications": true
"group_notifications": true,
"admin_notifications": true
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

@@ -161,7 +161,7 @@ def __init__(
command=['python3.9', '-m', 'dataall.core.environment.tasks.env_stacks_updater'],
container_id='container',
ecr_repository=ecr_repository,
environment=self._create_env(),
environment=self.env_vars,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Switching to env_vars as those contains the same as self._create_env()

@TejasRGitHub
Copy link
Contributor Author

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

  1. Notifications after share is failed ( email + UI ) ✅
  2. Notifications after share is Unhealthy ( email + UI ) ✅
  3. Notifications after share is healthy ( email + UI ) ✅
  4. Weekly digest reminder notifications ( email ) ✅
  5. Notifications to owner ( when table are deleted, added, synced ) and share owners ( if there exists a share on the table ) - ✅
  6. Notifications when ECS or any service fails to Admins ✅

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

notification improvements
3 participants