Skip to content

Commit

Permalink
Fixed golden tests for new debug logging changes
Browse files Browse the repository at this point in the history
  • Loading branch information
gkevinzheng committed Dec 11, 2024
1 parent 7a3b71e commit 2274254
Show file tree
Hide file tree
Showing 5 changed files with 1,104 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
#
import logging as std_logging
from collections import OrderedDict
import re
from typing import Dict, Callable, Mapping, MutableMapping, MutableSequence, Optional, Sequence, Tuple, Type, Union
Expand Down Expand Up @@ -45,6 +46,13 @@
from .transports.grpc_asyncio import CloudRedisGrpcAsyncIOTransport
from .client import CloudRedisClient

try:
from google.api_core import client_logging # type: ignore
CLIENT_LOGGING_SUPPORTED = True # pragma: NO COVER
except ImportError: # pragma: NO COVER
CLIENT_LOGGING_SUPPORTED = False

_LOGGER = std_logging.getLogger(__name__)

class CloudRedisAsyncClient:
"""Configures and manages Cloud Memorystore for Redis instances
Expand Down Expand Up @@ -255,6 +263,20 @@ def __init__(self, *,

)

if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor(std_logging.DEBUG): # pragma: NO COVER
_LOGGER.debug(
"Created client `google.cloud.redis_v1.CloudRedisAsyncClient`.",
extra = {
"serviceName": "google.cloud.redis.v1.CloudRedis",
"universeDomain": getattr(self._client._transport._credentials, "universe_domain", ""),
"credentialsType": f"{type(self._client._transport._credentials).__module__}.{type(self._client._transport._credentials).__qualname__}",
"credentialsInfo": getattr(self.transport._credentials, "get_cred_info", lambda: None)(),
} if hasattr(self._client._transport, "_credentials") else {
"serviceName": "google.cloud.redis.v1.CloudRedis",
"credentialsType": None,
}
)

async def list_instances(self,
request: Optional[Union[cloud_redis.ListInstancesRequest, dict]] = None,
*,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
# limitations under the License.
#
from collections import OrderedDict
import logging as std_logging
import os
import re
from typing import Dict, Callable, Mapping, MutableMapping, MutableSequence, Optional, Sequence, Tuple, Type, Union, cast
Expand All @@ -36,6 +37,14 @@
except AttributeError: # pragma: NO COVER
OptionalRetry = Union[retries.Retry, object, None] # type: ignore

try:
from google.api_core import client_logging # type: ignore
CLIENT_LOGGING_SUPPORTED = True # pragma: NO COVER
except ImportError: # pragma: NO COVER
CLIENT_LOGGING_SUPPORTED = False

_LOGGER = std_logging.getLogger(__name__)

from google.api_core import operation # type: ignore
from google.api_core import operation_async # type: ignore
from google.cloud.location import locations_pb2 # type: ignore
Expand Down Expand Up @@ -530,6 +539,10 @@ def __init__(self, *,
# Initialize the universe domain validation.
self._is_universe_domain_valid = False

if CLIENT_LOGGING_SUPPORTED: # pragma: NO COVER
# Setup logging.
client_logging.initialize_logging()

api_key_value = getattr(self._client_options, "api_key", None)
if api_key_value and credentials:
raise ValueError("client_options.api_key and credentials are mutually exclusive")
Expand Down Expand Up @@ -604,6 +617,21 @@ def __init__(self, *,
api_audience=self._client_options.api_audience,
)

if "async" not in str(self._transport):
if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor(std_logging.DEBUG): # pragma: NO COVER
_LOGGER.debug(
"Created client `google.cloud.redis_v1.CloudRedisClient`.",
extra = {
"serviceName": "google.cloud.redis.v1.CloudRedis",
"universeDomain": getattr(self._transport._credentials, "universe_domain", ""),
"credentialsType": f"{type(self._transport._credentials).__module__}.{type(self._transport._credentials).__qualname__}",
"credentialsInfo": getattr(self.transport._credentials, "get_cred_info", lambda: None)(),
} if hasattr(self._transport, "_credentials") else {
"serviceName": "google.cloud.redis.v1.CloudRedis",
"credentialsType": None,
}
)

def list_instances(self,
request: Optional[Union[cloud_redis.ListInstancesRequest, dict]] = None,
*,
Expand Down
Loading

0 comments on commit 2274254

Please sign in to comment.