K8s health utilities for cic containers

This commit is contained in:
Louis Holbrook
2021-04-21 17:34:13 +00:00
parent 3ee84f780e
commit 1bc7cde1f0
21 changed files with 471 additions and 6 deletions

View File

@@ -0,0 +1,7 @@
from cic_eth.db.models.base import SessionBase
def health(*args, **kwargs):
session = SessionBase.create_session()
session.execute('SELECT count(*) from alembic_version')
session.close()
return True

View File

@@ -15,6 +15,7 @@ from chainlib.connection import RPCConnection
from chainlib.eth.connection import EthUnixSignerConnection
from chainlib.chain import ChainSpec
from chainqueue.db.models.otx import Otx
import liveness.linux
# local imports
from cic_eth.eth import (
@@ -52,6 +53,7 @@ from cic_eth.registry import (
connect_token_registry,
)
logging.basicConfig(level=logging.WARNING)
logg = logging.getLogger()
@@ -90,14 +92,15 @@ config.censor('PASSWORD', 'DATABASE')
config.censor('PASSWORD', 'SSL')
logg.debug('config loaded from {}:\n{}'.format(args.c, config))
health_modules = config.get('CIC_HEALTH_MODULES', [])
if len(health_modules) != 0:
health_modules = health_modules.split(',')
logg.debug('health mods {}'.format(health_modules))
# connect to database
dsn = dsn_from_config(config)
SessionBase.connect(dsn, pool_size=int(config.get('DATABASE_POOL_SIZE')), debug=config.true('DATABASE_DEBUG'))
# verify database connection with minimal sanity query
session = SessionBase.create_session()
session.execute('select version_num from alembic_version')
session.close()
# set up celery
current_app = celery.Celery(__name__)
@@ -139,6 +142,7 @@ RPCConnection.register_location(config.get('SIGNER_SOCKET_PATH'), chain_spec, 's
Otx.tracing = config.true('TASKS_TRACE_QUEUE_STATUS')
liveness.linux.load(health_modules)
def main():
argv = ['worker']
@@ -173,8 +177,10 @@ def main():
logg.info('using trusted address {}'.format(address))
connect_declarator(rpc, chain_spec, trusted_addresses)
connect_token_registry(rpc, chain_spec)
liveness.linux.set()
current_app.worker_main(argv)
liveness.linux.reset()
@celery.signals.eventlet_pool_postshutdown.connect

View File

@@ -3,3 +3,4 @@ registry_address =
chain_spec = evm:bloxberg:8996
tx_retry_delay =
trust_address =
health_modules = cic_eth.k8s.db

View File

@@ -53,3 +53,5 @@ COPY cic-eth/crypto_dev_signer_config/ /usr/local/etc/crypto-dev-signer/
RUN git clone https://gitlab.com/grassrootseconomics/cic-contracts.git && \
mkdir -p /usr/local/share/cic/solidity && \
cp -R cic-contracts/abis /usr/local/share/cic/solidity/abi
COPY util/liveness/health.sh /usr/local/bin/health.sh

View File

@@ -1,4 +1,4 @@
cic-base~=0.1.2a76
cic-base==0.1.2a79+build.35e442bc
celery==4.4.7
crypto-dev-signer~=0.4.14b2
confini~=0.3.6rc3

View File

@@ -38,6 +38,7 @@ packages =
cic_eth.runnable.daemons.filters
cic_eth.callbacks
cic_eth.sync
cic_eth.k8s
scripts =
./scripts/migrate.py