Converted readiness check to httpget
Change-Id: I4030fc54dd187a997483c7d045ce0921f11af03d
This commit is contained in:
parent
100c479844
commit
e5d4a8679a
|
@ -1,6 +1,5 @@
|
||||||
#!/usr/bin/env python
|
#!/usr/bin/env python
|
||||||
|
|
||||||
import argparse
|
|
||||||
import BaseHTTPServer
|
import BaseHTTPServer
|
||||||
import functools
|
import functools
|
||||||
import json
|
import json
|
||||||
|
@ -8,7 +7,6 @@ import logging
|
||||||
import os
|
import os
|
||||||
import os.path
|
import os.path
|
||||||
import socket
|
import socket
|
||||||
import sys
|
|
||||||
import time
|
import time
|
||||||
|
|
||||||
import etcd
|
import etcd
|
||||||
|
@ -112,7 +110,10 @@ class GaleraChecker(object):
|
||||||
|
|
||||||
def check_if_galera_ready(self):
|
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()
|
wsrep_data = self.fetch_wsrep_data()
|
||||||
uuid = self.etcd_get_cluster_uuid()
|
uuid = self.etcd_get_cluster_uuid()
|
||||||
|
|
||||||
|
@ -239,24 +240,29 @@ class GaleraChecker(object):
|
||||||
|
|
||||||
return self._etcd_read('uuid')
|
return self._etcd_read('uuid')
|
||||||
|
|
||||||
def check_cluster_state(self):
|
def fetch_cluster_state(self):
|
||||||
|
|
||||||
state = self._etcd_read('state')
|
return self._etcd_read('state')
|
||||||
if state != 'STEADY':
|
|
||||||
LOG.error("Cluster state is not STEADY")
|
|
||||||
sys.exit(1)
|
|
||||||
|
|
||||||
|
|
||||||
class GaleraHttpHandler(BaseHTTPServer.BaseHTTPRequestHandler):
|
class GaleraHttpHandler(BaseHTTPServer.BaseHTTPRequestHandler):
|
||||||
|
|
||||||
def do_GET(self):
|
def do_GET(self):
|
||||||
|
|
||||||
LOG.debug("Started processing GET request")
|
uri = self.path
|
||||||
try:
|
LOG.debug("Started processing GET '%s' request", uri)
|
||||||
checker = GaleraChecker()
|
checker = GaleraChecker()
|
||||||
alive = checker.check_if_galera_alive()
|
try:
|
||||||
state = 200 if alive else 503
|
if uri == "/liveness":
|
||||||
self.send_response(state)
|
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()
|
self.end_headers()
|
||||||
except Exception as err:
|
except Exception as err:
|
||||||
LOG.exception(err)
|
LOG.exception(err)
|
||||||
|
@ -266,7 +272,7 @@ class GaleraHttpHandler(BaseHTTPServer.BaseHTTPRequestHandler):
|
||||||
LOG.debug("Finished processing GET request")
|
LOG.debug("Finished processing GET request")
|
||||||
|
|
||||||
|
|
||||||
def run_liveness(port=8080):
|
def run_server(port=8080):
|
||||||
server_class = BaseHTTPServer.HTTPServer
|
server_class = BaseHTTPServer.HTTPServer
|
||||||
handler_class = GaleraHttpHandler
|
handler_class = GaleraHttpHandler
|
||||||
server_address = ('', port)
|
server_address = ('', port)
|
||||||
|
@ -275,12 +281,6 @@ def run_liveness(port=8080):
|
||||||
httpd.serve_forever()
|
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():
|
def get_config():
|
||||||
|
|
||||||
LOG.info("Getting global variables from %s", GLOBALS_PATH)
|
LOG.info("Getting global variables from %s", GLOBALS_PATH)
|
||||||
|
@ -309,13 +309,6 @@ def set_globals():
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
|
||||||
parser = argparse.ArgumentParser()
|
|
||||||
parser.add_argument('type', choices=['liveness', 'readiness'])
|
|
||||||
args = parser.parse_args()
|
|
||||||
|
|
||||||
get_config()
|
get_config()
|
||||||
set_globals()
|
set_globals()
|
||||||
if args.type == 'liveness':
|
run_server()
|
||||||
run_liveness()
|
|
||||||
elif args.type == 'readiness':
|
|
||||||
run_readiness()
|
|
||||||
|
|
|
@ -17,7 +17,7 @@ service:
|
||||||
- galera-checker
|
- galera-checker
|
||||||
dependencies:
|
dependencies:
|
||||||
- etcd
|
- etcd
|
||||||
command: "/opt/ccp/bin/galera_checker.py liveness"
|
command: "/opt/ccp/bin/galera_checker.py"
|
||||||
- name: galera-haproxy
|
- name: galera-haproxy
|
||||||
image: galera-haproxy
|
image: galera-haproxy
|
||||||
probes:
|
probes:
|
||||||
|
@ -37,9 +37,13 @@ service:
|
||||||
- name: galera
|
- name: galera
|
||||||
image: percona
|
image: percona
|
||||||
probes:
|
probes:
|
||||||
readiness: "/opt/ccp/bin/galera_checker.py readiness"
|
readiness:
|
||||||
|
path: "/readiness"
|
||||||
|
type: "httpGet"
|
||||||
|
port: 8080
|
||||||
|
timeout: 5
|
||||||
liveness:
|
liveness:
|
||||||
path: "/"
|
path: "/liveness"
|
||||||
type: "httpGet"
|
type: "httpGet"
|
||||||
port: 8080
|
port: 8080
|
||||||
timeout: 5
|
timeout: 5
|
||||||
|
|
Loading…
Reference in New Issue