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

Merged
Merged
Show file tree
Hide file tree
Changes from 42 commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
0b9992e
change recipient in warning level
rv0lt Oct 11, 2024
fb39bd9
updated technical overview
rv0lt Oct 11, 2024
6ad37e9
correct email
rv0lt Oct 11, 2024
64d913e
Merge branch 'dev' into DDS-1675-Alert-unit-email-instead-of-us-if-st…
rv0lt Oct 15, 2024
34a964e
modify test for warning to check correct recipient
rv0lt Oct 16, 2024
cbac005
send email to correct recipient
rv0lt Oct 16, 2024
2af8de1
sprintlog
rv0lt Oct 16, 2024
13ed68a
merge
rv0lt Oct 16, 2024
5c2e542
Merge branch 'dev' into DDS-1675-Alert-unit-email-instead-of-us-if-st…
rv0lt Oct 17, 2024
18b1a1a
updated sprintlog
rv0lt Oct 17, 2024
0422e34
modified monitor usage
rv0lt Oct 18, 2024
3d51dea
adapt testsç
rv0lt Oct 18, 2024
488fbca
black linter
rv0lt Oct 18, 2024
0c14f3c
check for the second recipient in test
rv0lt Oct 22, 2024
ae0a96d
fix emails
rv0lt Oct 22, 2024
0277590
Merge branch 'dev' into DDS-1675-Alert-unit-email-instead-of-us-if-st…
rv0lt Oct 22, 2024
805273e
spritnlog
rv0lt Oct 22, 2024
5ec77b2
move entry to current sprint
rv0lt Oct 23, 2024
d1081ed
update technical overview
rv0lt Oct 23, 2024
b030727
typo
rv0lt Oct 24, 2024
c757874
Merge branch 'dev' into DDS-1675-Alert-unit-email-instead-of-us-if-st…
rv0lt Nov 1, 2024
f0e55bf
prettier
rv0lt Nov 1, 2024
b3c09a6
Merge branch 'dev' into DDS-1675-Alert-unit-email-instead-of-us-if-st…
rv0lt Nov 28, 2024
bd2e7fd
Update dds_web/commands.py
rv0lt Nov 28, 2024
2259ac4
migration
rv0lt Dec 2, 2024
a749a68
Merge branch 'DDS-1675-Alert-unit-email-instead-of-us-if-storage-thre…
rv0lt Dec 2, 2024
4b0a6dd
fix tests
rv0lt Dec 2, 2024
a6263eb
Merge branch 'dev' into DDS-1675-Alert-unit-email-instead-of-us-if-st…
rv0lt Dec 2, 2024
d109b61
Merge branch 'dev' into DDS-1675-Alert-unit-email-instead-of-us-if-st…
rv0lt Dec 3, 2024
17a11b4
move sprintlog
rv0lt Dec 3, 2024
e3e6086
fix migration
rv0lt Dec 3, 2024
c3c871b
set default
rv0lt Dec 3, 2024
557a693
proper migration file
rv0lt Dec 3, 2024
a99aaf0
Delete migrations/versions/e02fe8fde71e_unit_contact_email_non_nullab…
rv0lt Dec 3, 2024
d389728
black
rv0lt Dec 3, 2024
736cd47
added a proper readme
rv0lt Dec 4, 2024
abb19f6
undo readme
rv0lt Dec 4, 2024
0c94135
set default for null entries
rv0lt Dec 5, 2024
e841ca6
Merge branch 'dev' into DDS-1675-Alert-unit-email-instead-of-us-if-st…
rv0lt Dec 12, 2024
6fa6a9c
Merge branch 'dev' into DDS-1675-Alert-unit-email-instead-of-us-if-st…
rv0lt Dec 12, 2024
8357a8a
merge
rv0lt Dec 12, 2024
346424a
merge
rv0lt Dec 12, 2024
13bc6de
Update migrations/versions/0cd0a3b251e0_unit_contact_email_non_nullab…
rv0lt Dec 13, 2024
260b2e9
black
rv0lt Dec 13, 2024
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 SPRINTLOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -466,3 +466,4 @@ _Nothing merged during this sprint_
- Bugfix: Quick and dirty change to prevent `dds ls --tree` from failing systematically ([#1575](https://github.com/ScilifelabDataCentre/dds_web/pull/1575))
- Update backend Dockerfile to pin a fixed version of mariadb-client ([#1581](https://github.com/ScilifelabDataCentre/dds_web/pull/1581))
- Update documentation regarding 'Upload' or 'Download' added to end of delivery directory name depending on command ([#1580](https://github.com/ScilifelabDataCentre/dds_web/pull/1580))
- 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))
10 changes: 6 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,17 @@ def monitor_usage():
# Email if the unit is using more
if perc_used_decimal > warn_after:
# Email settings
unit_contact: str = unit.contact_email
i-oden marked this conversation as resolved.
Show resolved Hide resolved
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 (see details below).\n\n"
f"NB! If you would like to increase or decrease the allocated quota ('Quota') or the level after which you receive this email ('Warning level'), the technical contact person for your unit must send a request to {dds_contact}.\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 dds_web/database/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ class Unit(db.Model):
public_id = db.Column(db.String(50), unique=True, nullable=False)
name = db.Column(db.String(255), unique=True, nullable=False)
external_display_name = db.Column(db.String(255), unique=False, nullable=False)
contact_email = db.Column(db.String(255), unique=False, nullable=True)
contact_email = db.Column(db.String(255), unique=False, nullable=False)
internal_ref = db.Column(db.String(50), unique=True, nullable=False)

# Safespring storage
Expand Down
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
"""unit_contact_email_non_nullable

Revision ID: 0cd0a3b251e0
Revises: 3d610b382383
Create Date: 2024-12-03 10:51:34.143028

"""

from alembic import op
import sqlalchemy as sa
from sqlalchemy.dialects import mysql

# revision identifiers, used by Alembic.
revision = "0cd0a3b251e0"
down_revision = "3d610b382383"
branch_labels = None
depends_on = None


def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.execute(
"UPDATE units SET contact_email = '[email protected]' WHERE contact_email IS NULL"
)
rv0lt marked this conversation as resolved.
Show resolved Hide resolved
op.alter_column(
"units",
"contact_email",
existing_type=mysql.VARCHAR(length=255),
nullable=False,
server_default="[email protected]",
)
# ### end Alembic commands ###


def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.alter_column(
"units", "contact_email", existing_type=mysql.VARCHAR(length=255), nullable=True
)
# ### end Alembic commands ###
24 changes: 13 additions & 11 deletions tests/test_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -1432,19 +1432,21 @@ 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 "Your unit is approaching the allocated data quota" in err
assert f"Unit name: {unit.name}" in err
i += 1


# set_available_to_expired
Expand Down
Loading