Skip to content

Commit

Permalink
fix(metrics): only log the bucket for the protocol used
Browse files Browse the repository at this point in the history
  • Loading branch information
Avantol13 committed Dec 1, 2023
1 parent fc1b08d commit 51f9340
Showing 1 changed file with 19 additions and 16 deletions.
35 changes: 19 additions & 16 deletions fence/blueprints/data/indexd.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,34 +160,37 @@ def get_signed_url_for_file(
}

_log_signed_url_data_info(
index_document=indexed_file.index_document,
user_sub=flask.g.audit_data.get("sub", "")
indexed_file=indexed_file,
user_sub=flask.g.audit_data.get("sub", ""),
requested_protocol=requested_protocol
)

return {"url": signed_url}


def _log_signed_url_data_info(index_document, user_sub):
size_in_kibibytes = index_document.get("size", 0) / 1024
acl = index_document.get("acl")
authz = index_document.get("authz")
buckets = set()
def _log_signed_url_data_info(indexed_file, user_sub, requested_protocol):
size_in_kibibytes = indexed_file.index_document.get("size", 0) / 1024
acl = indexed_file.index_document.get("acl")
authz = indexed_file.index_document.get("authz")

for url in index_document.get("urls", []):
# the behavior later on is to pick the 1st location as the signed URL if a protocol is not requested
protocol = requested_protocol or indexed_file.indexed_file_locations[0].protocol

# figure out which bucket was used based on the protocol
bucket = ""
for url in indexed_file.index_document.get("urls", []):
bucket_name = None
if "://" in url:
# Extract the protocol and the rest of the URL
protocol, rest_of_url = url.split("://", 1)

# Extract bucket name
bucket_name = rest_of_url.split("/")[0]
bucket_protocol, rest_of_url = url.split("://", 1)

buckets.add(bucket_name)

buckets_formatted = ",".join(buckets)
if bucket_protocol == protocol:
# Extract bucket name
bucket = rest_of_url.split("/")[0]
break

logger.info(
f"Signed URL Generated. size_in_kibibytes={size_in_kibibytes} acl={acl} authz={authz} buckets={buckets_formatted} user_sub={user_sub}"
f"Signed URL Generated. size_in_kibibytes={size_in_kibibytes} acl={acl} authz={authz} bucket={bucket} user_sub={user_sub}"
)


Expand Down

0 comments on commit 51f9340

Please sign in to comment.