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

feat: Add ListHotTablets API method and protobufs #542

Merged
merged 3 commits into from Mar 24, 2022
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 6 additions & 0 deletions google/cloud/bigtable_admin_v2/__init__.py
Expand Up @@ -34,6 +34,8 @@
from .types.bigtable_instance_admin import ListAppProfilesResponse
from .types.bigtable_instance_admin import ListClustersRequest
from .types.bigtable_instance_admin import ListClustersResponse
from .types.bigtable_instance_admin import ListHotTabletsRequest
from .types.bigtable_instance_admin import ListHotTabletsResponse
from .types.bigtable_instance_admin import ListInstancesRequest
from .types.bigtable_instance_admin import ListInstancesResponse
from .types.bigtable_instance_admin import PartialUpdateClusterMetadata
Expand Down Expand Up @@ -78,6 +80,7 @@
from .types.instance import AutoscalingLimits
from .types.instance import AutoscalingTargets
from .types.instance import Cluster
from .types.instance import HotTablet
from .types.instance import Instance
from .types.table import Backup
from .types.table import BackupInfo
Expand Down Expand Up @@ -130,13 +133,16 @@
"GetInstanceRequest",
"GetSnapshotRequest",
"GetTableRequest",
"HotTablet",
"Instance",
"ListAppProfilesRequest",
"ListAppProfilesResponse",
"ListBackupsRequest",
"ListBackupsResponse",
"ListClustersRequest",
"ListClustersResponse",
"ListHotTabletsRequest",
"ListHotTabletsResponse",
"ListInstancesRequest",
"ListInstancesResponse",
"ListSnapshotsRequest",
Expand Down
10 changes: 10 additions & 0 deletions google/cloud/bigtable_admin_v2/gapic_metadata.json
Expand Up @@ -70,6 +70,11 @@
"list_clusters"
]
},
"ListHotTablets": {
"methods": [
"list_hot_tablets"
]
},
"ListInstances": {
"methods": [
"list_instances"
Expand Down Expand Up @@ -175,6 +180,11 @@
"list_clusters"
]
},
"ListHotTablets": {
"methods": [
"list_hot_tablets"
]
},
"ListInstances": {
"methods": [
"list_instances"
Expand Down
Expand Up @@ -69,8 +69,14 @@ class BigtableInstanceAdminAsyncClient:
parse_crypto_key_path = staticmethod(
BigtableInstanceAdminClient.parse_crypto_key_path
)
hot_tablet_path = staticmethod(BigtableInstanceAdminClient.hot_tablet_path)
parse_hot_tablet_path = staticmethod(
BigtableInstanceAdminClient.parse_hot_tablet_path
)
instance_path = staticmethod(BigtableInstanceAdminClient.instance_path)
parse_instance_path = staticmethod(BigtableInstanceAdminClient.parse_instance_path)
table_path = staticmethod(BigtableInstanceAdminClient.table_path)
parse_table_path = staticmethod(BigtableInstanceAdminClient.parse_table_path)
common_billing_account_path = staticmethod(
BigtableInstanceAdminClient.common_billing_account_path
)
Expand Down Expand Up @@ -2109,6 +2115,98 @@ async def test_iam_permissions(
# Done; return the response.
return response

async def list_hot_tablets(
self,
request: Union[bigtable_instance_admin.ListHotTabletsRequest, dict] = None,
*,
parent: str = None,
retry: OptionalRetry = gapic_v1.method.DEFAULT,
timeout: float = None,
metadata: Sequence[Tuple[str, str]] = (),
) -> pagers.ListHotTabletsAsyncPager:
r"""Lists hot tablets in a cluster, within the time range
provided. Hot tablets are ordered based on CPU usage.

Args:
request (Union[google.cloud.bigtable_admin_v2.types.ListHotTabletsRequest, dict]):
The request object. Request message for
BigtableInstanceAdmin.ListHotTablets.
parent (:class:`str`):
Required. The cluster name to list hot tablets. Value is
in the following form:
``projects/{project}/instances/{instance}/clusters/{cluster}``.

This corresponds to the ``parent`` field
on the ``request`` instance; if ``request`` is provided, this
should not be set.
retry (google.api_core.retry.Retry): Designation of what errors, if any,
should be retried.
timeout (float): The timeout for this request.
metadata (Sequence[Tuple[str, str]]): Strings which should be
sent along with the request as metadata.

Returns:
google.cloud.bigtable_admin_v2.services.bigtable_instance_admin.pagers.ListHotTabletsAsyncPager:
Response message for
BigtableInstanceAdmin.ListHotTablets.
Iterating over this object will yield
results and resolve additional pages
automatically.

"""
# Create or coerce a protobuf request object.
# Quick check: If we got a request object, we should *not* have
# gotten any keyword arguments that map to the request.
has_flattened_params = any([parent])
if request is not None and has_flattened_params:
raise ValueError(
"If the `request` argument is set, then none of "
"the individual field arguments should be set."
)

request = bigtable_instance_admin.ListHotTabletsRequest(request)

# If we have keyword arguments corresponding to fields on the
# request, apply these.
if parent is not None:
request.parent = parent

# Wrap the RPC method; this adds retry and timeout information,
# and friendly error handling.
rpc = gapic_v1.method_async.wrap_method(
self._client._transport.list_hot_tablets,
default_retry=retries.Retry(
initial=1.0,
maximum=60.0,
multiplier=2,
predicate=retries.if_exception_type(
core_exceptions.DeadlineExceeded,
core_exceptions.ServiceUnavailable,
),
deadline=60.0,
),
default_timeout=60.0,
client_info=DEFAULT_CLIENT_INFO,
)

# Certain fields should be provided within the metadata header;
# add these here.
metadata = tuple(metadata) + (
gapic_v1.routing_header.to_grpc_metadata((("parent", request.parent),)),
)

# Send the request.
response = await rpc(request, retry=retry, timeout=timeout, metadata=metadata,)

# This method is paged; wrap the response in a pager, which provides
# an `__aiter__` convenience method.
response = pagers.ListHotTabletsAsyncPager(
method=rpc, request=request, response=response, metadata=metadata,
)

# Done; return the response.
return response

async def __aenter__(self):
return self

Expand Down
Expand Up @@ -227,6 +227,24 @@ def parse_crypto_key_path(path: str) -> Dict[str, str]:
)
return m.groupdict() if m else {}

@staticmethod
def hot_tablet_path(
project: str, instance: str, cluster: str, hot_tablet: str,
) -> str:
"""Returns a fully-qualified hot_tablet string."""
return "projects/{project}/instances/{instance}/clusters/{cluster}/hotTablets/{hot_tablet}".format(
project=project, instance=instance, cluster=cluster, hot_tablet=hot_tablet,
)

@staticmethod
def parse_hot_tablet_path(path: str) -> Dict[str, str]:
"""Parses a hot_tablet path into its component segments."""
m = re.match(
r"^projects/(?P<project>.+?)/instances/(?P<instance>.+?)/clusters/(?P<cluster>.+?)/hotTablets/(?P<hot_tablet>.+?)$",
path,
)
return m.groupdict() if m else {}

@staticmethod
def instance_path(project: str, instance: str,) -> str:
"""Returns a fully-qualified instance string."""
Expand All @@ -240,6 +258,22 @@ def parse_instance_path(path: str) -> Dict[str, str]:
m = re.match(r"^projects/(?P<project>.+?)/instances/(?P<instance>.+?)$", path)
return m.groupdict() if m else {}

@staticmethod
def table_path(project: str, instance: str, table: str,) -> str:
"""Returns a fully-qualified table string."""
return "projects/{project}/instances/{instance}/tables/{table}".format(
project=project, instance=instance, table=table,
)

@staticmethod
def parse_table_path(path: str) -> Dict[str, str]:
"""Parses a table path into its component segments."""
m = re.match(
r"^projects/(?P<project>.+?)/instances/(?P<instance>.+?)/tables/(?P<table>.+?)$",
path,
)
return m.groupdict() if m else {}

@staticmethod
def common_billing_account_path(billing_account: str,) -> str:
"""Returns a fully-qualified billing_account string."""
Expand Down Expand Up @@ -2215,6 +2249,88 @@ def test_iam_permissions(
# Done; return the response.
return response

def list_hot_tablets(
self,
request: Union[bigtable_instance_admin.ListHotTabletsRequest, dict] = None,
*,
parent: str = None,
retry: OptionalRetry = gapic_v1.method.DEFAULT,
timeout: float = None,
metadata: Sequence[Tuple[str, str]] = (),
) -> pagers.ListHotTabletsPager:
r"""Lists hot tablets in a cluster, within the time range
provided. Hot tablets are ordered based on CPU usage.

Args:
request (Union[google.cloud.bigtable_admin_v2.types.ListHotTabletsRequest, dict]):
The request object. Request message for
BigtableInstanceAdmin.ListHotTablets.
parent (str):
Required. The cluster name to list hot tablets. Value is
in the following form:
``projects/{project}/instances/{instance}/clusters/{cluster}``.

This corresponds to the ``parent`` field
on the ``request`` instance; if ``request`` is provided, this
should not be set.
retry (google.api_core.retry.Retry): Designation of what errors, if any,
should be retried.
timeout (float): The timeout for this request.
metadata (Sequence[Tuple[str, str]]): Strings which should be
sent along with the request as metadata.

Returns:
google.cloud.bigtable_admin_v2.services.bigtable_instance_admin.pagers.ListHotTabletsPager:
Response message for
BigtableInstanceAdmin.ListHotTablets.
Iterating over this object will yield
results and resolve additional pages
automatically.

"""
# Create or coerce a protobuf request object.
# Quick check: If we got a request object, we should *not* have
# gotten any keyword arguments that map to the request.
has_flattened_params = any([parent])
if request is not None and has_flattened_params:
raise ValueError(
"If the `request` argument is set, then none of "
"the individual field arguments should be set."
)

# Minor optimization to avoid making a copy if the user passes
# in a bigtable_instance_admin.ListHotTabletsRequest.
# There's no risk of modifying the input as we've already verified
# there are no flattened fields.
if not isinstance(request, bigtable_instance_admin.ListHotTabletsRequest):
request = bigtable_instance_admin.ListHotTabletsRequest(request)
# If we have keyword arguments corresponding to fields on the
# request, apply these.
if parent is not None:
request.parent = parent

# Wrap the RPC method; this adds retry and timeout information,
# and friendly error handling.
rpc = self._transport._wrapped_methods[self._transport.list_hot_tablets]

# Certain fields should be provided within the metadata header;
# add these here.
metadata = tuple(metadata) + (
gapic_v1.routing_header.to_grpc_metadata((("parent", request.parent),)),
)

# Send the request.
response = rpc(request, retry=retry, timeout=timeout, metadata=metadata,)

# This method is paged; wrap the response in a pager, which provides
# an `__iter__` convenience method.
response = pagers.ListHotTabletsPager(
method=rpc, request=request, response=response, metadata=metadata,
)

# Done; return the response.
return response

def __enter__(self):
return self

Expand Down