Skip to content

Commit

Permalink
Make pytype happy
Browse files Browse the repository at this point in the history
  • Loading branch information
jankatins committed Sep 15, 2021
1 parent 8c9d3bd commit defb2ce
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 9 deletions.
4 changes: 2 additions & 2 deletions pglookout/cluster_monitor.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,8 @@ def _connect_to_db(self, instance, dsn):

def _fetch_observer_state(self, instance, uri):
result = {"fetch_time": get_iso_timestamp(), "connection": True}
fetch_uri = uri + "/state.json"
try:
fetch_uri = uri + "/state.json"
response = self.session.get(fetch_uri, timeout=5.0)

# check time difference for large skews
Expand Down Expand Up @@ -162,8 +162,8 @@ def _query_cluster_member_state(self, instance, db_conn):
db_conn = self._connect_to_db(instance, self.config["remote_conns"].get(instance))
if not db_conn:
return result
phase = "querying status from"
try:
phase = "querying status from"
self.log.debug("%s %r", phase, instance)
c = db_conn.cursor(cursor_factory=RealDictCursor)
if db_conn.server_version >= 100000:
Expand Down
11 changes: 6 additions & 5 deletions pglookout/pglookout.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@
class PgLookout:
def __init__(self, config_path):
self.log = logging.getLogger("pglookout")
self.stats = None
# dummy to make sure we never get an AttributeError -> gets overwritten after the first config loading
self.stats = statsd.StatsClient(host=None)
self.running = True
self.replication_lag_over_warning_limit = False

Expand Down Expand Up @@ -172,9 +173,9 @@ def write_cluster_state_to_json_file(self):
"""
start_time = time.monotonic()
state_file_path = self.config.get("json_state_file_path", "/tmp/pglookout_state.json")
overall_state = {"db_nodes": self.cluster_state, "observer_nodes": self.observer_state,
"current_master": self.current_master}
try:
overall_state = {"db_nodes": self.cluster_state, "observer_nodes": self.observer_state,
"current_master": self.current_master}
json_to_dump = json.dumps(overall_state, indent=4)
self.log.debug("Writing JSON state file to: %r, file_size: %r", state_file_path, len(json_to_dump))
with open(state_file_path + ".tmp", "w") as fp:
Expand Down Expand Up @@ -628,12 +629,12 @@ def create_alert_file(self, filename):
with open(filepath, "w") as fp:
fp.write("alert")
except Exception as ex: # pylint: disable=broad-except
self.log.exception("Problem writing alert file: %r", filepath)
self.log.exception("Problem writing alert file: %r", filename)
self.stats.unexpected_exception(ex, where="create_alert_file")

def delete_alert_file(self, filename):
filepath = os.path.join(self.config.get("alert_file_dir", os.getcwd()), filename)
try:
filepath = os.path.join(self.config.get("alert_file_dir", os.getcwd()), filename)
if os.path.exists(filepath):
self.log.debug("Deleting alert file: %r", filepath)
os.unlink(filepath)
Expand Down
6 changes: 4 additions & 2 deletions pglookout/webserver.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,24 +50,26 @@ def close(self):

class RequestHandler(SimpleHTTPRequestHandler):
def do_GET(self):
assert isinstance(self.server, ThreadedWebServer), f"server: {self.server!r}"
self.server.log.debug("Got request: %r", self.path)
if self.path.startswith("/state.json"):
self.send_response(200)
self.send_header('Content-type', 'application/json')
response = json.dumps(self.server.cluster_state, indent=4).encode("utf8")
self.send_header('Content-length', len(response))
self.send_header('Content-length', str(len(response)))
self.end_headers()
self.wfile.write(response)
else:
self.send_response(404)

def do_POST(self):
assert isinstance(self.server, ThreadedWebServer), f"server: {self.server!r}"
self.server.log.debug("Got request: %r", self.path)
if self.path.startswith("/check"):
self.server.cluster_monitor_check_queue.put("request from webserver")
self.server.log.info("Immediate status check requested")
self.send_response(204)
self.send_header('Content-length', 0)
self.send_header('Content-length', str(0))
self.end_headers()
else:
self.send_response(404)

0 comments on commit defb2ce

Please sign in to comment.