-
Notifications
You must be signed in to change notification settings - Fork 161
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
custom metrics return function memory location #170
Comments
Hi, |
unfortunately I won't be able to send everything, just a small snippet, as the code is too big to fit here. But the idea is there, of how we are using the library. Furthermore, from what I can see, it is only the histogram that has this problem. # metrics.py
from prometheus_flask_exporter import PrometheusMetrics
METRICS_PORT = os.environ.get('METRICS_PORT')
def init(flask_app: Flask):
"""
Receives Flask instance to initialize metrics.
"""
if not METRICS_PORT:
logging.warning(f"Metrics could NOT enabled: port is missing ({METRICS_PORT})")
return
global prometheus_metrics
global metrics_counter
global metrics_histogram
prometheus_metrics = PrometheusMetrics(flask_app,
excluded_paths=["^/static/.*$"],
export_defaults=False,
path=None #disables '/metrics' route
)
metrics_counter = prometheus_metrics.counter(
'flask_http_request_total',
'Total number of HTTP requests for all Flask requests.',
labels={'method': lambda: request.method,
'status': lambda r: r.status_code,
'path': lambda: censor_uuids(request.path)})
metrics_histogram = prometheus_metrics.histogram(
'flask_http_request_duration_seconds',
'Flask HTTP request duration in seconds for all Flask requests.',
labels={'method': lambda: request.method,
'status': lambda r: r.status_code,
'path': lambda: censor_uuids(request.path)})
def record_metrics(func):
"""Decorator to record metrics of flask route if metrics are enabled"""
if prometheus_metrics:
@metrics_counter
@metrics_histogram
@wraps(func)
def wrapper(*args, **kwargs):
result = func(*args, **kwargs)
return result
return wrapper
else:
return func # main.py
import metrics
from flask import Flask
application = Flask(...)
metrics.init(application)
@application.route('/how')
@metrics.record_metrics
def how():
return render_template("how.html", is_logged=oidc.user_loggedin) I understand that possibly with the information I have provided it may be difficult to find a solution, so there is no need to stress if it is a hassle. |
Thanks a lot! This should help reproduce it! |
I think I solved the problem by changing the version of prometheus-flask-exporter from 0.22.3 to 0.23.0, but I definitely don't understand why. Thank you for the quick response and attention. |
The entire metrics issue is implemented in another .py file and is imported when used in a flask route to check its metrics. Additionally, custom metrics were created using lambdas and these memory locations refer to them.
Below is an example.
flask_http_request_total{method="<function init.<locals>.<lambda> at 0x7f7657e81580>",path="<function init.<locals>.<lambda> at 0x7f7657e816c0>",path_without_uuid="<function init.<locals>.<lambda> at 0x7f7657e81760>",status="<function init.<locals>.<lambda> at 0x7f7657e81620>"} 0.0
The text was updated successfully, but these errors were encountered: