|
3 | 3 | import threading |
4 | 4 |
|
5 | 5 | from flask import request, jsonify, Response, current_app |
| 6 | +from prometheus_client import Histogram, Gauge, Info |
| 7 | +from regression_model import __version__ as live_version |
6 | 8 |
|
| 9 | +from api.config import APP_NAME |
| 10 | +from api.persistence.data_access import PredictionPersistence, ModelType |
7 | 11 | from gradient_boosting_model import __version__ as shadow_version |
8 | | -from regression_model import __version__ as live_version |
9 | | -from prometheus_client import Histogram, Gauge, Info |
10 | 12 | from gradient_boosting_model.predict import make_prediction |
11 | | -from api.persistence.data_access import PredictionPersistence, ModelType |
12 | | -from api.config import APP_NAME |
13 | 13 |
|
| 14 | +_logger = logging.getLogger('mlapi') |
14 | 15 |
|
15 | | -_logger = logging.getLogger(__name__) |
16 | 16 |
|
17 | 17 | PREDICTION_TRACKER = Histogram( |
18 | 18 | name='house_price_prediction_dollars', |
|
45 | 45 |
|
46 | 46 | def health(): |
47 | 47 | if request.method == "GET": |
48 | | - return jsonify({"status": "ok"}) |
| 48 | + status = {"status": "ok"} |
| 49 | + _logger.debug(status) |
| 50 | + return jsonify(status) |
49 | 51 |
|
50 | 52 |
|
51 | 53 | def predict(): |
52 | 54 | if request.method == "POST": |
53 | 55 | # Step 1: Extract POST data from request body as JSON |
54 | 56 | json_data = request.get_json() |
| 57 | + _logger.info( |
| 58 | + f'Inputs for model: {ModelType.LASSO.name} ' |
| 59 | + f'Input values: {json_data}') |
55 | 60 |
|
56 | 61 | # Step 2a: Get and save live model predictions |
57 | 62 | persistence = PredictionPersistence(db_session=current_app.db_session) |
@@ -89,6 +94,10 @@ def predict(): |
89 | 94 | app_name=APP_NAME, |
90 | 95 | model_name=ModelType.LASSO.name, |
91 | 96 | model_version=live_version).set(_prediction) |
| 97 | + _logger.info( |
| 98 | + f'Prediction results for model: {ModelType.LASSO.name} ' |
| 99 | + f'version: {result.model_version} ' |
| 100 | + f'Output values: {result.predictions}') |
92 | 101 |
|
93 | 102 | # Step 5: Prepare prediction response |
94 | 103 | return jsonify( |
|
0 commit comments