mirror of
https://github.com/retspen/webvirtcloud
synced 2026-12-01 08:26:03 +00:00
fix(logs): a job's rows carry the address it was asked from, and a cancel its own user
A job keeps the client address of its submission (Operation.client_ip, migration operations.0003); the rows the worker writes for it, including the migration's and the VM delete's own rows, carry it. A cancel is written under the user who asked and from their address, also when an administrator cancels another user's job; a running job's cancel gets a row when asked, and its end a row when it stops. A resolution carries the administrator's address.
This commit is contained in:
parent
528b4492f6
commit
c5c6de6ba8
9 changed files with 85 additions and 14 deletions
|
|
@ -5,6 +5,9 @@ import contextvars
|
|||
import logging
|
||||
|
||||
current_request = contextvars.ContextVar("current_request", default=None)
|
||||
# the client address while a request is handled, reset when it is answered
|
||||
# (current_request stays for Django's log line): the Logs rows of the jobs it submits
|
||||
request_ip = contextvars.ContextVar("request_ip", default=None)
|
||||
|
||||
|
||||
class RequestFilter(logging.Filter):
|
||||
|
|
|
|||
|
|
@ -13,6 +13,7 @@ from operations import claims, jobs
|
|||
from operations.utils import busy_message, public_error_text, said, summary, words
|
||||
|
||||
from vrtManager.util import ConnectionFailed, InUse
|
||||
from webvirtcloud import log_context
|
||||
from webvirtcloud.log_context import current_request
|
||||
|
||||
API_PREFIX = "/api/"
|
||||
|
|
@ -83,7 +84,11 @@ class RequestIdMiddleware:
|
|||
request.client_ip = request_ip(request)
|
||||
# not reset after the response: Django logs a 4xx or 5xx answer after the middleware returns
|
||||
current_request.set(request)
|
||||
response = self.get_response(request)
|
||||
token = log_context.request_ip.set(request.client_ip)
|
||||
try:
|
||||
response = self.get_response(request)
|
||||
finally:
|
||||
log_context.request_ip.reset(token)
|
||||
response["X-Request-ID"] = request.request_id
|
||||
return response
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue