Skip to content

Commit 76f5960

Browse files
Merge pull request #1117 from roboflow/feat/pass-service-name-received-within-request-path-param
Feat/pass service name received within request path param
2 parents 1a14322 + 1bbd64f commit 76f5960

File tree

4 files changed

+29
-11
lines changed

4 files changed

+29
-11
lines changed

inference/models/__init__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@
7373
pass
7474

7575
from inference.models.resnet import ResNetClassification
76+
from inference.models.rfdetr import RFDETRObjectDetection
7677
from inference.models.vit import VitClassification
7778
from inference.models.yolact import YOLACT
7879
from inference.models.yolonas import YOLONASObjectDetection
@@ -92,4 +93,3 @@
9293
YOLOv11ObjectDetection,
9394
)
9495
from inference.models.yolov12 import YOLOv12ObjectDetection
95-
from inference.models.rfdetr import RFDETRObjectDetection

inference/models/rfdetr/__init__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
from inference.models.rfdetr.rfdetr import RFDETRObjectDetection
22

3-
__all__ = ["RFDETRObjectDetection"]
3+
__all__ = ["RFDETRObjectDetection"]

inference/usage_tracking/collector.py

+20-3
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ def _calculate_resource_hash(resource_details: Dict[str, Any]) -> str:
223223
return sha256_hash(json.dumps(resource_details, sort_keys=True))
224224

225225
def _enqueue_payload(self, payload: UsagePayload):
226-
logger.debug("Enqueuing usage payload %s", payload)
226+
logger.debug("Enqueuing usage payload")
227227
if not payload:
228228
return
229229
with self._queue_lock:
@@ -347,6 +347,8 @@ def _update_usage_payload(
347347
inference_test_run: bool = False,
348348
fps: float = 0,
349349
execution_duration: float = 0,
350+
roboflow_service_name: Optional[str] = None,
351+
roboflow_internal_secret: Optional[str] = None,
350352
):
351353
source = str(source) if source else ""
352354
try:
@@ -382,7 +384,8 @@ def _update_usage_payload(
382384
source_usage["ip_address_hash"] = ip_address_hash
383385
source_usage["is_gpu_available"] = is_gpu_available
384386
source_usage["execution_duration"] += execution_duration
385-
logger.debug("Updated usage: %s", source_usage)
387+
source_usage["roboflow_service_name"] = roboflow_service_name
388+
source_usage["roboflow_internal_secret"] = roboflow_internal_secret
386389

387390
def record_usage(
388391
self,
@@ -395,6 +398,8 @@ def record_usage(
395398
inference_test_run: bool = False,
396399
fps: float = 0,
397400
execution_duration: float = 0,
401+
roboflow_service_name: Optional[str] = None,
402+
roboflow_internal_secret: Optional[str] = None,
398403
):
399404
if not api_key:
400405
return
@@ -417,6 +422,8 @@ def record_usage(
417422
inference_test_run=inference_test_run,
418423
fps=fps,
419424
execution_duration=execution_duration,
425+
roboflow_service_name=roboflow_service_name,
426+
roboflow_internal_secret=roboflow_internal_secret,
420427
)
421428

422429
async def async_record_usage(
@@ -430,6 +437,8 @@ async def async_record_usage(
430437
inference_test_run: bool = False,
431438
fps: float = 0,
432439
execution_duration: float = 0,
440+
roboflow_service_name: Optional[str] = None,
441+
roboflow_internal_secret: Optional[str] = None,
433442
):
434443
if self._async_lock:
435444
async with self._async_lock:
@@ -443,6 +452,8 @@ async def async_record_usage(
443452
inference_test_run=inference_test_run,
444453
fps=fps,
445454
execution_duration=execution_duration,
455+
roboflow_internal_service_name=roboflow_service_name,
456+
roboflow_internal_secret=roboflow_internal_secret,
446457
)
447458
else:
448459
self.record_usage(
@@ -455,6 +466,8 @@ async def async_record_usage(
455466
inference_test_run=inference_test_run,
456467
fps=fps,
457468
execution_duration=execution_duration,
469+
roboflow_internal_service_name=roboflow_service_name,
470+
roboflow_internal_secret=roboflow_internal_secret,
458471
)
459472

460473
def _usage_collector(self):
@@ -515,7 +528,6 @@ def _offload_to_api(self, payloads: List[APIKeyUsage]):
515528
self._plan_details._is_enterprise_col_name
516529
]
517530

518-
logger.debug("Sending usage payload %s", payload)
519531
api_keys_hashes_failed = send_usage_payload(
520532
payload=payload,
521533
api_usage_endpoint_url=self._settings.api_usage_endpoint_url,
@@ -644,6 +656,9 @@ def _extract_usage_params_from_func_kwargs(
644656
else:
645657
logger.debug("Could not obtain API key from func kwargs")
646658

659+
roboflow_service_name = func_kwargs.get("source_info")
660+
roboflow_internal_secret = func_kwargs.get("service_secret")
661+
647662
return {
648663
"source": source,
649664
"api_key": usage_api_key,
@@ -653,6 +668,8 @@ def _extract_usage_params_from_func_kwargs(
653668
"inference_test_run": usage_inference_test_run,
654669
"fps": usage_fps,
655670
"execution_duration": execution_duration,
671+
"roboflow_service_name": roboflow_service_name,
672+
"roboflow_internal_secret": roboflow_internal_secret,
656673
}
657674

658675
def __call__(

inference/usage_tracking/decorator_helpers.py

+7-6
Original file line numberDiff line numberDiff line change
@@ -125,14 +125,15 @@ def get_request_resource_id_from_kwargs(func_kwargs: Dict[str, Any]) -> Optional
125125
def get_request_resource_details_from_kwargs(
126126
func_kwargs: Dict[str, Any],
127127
) -> Dict[str, Any]:
128+
resource_details = {}
128129
if "workflow_request" in func_kwargs:
129130
workflow_request = func_kwargs["workflow_request"]
130131
if hasattr(workflow_request, "specification") and isinstance(
131132
workflow_request.specification, dict
132133
):
133-
return {
134-
"steps": get_resource_details_from_workflow_json(
135-
workflow_json=workflow_request.specification,
136-
)
137-
}
138-
return {}
134+
resource_details["steps"] = get_resource_details_from_workflow_json(
135+
workflow_json=workflow_request.specification,
136+
)
137+
if "countinference" in func_kwargs:
138+
resource_details["billable"] = func_kwargs["countinference"]
139+
return resource_details

0 commit comments

Comments
 (0)