From 115d1cc6b367284dcaa7b440651af0b2fd282bb4 Mon Sep 17 00:00:00 2001 From: Tom Kralidis Date: Wed, 13 Mar 2024 15:51:43 -0400 Subject: [PATCH] abstract zipfile location to env var, add metrics API endpoint --- docker/docker-compose.yml | 7 ++++++- docker/wis2-gdc-api/app.py | 21 ++++++++++++--------- docker/wis2-gdc-api/wis2-gdc-api.yml | 6 ++++++ docker/wis2-gdc-management.cron | 2 +- docker/wis2-gdc.env | 3 ++- requirements.txt | 1 + wis2-gdc.env | 5 +++-- 7 files changed, 31 insertions(+), 14 deletions(-) diff --git a/docker/docker-compose.yml b/docker/docker-compose.yml index f9c8699..104bb39 100644 --- a/docker/docker-compose.yml +++ b/docker/docker-compose.yml @@ -71,6 +71,10 @@ services: depends_on: elasticsearch: condition: service_healthy + healthcheck: + test: ["CMD", "curl", "-f", "http://elasticsearch:9200/wis2-discovery-metadata"] + interval: 5s + retries: 3 volumes: - wis2-gdc-management-data:/data restart: always @@ -84,7 +88,8 @@ services: context: wis2-gdc-api/ image: geopython/pygeoapi:latest depends_on: - - wis2-gdc-management + wis2-gdc-management: + condition: service_healthy volumes: - wis2-gdc-management-data:/data healthcheck: diff --git a/docker/wis2-gdc-api/app.py b/docker/wis2-gdc-api/app.py index 04755cd..266b01a 100644 --- a/docker/wis2-gdc-api/app.py +++ b/docker/wis2-gdc-api/app.py @@ -19,7 +19,9 @@ # ############################################################################### -from flask import Flask, make_response, redirect +import os + +from flask import Flask, send_file from pygeoapi.flask_app import BLUEPRINT as pygeoapi_blueprint app = Flask(__name__, static_url_path='/static') @@ -37,14 +39,15 @@ @app.route('/wis2-discovery-metadata-archive.zip') def archive(): - headers = { - 'Content-Type': 'application/zip' - } + zip_file = os.environ.get('WIS2_GDC_METADATA_ARCHIVE_ZIPFILE') + + return send_file(zip_file, mimetype='application/zip', add_etags=True) + - with open('/data/wis2-discovery-metadata-archive.zip') as fh: - response = make_response(fh.read(), 200) - response.headers = headers +@app.route('/wis2-gdc-metrics.txt') +def metrics(): - return response + metrics_file = os.environ.get('WIS2_GDC_OPENMETRICS_FILE') - return redirect('https://docs.wis2box.wis.wmo.int', code=302) + return send_file(metrics_file, mimetype='text/plain', + add_etags=True) diff --git a/docker/wis2-gdc-api/wis2-gdc-api.yml b/docker/wis2-gdc-api/wis2-gdc-api.yml index 0f44d52..a84e67e 100644 --- a/docker/wis2-gdc-api/wis2-gdc-api.yml +++ b/docker/wis2-gdc-api/wis2-gdc-api.yml @@ -75,6 +75,12 @@ resources: href: ${WIS2_GDC_API_URL}/wis2-discovery-metadata-archive.zip hreflang: en-CA length: -1 + - type: text/plain + rel: related + title: WIS2 Global Discovery Catalogue metrics + href: ${WIS2_GDC_API_URL}/{WIS2_GDC_OPENMETRICS_FILE} + hreflang: en-CA + extents: extents: spatial: bbox: [-180, -90, 180, 90] diff --git a/docker/wis2-gdc-management.cron b/docker/wis2-gdc-management.cron index 0fbe7d5..54be3c4 100644 --- a/docker/wis2-gdc-management.cron +++ b/docker/wis2-gdc-management.cron @@ -1 +1 @@ -0 0 * * * su -c "wis2-gdc archive /data/wis2-discovery-metadata-archive.zip" > /proc/1/fd/1 2>/proc/1/fd/2 +0 0 * * * su -c "wis2-gdc archive $WIS2_GDC_METADATA_ARCHIVE_ZIPFILE" > /proc/1/fd/1 2>/proc/1/fd/2 diff --git a/docker/wis2-gdc.env b/docker/wis2-gdc.env index b548fec..406eef4 100644 --- a/docker/wis2-gdc.env +++ b/docker/wis2-gdc.env @@ -5,8 +5,9 @@ export WIS2_GDC_BACKEND_CONNECTION=http://elasticsearch:9200/wis2-discovery-meta export WIS2_GDC_BROKER_URL=mqtt://wis2-gdc:wis2-gdc@mosquitto:1883 export WIS2_GDC_CENTRE_ID=ca-eccc-msc-gdc export WIS2_GDC_GB=mqtt://everyone:everyone@mosquitto:1883 -export WIS2_GDC_GB_TOPIC=origin/a/wis2/+/+/metadata/# +export WIS2_GDC_GB_TOPIC=origin/a/wis2/+/metadata/# export WIS2_GDC_OPENMETRICS_FILE=/tmp/wis2-gdc-openmetrics.txt +export WIS2_GDC_METADATA_ARCHIVE_ZIPFILE=/data/wis2-discovery-metadata-archive.zip export WIS2_GDC_PUBLISH_REPORTS=true # global broker links diff --git a/requirements.txt b/requirements.txt index db5caee..80e1bd5 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,4 +1,5 @@ click +prometheus-client pywcmp pywis-pubsub requests diff --git a/wis2-gdc.env b/wis2-gdc.env index 45ac7b3..01b1c63 100644 --- a/wis2-gdc.env +++ b/wis2-gdc.env @@ -1,12 +1,13 @@ export WIS2_GDC_API_URL=http://localhost export WIS2_GDC_API_URL_DOCKER=http://wis2-gdc-api export WIS2_GDC_BACKEND_TYPE=Elasticsearch -export WIS2_GDC_BACKEND_CONNECTION=http://localhost:9200/wis2-discovery-metadata -export WIS2_GDC_BROKER_URL=mqtt://wis2-gdc:wis2-gdc@localhost:1883 +export WIS2_GDC_BACKEND_CONNECTION=http://elasticsearch:9200/wis2-discovery-metadata +export WIS2_GDC_BROKER_URL=mqtt://wis2-gdc:wis2-gdc@mosquitto:1883 export WIS2_GDC_CENTRE_ID=ca-eccc-msc-global-discovery-catalogue export WIS2_GDC_GB=mqtt://everyone:everyone@localhost:1883 export WIS2_GDC_GB_TOPIC=origin/a/wis2/+/metadata/# export WIS2_GDC_OPENMETRICS_FILE=/tmp/wis2-gdc-openmetrics.txt +export WIS2_GDC_METADATA_ARCHIVE_ZIPFILE=/tmp/wis2-discovery-metadata.zip export WIS2_GDC_PUBLISH_REPORTS=true export WIS2_GDC_REJECT_ON_FAILING_ETS=true export WIS2_GDC_RUN_KPI=true