diff --git a/google/cloud/monitoring_dashboard/__init__.py b/google/cloud/monitoring_dashboard/__init__.py index c3a499f..e18582a 100644 --- a/google/cloud/monitoring_dashboard/__init__.py +++ b/google/cloud/monitoring_dashboard/__init__.py @@ -21,6 +21,7 @@ DashboardsServiceAsyncClient, ) +from google.cloud.monitoring_dashboard_v1.types.alertchart import AlertChart from google.cloud.monitoring_dashboard_v1.types.common import Aggregation from google.cloud.monitoring_dashboard_v1.types.common import PickTimeSeriesFilter from google.cloud.monitoring_dashboard_v1.types.common import ( @@ -63,6 +64,7 @@ __all__ = ( "DashboardsServiceClient", "DashboardsServiceAsyncClient", + "AlertChart", "Aggregation", "PickTimeSeriesFilter", "StatisticalTimeSeriesFilter", diff --git a/google/cloud/monitoring_dashboard_v1/__init__.py b/google/cloud/monitoring_dashboard_v1/__init__.py index e7fb1de..bd617b4 100644 --- a/google/cloud/monitoring_dashboard_v1/__init__.py +++ b/google/cloud/monitoring_dashboard_v1/__init__.py @@ -17,6 +17,7 @@ from .services.dashboards_service import DashboardsServiceClient from .services.dashboards_service import DashboardsServiceAsyncClient +from .types.alertchart import AlertChart from .types.common import Aggregation from .types.common import PickTimeSeriesFilter from .types.common import StatisticalTimeSeriesFilter @@ -45,6 +46,7 @@ __all__ = ( "DashboardsServiceAsyncClient", "Aggregation", + "AlertChart", "ChartOptions", "ColumnLayout", "CreateDashboardRequest", diff --git a/google/cloud/monitoring_dashboard_v1/services/dashboards_service/async_client.py b/google/cloud/monitoring_dashboard_v1/services/dashboards_service/async_client.py index b75ef4d..2760cad 100644 --- a/google/cloud/monitoring_dashboard_v1/services/dashboards_service/async_client.py +++ b/google/cloud/monitoring_dashboard_v1/services/dashboards_service/async_client.py @@ -45,6 +45,10 @@ class DashboardsServiceAsyncClient: DEFAULT_ENDPOINT = DashboardsServiceClient.DEFAULT_ENDPOINT DEFAULT_MTLS_ENDPOINT = DashboardsServiceClient.DEFAULT_MTLS_ENDPOINT + alert_policy_path = staticmethod(DashboardsServiceClient.alert_policy_path) + parse_alert_policy_path = staticmethod( + DashboardsServiceClient.parse_alert_policy_path + ) dashboard_path = staticmethod(DashboardsServiceClient.dashboard_path) parse_dashboard_path = staticmethod(DashboardsServiceClient.parse_dashboard_path) common_billing_account_path = staticmethod( @@ -175,11 +179,10 @@ async def create_dashboard( ) -> dashboard.Dashboard: r"""Creates a new custom dashboard. For examples on how you can use this API to create dashboards, see `Managing dashboards by - API `__. - This method requires the ``monitoring.dashboards.create`` - permission on the specified project. For more information about - permissions, see `Cloud Identity and Access - Management `__. + API `__. This method + requires the ``monitoring.dashboards.create`` permission on the + specified project. For more information about permissions, see + `Cloud Identity and Access Management `__. Args: request (:class:`google.cloud.monitoring_dashboard_v1.types.CreateDashboardRequest`): diff --git a/google/cloud/monitoring_dashboard_v1/services/dashboards_service/client.py b/google/cloud/monitoring_dashboard_v1/services/dashboards_service/client.py index 71fab17..2ea98f2 100644 --- a/google/cloud/monitoring_dashboard_v1/services/dashboards_service/client.py +++ b/google/cloud/monitoring_dashboard_v1/services/dashboards_service/client.py @@ -161,6 +161,21 @@ def transport(self) -> DashboardsServiceTransport: """ return self._transport + @staticmethod + def alert_policy_path(project: str, alert_policy: str,) -> str: + """Returns a fully-qualified alert_policy string.""" + return "projects/{project}/alertPolicies/{alert_policy}".format( + project=project, alert_policy=alert_policy, + ) + + @staticmethod + def parse_alert_policy_path(path: str) -> Dict[str, str]: + """Parses a alert_policy path into its component segments.""" + m = re.match( + r"^projects/(?P.+?)/alertPolicies/(?P.+?)$", path + ) + return m.groupdict() if m else {} + @staticmethod def dashboard_path(project: str, dashboard: str,) -> str: """Returns a fully-qualified dashboard string.""" @@ -359,11 +374,10 @@ def create_dashboard( ) -> dashboard.Dashboard: r"""Creates a new custom dashboard. For examples on how you can use this API to create dashboards, see `Managing dashboards by - API `__. - This method requires the ``monitoring.dashboards.create`` - permission on the specified project. For more information about - permissions, see `Cloud Identity and Access - Management `__. + API `__. This method + requires the ``monitoring.dashboards.create`` permission on the + specified project. For more information about permissions, see + `Cloud Identity and Access Management `__. Args: request (google.cloud.monitoring_dashboard_v1.types.CreateDashboardRequest): diff --git a/google/cloud/monitoring_dashboard_v1/services/dashboards_service/transports/grpc.py b/google/cloud/monitoring_dashboard_v1/services/dashboards_service/transports/grpc.py index 2dd8b7b..61ec5ce 100644 --- a/google/cloud/monitoring_dashboard_v1/services/dashboards_service/transports/grpc.py +++ b/google/cloud/monitoring_dashboard_v1/services/dashboards_service/transports/grpc.py @@ -236,11 +236,10 @@ def create_dashboard( Creates a new custom dashboard. For examples on how you can use this API to create dashboards, see `Managing dashboards by - API `__. - This method requires the ``monitoring.dashboards.create`` - permission on the specified project. For more information about - permissions, see `Cloud Identity and Access - Management `__. + API `__. This method + requires the ``monitoring.dashboards.create`` permission on the + specified project. For more information about permissions, see + `Cloud Identity and Access Management `__. Returns: Callable[[~.CreateDashboardRequest], diff --git a/google/cloud/monitoring_dashboard_v1/services/dashboards_service/transports/grpc_asyncio.py b/google/cloud/monitoring_dashboard_v1/services/dashboards_service/transports/grpc_asyncio.py index 6b5e30e..5896867 100644 --- a/google/cloud/monitoring_dashboard_v1/services/dashboards_service/transports/grpc_asyncio.py +++ b/google/cloud/monitoring_dashboard_v1/services/dashboards_service/transports/grpc_asyncio.py @@ -241,11 +241,10 @@ def create_dashboard( Creates a new custom dashboard. For examples on how you can use this API to create dashboards, see `Managing dashboards by - API `__. - This method requires the ``monitoring.dashboards.create`` - permission on the specified project. For more information about - permissions, see `Cloud Identity and Access - Management `__. + API `__. This method + requires the ``monitoring.dashboards.create`` permission on the + specified project. For more information about permissions, see + `Cloud Identity and Access Management `__. Returns: Callable[[~.CreateDashboardRequest], diff --git a/google/cloud/monitoring_dashboard_v1/types/__init__.py b/google/cloud/monitoring_dashboard_v1/types/__init__.py index 1644bbb..0c1af71 100644 --- a/google/cloud/monitoring_dashboard_v1/types/__init__.py +++ b/google/cloud/monitoring_dashboard_v1/types/__init__.py @@ -13,6 +13,7 @@ # See the License for the specific language governing permissions and # limitations under the License. # +from .alertchart import AlertChart from .common import ( Aggregation, PickTimeSeriesFilter, @@ -49,6 +50,7 @@ ) __all__ = ( + "AlertChart", "Aggregation", "PickTimeSeriesFilter", "StatisticalTimeSeriesFilter", diff --git a/google/cloud/monitoring_dashboard_v1/types/alertchart.py b/google/cloud/monitoring_dashboard_v1/types/alertchart.py new file mode 100644 index 0000000..0bb3029 --- /dev/null +++ b/google/cloud/monitoring_dashboard_v1/types/alertchart.py @@ -0,0 +1,39 @@ +# -*- coding: utf-8 -*- +# Copyright 2020 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +import proto # type: ignore + + +__protobuf__ = proto.module( + package="google.monitoring.dashboard.v1", manifest={"AlertChart",}, +) + + +class AlertChart(proto.Message): + r"""A chart that displays alert policy data. + Attributes: + name (str): + Required. The resource name of the alert policy. The format + is: + + :: + + projects/[PROJECT_ID_OR_NUMBER]/alertPolicies/[ALERT_POLICY_ID] + """ + + name = proto.Field(proto.STRING, number=1,) + + +__all__ = tuple(sorted(__protobuf__.manifest)) diff --git a/google/cloud/monitoring_dashboard_v1/types/dashboards_service.py b/google/cloud/monitoring_dashboard_v1/types/dashboards_service.py index 6956e34..825228e 100644 --- a/google/cloud/monitoring_dashboard_v1/types/dashboards_service.py +++ b/google/cloud/monitoring_dashboard_v1/types/dashboards_service.py @@ -47,10 +47,14 @@ class CreateDashboardRequest(proto.Message): dashboard (google.cloud.monitoring_dashboard_v1.types.Dashboard): Required. The initial dashboard specification. + validate_only (bool): + If set, validate the request and preview the + review, but do not actually save it. """ parent = proto.Field(proto.STRING, number=1,) dashboard = proto.Field(proto.MESSAGE, number=2, message=gmd_dashboard.Dashboard,) + validate_only = proto.Field(proto.BOOL, number=3,) class ListDashboardsRequest(proto.Message): @@ -136,9 +140,13 @@ class UpdateDashboardRequest(proto.Message): dashboard (google.cloud.monitoring_dashboard_v1.types.Dashboard): Required. The dashboard that will replace the existing dashboard. + validate_only (bool): + If set, validate the request and preview the + review, but do not actually save it. """ dashboard = proto.Field(proto.MESSAGE, number=1, message=gmd_dashboard.Dashboard,) + validate_only = proto.Field(proto.BOOL, number=3,) __all__ = tuple(sorted(__protobuf__.manifest)) diff --git a/google/cloud/monitoring_dashboard_v1/types/widget.py b/google/cloud/monitoring_dashboard_v1/types/widget.py index c70cddb..1b74bca 100644 --- a/google/cloud/monitoring_dashboard_v1/types/widget.py +++ b/google/cloud/monitoring_dashboard_v1/types/widget.py @@ -15,6 +15,7 @@ # import proto # type: ignore +from google.cloud.monitoring_dashboard_v1.types import alertchart from google.cloud.monitoring_dashboard_v1.types import scorecard as gmd_scorecard from google.cloud.monitoring_dashboard_v1.types import text as gmd_text from google.cloud.monitoring_dashboard_v1.types import xychart @@ -42,6 +43,8 @@ class Widget(proto.Message): content. blank (google.protobuf.empty_pb2.Empty): A blank space. + alert_chart (google.cloud.monitoring_dashboard_v1.types.AlertChart): + A chart of alert policy data. """ title = proto.Field(proto.STRING, number=1,) @@ -55,6 +58,9 @@ class Widget(proto.Message): blank = proto.Field( proto.MESSAGE, number=5, oneof="content", message=empty_pb2.Empty, ) + alert_chart = proto.Field( + proto.MESSAGE, number=7, oneof="content", message=alertchart.AlertChart, + ) __all__ = tuple(sorted(__protobuf__.manifest)) diff --git a/google/cloud/monitoring_dashboard_v1/types/xychart.py b/google/cloud/monitoring_dashboard_v1/types/xychart.py index 66b5612..0f78b40 100644 --- a/google/cloud/monitoring_dashboard_v1/types/xychart.py +++ b/google/cloud/monitoring_dashboard_v1/types/xychart.py @@ -64,7 +64,7 @@ class DataSet(proto.Message): min_alignment_period (google.protobuf.duration_pb2.Duration): Optional. The lower bound on data point frequency for this data set, implemented by specifying the minimum alignment - period to use in a time series query. For example, if the + period to use in a time series query For example, if the data is published once every 10 minutes, the ``min_alignment_period`` should be at least 10 minutes. It would not make sense to fetch and align data at one minute diff --git a/scripts/fixup_dashboard_v1_keywords.py b/scripts/fixup_dashboard_v1_keywords.py index db3aefd..a854483 100644 --- a/scripts/fixup_dashboard_v1_keywords.py +++ b/scripts/fixup_dashboard_v1_keywords.py @@ -39,11 +39,11 @@ def partition( class dashboardCallTransformer(cst.CSTTransformer): CTRL_PARAMS: Tuple[str] = ('retry', 'timeout', 'metadata') METHOD_TO_PARAMS: Dict[str, Tuple[str]] = { - 'create_dashboard': ('parent', 'dashboard', ), + 'create_dashboard': ('parent', 'dashboard', 'validate_only', ), 'delete_dashboard': ('name', ), 'get_dashboard': ('name', ), 'list_dashboards': ('parent', 'page_size', 'page_token', ), - 'update_dashboard': ('dashboard', ), + 'update_dashboard': ('dashboard', 'validate_only', ), } def leave_Call(self, original: cst.Call, updated: cst.Call) -> cst.CSTNode: diff --git a/tests/unit/gapic/dashboard_v1/test_dashboards_service.py b/tests/unit/gapic/dashboard_v1/test_dashboards_service.py index 40b3096..5bb3baf 100644 --- a/tests/unit/gapic/dashboard_v1/test_dashboards_service.py +++ b/tests/unit/gapic/dashboard_v1/test_dashboards_service.py @@ -42,6 +42,7 @@ from google.cloud.monitoring_dashboard_v1.services.dashboards_service.transports.base import ( _GOOGLE_AUTH_VERSION, ) +from google.cloud.monitoring_dashboard_v1.types import alertchart from google.cloud.monitoring_dashboard_v1.types import common from google.cloud.monitoring_dashboard_v1.types import dashboard from google.cloud.monitoring_dashboard_v1.types import dashboards_service @@ -1851,9 +1852,31 @@ def test_dashboards_service_transport_channel_mtls_with_adc(transport_class): assert transport.grpc_channel == mock_grpc_channel -def test_dashboard_path(): +def test_alert_policy_path(): project = "squid" - dashboard = "clam" + alert_policy = "clam" + expected = "projects/{project}/alertPolicies/{alert_policy}".format( + project=project, alert_policy=alert_policy, + ) + actual = DashboardsServiceClient.alert_policy_path(project, alert_policy) + assert expected == actual + + +def test_parse_alert_policy_path(): + expected = { + "project": "whelk", + "alert_policy": "octopus", + } + path = DashboardsServiceClient.alert_policy_path(**expected) + + # Check that the path construction is reversible. + actual = DashboardsServiceClient.parse_alert_policy_path(path) + assert expected == actual + + +def test_dashboard_path(): + project = "oyster" + dashboard = "nudibranch" expected = "projects/{project}/dashboards/{dashboard}".format( project=project, dashboard=dashboard, ) @@ -1863,8 +1886,8 @@ def test_dashboard_path(): def test_parse_dashboard_path(): expected = { - "project": "whelk", - "dashboard": "octopus", + "project": "cuttlefish", + "dashboard": "mussel", } path = DashboardsServiceClient.dashboard_path(**expected) @@ -1874,7 +1897,7 @@ def test_parse_dashboard_path(): def test_common_billing_account_path(): - billing_account = "oyster" + billing_account = "winkle" expected = "billingAccounts/{billing_account}".format( billing_account=billing_account, ) @@ -1884,7 +1907,7 @@ def test_common_billing_account_path(): def test_parse_common_billing_account_path(): expected = { - "billing_account": "nudibranch", + "billing_account": "nautilus", } path = DashboardsServiceClient.common_billing_account_path(**expected) @@ -1894,7 +1917,7 @@ def test_parse_common_billing_account_path(): def test_common_folder_path(): - folder = "cuttlefish" + folder = "scallop" expected = "folders/{folder}".format(folder=folder,) actual = DashboardsServiceClient.common_folder_path(folder) assert expected == actual @@ -1902,7 +1925,7 @@ def test_common_folder_path(): def test_parse_common_folder_path(): expected = { - "folder": "mussel", + "folder": "abalone", } path = DashboardsServiceClient.common_folder_path(**expected) @@ -1912,7 +1935,7 @@ def test_parse_common_folder_path(): def test_common_organization_path(): - organization = "winkle" + organization = "squid" expected = "organizations/{organization}".format(organization=organization,) actual = DashboardsServiceClient.common_organization_path(organization) assert expected == actual @@ -1920,7 +1943,7 @@ def test_common_organization_path(): def test_parse_common_organization_path(): expected = { - "organization": "nautilus", + "organization": "clam", } path = DashboardsServiceClient.common_organization_path(**expected) @@ -1930,7 +1953,7 @@ def test_parse_common_organization_path(): def test_common_project_path(): - project = "scallop" + project = "whelk" expected = "projects/{project}".format(project=project,) actual = DashboardsServiceClient.common_project_path(project) assert expected == actual @@ -1938,7 +1961,7 @@ def test_common_project_path(): def test_parse_common_project_path(): expected = { - "project": "abalone", + "project": "octopus", } path = DashboardsServiceClient.common_project_path(**expected) @@ -1948,8 +1971,8 @@ def test_parse_common_project_path(): def test_common_location_path(): - project = "squid" - location = "clam" + project = "oyster" + location = "nudibranch" expected = "projects/{project}/locations/{location}".format( project=project, location=location, ) @@ -1959,8 +1982,8 @@ def test_common_location_path(): def test_parse_common_location_path(): expected = { - "project": "whelk", - "location": "octopus", + "project": "cuttlefish", + "location": "mussel", } path = DashboardsServiceClient.common_location_path(**expected)