Skip to content

Commit

Permalink
feat(couch-backlog): multi-couch2pg isntances on 1 db, update fake-ch…
Browse files Browse the repository at this point in the history
…t, 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
  • Loading branch information
mrjones-plip authored May 16, 2024
1 parent 70ab33c commit 7bfcbf7
Show file tree
Hide file tree
Showing 10 changed files with 26 additions and 44 deletions.
7 changes: 7 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion development/fake-cht/docker-compose.fake-cht.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ services:
sh -c "npm install &&
npm start"
postgres:
fake-postgres:
image: postgres:15
environment:
POSTGRES_DB: cht
Expand Down
2 changes: 1 addition & 1 deletion development/fake-cht/example-config/sql_servers.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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

4 changes: 2 additions & 2 deletions development/fake-cht/src/postgres.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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) => {
Expand Down

This file was deleted.

This file was deleted.

2 changes: 2 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
8 changes: 6 additions & 2 deletions exporters/postgres/couch2pg_collector.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,23 @@ 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
type: counter
help: 'couch2pg backlog.'
key_labels:
- db
- cht_instance
values: [sequence]
query_ref: couch2pg-query
7 changes: 5 additions & 2 deletions exporters/postgres/sql_servers_example.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:[email protected]: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:[email protected]:5432/cht?sslmode=disable' # //NOSONAR - password is safe to commit

4 changes: 2 additions & 2 deletions grafana/provisioning/dashboards/CHT/cht_admin_overview.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -2340,6 +2340,6 @@
"timezone": "",
"title": "CHT Admin Overview",
"uid": "oa2OfL-Vk",
"version": 36,
"version": 37,
"weekStart": ""
}

0 comments on commit 7bfcbf7

Please sign in to comment.