-
Notifications
You must be signed in to change notification settings - Fork 136
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 experimental batch support #84
Conversation
@aschmolck I'm reasonably happy with the state of this now. There's quite a major refactor involved here, in order to keep as much functionality as possible between the regular job and the batch job. As such, the tests have been shuffled around quite a lot too. I'm not entirely happy with the state of the batch job tests, as there are some core tests missing here, but to be honest I do find the mock API setup a bit confusing and I think it'd be nicer to get this merged and improve on that later, especially as this functionality is considered experimental for now. |
Generally looks great! Just needs a minor bit of cleanup (history, a typo here and there, that sort of thing). Only real nit is that I'd personally prefer is fewer uses of Mocks (I think the state machine approach of Mocklab is nicer), but that won't stand in the way of merging it. |
Signed-off-by: Marian.Rusu <rusumarian91@gmail.com>
Will be needed by batch merge job Signed-off-by: Marian.Rusu <rusumarian91@gmail.com>
Make some things reusable in preparation for batch job Signed-off-by: Marian.Rusu <rusumarian91@gmail.com>
Rebased. What are the typos you want me to fix? Regarding the history, I actually think the commits are separate enough to warrant the number, unless you want a big super-commit - but seeing as the big refactor is halfway through, I'm not sure this makes sense. If you have any suggestions for commits to squash I'd appreciate it. I agree that using the state machine would've been the nicest approach, but I had a hard time getting my head around it. This was the easier method, for now, and we can probably work towards improving the tests later. |
Super-commit: I fully agree that it's not desirable to squash the mid-way refactoring nor the refinements such as the job cancellation or the modification to the batching logic away, just intermediate fixups to these (fix tests; rebase fixes etc). I have annotated the individual commits that I think are candidates. Typos: Tests: agreed. |
marge/batch_job.py
Outdated
api=self._api, | ||
project_id=self._project.id, | ||
params=params, | ||
) or [] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it looks to me like the or []
is bogus, correct?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Correct. Will fix.
marge/batch_job.py
Outdated
self._api, | ||
) | ||
error_message = 'The {} changed whilst merging!' | ||
if changed_mr.source_branch != merge_request.source_branch: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd be tempted to condense this down to:
for attr in 'source_branch source_project_id target_branch target_project_id sha'.split():
if getattr(changed_mr, attr) != getattr(merge_request, attr):
raise CannotMerge(error_message.format(attr.replace('_', ' ')))
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
marge/git.py
Outdated
def checkout_branch(self, branch, start_point=''): | ||
self.git('checkout', '-B', branch, start_point, '--') | ||
|
||
def push(self, branch, source_repo_url=None, force=False): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd change signature to:
def push(self, branch, *, source_repo_url=None, force=False):
(esp. since force is risky)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
marge/git.py
Outdated
force_flag = '--force' if force else '' | ||
self.git('push', force_flag, source, '%s:%s' % (branch, branch)) | ||
|
||
def push_force(self, branch, source_repo_url=None): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lose this method?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep, not sure why it really existed in the first place.
marge/batch_job.py
Outdated
@@ -15,7 +15,7 @@ | |||
'WIP': 'Is marked as Work-In-Progress.', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@JaimeLennox squash please
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
marge/batch_job.py
Outdated
@@ -219,6 +219,8 @@ def execute(self): | |||
batch_mr = self.create_batch_mr( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@JaimeLennox can't comment on previous commit, since no changes other than rename, but I think it should be squashed (the previous rename commit).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thought it better to leave a rename commit as separate, as not to mess with the history too much (and to make it easier to git blame
in the future.
marge/batch_job.py
Outdated
@@ -229,6 +229,8 @@ def execute(self): | |||
continue | |||
else: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This belongs to your try to continue batching as many as possible, right? If so, I think it should be squashed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
marge/batch_job.py
Outdated
@@ -1,3 +1,4 @@ | |||
# pylint: disable=too-many-branches,too-many-statements | |||
import logging as log |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@JaimeLennox Nice! Maybe squash into refactor commit?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
README.md
Outdated
@@ -105,6 +105,8 @@ optional arguments: | |||
[env var: MARGE_BRANCH_REGEXP] (default: .*) | |||
--debug Debug logging (includes all HTTP requests etc). | |||
[env var: MARGE_DEBUG] (default: False) | |||
---batch Enable processing MRs in batches. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
s/---batch/--batch/
, spacing looks off.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
@@ -5,7 +5,6 @@ | |||
from datetime import datetime, timedelta | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@JaimeLennox would be nice to squash this PR
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I appear to have lost which commit this refers to.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually, if this was a reference to the "rebase fixes" commit, then I've since squashed that.
This is an attempt to make marge-bot faster by batching MRs Signed-off-by: Marian.Rusu <rusumarian91@gmail.com>
MergeJob now has as much common functionality as possible.
With batches we do a lot of work with local branches, and don't always want to use the remote branch.
We'd previously fail the batch job and start a regular job if any merge requests failed on rebasing. Instead, we can skip that one and continue with the rest. This way only the failing job is removed from the batch. If there's not enough merge jobs for the batch then we'll continue with a regular job as usual.
This gives visibility into the process and means people have a better idea if their MR is being handled.
Due to the way we update merge requests in a batch before pushing to master, extra pipelines will be triggered for each of these. We should try to cancel them to avoid extra work.
* Rename the group to make it clearer these are experimental features. * Rename --experimental-batch to --batch. The help message marks it as experimental instead, which is consistent with the --add-merge-strategy option. Note that putting the batch option in this group means the merge strategy can't be used with batching. There doesn't seem to be a good way of using the same argument in different mutually exclusive groups, and this seems acceptable for now given they are both experimental features.
This includes an explanation of the current implementation for batch jobs, along with some limitations.
The pipeline doesn't appear immediately, and so it's likely we'll hit the assertion error. Instead, we can wait for the first pipeline fetched to match our commit sha.
@aschmolck I've made the changes requested, including squashing the intermediate commits. Could you have another look and check everything is ok now? |
@JaimeLennox great -- merged! Thanks, and sorry for the wait! |
No description provided.