From 9cb28cd04a0cd5e34552053d0946191616d08f68 Mon Sep 17 00:00:00 2001 From: SolomonLake Date: Mon, 4 Nov 2024 16:15:29 -0600 Subject: [PATCH 1/2] Pass countinference to usage collector --- inference/core/interfaces/http/http_api.py | 5 +++++ inference/usage_tracking/collector.py | 2 ++ 2 files changed, 7 insertions(+) diff --git a/inference/core/interfaces/http/http_api.py b/inference/core/interfaces/http/http_api.py index 231f69eb6..48bbef3f5 100644 --- a/inference/core/interfaces/http/http_api.py +++ b/inference/core/interfaces/http/http_api.py @@ -2239,6 +2239,10 @@ async def legacy_infer_from_request( f"Invalid Content-Type: {request.headers['Content-Type']}" ) + if not countinference and service_secret != ROBOFLOW_SERVICE_SECRET: + raise MissingServiceSecretError( + "Service secret is required to disable inference usage tracking" + ) if LAMBDA: request_model_id = ( request.scope["aws.event"]["requestContext"]["authorizer"][ @@ -2301,6 +2305,7 @@ async def legacy_infer_from_request( active_learning_target_dataset=active_learning_target_dataset, source=source, source_info=source_info, + countinference=countinference, **args, ) diff --git a/inference/usage_tracking/collector.py b/inference/usage_tracking/collector.py index adcd32b2d..74530c972 100644 --- a/inference/usage_tracking/collector.py +++ b/inference/usage_tracking/collector.py @@ -558,6 +558,7 @@ def _extract_usage_params_from_func_kwargs( resource_id = "unknown" category = "unknown" + countinference = kwargs.get("countinference", True) source = None runtime_parameters = func_kwargs.get("runtime_parameters") if ( @@ -597,6 +598,7 @@ def _extract_usage_params_from_func_kwargs( "resource_id": resource_id, "inference_test_run": usage_inference_test_run, "fps": usage_fps, + "count_inference": countinference, } def __call__(self, func: Callable[P, T]) -> Callable[P, T]: From ffcefa7d08771946252c9d5ac42b8a8903b5b74c Mon Sep 17 00:00:00 2001 From: Grzegorz Klimaszewski <166530809+grzegorz-roboflow@users.noreply.github.com> Date: Tue, 5 Nov 2024 13:51:54 +0100 Subject: [PATCH 2/2] Store countinference as resource_details.billable --- inference/core/interfaces/http/http_api.py | 2 +- inference/usage_tracking/collector.py | 11 ++++++++--- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/inference/core/interfaces/http/http_api.py b/inference/core/interfaces/http/http_api.py index 48bbef3f5..180e1e845 100644 --- a/inference/core/interfaces/http/http_api.py +++ b/inference/core/interfaces/http/http_api.py @@ -2305,7 +2305,7 @@ async def legacy_infer_from_request( active_learning_target_dataset=active_learning_target_dataset, source=source, source_info=source_info, - countinference=countinference, + usage_billable=countinference, **args, ) diff --git a/inference/usage_tracking/collector.py b/inference/usage_tracking/collector.py index 74530c972..e8979aeba 100644 --- a/inference/usage_tracking/collector.py +++ b/inference/usage_tracking/collector.py @@ -504,12 +504,15 @@ def _extract_usage_params_from_func_kwargs( usage_workflow_id: str, usage_workflow_preview: bool, usage_inference_test_run: bool, + usage_billable: bool, func: Callable[[Any], Any], args: List[Any], kwargs: Dict[str, Any], ) -> Dict[str, Any]: func_kwargs = collect_func_params(func, args, kwargs) - resource_details = {} + resource_details = { + "billable": usage_billable, + } resource_id = "" category = None # TODO: add requires_api_key, True if workflow definition comes from platform or model comes from workspace @@ -558,7 +561,6 @@ def _extract_usage_params_from_func_kwargs( resource_id = "unknown" category = "unknown" - countinference = kwargs.get("countinference", True) source = None runtime_parameters = func_kwargs.get("runtime_parameters") if ( @@ -598,7 +600,6 @@ def _extract_usage_params_from_func_kwargs( "resource_id": resource_id, "inference_test_run": usage_inference_test_run, "fps": usage_fps, - "count_inference": countinference, } def __call__(self, func: Callable[P, T]) -> Callable[P, T]: @@ -610,6 +611,7 @@ def sync_wrapper( usage_workflow_id: str = "", usage_workflow_preview: bool = False, usage_inference_test_run: bool = False, + usage_billable: bool = True, **kwargs: P.kwargs, ) -> T: self.record_usage( @@ -619,6 +621,7 @@ def sync_wrapper( usage_workflow_id=usage_workflow_id, usage_workflow_preview=usage_workflow_preview, usage_inference_test_run=usage_inference_test_run, + usage_billable=usage_billable, func=func, args=args, kwargs=kwargs, @@ -634,6 +637,7 @@ async def async_wrapper( usage_workflow_id: str = "", usage_workflow_preview: bool = False, usage_inference_test_run: bool = False, + usage_billable: bool = True, **kwargs: P.kwargs, ) -> T: await self.async_record_usage( @@ -643,6 +647,7 @@ async def async_wrapper( usage_workflow_id=usage_workflow_id, usage_workflow_preview=usage_workflow_preview, usage_inference_test_run=usage_inference_test_run, + usage_billable=usage_billable, func=func, args=args, kwargs=kwargs,