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

DATAUP-530 Refactor to bulk insert #406

Merged
merged 33 commits into from
Aug 6, 2021
Merged

DATAUP-530 Refactor to bulk insert #406

merged 33 commits into from
Aug 6, 2021

Conversation

bio-boris
Copy link
Collaborator

@bio-boris bio-boris commented Jul 16, 2021

Description of PR purpose/changes

  • In favor of DATAUP-530 Multiple submissions #403
  • Use a mongoengine bulk create (with no limit on number of docs that can be written)
  • Use a pymongo bulk update job status
  • Change kafka creation message order
  • Batch submits via the bulk submit.

Testing Instructions

  • Deployed on CI

Dev Checklist:

  • My code follows the guidelines at https://sites.google.com/truss.works/kbasetruss/data-upload-project/development
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • Any dependent changes have been merged and published in downstream modules
  • I have run Black and Flake8 on changed Python Code manually or with git precommit (and the Github Actions build passes)

Updating Version and Release Notes (if applicable)

@bio-boris bio-boris requested a review from MrCreosote July 16, 2021 22:17
Copy link
Member

@MrCreosote MrCreosote left a comment

Choose a reason for hiding this comment

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

Mostly looks pretty reasonable. I have a few questions re error handling and some internal api suggestions

@MrCreosote
Copy link
Member

Oh, there's a couple of checklist things that aren't checked or marked as N/A, missed that

@bio-boris bio-boris requested a review from MrCreosote July 20, 2021 19:50
Copy link
Member

@MrCreosote MrCreosote left a comment

Choose a reason for hiding this comment

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

Couple questions on the new stuff

Copy link
Member

@MrCreosote MrCreosote left a comment

Choose a reason for hiding this comment

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

couple questions on the new stuff

@MrCreosote
Copy link
Member

Well that's weird, not quite sure what happened there

@bio-boris bio-boris requested a review from MrCreosote July 22, 2021 22:34
Copy link
Member

@MrCreosote MrCreosote left a comment

Choose a reason for hiding this comment

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

Taking a look at the newer changes

@bio-boris bio-boris requested review from MrCreosote and removed request for MrCreosote August 2, 2021 19:58
@bio-boris
Copy link
Collaborator Author

Working on tests and coverage

@lgtm-com
Copy link

lgtm-com bot commented Aug 2, 2021

This pull request introduces 1 alert when merging 9be3578 into 3150622 - view on LGTM.com

new alerts:

  • 1 for Unused import

except Exception as e:
logging.info(
logging.error(
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Removed extra info from logs

@@ -29,7 +29,7 @@ def setUpClass(cls):

def test_status_change(self):

with self.assertRaisesRegexp(
with self.assertRaisesRegex(
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

fixing warning

@@ -334,7 +334,7 @@ def test_retry_job_multiple(self, rq_mock, condor_mock):
"'123' is not a valid ObjectId, it must be a 12-byte input or a 24-character "
"hex string"
)
with self.assertRaisesRegexp(RetryFailureException, errmsg):
with self.assertRaisesRegex(RetryFailureException, errmsg):
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

fixing warning

from lib.execution_engine2.exceptions import InvalidStatusTransitionException
from lib.execution_engine2.sdk.SDKMethodRunner import SDKMethodRunner
from lib.execution_engine2.utils.CondorTuples import SubmissionInfo
from execution_engine2.db.models.models import Job, Status, TerminatedCode
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

fixing imports

Copy link
Member

@MrCreosote MrCreosote left a comment

Choose a reason for hiding this comment

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

code seems fine but the tests aren't passing, so I assume there's more work there to do and haven't looked at them yet

@bio-boris
Copy link
Collaborator Author

Tests are done, not sure why that one failed all of a sudden on github actions. It's been failing locally on my machine for months but not on github actions. It was a bad test because the underlying functionality is actually wrong and the test is flaky depending on where you run it

@bio-boris bio-boris requested a review from MrCreosote August 3, 2021 03:41
@MrCreosote
Copy link
Member

Interesting, the tests passed consistently on my machine when I was doing ee2 work.

@MrCreosote
Copy link
Member

MrCreosote commented Aug 4, 2021

Note to self: New behaviors are

  1. Batch jobs are saved via SDKMR.save_jobs vs save_job (calling MongoUtil.insert_jobs)
  2. Batch jobs are set to updated by MongoUtil.update_jobs_to_queued
  3. Any batch jobs canceled prior to the update in 2) have SDKMR.cancel_job called on them
  4. Parent job is updated with child jobs via SDKMR.add_child_jobs

@MrCreosote
Copy link
Member

Further note to self: there are API to DB integration tests that exercise run_batch which pass without changes, which is reassuring

Copy link
Member

@MrCreosote MrCreosote left a comment

Choose a reason for hiding this comment

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

Looks good, just a few minor changes and some unit tests that I think should be pretty easy

@@ -420,6 +486,18 @@ def update_job_status(self, job_id, status, msg=None, error_message=None):
def mongo_engine_connection(self):
yield self.me_connection

def insert_jobs(self, jobs_to_insert: List[Job]) -> List[ObjectId]:
"""
Copy link
Member

Choose a reason for hiding this comment

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

There aren't any unit tests for this function

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Ok, wrote a basic test

Copy link
Member

Choose a reason for hiding this comment

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

It tests that the method returns job IDs, but not that the jobs are actually correctly inserted to the DB. If this were me writing the tests I'd retrieve the jobs either via the MongoUtil API or directly from mongo and ensure the data was what I expected

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Alright, added that, but not quite sure if that's what you had in mind

Copy link
Member

Choose a reason for hiding this comment

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

it is, except the problem is that equality on Job objects only tests the _id, not any other fields. So the insert method could completely trash the incoming Job object and save it and the test will still pass. I'd update to use the assert_job_equal method from EE2RunJob_test.py (maybe that should be moved to a utility class at some point)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Alright well how about using

        for i, retrieved_job in enumerate(retrieved_jobs):
            assert jobs_to_insert[i].to_json() == retrieved_job.to_json()
            assert jobs_to_insert[i].to_mongo() == retrieved_job.to_mongo()
            assert jobs_to_insert[i].to_dbref() == retrieved_job.to_dbref()

Copy link
Member

Choose a reason for hiding this comment

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

Seems reasonable

Copy link
Collaborator Author

@bio-boris bio-boris Aug 6, 2021

Choose a reason for hiding this comment

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

Bah, realized that the modify command isn't updating the "updated" timestamp

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Added this test in a new PR #416

@bio-boris bio-boris requested a review from MrCreosote August 6, 2021 17:37
@bio-boris bio-boris added this to the Post-GSP-Release milestone Aug 6, 2021
Copy link
Member

@MrCreosote MrCreosote left a comment

Choose a reason for hiding this comment

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

LGTM

@bio-boris bio-boris merged commit 8ee6c0b into develop Aug 6, 2021
@bio-boris bio-boris deleted the multiple_inserts branch August 6, 2021 21:49
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.

2 participants