diff --git a/config/__init__.py b/config/__init__.py index f44eefaa7..a66846f5f 100644 --- a/config/__init__.py +++ b/config/__init__.py @@ -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 diff --git a/config/environment.py b/config/environment.py index e3129148e..ee707e9dc 100644 --- a/config/environment.py +++ b/config/environment.py @@ -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') @@ -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 @@ -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. diff --git a/config/requirements.txt b/config/requirements.txt index c12340fe7..3c7d1ab64 100644 --- a/config/requirements.txt +++ b/config/requirements.txt @@ -1,4 +1,5 @@ blinker==1.4 +elasticsearch==8.2.0 Flask==2.0.1 Flask-Firehose==0.2.3 Flask-Limiter==1.4 diff --git a/webcompat/webhooks/model.py b/webcompat/webhooks/model.py index 64d1de039..c0de1263b 100644 --- a/webcompat/webhooks/model.py +++ b/webcompat/webhooks/model.py @@ -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 @@ -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: @@ -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'