Skip to content
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

fix(ingestion/bigquery): user exceeded quota for concurrent project.lists requests #10578

Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
6385a63
add Bigquery list projects rate limit
shubhamjagtap639 May 23, 2024
fc9a8cc
Address review comments
shubhamjagtap639 May 24, 2024
58194de
Modify comment
shubhamjagtap639 May 24, 2024
1bb7819
Merge branch 'master' into bigquery-project.lists-requests-quota-exce…
hsheth2 May 24, 2024
bcedaf5
Add rate limiter for bq client list projects request
shubhamjagtap639 May 27, 2024
18e3b90
Revert test case changes
shubhamjagtap639 May 27, 2024
8061a37
Modify ratelimiter code and reduce the max result of list project api
shubhamjagtap639 May 28, 2024
206a123
Modify the max result and page size in bq client list project
shubhamjagtap639 May 30, 2024
9fa2318
temporary debug changes
shubhamjagtap639 Jun 5, 2024
02b69a0
Temporary debug changes
shubhamjagtap639 Jun 5, 2024
6fc9842
Add retry to bq client list project api
shubhamjagtap639 Jun 5, 2024
f4f7388
Modify bq get project method
shubhamjagtap639 Jun 11, 2024
31eece4
Modify bq get project method
shubhamjagtap639 Jun 11, 2024
29a22a6
Add debug log in bg list project request
shubhamjagtap639 Jun 11, 2024
28b4a6e
Add back retry to bq client list project request
shubhamjagtap639 Jun 11, 2024
be8a63c
Revert the get_projects method and add retry in list project request
shubhamjagtap639 Jun 12, 2024
a8bb758
Modify get_project method and list project count in report
shubhamjagtap639 Jun 12, 2024
ae42a79
Modify comment in get_project method
shubhamjagtap639 Jun 12, 2024
a685b27
Merge branch 'master' into bigquery-project.lists-requests-quota-exce…
hsheth2 Jun 14, 2024
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
Original file line number Diff line number Diff line change
Expand Up @@ -150,12 +150,22 @@ def get_query_result(self, query: str) -> RowIterator:
def get_projects(self) -> List[BigqueryProject]:
with self.report.list_projects:
try:
projects = self.bq_client.list_projects()

return [
BigqueryProject(id=p.project_id, name=p.friendly_name)
for p in projects
]
projects: List[BigqueryProject] = []
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add a comment explaining why this was required

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, Let me add the comment.
The thing is we are not able to regenerate the error but from doc we got to know two project.lists request is allowed per second and assumed that bigquery client method list_projects is not adding any limit in calling request.
Hence we are trying to add limit in requests per second externally,

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yup I understand that, but having it as a comment in the code will help future editors of this file

page_token: Optional[str] = None
while True:
projects_iterator = self.bq_client.list_projects(
max_results=5, page_token=page_token
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why is max_results=5?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, this should be 50 as API returns max 50 projects per page. Refer link

)
projects.extend(
[
BigqueryProject(id=p.project_id, name=p.friendly_name)
for p in projects_iterator
]
)
page_token = projects_iterator.next_page_token
if page_token is None:
break
return projects
except Exception as e:
logger.error(f"Error getting projects. {e}", exc_info=True)
return []
Expand Down
26 changes: 16 additions & 10 deletions metadata-ingestion/tests/unit/test_bigquery_source.py
Original file line number Diff line number Diff line change
Expand Up @@ -271,18 +271,24 @@ def test_get_projects_with_single_project_id(get_bq_client_mock):

@patch.object(BigQueryV2Config, "get_bigquery_client")
def test_get_projects_by_list(get_bq_client_mock):
mock_projects = MagicMock()
mock_projects.__iter__.return_value = iter(
[
SimpleNamespace(
project_id="test-1",
friendly_name="one",
),
SimpleNamespace(
project_id="test-2",
friendly_name="two",
),
]
)
mock_projects.next_page_token = None

client_mock = MagicMock()
get_bq_client_mock.return_value = client_mock
client_mock.list_projects.return_value = [
SimpleNamespace(
project_id="test-1",
friendly_name="one",
),
SimpleNamespace(
project_id="test-2",
friendly_name="two",
),
]
client_mock.list_projects.return_value = mock_projects

config = BigQueryV2Config.parse_obj({})
source = BigqueryV2Source(config=config, ctx=PipelineContext(run_id="test1"))
Expand Down
Loading