Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 4f3db3d

Browse files
authoredDec 14, 2023
feat: add module/class level api tracking (#272)
* feat: add module/class level api tracking * fix the failing unit test * fix: follow the labels requirement
1 parent b54791c commit 4f3db3d

File tree

3 files changed

+15
-13
lines changed

3 files changed

+15
-13
lines changed
 

‎bigframes/core/log_adapter.py

+5-3
Original file line numberDiff line numberDiff line change
@@ -25,19 +25,21 @@ def class_logger(decorated_cls):
2525
"""Decorator that adds logging functionality to each method of the class."""
2626
for attr_name, attr_value in decorated_cls.__dict__.items():
2727
if callable(attr_value):
28-
setattr(decorated_cls, attr_name, method_logger(attr_value))
28+
setattr(decorated_cls, attr_name, method_logger(attr_value, decorated_cls))
2929
return decorated_cls
3030

3131

32-
def method_logger(method):
32+
def method_logger(method, decorated_cls):
3333
"""Decorator that adds logging functionality to a method."""
3434

3535
@functools.wraps(method)
3636
def wrapper(*args, **kwargs):
37+
class_name = decorated_cls.__name__ # Access decorated class name
3738
api_method_name = str(method.__name__)
39+
full_method_name = f"{class_name.lower()}-{api_method_name}"
3840
# Track regular and "dunder" methods
3941
if api_method_name.startswith("__") or not api_method_name.startswith("_"):
40-
add_api_method(api_method_name)
42+
add_api_method(full_method_name)
4143
return method(*args, **kwargs)
4244

4345
return wrapper

‎tests/unit/core/test_log_adapter.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@ def test_method_logging(test_instance):
4040
# Check if the methods were added to the _api_methods list
4141
api_methods = log_adapter.get_and_reset_api_methods()
4242
assert api_methods is not None
43-
assert "method1" in api_methods
44-
assert "method2" in api_methods
43+
assert "testclass-method1" in api_methods
44+
assert "testclass-method2" in api_methods
4545

4646

4747
def test_add_api_method_limit(test_instance):

‎tests/unit/session/test_io_bigquery.py

+8-8
Original file line numberDiff line numberDiff line change
@@ -76,11 +76,11 @@ def test_create_job_configs_labels_log_adaptor_call_method_under_length_limit():
7676
expected_dict = {
7777
"bigframes-api": "read_pandas",
7878
"source": "bigquery-dataframes-temp",
79-
"recent-bigframes-api-0": "__init__",
80-
"recent-bigframes-api-1": "max",
81-
"recent-bigframes-api-2": "__init__",
82-
"recent-bigframes-api-3": "head",
83-
"recent-bigframes-api-4": "__init__",
79+
"recent-bigframes-api-0": "series-__init__",
80+
"recent-bigframes-api-1": "dataframe-max",
81+
"recent-bigframes-api-2": "dataframe-__init__",
82+
"recent-bigframes-api-3": "dataframe-head",
83+
"recent-bigframes-api-4": "dataframe-__init__",
8484
}
8585
assert labels is not None
8686
assert len(labels) == 7
@@ -100,7 +100,7 @@ def test_create_job_configs_labels_length_limit_met_and_labels_is_none():
100100
)
101101
assert labels is not None
102102
assert len(labels) == 64
103-
assert "head" in labels.values()
103+
assert "dataframe-head" in labels.values()
104104

105105

106106
def test_create_job_configs_labels_length_limit_met():
@@ -125,8 +125,8 @@ def test_create_job_configs_labels_length_limit_met():
125125
)
126126
assert labels is not None
127127
assert len(labels) == 64
128-
assert "max" in labels.values()
129-
assert "head" not in labels.values()
128+
assert "dataframe-max" in labels.values()
129+
assert "dataframe-head" not in labels.values()
130130
assert "bigframes-api" in labels.keys()
131131
assert "source" in labels.keys()
132132

0 commit comments

Comments
 (0)
Failed to load comments.