Skip to content

Commit

Permalink
Merge pull request #772 from roboflow/do-not-store-usage-when-api-key…
Browse files Browse the repository at this point in the history
…-unavailable

Do not store usage in cache when API key is not available
  • Loading branch information
grzegorz-roboflow authored Nov 4, 2024
2 parents 7247ce1 + aa8b611 commit 9ffd56c
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 24 deletions.
2 changes: 2 additions & 0 deletions inference/usage_tracking/collector.py
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,8 @@ def record_usage(
inference_test_run: bool = False,
fps: float = 0,
) -> DefaultDict[str, Any]:
if not api_key:
return
if self._settings.opt_out and not api_key:
return
self.record_system_info()
Expand Down
23 changes: 1 addition & 22 deletions inference/usage_tracking/payload_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,28 +56,7 @@ def zip_usage_payloads(usage_payloads: List[APIKeyUsage]) -> List[APIKeyUsage]:
for usage_payload in usage_payloads:
for api_key_hash, resource_payloads in usage_payload.items():
if api_key_hash == "":
if (
resource_payloads
and len(resource_payloads) > 1
or list(resource_payloads.keys()) != [""]
):
continue
api_key_usage_with_resource = get_api_key_usage_containing_resource(
api_key_hash=api_key_hash,
usage_payloads=usage_payloads,
)
if not api_key_usage_with_resource:
system_info_payload = resource_payloads
continue
api_key_hash = api_key_usage_with_resource["api_key_hash"]
resource_id = api_key_usage_with_resource["resource_id"]
category = api_key_usage_with_resource.get("category")
for v in resource_payloads.values():
v["api_key_hash"] = api_key_hash
if "resource_id" not in v or not v["resource_id"]:
v["resource_id"] = resource_id
if "category" not in v or not v["category"]:
v["category"] = category
continue
api_key_usage_by_exec_session_id = usage_by_exec_session_id.setdefault(
api_key_hash, {}
)
Expand Down
4 changes: 2 additions & 2 deletions tests/inference/unit_tests/usage_tracking/test_collector.py
Original file line number Diff line number Diff line change
Expand Up @@ -486,9 +486,9 @@ def test_zip_usage_payloads_with_system_info_missing_resource_id():
def test_zip_usage_payloads_with_system_info_missing_resource_id_and_api_key():
dumped_usage_payloads = [
{
"": {
"api2": {
"": {
"api_key_hash": "",
"api_key_hash": "api2",
"resource_id": "",
"timestamp_start": 1721032989934855000,
"is_gpu_available": False,
Expand Down

0 comments on commit 9ffd56c

Please sign in to comment.