Skip to content
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.
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 @@ -71,6 +71,10 @@ class MetricServiceAsyncClient:
_DEFAULT_ENDPOINT_TEMPLATE = MetricServiceClient._DEFAULT_ENDPOINT_TEMPLATE
_DEFAULT_UNIVERSE = MetricServiceClient._DEFAULT_UNIVERSE

metric_descriptor_path = staticmethod(MetricServiceClient.metric_descriptor_path)
parse_metric_descriptor_path = staticmethod(
MetricServiceClient.parse_metric_descriptor_path
)
monitored_resource_descriptor_path = staticmethod(
MetricServiceClient.monitored_resource_descriptor_path
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,26 @@ def transport(self) -> MetricServiceTransport:
"""
return self._transport

@staticmethod
def metric_descriptor_path(
project: str,
metric_descriptor: str,
) -> str:
"""Returns a fully-qualified metric_descriptor string."""
return "projects/{project}/metricDescriptors/{metric_descriptor}".format(
project=project,
metric_descriptor=metric_descriptor,
)

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

@staticmethod
def monitored_resource_descriptor_path(
project: str,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4536,6 +4536,29 @@ def test_metric_service_transport_channel_mtls_with_adc(transport_class):
assert transport.grpc_channel == mock_grpc_channel


def test_metric_descriptor_path():
project = "squid"
metric_descriptor = "clam"
expected = "projects/{project}/metricDescriptors/{metric_descriptor}".format(
project=project,
metric_descriptor=metric_descriptor,
)
actual = MetricServiceClient.metric_descriptor_path(project, metric_descriptor)
assert expected == actual


def test_parse_metric_descriptor_path():
expected = {
"project": "whelk",
"metric_descriptor": "octopus",
}
path = MetricServiceClient.metric_descriptor_path(**expected)

# Check that the path construction is reversible.
actual = MetricServiceClient.parse_metric_descriptor_path(path)
assert expected == actual


def test_monitored_resource_descriptor_path():
project = "oyster"
monitored_resource_descriptor = "nudibranch"
Expand Down