Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

feat: add module/class level api tracking #272

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Dec 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions 8 bigframes/core/log_adapter.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,19 +25,21 @@ def class_logger(decorated_cls):
"""Decorator that adds logging functionality to each method of the class."""
for attr_name, attr_value in decorated_cls.__dict__.items():
if callable(attr_value):
setattr(decorated_cls, attr_name, method_logger(attr_value))
setattr(decorated_cls, attr_name, method_logger(attr_value, decorated_cls))
return decorated_cls


def method_logger(method):
def method_logger(method, decorated_cls):
"""Decorator that adds logging functionality to a method."""

@functools.wraps(method)
def wrapper(*args, **kwargs):
class_name = decorated_cls.__name__ # Access decorated class name
api_method_name = str(method.__name__)
full_method_name = f"{class_name.lower()}-{api_method_name}"
# Track regular and "dunder" methods
if api_method_name.startswith("__") or not api_method_name.startswith("_"):
add_api_method(api_method_name)
add_api_method(full_method_name)
return method(*args, **kwargs)

return wrapper
Expand Down
4 changes: 2 additions & 2 deletions 4 tests/unit/core/test_log_adapter.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ def test_method_logging(test_instance):
# Check if the methods were added to the _api_methods list
api_methods = log_adapter.get_and_reset_api_methods()
assert api_methods is not None
assert "method1" in api_methods
assert "method2" in api_methods
assert "testclass-method1" in api_methods
assert "testclass-method2" in api_methods


def test_add_api_method_limit(test_instance):
Expand Down
16 changes: 8 additions & 8 deletions 16 tests/unit/session/test_io_bigquery.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,11 @@ def test_create_job_configs_labels_log_adaptor_call_method_under_length_limit():
expected_dict = {
"bigframes-api": "read_pandas",
"source": "bigquery-dataframes-temp",
"recent-bigframes-api-0": "__init__",
"recent-bigframes-api-1": "max",
"recent-bigframes-api-2": "__init__",
"recent-bigframes-api-3": "head",
"recent-bigframes-api-4": "__init__",
"recent-bigframes-api-0": "series-__init__",
"recent-bigframes-api-1": "dataframe-max",
"recent-bigframes-api-2": "dataframe-__init__",
"recent-bigframes-api-3": "dataframe-head",
"recent-bigframes-api-4": "dataframe-__init__",
}
assert labels is not None
assert len(labels) == 7
Expand All @@ -100,7 +100,7 @@ def test_create_job_configs_labels_length_limit_met_and_labels_is_none():
)
assert labels is not None
assert len(labels) == 64
assert "head" in labels.values()
assert "dataframe-head" in labels.values()


def test_create_job_configs_labels_length_limit_met():
Expand All @@ -125,8 +125,8 @@ def test_create_job_configs_labels_length_limit_met():
)
assert labels is not None
assert len(labels) == 64
assert "max" in labels.values()
assert "head" not in labels.values()
assert "dataframe-max" in labels.values()
assert "dataframe-head" not in labels.values()
assert "bigframes-api" in labels.keys()
assert "source" in labels.keys()

Expand Down
Morty Proxy This is a proxified and sanitized view of the page, visit original site.