From 7bfcbf7819a4ee82a906109804d110b5a476387b Mon Sep 17 00:00:00 2001 From: Ashley <8253488+mrjones-plip@users.noreply.github.com> Date: Thu, 16 May 2024 15:12:24 -0700 Subject: [PATCH] feat(couch-backlog): multi-couch2pg isntances on 1 db, update fake-cht, add prometheus env vars (#108) * feat(couch-backlog): allow multi-couch2pg isntances in one postgres db, backwards compatible * change sql server for fake-cht to fake-postgres, add interface and port for prometheus * update config to denote we need to enumerate * add dev values to .env example per feedback * add instructions to use db server name in yaml per feedback * remove unused patch files for dev settings --- .env.example | 7 +++++++ .../fake-cht/docker-compose.fake-cht.yml | 2 +- .../fake-cht/example-config/sql_servers.yml | 2 +- development/fake-cht/src/postgres.js | 4 ++-- ...ters.postgres.config.scrape_config.yml.patch | 17 ----------------- ...ters.postgres.config.scrape_config.yml.patch | 17 ----------------- docker-compose.yml | 2 ++ exporters/postgres/couch2pg_collector.yml | 8 ++++++-- exporters/postgres/sql_servers_example.yml | 7 +++++-- .../dashboards/CHT/cht_admin_overview.json | 4 ++-- 10 files changed, 26 insertions(+), 44 deletions(-) delete mode 100644 development/patches/apply/exporters.postgres.config.scrape_config.yml.patch delete mode 100644 development/patches/revert/exporters.postgres.config.scrape_config.yml.patch diff --git a/.env.example b/.env.example index b086b92..210e631 100644 --- a/.env.example +++ b/.env.example @@ -23,3 +23,10 @@ PROMETHEUS_RETENTION_TIME=60d SQL_EXPORTER_IP=127.0.0.1 # 9399 is default from upstream project SQL_EXPORTER_PORT=9399 + + +# For deveopment use only!! +# If you want to expose your prometheus container on your local dev host, uncomment this and set to +# public IP of your dev host +#PROMETHEUS_BIND=127.0.0.1 +#PROMETHEUS_PORT=9090 diff --git a/development/fake-cht/docker-compose.fake-cht.yml b/development/fake-cht/docker-compose.fake-cht.yml index 9ece4d3..bb788e3 100644 --- a/development/fake-cht/docker-compose.fake-cht.yml +++ b/development/fake-cht/docker-compose.fake-cht.yml @@ -16,7 +16,7 @@ services: sh -c "npm install && npm start" - postgres: + fake-postgres: image: postgres:15 environment: POSTGRES_DB: cht diff --git a/development/fake-cht/example-config/sql_servers.yml b/development/fake-cht/example-config/sql_servers.yml index e916fcb..529fa8d 100644 --- a/development/fake-cht/example-config/sql_servers.yml +++ b/development/fake-cht/example-config/sql_servers.yml @@ -25,5 +25,5 @@ jobs: static_configs: - targets: # " same as URL in cht-instances.yml ": 'postgres://USERNAME:PASSWORD@DB_SERVER_IP/DATABASE - "fake-cht:8081": 'postgres://cht_couch2pg:cht_couch2pg_password@postgres:5432/cht?sslmode=disable' # //NOSONAR - password is safe to commit + "db": 'postgres://cht_couch2pg:cht_couch2pg_password@fake-postgres:5432/cht?sslmode=disable' # //NOSONAR - password is safe to commit diff --git a/development/fake-cht/src/postgres.js b/development/fake-cht/src/postgres.js index 5091204..5fd84cc 100644 --- a/development/fake-cht/src/postgres.js +++ b/development/fake-cht/src/postgres.js @@ -3,7 +3,7 @@ const { randomUUID } = require('crypto'); const POSTGRES_CLIENT_CONFIG = { user: 'cht_couch2pg', - host: 'postgres', + host: 'fake-postgres', database: 'cht', password: 'cht_couch2pg_password', port: 5432, @@ -24,7 +24,7 @@ const insertCouchdbProgress = (seq, dbName) => [ DO UPDATE SET seq = $1; `, - [`${seq}-${randomUUID()}`, `fake-cht/${dbName}`] + [`${seq}-${randomUUID()}`, `fake-cht:8081/${dbName}`] ]; const populateCouchdbProcessTable = async (client, metrics) => { diff --git a/development/patches/apply/exporters.postgres.config.scrape_config.yml.patch b/development/patches/apply/exporters.postgres.config.scrape_config.yml.patch deleted file mode 100644 index 0572aea..0000000 --- a/development/patches/apply/exporters.postgres.config.scrape_config.yml.patch +++ /dev/null @@ -1,17 +0,0 @@ -*** exporters/postgres/config/scrape_config.yml 2023-05-01 09:11:50.580353623 -0500 ---- exporters/postgres/config/scrape_config1.yml 2023-05-01 10:55:44.066414120 -0500 -*************** -*** 1,6 **** - scrape_configs: - - job_name: postgres -! scrape_interval: 5m - metrics_path: /probe - file_sd_configs: - - files: ---- 1,6 ---- - scrape_configs: - - job_name: postgres -! scrape_interval: 1s - metrics_path: /probe - file_sd_configs: - - files: diff --git a/development/patches/revert/exporters.postgres.config.scrape_config.yml.patch b/development/patches/revert/exporters.postgres.config.scrape_config.yml.patch deleted file mode 100644 index f2ea8d4..0000000 --- a/development/patches/revert/exporters.postgres.config.scrape_config.yml.patch +++ /dev/null @@ -1,17 +0,0 @@ -*** exporters/postgres/config/scrape_config1.yml 2023-05-01 10:55:44.066414120 -0500 ---- exporters/postgres/config/scrape_config.yml 2023-05-01 09:11:50.580353623 -0500 -*************** -*** 1,6 **** - scrape_configs: - - job_name: postgres -! scrape_interval: 1s - metrics_path: /probe - file_sd_configs: - - files: ---- 1,6 ---- - scrape_configs: - - job_name: postgres -! scrape_interval: 5m - metrics_path: /probe - file_sd_configs: - - files: diff --git a/docker-compose.yml b/docker-compose.yml index 79a814c..bcf8f37 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -16,6 +16,8 @@ volumes: services: prometheus: image: prom/prometheus:${PROMETHEUS_VERSION:-v2.46.0} + ports: + - "${PROMETHEUS_BIND:-127.0.0.1}:${PROMETHEUS_PORT:-9090}:9090" command: - '--config.file=/etc/prometheus/prometheus.yml' - '--storage.tsdb.path=/prometheus' diff --git a/exporters/postgres/couch2pg_collector.yml b/exporters/postgres/couch2pg_collector.yml index dbdfc72..ac62430 100644 --- a/exporters/postgres/couch2pg_collector.yml +++ b/exporters/postgres/couch2pg_collector.yml @@ -4,13 +4,16 @@ queries: - query_name: couch2pg-query query: | SELECT - substring(seq for position('-' in seq) - 1) as sequence, - substring(source from position('/' in source) + 1) as db + split_part(seq,'-',1) as sequence, + split_part(source,'/',2) as db, + split_part(source,'/',1) as cht_instance FROM couchdb_progress WHERE source like '%/%' and seq like '%-%' + ORDER BY + cht_instance, db metrics: - metric_name: couch2pg_progress_sequence @@ -18,5 +21,6 @@ metrics: help: 'couch2pg backlog.' key_labels: - db + - cht_instance values: [sequence] query_ref: couch2pg-query diff --git a/exporters/postgres/sql_servers_example.yml b/exporters/postgres/sql_servers_example.yml index 1c15381..31e7d67 100644 --- a/exporters/postgres/sql_servers_example.yml +++ b/exporters/postgres/sql_servers_example.yml @@ -24,6 +24,9 @@ jobs: enable_ping: true static_configs: - targets: - # " same as URL in cht-instances.yml ": 'postgres://USERNAME:PASSWORD@DB_SERVER_IP/DATABASE - "172-17-0-1.local-ip.medicmobile.org:10464": 'postgres://cht_couch2pg:cht_couch2pg_password@172.17.0.1:5432/cht?sslmode=disable' # //NOSONAR - password is safe to commit + # change USERNAME, PASSWORD, DB_SERVER as needed. Likely DATABASE and PORT don't need to change. + # be sure each new server gets a unique name. A good rule of thumb is to use the name of the + # sql server (eg "postgres-rds-prod", "postgres-rds-dev1" etc.) + # 'postgres://USERNAME:PASSWORD@DB_SERVER_IP/DATABASE:PORT + "db1": 'postgres://cht_couch2pg:cht_couch2pg_password@172.17.0.1:5432/cht?sslmode=disable' # //NOSONAR - password is safe to commit diff --git a/grafana/provisioning/dashboards/CHT/cht_admin_overview.json b/grafana/provisioning/dashboards/CHT/cht_admin_overview.json index 7ae8eff..b97d359 100644 --- a/grafana/provisioning/dashboards/CHT/cht_admin_overview.json +++ b/grafana/provisioning/dashboards/CHT/cht_admin_overview.json @@ -1215,7 +1215,7 @@ }, "editorMode": "builder", "exemplar": false, - "expr": "sum(couch2pg_progress_sequence{target=~\"$cht_instance\", db=~\"medic|medic-sentinel|medic-users-meta\"})", + "expr": "sum(couch2pg_progress_sequence{cht_instance=~\"$cht_instance\", db=~\"medic|medic-sentinel|medic-users-meta\"})", "hide": false, "instant": true, "legendFormat": "__auto", @@ -2340,6 +2340,6 @@ "timezone": "", "title": "CHT Admin Overview", "uid": "oa2OfL-Vk", - "version": 36, + "version": 37, "weekStart": "" }