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

Add all expid_dir_path functions to autosubmit.py, add attached files to emails #1997

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

kinow
Copy link
Member

@kinow kinow commented Dec 13, 2024

In GitLab by @isimo00 on Nov 5, 2024, 12:27

All previous definitions all expid_path, tmp_path, log_path and aslogs_path (and similar) have been removed and their calls have been switched for BasicConfig.foo() calls. Impacted tests are mainly affected in terms of adding Mock objects since BasicConfig.foo() functions are not available in autosubmitconfigparser yet. No new tests added.

  • Resolve merging conflicts
  • Remove mocked tests and use testing from latest configparser commit until new version is launched

@kinow kinow added this to the Autosubmit 4.1.12 milestone Dec 13, 2024
@kinow
Copy link
Member Author

kinow commented Dec 13, 2024

In GitLab by @isimo00 on Nov 5, 2024, 12:27

requested review from @kinow

@kinow
Copy link
Member Author

kinow commented Dec 13, 2024

In GitLab by @isimo00 on Nov 5, 2024, 12:27

requested review from @dbeltrankyl and removed review request for @kinow

@kinow
Copy link
Member Author

kinow commented Dec 13, 2024

In GitLab by @isimo00 on Nov 5, 2024, 12:49

mentioned in commit 4eec259671daf0dcadb2454ac58c7a91dd9b5afe

@kinow
Copy link
Member Author

kinow commented Dec 13, 2024

In GitLab by @isimo00 on Nov 5, 2024, 12:49

added 9 commits

  • 1dbf37a0...7a32f96f - 6 commits from branch master
  • 4eec2596 - Add all expid_dir_path functions to autosubmit.py and fix tests !509
  • daeeaf8f - Add expid paths to error notifications Possible bug in STATUS: RUNNING dependencies #1435
  • af6e9e63 - Merge branch 'iss1435' of https://earth.bsc.es/gitlab/es/autosubmit into iss1435

Compare with previous version

@kinow
Copy link
Member Author

kinow commented Dec 13, 2024

In GitLab by @dbeltrankyl on Nov 5, 2024, 12:54

Commented on autosubmit/notifications/mail_notifier.py line 76

Hello @isimo00,

Thanks for working on it!

I think it should point directly to the exact err and exact out instead of the folder.

Maybe.. we can attach the logs in the mail itself? and/or point to the specific log in GUI? As it can be easily read ( the latter, not sure how to do it without hardcore it FYI @LuiggiTenorioK )

what do you think?

@kinow
Copy link
Member Author

kinow commented Dec 13, 2024

In GitLab by @isimo00 on Nov 5, 2024, 12:58

marked the checklist item Resolve merging conflicts as completed

@kinow
Copy link
Member Author

kinow commented Dec 13, 2024

In GitLab by @dbeltrankyl on Nov 5, 2024, 12:58

Commented on test/unit/conftest.py line 68

Hello,

Why the change of / per os.path.join? / is used for Path() objects

Maybe we can use Path().joinpath() if you find that / is not readable enough instead of using two different libs

FYI @kinow

@kinow
Copy link
Member Author

kinow commented Dec 13, 2024

In GitLab by @dbeltrankyl on Nov 5, 2024, 12:58

Commented on test/unit/conftest.py line 68

