-
Notifications
You must be signed in to change notification settings - Fork 50
feat: log most recent API calls as recent-bigframes-api-xx
labels on BigQuery jobs
#145
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
Changes from all commits
Commits
Show all changes
45 commits
Select commit
Hold shift + click to select a range
c2009ed
docs: link to ML.EVALUATE BQML page for score() methods
ashleyxuu 09ad5e4
feat: label query job with bigframes-api-xx using decorator
ashleyxuu 4f4eb9b
reorganize the commit
ashleyxuu 9ee937c
Merge branch 'main' into ashleyxu-add-api-methods
ashleyxuu 272f0af
test: Log slowest tests durations (#146)
shobsi 0e4c49c
docs: link to ML.EVALUATE BQML page for score() methods (#137)
ashleyxuu aad2c1a
feat: populate ibis version in user agent (#140)
ashleyxuu 1043d6d
fix: don't override the global logging config (#138)
tswast 1f49ef9
fix: use indexee's session for loc listlike cases (#152)
milkshakeiii c4c1e6e
feat: add pandas.qcut (#104)
TrevorBergeron 4a27f44
feat: add unstack to series, add level param (#115)
TrevorBergeron fface57
feat: add `DataFrame.to_pandas_batches()` to download large `DataFram…
tswast bbc3c69
fix: resolve plotly rendering issue by using ipython html for job pro…
orrbradford a99d62c
refactor: ArrayValue is now a tree that defers conversion to ibis (#110)
TrevorBergeron f37d0b0
fix: fix bug with column names under repeated column assignment (#150)
milkshakeiii aba301c
test: refactor remote function tests (#147)
shobsi 53bb2cd
feat: add dataframe melt (#116)
TrevorBergeron 2bf4bcc
docs: add artithmetic df sample code (#153)
ashleyxuu 343414a
feat: Implement operator `@` for `DataFrame.dot` (#139)
shobsi 4eac10d
fix: fix typo and address comments
ashleyxuu 868d2ad
Merge branch 'main' into ashleyxu-add-api-methods
ashleyxuu c03a8d9
Merge branch 'main' into ashleyxu-add-api-methods
tswast 39321e4
fix: address comments
ashleyxuu aebcf11
Remove utils folder and refactor it in core directory
ashleyxuu 72217c2
Merge branch 'main' into ashleyxu-add-api-methods
ashleyxuu ec526b5
Remove utils folder and refactor it in core directory
ashleyxuu 9edfe31
Merge remote-tracking branch 'origin/ashleyxu-add-api-methods' into a…
ashleyxuu 4baa373
Merge branch 'main' into ashleyxu-add-api-methods
ashleyxuu 3a94c23
🦉 Updates from OwlBot post-processor
gcf-owl-bot[bot] d84c569
fix merge conflicts
ashleyxuu 308c9a7
Merge remote-tracking branch 'origin/ashleyxu-add-api-methods' into a…
ashleyxuu 4618107
commit the conflicts
ashleyxuu a87bcb8
redesign the log adapter
ashleyxuu cf97f8b
resolve conflicts and merge remote-tracking branch 'origin/main' into…
ashleyxuu 53a99f9
Make the global _api_methods and lock threads
ashleyxuu 3cc3599
Merge branch 'main' into ashleyxu-add-api-methods
ashleyxuu 1c3deb5
Make the global _api_methods and lock threads
ashleyxuu 99f423b
merge conflicts
ashleyxuu 115de27
address comments
ashleyxuu b0adf27
address comments
ashleyxuu b4ea9e3
Merge remote-tracking branch 'origin/ashleyxu-add-api-methods' into a…
ashleyxuu df9c9c0
fix error
ashleyxuu 00bb6de
fix None job_config error
ashleyxuu 36fea06
address comments
ashleyxuu e872d18
Merge branch 'main' into ashleyxu-add-api-methods
ashleyxuu File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
# Copyright 2023 Google LLC | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
import functools | ||
import threading | ||
from typing import List | ||
|
||
_lock = threading.Lock() | ||
MAX_LABELS_COUNT = 64 | ||
_api_methods: List = [] | ||
|
||
|
||
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)) | ||
return decorated_cls | ||
|
||
|
||
def method_logger(method): | ||
"""Decorator that adds logging functionality to a method.""" | ||
|
||
@functools.wraps(method) | ||
def wrapper(*args, **kwargs): | ||
api_method_name = str(method.__name__) | ||
# Track regular and "dunder" methods | ||
if api_method_name.startswith("__") or not api_method_name.startswith("_"): | ||
add_api_method(api_method_name) | ||
return method(*args, **kwargs) | ||
|
||
return wrapper | ||
|
||
|
||
def add_api_method(api_method_name): | ||
global _lock | ||
global _api_methods | ||
with _lock: | ||
# Push the method to the front of the _api_methods list | ||
_api_methods.insert(0, api_method_name) | ||
# Keep the list length within the maximum limit (adjust MAX_LABELS_COUNT as needed) | ||
_api_methods = _api_methods[:MAX_LABELS_COUNT] | ||
|
||
|
||
def get_and_reset_api_methods(): | ||
global _lock | ||
with _lock: | ||
previous_api_methods = list(_api_methods) | ||
_api_methods.clear() | ||
return previous_api_methods |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
# Copyright 2023 Google LLC | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
import pytest | ||
ashleyxuu marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
from bigframes.core import log_adapter | ||
|
||
MAX_LABELS_COUNT = 64 | ||
|
||
|
||
@pytest.fixture | ||
def test_instance(): | ||
# Create a simple class for testing | ||
@log_adapter.class_logger | ||
class TestClass: | ||
def method1(self): | ||
pass | ||
|
||
def method2(self): | ||
pass | ||
|
||
return TestClass() | ||
|
||
|
||
def test_method_logging(test_instance): | ||
test_instance.method1() | ||
test_instance.method2() | ||
|
||
# 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 | ||
|
||
|
||
def test_add_api_method_limit(test_instance): | ||
# Ensure that add_api_method correctly adds a method to _api_methods | ||
for i in range(70): | ||
test_instance.method2() | ||
assert len(log_adapter._api_methods) == MAX_LABELS_COUNT | ||
|
||
|
||
def test_get_and_reset_api_methods(test_instance): | ||
# Ensure that get_and_reset_api_methods returns a copy and resets the list | ||
test_instance.method1() | ||
test_instance.method2() | ||
previous_methods = log_adapter.get_and_reset_api_methods() | ||
assert previous_methods is not None | ||
assert log_adapter._api_methods == [] |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.