Skip to content

Commit

Permalink
Apply changes from pre-commit fixers
Browse files Browse the repository at this point in the history
The only manual change needed was `typing-as-t`.
  • Loading branch information
sirosen committed Aug 28, 2024
1 parent e3b4bb3 commit d3c68b1
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 31 deletions.
2 changes: 1 addition & 1 deletion client/globus_cw_client/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
12 changes: 6 additions & 6 deletions daemon/globus_cw_daemon/cwlogs.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
40 changes: 20 additions & 20 deletions daemon/globus_cw_daemon/daemon.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

Expand Down Expand Up @@ -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

Expand All @@ -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

Expand All @@ -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"
Expand Down
7 changes: 3 additions & 4 deletions daemon/globus_cw_daemon_install/install.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."
Expand Down

0 comments on commit d3c68b1

Please sign in to comment.