In general, I think that @kinow recommended using Path for all ( per example, os.path.exists -> Path().exists() ) , os.makedirs -> Path().mkdir(Parents=True,exists_ok=True) ( didn't double check the syntax) )

edit: There are other similar cases across the changes

@kinow
Copy link
Member Author

kinow commented Dec 13, 2024

In GitLab by @dbeltrankyl on Nov 5, 2024, 13:04

Commented on test/unit/conftest.py line 197

Can we use the mocker fixture there?

Instead of using

from unittest import mock

@kinow
Copy link
Member Author

kinow commented Dec 13, 2024

In GitLab by @isimo00 on Nov 5, 2024, 13:04

Commented on test/unit/conftest.py line 68

The functions added here (e.g. aslogs_dir = BasicConfig.aslog_dir_mock(expid) in line 50) return str objects created with os.path.join() - see commit in configparser -. I didn't give it much thought and carried on with str instead of PosixPath objects when possible. All of them could be switched back to Path

@kinow
Copy link
Member Author

kinow commented Dec 13, 2024

In GitLab by @dbeltrankyl on Nov 5, 2024, 13:06

Thanks @isimo00!

I comment in one stuff to change ( maybe)

and commented on some stuff about the tests. I think we should agree on what to use for the Paths with @kinow , @LuiggiTenorioK mainly to normalize the code

@kinow
Copy link
Member Author

kinow commented Dec 13, 2024

In GitLab by @isimo00 on Nov 5, 2024, 13:06

Commented on autosubmit/notifications/mail_notifier.py line 76

You mean adding/pasting the content of the log files in the mail?

@kinow
Copy link
Member Author

kinow commented Dec 13, 2024

In GitLab by @dbeltrankyl on Nov 5, 2024, 13:15

Commented on autosubmit/notifications/mail_notifier.py line 76

I mean:

  • Point to the final err ( $expid/tmp/Log_$expid/$job_name....err) ( and out)
  • Adding it as an attached file ( see the screenshot ) (perhaps we can compress it before adding it )

image

@kinow
Copy link
Member Author

kinow commented Dec 13, 2024

In GitLab by @LuiggiTenorioK on Nov 5, 2024, 13:34

Commented on autosubmit/notifications/mail_notifier.py line 76

Maybe.. we can attach the logs in the mail itself? and/or point to the specific log in GUI? As it can be easily read ( the latter, not sure how to do it without hardcore it FYI @LuiggiTenorioK )

The GUI shows the latest {expid}/tmp/ASLOGS/****_run.log file. Then, you'll have to append the log into that file if you want to show it.

@kinow
Copy link
Member Author

kinow commented Dec 13, 2024

In GitLab by @LuiggiTenorioK on Nov 5, 2024, 13:38

and commented on some stuff about the tests. I think we should agree on what to use for the Paths with @kinow , @LuiggiTenorioK mainly to normalize the code

Agree that using pathlib is better than os.path since is a newer implementation based on OOP and has more options. However, I do find using / less readable than os.path.join so maybe we should use its pathlib equivalent (Path(...).joinpath()) instead.

@kinow
Copy link
Member Author

kinow commented Dec 13, 2024

In GitLab by @isimo00 on Nov 5, 2024, 14:35

Started switching back to pathlib in configparser - github's pull request num. 51 - with Path(...).joinpath(). Will extend to autosubmit.

@kinow
Copy link
Member Author

kinow commented Dec 13, 2024

In GitLab by @isimo00 on Nov 5, 2024, 15:33

mentioned in commit 867e93ff52b3583772ea6e97371c5dabf5619ea0

@kinow
Copy link
Member Author

kinow commented Dec 13, 2024

In GitLab by @isimo00 on Nov 5, 2024, 15:33

added 1 commit

Compare with previous version

@kinow
Copy link
Member Author

kinow commented Dec 13, 2024

In GitLab by @isimo00 on Nov 5, 2024, 15:47

Commented on test/unit/conftest.py line 197

changed this line in version 4 of the diff

@kinow
Copy link
Member Author

kinow commented Dec 13, 2024

In GitLab by @isimo00 on Nov 5, 2024, 15:47

added 1 commit

  • 298b0cda - Use mocker instead of mock from unittest

Compare with previous version

@kinow
Copy link
Member Author

kinow commented Dec 13, 2024

In GitLab by @isimo00 on Nov 5, 2024, 15:55

Commented on test/unit/conftest.py line 68

changed this line in version 5 of the diff

@kinow
Copy link
Member Author

kinow commented Dec 13, 2024

In GitLab by @isimo00 on Nov 5, 2024, 15:55

added 1 commit

  • 1ac2fe49 - Fix forgotten Path

Compare with previous version

@kinow
Copy link
Member Author

kinow commented Dec 13, 2024

In GitLab by @kinow on Nov 6, 2024, 10:13

Commented on autosubmit/notifications/mail_notifier.py line 76

Not reviewing this one, just going through inbox emails... but maybe we could use a single f-string multiline text without concatenation?

Instead of

  f'some string {vars} \n\n' \
  + f'another string being concatenated {vars} \n etc'

I think this should work too?

f'''some string {vars} \n\n
more text {vars}
etc'''

@kinow
Copy link
Member Author

kinow commented Dec 13, 2024

In GitLab by @isimo00 on Nov 26, 2024, 13:18

Commented on autosubmit/notifications/mail_notifier.py line 76

changed this line in version 6 of the diff

@kinow
Copy link
Member Author

kinow commented Dec 13, 2024

In GitLab by @isimo00 on Nov 26, 2024, 13:18

added 1 commit

  • 0dab1606 - Add log file attached to mail message

Compare with previous version

@kinow
Copy link
Member Author

kinow commented Dec 13, 2024

In GitLab by @isimo00 on Dec 4, 2024, 11:46

added 1 commit

  • a776f65c - Fix message text

Compare with previous version

@kinow
Copy link
Member Author

kinow commented Dec 13, 2024

In GitLab by @isimo00 on Dec 5, 2024, 10:46

mentioned in commit df8c557e5713428f0c8e1afca942081ed958e55e

@kinow
Copy link
Member Author

kinow commented Dec 13, 2024

In GitLab by @isimo00 on Dec 5, 2024, 10:46

added 1 commit

Compare with previous version

@kinow
Copy link
Member Author

kinow commented Dec 19, 2024

Maybe we can split it, and leave the pathlib/os.path/BasicConfig changes in the other PR... then this one just adds the email thingy.

@isimo00 isimo00 changed the title Draft: Add all expid_dir_path functions to autosubmit.py and fix tests Add all expid_dir_path functions to autosubmit.py, add attached files to emails Dec 20, 2024
@isimo00
Copy link

isimo00 commented Dec 20, 2024

@kinow For some reason I can't tag you as a reviewer, but this is finally done now!

@isimo00 isimo00 removed the working on Someone is working on it label Dec 20, 2024
@isimo00 isimo00 mentioned this pull request Dec 20, 2024
12 tasks
@kinow
Copy link
Member Author

kinow commented Dec 20, 2024

@kinow For some reason I can't tag you as a reviewer, but this is finally done now!

It's because I'm the creator of this pull request (due to how the migration script works -- it uses the migration user in the GitHub API calls, as owner).

@isimo00
Copy link

isimo00 commented Dec 20, 2024

Ah I see. Well @kinow , let me know if you think something else is missing / you can't review it or I can tag Luiggi :)

Copy link
Member Author

@kinow kinow left a comment

Choose a reason for hiding this comment

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

@isimo00 reviewed most of the changes, pending just mail_notifier.py now (:coffee: break)

test/unit/conftest.py Show resolved Hide resolved
test/unit/conftest.py Show resolved Hide resolved
test/unit/conftest.py Show resolved Hide resolved
test/unit/conftest.py Show resolved Hide resolved
test/unit/test_catlog.py Show resolved Hide resolved
test/unit/test_describe.py Show resolved Hide resolved
test/unit/test_describe.py Show resolved Hide resolved
test/unit/test_describe.py Show resolved Hide resolved
test/unit/test_describe.py Show resolved Hide resolved
test/unit/test_mail.py Show resolved Hide resolved
autosubmit/notifications/mail_notifier.py Show resolved Hide resolved
autosubmit/notifications/mail_notifier.py Show resolved Hide resolved
autosubmit/notifications/mail_notifier.py Show resolved Hide resolved
autosubmit/notifications/mail_notifier.py Show resolved Hide resolved

class MailNotifier:
def __init__(self, basic_config):
self.config = basic_config

def notify_experiment_status(self, exp_id,mail_to,platform):
message_text = self._generate_message_experiment_status(exp_id, platform)
message = MIMEText(message_text)
message = MIMEMultipart()
Copy link
Member Author

Choose a reason for hiding this comment

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

We need to confirm if this is the best option. I remember the discussion, but I didn't have time to ponder about it, sorry.

@mcastril, here we have a few options, basically,

  1. we send a notification as we already do, but include the location of the logs in the VM/hub/somewhere
  2. we attach the complete log as-is into the email body
  3. we compress and then attach the logs (and delete the compressed archive as the original logs will remain anyway) into the email body

I think I am more included towards 1) to simplify or a 1.5) option, where we let users choose whether they want the location or the attachment, but I had seen a comment about doing the option 2), which is implemented here.

WDYT, Miguel?

Copy link
Member Author

Choose a reason for hiding this comment

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

@isimo00 from today's AS meeting:

  • Let's compress the file by default
  • We don't have to worry about extremely large files as we are only attaching _run logs (shouldn't be in the GB, mayyyybe MB, more likely b/kb)
  • I will create separate issues for toggle/flags that disable attachment or restrict the attachment size 👍

So if you add the compression here by default, we can review & merge it :-)

Copy link
Member Author

Choose a reason for hiding this comment

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

Added to 4.1.13 backlog, #2050

autosubmit/notifications/mail_notifier.py Outdated Show resolved Hide resolved
autosubmit/notifications/mail_notifier.py Outdated Show resolved Hide resolved
autosubmit/notifications/mail_notifier.py Show resolved Hide resolved
@isimo00
Copy link

isimo00 commented Dec 20, 2024

Thank you for the extensive review @kinow! I've taken it as a sign to finally start using pylint and autopep8. I've marked as resolved the comments for which I've already followed your suggestions so far, will continue on Monday :)

@kinow
Copy link
Member Author

kinow commented Dec 20, 2024

Thank you for the extensive review @kinow! I've taken it as a sign to finally start using pylint and autopep8. I've marked as resolved the comments for which I've already followed your suggestions so far, will continue on Monday :)

I think Luiggi is using Ruff. In the end, these tools in Python tend to follow more or less the same set of rules, based on pep8 (normally pep8 is a subset of all lint rules, as these tools add more on top of it). So that's a good start! But maybe check with Luiggi if it would be better if you used ruff too. This is up to discussion too, but ruff is also used in other BSC projects (and DestinE workflow, GSV, etc.) so there is a good case for us to use that too.

And thank you for the great PR with tests, and for splitting the change in the pathlib that would require more test coverage.

Copy link
Member Author

@kinow kinow left a comment

Choose a reason for hiding this comment

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

Finished reviewing it, @isimo00 . I think we can wait for others (especially Miguel) to have time to review the part about attaching logs to the email body. But otherwise the code looks good to me. I added a couple of comments now after reading it one last time. The part about BaseException was already in the code, but maybe we can improve it here. Thanks!!

autosubmit/notifications/mail_notifier.py Show resolved Hide resolved
test/unit/conftest.py Outdated Show resolved Hide resolved
test/unit/test_job_pytest.py Outdated Show resolved Hide resolved
autosubmit/notifications/mail_notifier.py Outdated Show resolved Hide resolved
test/unit/test_mail.py Show resolved Hide resolved
Copy link
Member Author

@kinow kinow left a comment

Choose a reason for hiding this comment

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

There are some changes appearing here that I am not sure if they were part of your initial change. Maybe something went wrong rebasing?

There are also some conflicts...

image

@isimo00
Copy link

isimo00 commented Dec 27, 2024

I noticed that too and undid the rebase, thanks @kinow !

@kinow
Copy link
Member Author

kinow commented Dec 27, 2024

Great! @LuiggiTenorioK merged the PR that fixes the rocrate tests. I think if you rebase it (assuming your rebase was done earlier) that should fix the build here 🤞

All previous definitions all expid_path, tmp_path, log_path and
aslogs_path (and similar) have been removed and their calls have been
switched for BasicConfig.foo() calls. Impacted tests are mainly affected
in terms of adding Mock objects since BasicConfig.foo() functions are
not available in autosubmitconfigparser yet. No new tests added
@isimo00
Copy link

isimo00 commented Jan 10, 2025

@kinow I believe this is ready to merge, if you'd like to do a final revision I'll be checking the issue for further comments

@kinow
Copy link
Member Author

kinow commented Jan 10, 2025

@kinow I believe this is ready to merge, if you'd like to do a final revision I'll be checking the issue for further comments

Excellent @isimo00 ! I'm leaving it unread in my GH notifications, planning to review it next Monday! 💪

Thank you!

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.

4 participants