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 experimental batch support #84

Merged
merged 19 commits into from
Jun 6, 2018
Merged

Add experimental batch support #84

merged 19 commits into from
Jun 6, 2018

Conversation

mrusu91
Copy link
Contributor

@mrusu91 mrusu91 commented Feb 20, 2018

No description provided.

@JaimeLennox
Copy link
Contributor

JaimeLennox commented Apr 2, 2018

@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.

@aschmolck
Copy link
Contributor

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.

mrusu91 added 3 commits June 4, 2018 21:20
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>
@JaimeLennox
Copy link
Contributor

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.

@aschmolck
Copy link
Contributor

aschmolck commented Jun 5, 2018

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: ---batch, noted above; I thought there was another in a commit message, but since I can't see it anymore, maybe I misremembered. There are a few very minor things in the code I would change (drop the or [] above if it's indeed spurious etc).

Tests: agreed.

api=self._api,
project_id=self._project.id,
params=params,
) or []
Copy link
Contributor

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?

Copy link
Contributor

Choose a reason for hiding this comment

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

Correct. Will fix.

self._api,
)
error_message = 'The {} changed whilst merging!'
if changed_mr.source_branch != merge_request.source_branch:
Copy link
Contributor

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('_', ' ')))

Copy link
Contributor

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):
Copy link
Contributor

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)

Copy link
Contributor

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):
Copy link
Contributor

Choose a reason for hiding this comment

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

lose this method?

Copy link
Contributor

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.

@@ -15,7 +15,7 @@
'WIP': 'Is marked as Work-In-Progress.',
Copy link
Contributor

Choose a reason for hiding this comment

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

@JaimeLennox squash please

Copy link
Contributor

Choose a reason for hiding this comment

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

👍

@@ -219,6 +219,8 @@ def execute(self):
batch_mr = self.create_batch_mr(
Copy link
Contributor

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).

Copy link
Contributor

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.

@@ -229,6 +229,8 @@ def execute(self):
continue
else:
Copy link
Contributor

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.

Copy link
Contributor

Choose a reason for hiding this comment

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

👍

@@ -1,3 +1,4 @@
# pylint: disable=too-many-branches,too-many-statements
import logging as log
Copy link
Contributor

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?

Copy link
Contributor

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.
Copy link
Contributor

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.

Copy link
Contributor

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

Copy link
Contributor

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

Copy link
Contributor

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.

Copy link
Contributor

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.

mrusu91 and others added 16 commits June 5, 2018 21:07
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.
@JaimeLennox
Copy link
Contributor

@aschmolck I've made the changes requested, including squashing the intermediate commits. Could you have another look and check everything is ok now?

@aschmolck aschmolck merged commit 2fd3ef3 into smarkets:master Jun 6, 2018
@aschmolck
Copy link
Contributor

@JaimeLennox great -- merged! Thanks, and sorry for the wait!

@JaimeLennox JaimeLennox mentioned this pull request Jul 18, 2018
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.

3 participants