Reputation: 1
I am getting this error when trying to implement BigQuery Slot Reservation from google cloud in python as explained here: https://cloud.google.com/python/docs/reference/bigqueryreservation/latest/google.cloud.bigquery_reservation_v1.services.reservation_service.ReservationServiceClient
I have also tried to run the code as described in this blog: https://medium.com/google-cloud/optimize-bigquery-costs-with-flex-slots-e06ec5e4aa90
As far as I figured out I use the correct methods and arguments and the error appears when making the request. When I run
assign_config = Assignment(job_type='QUERY',
assignee='projects/{}'.format(user_project))
assign = res_api.create_assignment(parent=reservation_id,
assignment=assign_config)
I get this error
InactiveRpcError Traceback (most recent call last) /usr/local/lib/python3.7/dist-packages/google/api_core/grpc_helpers.py in error_remapped_callable(*args, **kwargs) 66 try: ---> 67 return callable(*args, **kwargs) 68 except grpc.RpcError as exc:
6 frames /usr/local/lib/python3.7/dist-packages/grpc/_channel.py in call(self, request, timeout, metadata, credentials, wait_for_ready, compression) 945 wait_for_ready, compression) --> 946 return _end_unary_response_blocking(state, call, False, None) 947
/usr/local/lib/python3.7/dist-packages/grpc/_channel.py in _end_unary_response_blocking(state, call, with_call, deadline) 848 else: --> 849 raise _InactiveRpcError(state) 850
_InactiveRpcError: <_InactiveRpcError of RPC that terminated with: status = StatusCode.INVALID_ARGUMENT details = "Request contains an invalid argument." debug_error_string = "{"created":"@1650884667.228899135","description":"Error received from peer ipv4:142.250.141.95:443","file":"src/core/lib/surface/call.cc","file_line":903,"grpc_message":"Request contains an invalid argument.","grpc_status":3}"
The above exception was the direct cause of the following exception:
InvalidArgument Traceback (most recent call last) in () 5 ) 6 ----> 7 assign = client.create_assignment(parent=res_id, assignment=assign_config)
/usr/local/lib/python3.7/dist-packages/google/cloud/bigquery_reservation_v1/services/reservation_service/client.py in create_assignment(self, request, parent, assignment, retry, timeout, metadata) 1871 1872 # Send the request. -> 1873 response = rpc(request, retry=retry, timeout=timeout, metadata=metadata,) 1874 1875 # Done; return the response.
/usr/local/lib/python3.7/dist-packages/google/api_core/gapic_v1/method.py in call(self, *args, **kwargs) 143 kwargs["metadata"] = metadata 144 --> 145 return wrapped_func(*args, **kwargs) 146 147
/usr/local/lib/python3.7/dist-packages/google/api_core/grpc_helpers.py in error_remapped_callable(*args, **kwargs) 67 return callable_(*args, **kwargs) 68 except grpc.RpcError as exc: ---> 69 six.raise_from(exceptions.from_grpc_error(exc), exc) 70 71 return error_remapped_callable
/usr/local/lib/python3.7/dist-packages/six.py in raise_from(value, from_value)
InvalidArgument: 400 Request contains an invalid argument.
My full code:
!pip install protobuf==3.19.0
!pip install google-api-python-client==2.45.0
!pip install google-cloud-bigquery-reservation
from google.colab import auth
auth.authenticate_user()
project_id = 'my-id'
region = 'EU'
parent_arg = "projects/{}/locations/{}".format(project_id,
region)
!gcloud config set project {project_id}
from google.cloud import bigquery_reservation_v1
from google.cloud.bigquery_reservation_v1 import *
from google.cloud import bigquery
client = bigquery_reservation_v1.ReservationServiceClient()
def purchase_commitment(slots=500):
commit_config = CapacityCommitment(plan='FLEX', slot_count=slots)
commit = client.create_capacity_commitment(parent=parent_arg,
capacity_commitment=commit_config)
print(commit)
return commit.name
def create_reservation(reservation_name, slots=500):
res_config = Reservation(slot_capacity=slots, ignore_idle_slots=False)
res = client.create_reservation(parent=parent_arg,
reservation_id=reservation_name,
reservation=res_config)
print(res)
return res.name
def create_assignment(reservation_id, user_project):
assign_config = bigquery_reservation_v1.Assignment(
#job_type=bigquery_reservation_v1.types.Assignment.JobType(2),
job_type="QUERY",
assignee=f"projects/{project_id}"
)
assign = client.create_assignment(parent=res_id, assignment=assign_config)
print(assign)
return assign.name
reservation_name = 'sample-reservation'
slots = 500
commit_id = purchase_commitment(slots)
res_id = create_reservation(reservation_name, slots)
assign_id = create_assignment(res_id, project_id)
Upvotes: 0
Views: 509
Reputation: 56
Instead of using the code above for making the assignment, I used the code below:
assignment_config = Assignment(job_type='QUERY', assignee='projects/{}'.format(project_id))
assignment = client.create_assignment(CreateAssignmentRequest(
parent=res_id,
assignment=assignment_config,
))
Also instead of using the project_id in number format, I used the full name of the project. This
Upvotes: 0