Skip to content

Commit

Permalink
[pre-commit.ci] auto fixes from pre-commit.com hooks
Browse files Browse the repository at this point in the history
for more information, see https://pre-commit.ci
  • Loading branch information
pre-commit-ci[bot] committed Aug 11, 2024
1 parent ec88ced commit 701ceb9
Showing 1 changed file with 13 additions and 13 deletions.
26 changes: 13 additions & 13 deletions proxy/core/event/metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def _get_counter(self, name: str) -> float:
path = os.path.join(DEFAULT_METRICS_DIRECTORY_PATH, f"{name}.counter")

Check warning on line 31 in proxy/core/event/metrics.py

View check run for this annotation

Codecov / codecov/patch

proxy/core/event/metrics.py#L31

Added line #L31 was not covered by tests
if not os.path.exists(path):
return 0
return float(Path(path).read_text(encoding="utf-8").strip())
return float(Path(path).read_text(encoding='utf-8').strip())

Check warning on line 34 in proxy/core/event/metrics.py

View check run for this annotation

Codecov / codecov/patch

proxy/core/event/metrics.py#L33-L34

Added lines #L33 - L34 were not covered by tests

def incr_counter(self, name: str, by: float = 1.0) -> None:
with self._lock:
Expand All @@ -40,7 +40,7 @@ def incr_counter(self, name: str, by: float = 1.0) -> None:
def _incr_counter(self, name: str, by: float = 1.0) -> None:
current = self._get_counter(name)
path = os.path.join(DEFAULT_METRICS_DIRECTORY_PATH, f"{name}.counter")
Path(path).write_text(str(current + by), encoding="utf-8")
Path(path).write_text(str(current + by), encoding='utf-8')

Check warning on line 43 in proxy/core/event/metrics.py

View check run for this annotation

Codecov / codecov/patch

proxy/core/event/metrics.py#L41-L43

Added lines #L41 - L43 were not covered by tests

def get_gauge(self, name: str) -> float:
with self._lock:
Expand All @@ -50,7 +50,7 @@ def _get_gauge(self, name: str) -> float:
path = os.path.join(DEFAULT_METRICS_DIRECTORY_PATH, f"{name}.gauge")

Check warning on line 50 in proxy/core/event/metrics.py

View check run for this annotation

Codecov / codecov/patch

proxy/core/event/metrics.py#L50

Added line #L50 was not covered by tests
if not os.path.exists(path):
return 0
return float(Path(path).read_text(encoding="utf-8").strip())
return float(Path(path).read_text(encoding='utf-8').strip())

Check warning on line 53 in proxy/core/event/metrics.py

View check run for this annotation

Codecov / codecov/patch

proxy/core/event/metrics.py#L52-L53

Added lines #L52 - L53 were not covered by tests

def set_gauge(self, name: str, value: float) -> None:
"""Stores a single values."""
Expand All @@ -59,7 +59,7 @@ def set_gauge(self, name: str, value: float) -> None:

def _set_gauge(self, name: str, value: float) -> None:
path = os.path.join(DEFAULT_METRICS_DIRECTORY_PATH, f"{name}.gauge")

Check warning on line 61 in proxy/core/event/metrics.py

View check run for this annotation

Codecov / codecov/patch

proxy/core/event/metrics.py#L61

Added line #L61 was not covered by tests
with open(path, "w", encoding="utf-8") as g:
with open(path, 'w', encoding='utf-8') as g:
g.write(str(value))

Check warning on line 63 in proxy/core/event/metrics.py

View check run for this annotation

Codecov / codecov/patch

proxy/core/event/metrics.py#L63

Added line #L63 was not covered by tests


Expand All @@ -79,7 +79,7 @@ def __init__(self, event_queue: EventQueue, metrics_lock: Lock) -> None:

def _setup_metrics_directory(self) -> None:
os.makedirs(DEFAULT_METRICS_DIRECTORY_PATH, exist_ok=True)
patterns = ["*.counter", "*.gauge"]
patterns = ['*.counter', '*.gauge']
for pattern in patterns:
files = glob.glob(os.path.join(DEFAULT_METRICS_DIRECTORY_PATH, pattern))
for file_path in files:
Expand All @@ -88,7 +88,7 @@ def _setup_metrics_directory(self) -> None:
except OSError as e:
print(f"Error deleting file {file_path}: {e}")

Check warning on line 89 in proxy/core/event/metrics.py

View check run for this annotation

Codecov / codecov/patch

proxy/core/event/metrics.py#L86-L89

Added lines #L86 - L89 were not covered by tests

def __enter__(self) -> "MetricsEventSubscriber":
def __enter__(self) -> 'MetricsEventSubscriber':
self._setup_metrics_directory()
self.subscriber.setup()
return self
Expand All @@ -98,11 +98,11 @@ def __exit__(self, *args: Any) -> None:

@staticmethod
def callback(storage: MetricsStorage, event: Dict[str, Any]) -> None:
if event["event_name"] == eventNames.WORK_STARTED:
storage.incr_counter("work_started")
elif event["event_name"] == eventNames.REQUEST_COMPLETE:
storage.incr_counter("request_complete")
elif event["event_name"] == eventNames.WORK_FINISHED:
storage.incr_counter("work_finished")
if event['event_name'] == eventNames.WORK_STARTED:
storage.incr_counter('work_started')

Check warning on line 102 in proxy/core/event/metrics.py

View check run for this annotation

Codecov / codecov/patch

proxy/core/event/metrics.py#L102

Added line #L102 was not covered by tests
elif event['event_name'] == eventNames.REQUEST_COMPLETE:
storage.incr_counter('request_complete')

Check warning on line 104 in proxy/core/event/metrics.py

View check run for this annotation

Codecov / codecov/patch

proxy/core/event/metrics.py#L104

Added line #L104 was not covered by tests
elif event['event_name'] == eventNames.WORK_FINISHED:
storage.incr_counter('work_finished')

Check warning on line 106 in proxy/core/event/metrics.py

View check run for this annotation

Codecov / codecov/patch

proxy/core/event/metrics.py#L106

Added line #L106 was not covered by tests
else:
print("Unhandled", event)
print('Unhandled', event)

Check warning on line 108 in proxy/core/event/metrics.py

View check run for this annotation

Codecov / codecov/patch

proxy/core/event/metrics.py#L108

Added line #L108 was not covered by tests

0 comments on commit 701ceb9

Please sign in to comment.