mirror of
https://github.com/prowler-cloud/prowler.git
synced 2026-10-23 11:54:20 +00:00
perf(sdk): cache misses in Provider._load_ep_provider
Repeated lookups for unknown provider names (built-ins, typos, names
with no registered entry point) re-iterated entry_points() on every
call because only hits were cached. importlib.metadata.entry_points()
walks the metadata of every installed Python package, so the cost is
proportional to the size of the venv, not just to Prowler.
Caches None on miss so subsequent lookups hit the existing
`if name in Provider._ep_providers` short-circuit and return
immediately. Aligns Provider._ep_providers with the symmetric cache
in tool_wrapper._ep_class_cache, which already had this behavior.
Includes a regression test that mocks importlib.metadata.entry_points,
calls _load_ep_provider("nonexistent") twice, and asserts entry_points
is invoked exactly once.
Also underscore-prefix the remaining unused parameters on the abstract
Provider stubs (get_output_options, get_stdout_detail,
generate_compliance_output, display_compliance_table) so vulture stops
flagging them now that the file is in the diff. Same pattern applied
in bbe3a7dbf for the previous batch.
This commit is contained in:
1 parent
e5b9fee942
commit
4fb14bbb21
2 files changed
+30
-9
No files matched your search
@@ -302,6 +302,21 @@ class TestProviderDiscovery:
|
||||
# load() should only be called once due to caching
|
||||
mock_ep.return_value[0].load.assert_called_once()
|
||||
|
||||
@patch("prowler.providers.common.provider.importlib.metadata.entry_points")
|
||||
def test_load_ep_provider_caches_misses(self, mock_ep):
|
||||
"""A miss (unknown provider) must also be cached so repeated lookups
|
||||
do not re-iterate entry_points(). Aligns with tool_wrapper._ep_class_cache,
|
||||
which already caches None on miss."""
|
||||
mock_ep.return_value = []
|
||||
|
||||
first = Provider._load_ep_provider("nonexistent")
|
||||
second = Provider._load_ep_provider("nonexistent")
|
||||
|
||||
assert first is None
|
||||
assert second is None
|
||||
# entry_points() should only be called once across the two lookups
|
||||
mock_ep.assert_called_once()
|
||||
|
||||
@patch("prowler.providers.common.provider.Provider._load_ep_provider")
|
||||
@patch("prowler.providers.common.provider.Provider.get_available_providers")
|
||||
def test_get_providers_help_text_reads_cli_help_text(
|
||||
|
||||
Reference in new issue
Block a user