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

Issue #3571: Use bugbug to classify issues #3573

Merged
merged 2 commits into from
May 19, 2021
Merged

Issue #3571: Use bugbug to classify issues #3573

merged 2 commits into from
May 19, 2021

Conversation

ksy36
Copy link
Contributor

@ksy36 ksy36 commented May 17, 2021

This PR fixes issue #3571

@ksy36 ksy36 marked this pull request as ready for review May 18, 2021 00:04
@ksy36
Copy link
Contributor Author

ksy36 commented May 18, 2021

r? @karlcow

Copy link
Member

@karlcow karlcow left a comment

Choose a reason for hiding this comment

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

thanks @ksy36
Super good progress in there.
Some comments to fix, some things to remove.
And a couple of questions to better understand.

config/environment.py Show resolved Hide resolved
tests/unit/test_webhook.py Outdated Show resolved Hide resolved
@@ -455,6 +455,13 @@ def test_prepare_rejected_issue(self):
self.assertEqual(type(actual), dict)
self.assertEqual(actual, expected)

@patch('webcompat.webhooks.helpers.make_classification_request')
def test_get_issue_classification(self, mock_classification):
"""Test that api is called only once with response code is 200."""
Copy link
Member

Choose a reason for hiding this comment

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

What is happening if it's called more than once?
Does it fail? Can't happen?

Copy link
Contributor Author

@ksy36 ksy36 May 18, 2021

Choose a reason for hiding this comment

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

It's making sure that if we receive a 200 status, make_classification_request is not called again.

So basically classification in bugbug is asynchronous, the first request submits an issue for classification (in response we get 202 as the result is not ready yet) and we need to make a second one to get the results (and we get 200).
This needs another test to test the above ^, but I'm not sure how to do it with a mock:

1 request -> 202
2 request -> 200
assert that mock_classification called twice

@@ -76,7 +76,7 @@ def test_model_instance():
@patch('webcompat.webhooks.model.make_request')
def test_close_private_issue(mock_mr):
"""Test issue state and API request that is sent to GitHub."""
mock_mr.return_value.status_code == 200
mock_mr.return_value.status_code = 200
Copy link
Member

Choose a reason for hiding this comment

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

So good to have caught this. Now I'm worried… because it doesn't change anything. I wonder what was the value then and how it would modify the test or not. Let's see.

Old:

tests/unit/test_webhook_model.py::test_close_private_issue <MagicMock name='make_request().status_code' id='4363956624'>
PASSED

New:

tests/unit/test_webhook_model.py::test_close_private_issue 200
PASSED

ok definitely wrong.

After removing them, everything is still passing.
So we don't test the status code in any ways.

I think we can safely remove all instances of mock_mr.return_value.status_code = 200

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah I was thinking that too :) I'll remove them

@@ -230,3 +234,35 @@ def prepare_rejected_issue():
payload_request['state'] = 'closed'
payload_request['milestone'] = invalid_id
return payload_request


def make_classification_request(issue_number):
Copy link
Member

Choose a reason for hiding this comment

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

I wonder if we should put the classification functions in a new file: webcompat/webhooks/ml.py?

Just in case in the future, it grows with more functions so we do not end up with a helpers being huge. Maybe it doesn't matter. Opinions?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, probably a good idea, I'll move it

@@ -230,3 +234,35 @@ def prepare_rejected_issue():
payload_request['state'] = 'closed'
payload_request['milestone'] = invalid_id
return payload_request


def make_classification_request(issue_number):
Copy link
Member

Choose a reason for hiding this comment

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

nit: Missing docstring

Comment on lines 259 to 262
if response.status_code == 202:
time.sleep(retry_sleep)
else:
break
Copy link
Member

Choose a reason for hiding this comment

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

202 code in this code is a wait instruction. aka the response is not ready.
200 and 4** and 500 will be treated the same.

Is it what we want?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, this code will basically keep retrying if the status is 202 up to a certain limit. If it's 200, 4** or 500, we don't need to retry. And in case of 4** or 500 the error will be raised in make_classification_request

else:
total_sleep = retry_count * retry_sleep
msg = f"Couldn't classify issue {issue_number} in {total_sleep} seconds, aborting" # noqa
raise Exception(msg)
Copy link
Member

Choose a reason for hiding this comment

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

we need a test for this, aka when there's a failure.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added a test in test_webhook.py 👍

webcompat/webhooks/model.py Show resolved Hide resolved
webcompat/webhooks/model.py Show resolved Hide resolved
@ksy36
Copy link
Contributor Author

ksy36 commented May 19, 2021

I've pushed the fixes, could you please take another look @karlcow?

Copy link
Member

@karlcow karlcow left a comment

Choose a reason for hiding this comment

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

Thanks @ksy36
This is good to go. Let's deploy it.

@karlcow karlcow merged commit fbe2cb9 into master May 19, 2021
@karlcow karlcow deleted the issue/3571/1 branch May 19, 2021 05:11
@karlcow karlcow linked an issue May 19, 2021 that may be closed by this pull request
@ksy36
Copy link
Contributor Author

ksy36 commented May 19, 2021

Thanks!

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.

Use bugbug to classify issues that are coming to web-bugs-private
2 participants