diff --git a/client/globus_cw_client/client.py b/client/globus_cw_client/client.py index c6cf407..ff5e10d 100644 --- a/client/globus_cw_client/client.py +++ b/client/globus_cw_client/client.py @@ -36,7 +36,7 @@ def log_event(message, retries=10, wait=0.1): if wait < 0: raise ValueError("wait must be non-negative") - req = dict() + req = {} req["message"] = message req["timestamp"] = int(time.time() * 1000) return _request(req, retries, wait) diff --git a/daemon/globus_cw_daemon/cwlogs.py b/daemon/globus_cw_daemon/cwlogs.py index 09137a5..e0fe6a8 100644 --- a/daemon/globus_cw_daemon/cwlogs.py +++ b/daemon/globus_cw_daemon/cwlogs.py @@ -83,7 +83,7 @@ def add(self, record): def get_records_for_boto(self): ret = [] for r in self.records: - ret.append(dict(timestamp=r.timestamp, message=r.unicode_message)) + ret.append({"timestamp": r.timestamp, "message": r.unicode_message}) return ret @staticmethod @@ -150,11 +150,11 @@ def _flush_events(self, events): raise ValueError("cannot flush with no events") while True: try: - kwargs = dict( - logGroupName=self.group_name, - logStreamName=self.stream_name, - logEvents=events, - ) + kwargs = { + "logGroupName": self.group_name, + "logStreamName": self.stream_name, + "logEvents": events, + } if self.sequence_token: kwargs["sequenceToken"] = self.sequence_token ret = self.client.put_log_events(**kwargs) diff --git a/daemon/globus_cw_daemon/daemon.py b/daemon/globus_cw_daemon/daemon.py index 3593c5a..ccf0c5f 100644 --- a/daemon/globus_cw_daemon/daemon.py +++ b/daemon/globus_cw_daemon/daemon.py @@ -10,7 +10,7 @@ import sys import threading import time -import typing +import typing as t import globus_cw_daemon.config as config import globus_cw_daemon.cwlogs as cwlogs @@ -32,14 +32,14 @@ # Data shared with flush thread _g_lock = threading.Lock() -_g_queue: typing.List[cwlogs.Event] = [] # List of Events +_g_queue: t.List[cwlogs.Event] = [] # List of Events _g_nr_dropped = 0 # get constant instance_id on start try: - INSTANCE_ID: typing.Union[str, None] = os.readlink("/var/lib/cloud/instance").split( - "/" - )[-1] + INSTANCE_ID: t.Union[str, None] = os.readlink("/var/lib/cloud/instance").split("/")[ + -1 + ] except OSError: INSTANCE_ID = None @@ -98,12 +98,12 @@ def _flush_thread_main(writer): def _get_drop_event(nr_dropped): - data = dict( - type="audit", - subtype="cwlogs.dropped", - dropped=nr_dropped, - instance_id=INSTANCE_ID, - ) + data = { + "type": "audit", + "subtype": "cwlogs.dropped", + "dropped": nr_dropped, + "instance_id": INSTANCE_ID, + } ret = cwlogs.Event(timestamp=None, message=json.dumps(data)) return ret @@ -119,16 +119,16 @@ def _health_info(q_len=None): if q_len is None: q_len = len(_g_queue) # no lock, but safe q_pct = (q_len / float(MAX_EVENT_QUEUE_LEN)) * 100 - return dict(queue_length=q_len, queue_percent_full=q_pct) + return {"queue_length": q_len, "queue_percent_full": q_pct} def _get_heartbeat_event(nr_found): - data = dict( - type="audit", - subtype="cwlogs.heartbeat", - instance_id=INSTANCE_ID, - health=_health_info(nr_found), - ) + data = { + "type": "audit", + "subtype": "cwlogs.heartbeat", + "instance_id": INSTANCE_ID, + "health": _health_info(nr_found), + } ret = cwlogs.Event(timestamp=None, message=json.dumps(data)) return ret @@ -153,10 +153,10 @@ def do_request(sock): try: _handle_request(d) - response = dict(status="ok", health=_health_info()) + response = {"status": "ok", "health": _health_info()} except Exception as e: _log.exception("error %r", e) - response = dict(status="error", message=repr(e)) + response = {"status": "error", "message": repr(e)} _log.debug("response: %r", response) buf = json.dumps(response, indent=None).encode("utf-8") + b"\n" diff --git a/daemon/globus_cw_daemon_install/install.py b/daemon/globus_cw_daemon_install/install.py index 208c45f..18d8c0f 100644 --- a/daemon/globus_cw_daemon_install/install.py +++ b/daemon/globus_cw_daemon_install/install.py @@ -18,17 +18,16 @@ def main(): # get group name argument parser = argparse.ArgumentParser() parser.add_argument( - "group_name", help="Name of the existing CloudWatch log group " "to log to." + "group_name", help="Name of the existing CloudWatch log group to log to." ) parser.add_argument( "--stream-name", - help="Specify a stream name. Default is the current " "ec2 instance id.", + help="Specify a stream name. Default is the current ec2 instance id.", ) parser.add_argument( "--heartbeat-interval", type=int, - help="Specify the time in seconds between heartbeats. " - "Default is 60 seconds.", + help="Specify the time in seconds between heartbeats. Default is 60 seconds.", ) parser.add_argument( "--no-heartbeats", action="store_true", help="Turn off heartbeats."