Converted readiness check to httpget

Change-Id: I4030fc54dd187a997483c7d045ce0921f11af03d
This commit is contained in:
Proskurin Kirill 2017-01-29 17:45:00 +00:00
parent 100c479844
commit e5d4a8679a
2 changed files with 28 additions and 31 deletions

View File

@ -1,6 +1,5 @@
#!/usr/bin/env python
import argparse
import BaseHTTPServer
import functools
import json
@ -8,7 +7,6 @@ import logging
import os
import os.path
import socket
import sys
import time
import etcd
@ -112,7 +110,10 @@ class GaleraChecker(object):
def check_if_galera_ready(self):
self.check_cluster_state()
state = self.fetch_cluster_state()
if state != 'STEADY':
LOG.error("Cluster state is not STEADY")
return False
wsrep_data = self.fetch_wsrep_data()
uuid = self.etcd_get_cluster_uuid()
@ -239,24 +240,29 @@ class GaleraChecker(object):
return self._etcd_read('uuid')
def check_cluster_state(self):
def fetch_cluster_state(self):
state = self._etcd_read('state')
if state != 'STEADY':
LOG.error("Cluster state is not STEADY")
sys.exit(1)
return self._etcd_read('state')
class GaleraHttpHandler(BaseHTTPServer.BaseHTTPRequestHandler):
def do_GET(self):
LOG.debug("Started processing GET request")
uri = self.path
LOG.debug("Started processing GET '%s' request", uri)
checker = GaleraChecker()
try:
checker = GaleraChecker()
alive = checker.check_if_galera_alive()
state = 200 if alive else 503
self.send_response(state)
if uri == "/liveness":
success = checker.check_if_galera_alive()
elif uri == "/readiness":
success = checker.check_if_galera_ready()
else:
LOG.error("Only '/liveness' and '/readiness' uri are"
" supported")
success = False
response = 200 if success else 503
self.send_response(response)
self.end_headers()
except Exception as err:
LOG.exception(err)
@ -266,7 +272,7 @@ class GaleraHttpHandler(BaseHTTPServer.BaseHTTPRequestHandler):
LOG.debug("Finished processing GET request")
def run_liveness(port=8080):
def run_server(port=8080):
server_class = BaseHTTPServer.HTTPServer
handler_class = GaleraHttpHandler
server_address = ('', port)
@ -275,12 +281,6 @@ def run_liveness(port=8080):
httpd.serve_forever()
def run_readiness():
checker = GaleraChecker()
ready = checker.check_if_galera_ready()
sys.exit(0) if ready else sys.exit(1)
def get_config():
LOG.info("Getting global variables from %s", GLOBALS_PATH)
@ -309,13 +309,6 @@ def set_globals():
if __name__ == "__main__":
parser = argparse.ArgumentParser()
parser.add_argument('type', choices=['liveness', 'readiness'])
args = parser.parse_args()
get_config()
set_globals()
if args.type == 'liveness':
run_liveness()
elif args.type == 'readiness':
run_readiness()
run_server()

View File

@ -17,7 +17,7 @@ service:
- galera-checker
dependencies:
- etcd
command: "/opt/ccp/bin/galera_checker.py liveness"
command: "/opt/ccp/bin/galera_checker.py"
- name: galera-haproxy
image: galera-haproxy
probes:
@ -37,9 +37,13 @@ service:
- name: galera
image: percona
probes:
readiness: "/opt/ccp/bin/galera_checker.py readiness"
readiness:
path: "/readiness"
type: "httpGet"
port: 8080
timeout: 5
liveness:
path: "/"
path: "/liveness"
type: "httpGet"
port: 8080
timeout: 5