add querystring logic to mongo db health check to accommodate consul vs haproxy checking

This commit is contained in:
Jonathan Math 2021-10-11 11:11:42 -05:00
parent 0bbff92c73
commit dd13af5bf1
5 changed files with 36 additions and 35 deletions

View file

@ -8,7 +8,7 @@
"port": 27017,
"checks": [{
"id": "mongo-ping",
"http": "http://{{ ansible_ssh_host }}:5579/db_check/mongo",
"http": "http://{{ ansible_ssh_host }}:5579/db_check/mongo?consul=1",
"interval": "15s",
"failures_before_critical": 4
}]

View file

@ -124,7 +124,7 @@ backend postgres
option httpchk GET /db_check/postgres
server postgres-db01 db_pgsql:5000 check inter 2000ms
backend mongo
option httpchk GET /db_check/mongo
option httpchk GET /db_check/mongo?haproxy=1
server mongo-db22 db_mongo:5000 check inter 2000ms
backend redis
option httpchk GET /db_check/redis

View file

@ -146,7 +146,7 @@ backend postgres
server postgres-db02 db_pgsql:5000 check inter 2000ms
backend mongo
option httpchk GET /db_check/mongo
option httpchk GET /db_check/mongo?haproxy=1
server mongo-db20d db20d:5000 check inter 2000ms
server mongo-db22 db22:5000 check inter 2000ms
server mongo-db23a db23a:5000 check inter 2000ms

View file

@ -167,7 +167,7 @@ backend postgres
server db-postgres db-postgres.node.nyc1.consul:5579 check inter 2000ms resolvers consul resolve-prefer ipv4 resolve-opts allow-dup-ip init-addr none
backend mongo
option httpchk GET /db_check/mongo
option httpchk GET /db_check/mongo?haproxy=1
default-server check inter 2000ms resolvers consul resolve-prefer ipv4 resolve-opts allow-dup-ip init-addr none
{% for host in groups.mongo %}
server {{host}} {{host}}.node.nyc1.consul:5579

View file

@ -1,4 +1,4 @@
from flask import Flask, abort
from flask import Flask, abort, request
import os
import psycopg2
import pymysql
@ -80,10 +80,11 @@ def db_check_mongo():
# The `mongo` hostname below is a reference to the newsblurnet docker network, where 172.18.0.0/16 is defined
client = pymongo.MongoClient(f"mongodb://{settings.MONGO_DB['username']}:{settings.MONGO_DB['password']}@{settings.SERVER_NAME}/?authSource=admin")
db = client.newsblur
if request.args.get('consul') == '1':
return str(1)
except:
abort(503)
if request.args.get('haproxy') == '1':
try:
stories = db.stories.estimated_document_count()
except (pymongo.errors.NotMasterError, pymongo.errors.ServerSelectionTimeoutError):