Pull request #14: RED-4329 add prometheus endpoint with summary metric
Merge in RR/image-prediction from RED-4329-add-prometheus to master
Squashed commit of the following:
commit 2b8446e703617c6897b6149846f2548ec292a9a1
Author: Julius Unverfehrt <julius.unverfehrt@iqser.com>
Date: Tue Jun 21 14:40:44 2022 +0200
RED-4329 add prometheus endpoint with summary metric
This commit is contained in:
parent
9f18ef9cd1
commit
fd0e4dc3cf
@ -3,6 +3,7 @@ import traceback
|
||||
from typing import Callable
|
||||
|
||||
from flask import Flask, request, jsonify
|
||||
from prometheus_client import generate_latest, CollectorRegistry, Summary
|
||||
|
||||
from image_prediction.utils import get_logger
|
||||
|
||||
@ -34,6 +35,10 @@ def wrap_in_process(func_to_wrap):
|
||||
|
||||
def make_prediction_server(predict_fn: Callable):
|
||||
app = Flask(__name__)
|
||||
registry = CollectorRegistry(auto_describe=True)
|
||||
metric = Summary(
|
||||
f"redactmanager_imageClassification_seconds", f"Time spent on image-service classification.", registry=registry
|
||||
)
|
||||
|
||||
@app.route("/ready", methods=["GET"])
|
||||
def ready():
|
||||
@ -54,6 +59,7 @@ def make_prediction_server(predict_fn: Callable):
|
||||
|
||||
@app.route("/predict", methods=["POST"])
|
||||
@app.route("/", methods=["POST"])
|
||||
@metric.time()
|
||||
def predict():
|
||||
|
||||
# Tensorflow does not free RAM. Workaround: Run prediction function (which instantiates a model) in sub-process.
|
||||
@ -71,4 +77,8 @@ def make_prediction_server(predict_fn: Callable):
|
||||
logger.error("Analysis failed.")
|
||||
return __failure()
|
||||
|
||||
@app.route("/prometheus", methods=["GET"])
|
||||
def prometheus():
|
||||
return generate_latest(registry=registry)
|
||||
|
||||
return app
|
||||
|
||||
@ -21,3 +21,4 @@ Pillow==9.1.0
|
||||
PDFNetPython3==9.1.0
|
||||
pdf2image==1.16.0
|
||||
frozendict==2.3.0
|
||||
prometheus-client==0.13.1
|
||||
Loading…
x
Reference in New Issue
Block a user