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

Fixes #3697 - Save classification result to elasticsearch db #3701

Merged
merged 1 commit into from
Jun 1, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions config/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,10 @@ def get_variation(variation_key, variations_dict, defaults_dict):
# See /docs/ab-testing.md for configuration instructions
AB_EXPERIMENTS = {}

ES_LOG_ENABLED = False

if PRODUCTION:
ES_LOG_ENABLED = True

from webcompat import app # noqa

Expand Down
10 changes: 10 additions & 0 deletions config/environment.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@
BUGBUG_HTTP_SERVER = "https://bugbug.herokuapp.com"
CLASSIFIER_PATH = "needsdiagnosis/predict/github/webcompat/web-bugs-private" # noqa
AUTOCLOSED_MILESTONE_ID = 15
ES_URL = os.environ.get('ES_URL')
ES_API_KEY_ID = os.environ.get('ES_API_KEY_ID')
ES_API_KEY = os.environ.get('ES_API_KEY')

if STAGING:
GITHUB_CLIENT_ID = os.environ.get('STAGING_GITHUB_CLIENT_ID')
Expand All @@ -61,6 +64,10 @@
BUGBUG_HTTP_SERVER = "https://bugbug.herokuapp.com"
CLASSIFIER_PATH = "needsdiagnosis/predict/github/webcompat/webcompat-tests-private" # noqa
AUTOCLOSED_MILESTONE_ID = 5
ES_URL = os.environ.get('ES_URL')
ES_API_KEY_ID = os.environ.get('ES_API_KEY_ID')
ES_API_KEY = os.environ.get('ES_API_KEY')


if LOCALHOST:
# for now we are using .env only on localhost
Expand All @@ -85,6 +92,9 @@
BUGBUG_HTTP_SERVER = "http://0.0.0.0:8000"
CLASSIFIER_PATH = "needsdiagnosis/predict/github/webcompat/webcompat-tests-private" # noqa
AUTOCLOSED_MILESTONE_ID = 5
ES_URL = os.environ.get('ES_URL')
ES_API_KEY_ID = os.environ.get('ES_API_KEY_ID')
ES_API_KEY = os.environ.get('ES_API_KEY')

# BUG STATUS
# The id will be initialized when the app is started.
Expand Down
1 change: 1 addition & 0 deletions config/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
blinker==1.4
elasticsearch==8.2.0
Flask==2.0.1
Flask-Firehose==0.2.3
Flask-Limiter==1.4
Expand Down
26 changes: 26 additions & 0 deletions webcompat/webhooks/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@

from dataclasses import dataclass
from typing import List
from datetime import datetime
from elasticsearch import Elasticsearch

from requests.exceptions import HTTPError, ConnectionError

Expand All @@ -29,6 +31,15 @@
AUTOCLOSED_MILESTONE_ID = app.config['AUTOCLOSED_MILESTONE_ID']
THRESHOLD = 0.97

if app.config['ES_LOG_ENABLED']:
ES = Elasticsearch(
app.config['ES_URL'],
api_key=(
app.config['ES_API_KEY_ID'],
app.config['ES_API_KEY']
)
)


@dataclass
class WebHookIssue:
Expand Down Expand Up @@ -267,6 +278,21 @@ def classify(self):
payload_request = {'milestone': AUTOCLOSED_MILESTONE_ID}
make_request('patch', path, payload_request)

if app.config['ES_LOG_ENABLED']:
# save prediction result to ES
doc = {
"issue": int(self.number),
"issue_url": self.html_url,
"predicted_at": datetime.now(),
"prediction": data,
}

ES.index(
index="bugbug_predictions",
id=int(self.number),
body=doc,
)

def add_bugbug_tracking_label(self, label_name):
payload = {'labels': [label_name]}
path = f'repos/{PUBLIC_REPO}/{self.number}/labels'
Expand Down