another take on metrics

This commit is contained in:
burnettk 2023-03-22 22:40:56 -04:00
parent bf84d48a69
commit 152be789ec
5 changed files with 49 additions and 2 deletions

View File

@ -0,0 +1 @@
{"version": "1.0.3"}

View File

@ -1258,6 +1258,29 @@ python-versions = ">=3.7"
"ruamel.yaml" = ">=0.15"
tomli = {version = ">=1.1.0", markers = "python_version < \"3.11\""}
[[package]]
name = "prometheus-client"
version = "0.16.0"
description = "Python client for the Prometheus monitoring system."
category = "main"
optional = false
python-versions = ">=3.6"
[package.extras]
twisted = ["twisted"]
[[package]]
name = "prometheus-flask-exporter"
version = "0.22.3"
description = "Prometheus metrics exporter for Flask"
category = "main"
optional = false
python-versions = "*"
[package.dependencies]
flask = "*"
prometheus-client = "*"
[[package]]
name = "prompt-toolkit"
version = "3.0.31"
@ -1895,7 +1918,7 @@ lxml = "*"
type = "git"
url = "https://github.com/sartography/SpiffWorkflow"
reference = "main"
resolved_reference = "f162aac43af3af18d1a55186aeccea154fb8b05d"
resolved_reference = "3c3345c85dd7f3b7112ad04aaa6487abbd2e9414"
[[package]]
name = "SQLAlchemy"
@ -2274,7 +2297,7 @@ testing = ["flake8 (<5)", "func-timeout", "jaraco.functools", "jaraco.itertools"
[metadata]
lock-version = "1.1"
python-versions = ">=3.9,<3.12"
content-hash = "b9ea32912509637f1378d060771de7548d93953aa3db12d6a48098f7dc15205f"
content-hash = "d851a6df0cc4fbb77d658455deb8bc3cb9c82fa7789ea581f20b373a96ae6078"
[metadata.files]
alabaster = [
@ -3056,6 +3079,14 @@ pre-commit-hooks = [
{file = "pre_commit_hooks-4.3.0-py2.py3-none-any.whl", hash = "sha256:9ccaf7c98794659d345080ee1ea0256a55ae059675045eebdbbc17c0be8c7e4b"},
{file = "pre_commit_hooks-4.3.0.tar.gz", hash = "sha256:fda598a4c834d030727e6a615722718b47510f4bed72df4c949f95ba9f5aaf88"},
]
prometheus-client = [
{file = "prometheus_client-0.16.0-py3-none-any.whl", hash = "sha256:0836af6eb2c8f4fed712b2f279f6c0a8bbab29f9f4aa15276b91c7cb0d1616ab"},
{file = "prometheus_client-0.16.0.tar.gz", hash = "sha256:a03e35b359f14dd1630898543e2120addfdeacd1a6069c1367ae90fd93ad3f48"},
]
prometheus-flask-exporter = [
{file = "prometheus_flask_exporter-0.22.3-py3-none-any.whl", hash = "sha256:16e6a3a7ce0089fc7c78a6956cdf28c184c3ac518e2b46a2a8e410b68d3a84a3"},
{file = "prometheus_flask_exporter-0.22.3.tar.gz", hash = "sha256:32b152aeb7970cbf04616627fc5bf20d82b0918e54c54f80dc8aaef3349fd333"},
]
prompt-toolkit = [
{file = "prompt_toolkit-3.0.31-py3-none-any.whl", hash = "sha256:9696f386133df0fc8ca5af4895afe5d78f5fcfe5258111c2a79a1c3e41ffa96d"},
{file = "prompt_toolkit-3.0.31.tar.gz", hash = "sha256:9ada952c9d1787f52ff6d5f3484d0b4df8952787c087edf6a1f7c2cb1ea88148"},

View File

@ -75,6 +75,7 @@ flask-jwt-extended = "^4.4.4"
pylint = "^2.15.10"
flask-simple-crypt = "^0.3.3"
cryptography = "^39.0.2"
prometheus-flask-exporter = "^0.22.3"
[tool.poetry.dev-dependencies]

View File

@ -4,10 +4,12 @@ import faulthandler
import os
import sys
from typing import Any
from prometheus_flask_exporter import PrometheusMetrics
import connexion # type: ignore
import flask.app
import flask.json
import json
import sqlalchemy
from apscheduler.schedulers.background import BackgroundScheduler # type: ignore
from apscheduler.schedulers.base import BaseScheduler # type: ignore
@ -125,6 +127,16 @@ def create_app() -> flask.app.Flask:
connexion_app = connexion.FlaskApp(__name__, server_args={"instance_path": os.environ.get("FLASK_INSTANCE_PATH")})
app = connexion_app.app
app.config["CONNEXION_APP"] = connexion_app
metrics = PrometheusMetrics(app)
info = metrics.info('dynamic_info', 'Something dynamic')
info.set(42.1)
# metrics.register_endpoint('/metricss')
app.config["PROMETHEUS_METRICS"] = metrics
app_version_data = {}
with open("app_version.json", 'r') as f:
app_version_data = json.load(f)
metrics.info('app_info', 'Application info', version='1.0.3')
app.config["SESSION_TYPE"] = "filesystem"
setup_config(app)

View File

@ -323,6 +323,8 @@ class AuthorizationService:
api_view_function
and api_view_function.__name__.startswith("login")
or api_view_function.__name__.startswith("logout")
or api_view_function.__name__.startswith("prom")
or api_view_function.__name__.startswith("metric")
or api_view_function.__name__.startswith("console_ui_")
or api_view_function.__name__ in authentication_exclusion_list
or api_view_function.__name__ in swagger_functions