diff --git a/Makefile b/Makefile index 688b756..7cc93d1 100644 --- a/Makefile +++ b/Makefile @@ -67,13 +67,13 @@ oc_delete_model_test: | oc delete -f - run_app_pipenv: - pipenv run python app.py + pipenv run python3 app.py run_test_pipenv: - pipenv run python test_model.py + pipenv run python3 test_model.py run_app: - python app.py + python3 app.py run_test: - python test_model.py + python3 test_model.py diff --git a/app.py b/app.py index 9f294cf..a2b7ba2 100644 --- a/app.py +++ b/app.py @@ -14,6 +14,8 @@ from configuration import Configuration import model import schedule +import threading + # Set up logging _LOGGER = logging.getLogger(__name__) @@ -29,6 +31,8 @@ headers=Configuration.prom_connect_headers, disable_ssl=True, ) +# print("hiiii") +# print(Configuration.prom_connect_headers) for metric in METRICS_LIST: # Initialize a predictor for all metrics first @@ -152,6 +156,7 @@ def train_individual_model(predictor_model, initial_run): metric_to_predict.metric_name, metric_to_predict.label_config, ) + return predictor_model def train_model(initial_run=False, data_queue=None): @@ -165,6 +170,8 @@ def train_model(initial_run=False, data_queue=None): PREDICTOR_MODEL_LIST = result data_queue.put(PREDICTOR_MODEL_LIST) +def start_ioloop(): + tornado.ioloop.IOLoop.current().start() if __name__ == "__main__": # Queue to share data between the tornado server and the model training @@ -176,9 +183,14 @@ def train_model(initial_run=False, data_queue=None): # Set up the tornado web app app = make_app(predicted_model_queue) app.listen(8080) - server_process = Process(target=tornado.ioloop.IOLoop.instance().start) - # Start up the server to expose the metrics. - server_process.start() + # server_process = Process(target=tornado.ioloop.IOLoop.instance().start) + # # Start up the server to expose the metrics. + # server_process.start() + + server_thread = threading.Thread(target=start_ioloop) + + # Start the server thread + server_thread.start() # Schedule the model training schedule.every(Configuration.retraining_interval_minutes).minutes.do( @@ -193,4 +205,4 @@ def train_model(initial_run=False, data_queue=None): time.sleep(1) # join the server process in case the main process ends - server_process.join() + server_thread.join() diff --git a/configuration.py b/configuration.py index 4d1fece..f6c63cf 100644 --- a/configuration.py +++ b/configuration.py @@ -24,10 +24,11 @@ class Configuration: # any headers that need to be passed while connecting to the prometheus host prom_connect_headers = None # example oath token passed as a header - if os.getenv("FLT_PROM_ACCESS_TOKEN"): - prom_connect_headers = { - "Authorization": "bearer " + os.getenv("FLT_PROM_ACCESS_TOKEN") - } + prom_connect_headers = { + "x-scope-org-id": "something-else-for-testing", + "X-Scope-OrgID": "something-else-for-testing" + } + # list of metrics that need to be scraped and predicted # multiple metrics can be separated with a ";"