Skip to content

Commit

Permalink
Quick: metrics log trackingid fix (#1502)
Browse files Browse the repository at this point in the history
* upgrade tapipy

* fix audit log tracking id typo

* refactor job post audit log
  • Loading branch information
rstijerina authored Dec 13, 2024
1 parent 067d799 commit b358988
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 32 deletions.
37 changes: 13 additions & 24 deletions designsafe/apps/workspace/api/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
from django.db.models import F, Count
from django.db.models.lookups import GreaterThan
from django.urls import reverse
from tapipy.tapis import TapisResult
from tapipy.errors import InternalServerError, UnauthorizedError
from designsafe.apps.api.exceptions import ApiException
from designsafe.apps.api.users.utils import get_user_data
Expand Down Expand Up @@ -787,21 +788,6 @@ def _submit_job(self, request, body, tapis, username):
headers={"X-Tapis-Tracking-ID": f"portals.{request.session.session_key}"},
)

METRICS.info(
"Jobs",
extra={
"user": username,
"sessionId": getattr(request.session, "session_key", ""),
"operation": "submitJob",
"agent": request.META.get("HTTP_USER_AGENT"),
"ip": get_client_ip(request),
"info": {
"body": body,
"uuid": response.uuid if response else None,
},
},
)

return response

def post(self, request, *args, **kwargs):
Expand Down Expand Up @@ -833,6 +819,17 @@ def post(self, request, *args, **kwargs):
"X-Tapis-Tracking-ID": f"portals.{request.session.session_key}"
},
)

else:
response = self._submit_job(request, body, tapis, username)

if isinstance(response, TapisResult):
metrics_info = {
"body": body,
}
response_uuid = response.get("uuid", None)
if response_uuid:
metrics_info["response_uuid"] = response_uuid
METRICS.info(
"Jobs",
extra={
Expand All @@ -841,18 +838,10 @@ def post(self, request, *args, **kwargs):
"operation": operation,
"agent": request.META.get("HTTP_USER_AGENT"),
"ip": get_client_ip(request),
"info": {
"body": body,
"response": response.__dict__ if response else None,
},
"info": metrics_info,
},
)

else:
# submit job
response = self._submit_job(request, body, tapis, username)


return JsonResponse(
{
"status": 200,
Expand Down
2 changes: 1 addition & 1 deletion designsafe/settings/common_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -442,7 +442,7 @@ def guid_filter(record):
'metrics': {
'format': '[METRICS] %(levelname)s %(module)s %(name)s.%(funcName)s:%(lineno)s:'
' %(message)s user=%(user)s ip=%(ip)s agent=%(agent)s sessionId=%(sessionId)s op=%(operation)s'
' info=%(info)s timestamp=%(asctime)s trackingId=portal.%(sessionId)s guid=%(logGuid)s portal=designsafe tenant=designsafe'
' info=%(info)s timestamp=%(asctime)s trackingId=portals.%(sessionId)s guid=%(logGuid)s portal=designsafe tenant=designsafe'
},
},
'handlers': {
Expand Down
12 changes: 6 additions & 6 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ django-select2 = "6.3.1"
djangocms-admin-style = "~3.2.6"
pydantic = "^2.5.0"
networkx = "^3.2.1"
tapipy = "^1.6.1"
tapipy = "^1.7.1"
pycryptodome = "^3.20.0"
paramiko = "^3.4.0"

Expand Down

0 comments on commit b358988

Please sign in to comment.