-
Notifications
You must be signed in to change notification settings - Fork 605
Add a lock around metrics recording for local apis #1377
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
Conversation
pkg/workloads/cortex/lib/type/api.py
Outdated
|
|
||
| def store_metrics_locally(self, status_code, total_time): | ||
| status_code_series = int(status_code / 100) | ||
| try: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The try/except block isn't required for the following 2 instructions:
self.metrics_file_lock.acquire()
status_code_series = int(status_code / 100)The 2 above will not fail. The only method that might fail though is self.increment_counter_file. So we could have something like:
try:
status_code_file_name = f"/mnt/workspace/{os.getpid()}.{status_code_series}XX"
self.increment_counter_file(status_code_file_name, 1)
request_time_file = f"/mnt/workspace/{os.getpid()}.request_time"
self.increment_counter_file(request_time_file, total_time)
finally:
self.metrics_file_lock.release()We could also decide to take the 2 string assignments out of the try block. I think this could be a little cleaner:
try:
self.increment_counter_file(status_code_file_name, 1)
self.increment_counter_file(request_time_file, total_time)
finally:
self.metrics_file_lock.release()
closes #1209
checklist:
make testandmake lint