Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update pre-commit configuration (round 2) #51

Merged
merged 2 commits into from
Aug 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
98 changes: 61 additions & 37 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,38 +1,62 @@
repos:
- repo: https://github.com/sirosen/texthooks
rev: 0.6.7
hooks:
- id: alphabetize-codeowners
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.6.0
hooks:
- id: check-merge-conflict
- id: trailing-whitespace
- repo: https://github.com/psf/black
rev: 24.8.0
hooks:
- id: black
- repo: https://github.com/PyCQA/flake8
rev: 7.1.1
hooks:
- id: flake8
additional_dependencies:
- 'flake8-bugbear==24.8.19'
- repo: https://github.com/asottile/pyupgrade
rev: v3.17.0
hooks:
- id: pyupgrade
args: ["--py38-plus"]
- repo: https://github.com/PyCQA/isort
rev: 5.13.2
hooks:
- id: isort
- repo: https://github.com/PyCQA/bandit
rev: 1.7.9
hooks:
- id: bandit
exclude: ^test/.*$
- repo: https://github.com/koalaman/shellcheck-precommit
rev: v0.10.0
hooks:
- id: shellcheck

- repo: https://github.com/pre-commit/pre-commit-hooks.git
rev: v4.6.0
hooks:
- id: check-merge-conflict
- id: trailing-whitespace
# ensure JSON files are well-formed and formatted
- id: check-json
- id: pretty-format-json
args: ["--autofix", "--no-sort-keys"]

- repo: https://github.com/sirosen/texthooks
rev: 0.6.7
hooks:
- id: alphabetize-codeowners

- repo: https://github.com/python-jsonschema/check-jsonschema
rev: 0.29.1
hooks:
- id: check-github-workflows
- id: check-dependabot

- repo: https://github.com/asottile/pyupgrade
rev: v3.17.0
hooks:
- id: pyupgrade
args: ["--py38-plus"]

- repo: https://github.com/sirosen/slyp
rev: 0.7.1
hooks:
- id: slyp

- repo: https://github.com/PyCQA/isort
rev: 5.13.2
hooks:
- id: isort

- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.6.0
hooks:
- id: check-merge-conflict
- id: trailing-whitespace

- repo: https://github.com/psf/black-pre-commit-mirror
rev: 24.8.0
hooks:
- id: black

- repo: https://github.com/PyCQA/flake8
rev: 7.1.1
hooks:
- id: flake8
additional_dependencies:
- 'flake8-bugbear==24.8.19'
- 'flake8-typing-as-t==0.0.3'

- repo: https://github.com/koalaman/shellcheck-precommit
rev: v0.10.0
hooks:
- id: shellcheck
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