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

Alert unit email and us if storage threshold reached #1562

Open
wants to merge 22 commits into
base: dev
Choose a base branch
from
Open
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: 4 additions & 0 deletions SPRINTLOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -450,3 +450,7 @@ _Nothing merged during this sprint_
- Workflow: Bump GitHub checkout action to v4 ([#1556](https://github.com/ScilifelabDataCentre/dds_web/pull/1556))
- Workflow: CodeQL action version(s) bumped to v3 ([#1569](https://github.com/ScilifelabDataCentre/dds_web/pull/1569))
- Workflow: Setup-node, codecov and upload-sarif action versions bumped to v4, v4 and v3, respectively ([#1570](https://github.com/ScilifelabDataCentre/dds_web/pull/1570))

# 2024-11-04 - 2024-11-15

- Modify the monitor usage command to send warning to the affected unit as well as Data Centre([#1562](https://github.com/ScilifelabDataCentre/dds_web/pull/1562))
9 changes: 5 additions & 4 deletions dds_web/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -1269,7 +1269,7 @@ def monitor_usage():
import dds_web.utils

# Email settings
recipient: str = flask.current_app.config.get("MAIL_DDS")
dds_contact: str = flask.current_app.config.get("MAIL_DDS")
default_subject: str = "DDS: Usage quota warning!"

# Run task
Expand Down Expand Up @@ -1305,15 +1305,16 @@ def monitor_usage():
# Email if the unit is using more
if perc_used_decimal > warn_after:
# Email settings
unit_contact: str = unit.contact_email
message: str = (
"A SciLifeLab Unit is approaching the allocated data quota.\n"
f"Affected unit: {unit.name}\n"
"Your unit is approaching the allocated data quota.\n"
f"Unit name: {unit.name}\n"
f"{info_string}"
)
flask.current_app.logger.info(message)
msg: flask_mail.Message = flask_mail.Message(
subject=default_subject,
recipients=[recipient],
recipients=[unit_contact, dds_contact],
body=message,
)
dds_web.utils.send_email_with_retry(msg=msg)
2 changes: 1 addition & 1 deletion doc/technical-overview.md
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ production instance, and should be collected from the agreements or additional c
| Days in Available | The number of days during which the data will be available for download by the Researchers. The countdown starts when the project is released. There is no time limit when the project is In Progress and the project has not been released. For more information on the project statuses and what actions can be performed during them, see the appendix ([Project Statuses](#b-project-statuses)). After Days in Available (DiA) number of days has passed, the project is automatically set as Expired. |
| Days in Expired | The number of days (after being available) during which the data is still stored but not available for download. During this time, the project can be renewed, leading to the project being available again and therefore allowing for downloads again. When the Days in Expired (DiE) number of days has passed, the project is automatically archived by the system. |
| Quota | The amount of storage space made available for a particular unit. This information should be included in the service agreement. Another value cannot be chosen by the Data Centre or by the unit. |
| Warning level | When a unit has used this percentage of it’s available storage space, an alert is triggered and sent to [[email protected]](mailto:[email protected]). In the event of an alert, the Data Centre contacts the unit to discuss whether or not the quota is sufficient. If not, the service agreement will need to be updated and the quota increased in both the database and at Safespring's S3 storage, for that specific Safespring project. |
| Warning level | When a unit has used this percentage of it’s available storage space, an alert is triggered and sent to the contact email within the unit, as well as a to [[email protected]](mailto:[email protected]). In the event of an alert, the unit affected should contact the Data Centre to discuss whether or not the quota is sufficient. If not, the service agreement will need to be updated and the quota increased in both the database and at Safespring's S3 storage, for that specific Safespring project. |
: Parameters used to configure a Unit within DDS

The unit also must provide the email addresses of at least two (but preferably three or more)
Expand Down
26 changes: 15 additions & 11 deletions tests/test_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -1432,19 +1432,23 @@ def test_monitor_usage_warning_sent(client, cli_runner, capfd: LogCaptureFixture
# Mock the size property of the Unit table
with patch("dds_web.database.models.Unit.size", new_callable=PropertyMock) as mock_size:
mock_size.return_value = 0.9 * quota_in_test
# Mock emails - only check if function call
with patch.object(flask_mail.Mail, "send") as mock_mail_send:

with mail.record_messages() as outbox:
# Run command
_: click.testing.Result = cli_runner.invoke(monitor_usage)
# Verify no email has been sent and stoud contains logging info
assert mock_mail_send.call_count == 2 # 2 because client and cli_runner both run

_, err = capfd.readouterr()
for unit in models.Unit.query.all():
assert (
f"A SciLifeLab Unit is approaching the allocated data quota.\nAffected unit: {unit.name}\n"
in err
)
# capture output
_, err = capfd.readouterr()

i = 0
for unit in models.Unit.query.all():
# Verify email has been sent to the correct recipient
assert outbox[i].recipients[0] == unit.contact_email
assert outbox[i].recipients[1] == "[email protected]"
assert (
f"Your unit is approaching the allocated data quota.\nUnit name: {unit.name}\n"
in err
)
i += 1


# set_available_to_expired
Expand Down