From 3ff855350ae015dff13a243b26979f058a09b267 Mon Sep 17 00:00:00 2001 From: jasquat Date: Fri, 7 Apr 2023 15:32:28 -0400 Subject: [PATCH] attempt to get git docker labels into version json file w/ burnettk --- .../docker_image_for_main_builds.yml | 10 +++++-- .gitignore | 3 ++- spiffworkflow-backend/app_version.json | 1 - .../src/spiffworkflow_backend/__init__.py | 26 +++++++++++-------- 4 files changed, 25 insertions(+), 15 deletions(-) delete mode 100644 spiffworkflow-backend/app_version.json diff --git a/.github/workflows/docker_image_for_main_builds.yml b/.github/workflows/docker_image_for_main_builds.yml index ec2da085..4e2f4f32 100644 --- a/.github/workflows/docker_image_for_main_builds.yml +++ b/.github/workflows/docker_image_for_main_builds.yml @@ -31,7 +31,7 @@ on: push: branches: - main - - feature/use_tasks_as_logs + - feature/prometheus-metrics jobs: create_frontend_docker_image: @@ -64,6 +64,12 @@ jobs: type=ref,event=branch,suffix=-latest type=ref,event=branch,suffix=-${{ steps.date.outputs.date }} + - name: Write app verison info + run: | + touch app_version.json + echo '${{ steps.meta.outputs.labels }}' > app_version.json + id: app_version_info + run: echo "date=$(date -u +'%Y-%m-%d_%H-%M-%S')" >> "$GITHUB_OUTPUT" - name: Build and push Frontend Docker image uses: docker/build-push-action@v4.0.0 with: @@ -73,7 +79,7 @@ jobs: tags: ${{ steps.meta.outputs.tags }} labels: ${{ steps.meta.outputs.labels }} - run: echo 'TAGS' >> "$GITHUB_STEP_SUMMARY" - - run: echo 'for tag in ${{ steps.meta.outputs.tags }}; do echo "* $tag"; done' >> "$GITHUB_STEP_SUMMARY" + - run: for tag in ${{ steps.meta.outputs.tags }}; do echo "* $tag"; done >> "$GITHUB_STEP_SUMMARY" create_backend_docker_image: runs-on: ubuntu-latest diff --git a/.gitignore b/.gitignore index 22f7178f..da7c9867 100644 --- a/.gitignore +++ b/.gitignore @@ -3,4 +3,5 @@ pyrightconfig.json t *~ .dccache -*~ \ No newline at end of file +*~ +app_version.json diff --git a/spiffworkflow-backend/app_version.json b/spiffworkflow-backend/app_version.json deleted file mode 100644 index c2ad4cfc..00000000 --- a/spiffworkflow-backend/app_version.json +++ /dev/null @@ -1 +0,0 @@ -{"version": "1.0.3"} diff --git a/spiffworkflow-backend/src/spiffworkflow_backend/__init__.py b/spiffworkflow-backend/src/spiffworkflow_backend/__init__.py index 3619e38f..06285eb5 100644 --- a/spiffworkflow-backend/src/spiffworkflow_backend/__init__.py +++ b/spiffworkflow-backend/src/spiffworkflow_backend/__init__.py @@ -4,7 +4,7 @@ import faulthandler import os import sys from typing import Any -from prometheus_flask_exporter import PrometheusMetrics +from prometheus_flask_exporter import ConnexionPrometheusMetrics import connexion # type: ignore import flask.app @@ -128,17 +128,8 @@ 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_prometheus_metrics(app, connexion_app) setup_config(app) db.init_app(app) @@ -194,6 +185,19 @@ def create_app() -> flask.app.Flask: return app # type: ignore +def _setup_prometheus_metrics(app: flask.app.Flask, connexion_app: connexion.apps.flask_app.FlaskApp) -> None: + metrics = ConnexionPrometheusMetrics(connexion_app) + info = metrics.info('dynamic_info', 'Something dynamic') + info.set(42.1) + + app.config["PROMETHEUS_METRICS"] = metrics + app_version_data = {} + if os.path.isfile("app_version.json"): + with open("app_version.json", 'r') as f: + app_version_data = json.load(f) + metrics.info('app_version_info', 'Application Version Info', **app_version_data) + + def get_hacked_up_app_for_script() -> flask.app.Flask: """Get_hacked_up_app_for_script.""" os.environ["SPIFFWORKFLOW_BACKEND_ENV"] = "local_development"