Skip to content

Commit 212ea59

Browse files
feat: added validation only mode when writing dashboards (#86)
PiperOrigin-RevId: 383440655 Source-Link: googleapis/googleapis@b5532bb Source-Link: googleapis/googleapis-gen@f3018d0 feat: added alert chart widget
1 parent e8a83ec commit 212ea59

File tree

13 files changed

+136
-39
lines changed

13 files changed

+136
-39
lines changed

packages/google-cloud-monitoring-dashboards/google/cloud/monitoring_dashboard/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
DashboardsServiceAsyncClient,
2222
)
2323

24+
from google.cloud.monitoring_dashboard_v1.types.alertchart import AlertChart
2425
from google.cloud.monitoring_dashboard_v1.types.common import Aggregation
2526
from google.cloud.monitoring_dashboard_v1.types.common import PickTimeSeriesFilter
2627
from google.cloud.monitoring_dashboard_v1.types.common import (
@@ -63,6 +64,7 @@
6364
__all__ = (
6465
"DashboardsServiceClient",
6566
"DashboardsServiceAsyncClient",
67+
"AlertChart",
6668
"Aggregation",
6769
"PickTimeSeriesFilter",
6870
"StatisticalTimeSeriesFilter",

packages/google-cloud-monitoring-dashboards/google/cloud/monitoring_dashboard_v1/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
from .services.dashboards_service import DashboardsServiceClient
1818
from .services.dashboards_service import DashboardsServiceAsyncClient
1919

20+
from .types.alertchart import AlertChart
2021
from .types.common import Aggregation
2122
from .types.common import PickTimeSeriesFilter
2223
from .types.common import StatisticalTimeSeriesFilter
@@ -45,6 +46,7 @@
4546
__all__ = (
4647
"DashboardsServiceAsyncClient",
4748
"Aggregation",
49+
"AlertChart",
4850
"ChartOptions",
4951
"ColumnLayout",
5052
"CreateDashboardRequest",

packages/google-cloud-monitoring-dashboards/google/cloud/monitoring_dashboard_v1/services/dashboards_service/async_client.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,10 @@ class DashboardsServiceAsyncClient:
4545
DEFAULT_ENDPOINT = DashboardsServiceClient.DEFAULT_ENDPOINT
4646
DEFAULT_MTLS_ENDPOINT = DashboardsServiceClient.DEFAULT_MTLS_ENDPOINT
4747

48+
alert_policy_path = staticmethod(DashboardsServiceClient.alert_policy_path)
49+
parse_alert_policy_path = staticmethod(
50+
DashboardsServiceClient.parse_alert_policy_path
51+
)
4852
dashboard_path = staticmethod(DashboardsServiceClient.dashboard_path)
4953
parse_dashboard_path = staticmethod(DashboardsServiceClient.parse_dashboard_path)
5054
common_billing_account_path = staticmethod(
@@ -175,11 +179,10 @@ async def create_dashboard(
175179
) -> dashboard.Dashboard:
176180
r"""Creates a new custom dashboard. For examples on how you can use
177181
this API to create dashboards, see `Managing dashboards by
178-
API <https://cloud.google.com/monitoring/dashboards/api-dashboard>`__.
179-
This method requires the ``monitoring.dashboards.create``
180-
permission on the specified project. For more information about
181-
permissions, see `Cloud Identity and Access
182-
Management <https://cloud.google.com/iam>`__.
182+
API </monitoring/dashboards/api-dashboard>`__. This method
183+
requires the ``monitoring.dashboards.create`` permission on the
184+
specified project. For more information about permissions, see
185+
`Cloud Identity and Access Management </iam>`__.
183186
184187
Args:
185188
request (:class:`google.cloud.monitoring_dashboard_v1.types.CreateDashboardRequest`):

packages/google-cloud-monitoring-dashboards/google/cloud/monitoring_dashboard_v1/services/dashboards_service/client.py

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,21 @@ def transport(self) -> DashboardsServiceTransport:
161161
"""
162162
return self._transport
163163

164+
@staticmethod
165+
def alert_policy_path(project: str, alert_policy: str,) -> str:
166+
"""Returns a fully-qualified alert_policy string."""
167+
return "projects/{project}/alertPolicies/{alert_policy}".format(
168+
project=project, alert_policy=alert_policy,
169+
)
170+
171+
@staticmethod
172+
def parse_alert_policy_path(path: str) -> Dict[str, str]:
173+
"""Parses a alert_policy path into its component segments."""
174+
m = re.match(
175+
r"^projects/(?P<project>.+?)/alertPolicies/(?P<alert_policy>.+?)$", path
176+
)
177+
return m.groupdict() if m else {}
178+
164179
@staticmethod
165180
def dashboard_path(project: str, dashboard: str,) -> str:
166181
"""Returns a fully-qualified dashboard string."""
@@ -359,11 +374,10 @@ def create_dashboard(
359374
) -> dashboard.Dashboard:
360375
r"""Creates a new custom dashboard. For examples on how you can use
361376
this API to create dashboards, see `Managing dashboards by
362-
API <https://cloud.google.com/monitoring/dashboards/api-dashboard>`__.
363-
This method requires the ``monitoring.dashboards.create``
364-
permission on the specified project. For more information about
365-
permissions, see `Cloud Identity and Access
366-
Management <https://cloud.google.com/iam>`__.
377+
API </monitoring/dashboards/api-dashboard>`__. This method
378+
requires the ``monitoring.dashboards.create`` permission on the
379+
specified project. For more information about permissions, see
380+
`Cloud Identity and Access Management </iam>`__.
367381
368382
Args:
369383
request (google.cloud.monitoring_dashboard_v1.types.CreateDashboardRequest):

packages/google-cloud-monitoring-dashboards/google/cloud/monitoring_dashboard_v1/services/dashboards_service/transports/grpc.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -236,11 +236,10 @@ def create_dashboard(
236236
237237
Creates a new custom dashboard. For examples on how you can use
238238
this API to create dashboards, see `Managing dashboards by
239-
API <https://cloud.google.com/monitoring/dashboards/api-dashboard>`__.
240-
This method requires the ``monitoring.dashboards.create``
241-
permission on the specified project. For more information about
242-
permissions, see `Cloud Identity and Access
243-
Management <https://cloud.google.com/iam>`__.
239+
API </monitoring/dashboards/api-dashboard>`__. This method
240+
requires the ``monitoring.dashboards.create`` permission on the
241+
specified project. For more information about permissions, see
242+
`Cloud Identity and Access Management </iam>`__.
244243
245244
Returns:
246245
Callable[[~.CreateDashboardRequest],

packages/google-cloud-monitoring-dashboards/google/cloud/monitoring_dashboard_v1/services/dashboards_service/transports/grpc_asyncio.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -241,11 +241,10 @@ def create_dashboard(
241241
242242
Creates a new custom dashboard. For examples on how you can use
243243
this API to create dashboards, see `Managing dashboards by
244-
API <https://cloud.google.com/monitoring/dashboards/api-dashboard>`__.
245-
This method requires the ``monitoring.dashboards.create``
246-
permission on the specified project. For more information about
247-
permissions, see `Cloud Identity and Access
248-
Management <https://cloud.google.com/iam>`__.
244+
API </monitoring/dashboards/api-dashboard>`__. This method
245+
requires the ``monitoring.dashboards.create`` permission on the
246+
specified project. For more information about permissions, see
247+
`Cloud Identity and Access Management </iam>`__.
249248
250249
Returns:
251250
Callable[[~.CreateDashboardRequest],

packages/google-cloud-monitoring-dashboards/google/cloud/monitoring_dashboard_v1/types/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
# See the License for the specific language governing permissions and
1414
# limitations under the License.
1515
#
16+
from .alertchart import AlertChart
1617
from .common import (
1718
Aggregation,
1819
PickTimeSeriesFilter,
@@ -49,6 +50,7 @@
4950
)
5051

5152
__all__ = (
53+
"AlertChart",
5254
"Aggregation",
5355
"PickTimeSeriesFilter",
5456
"StatisticalTimeSeriesFilter",
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# -*- coding: utf-8 -*-
2+
# Copyright 2020 Google LLC
3+
#
4+
# Licensed under the Apache License, Version 2.0 (the "License");
5+
# you may not use this file except in compliance with the License.
6+
# You may obtain a copy of the License at
7+
#
8+
# http://www.apache.org/licenses/LICENSE-2.0
9+
#
10+
# Unless required by applicable law or agreed to in writing, software
11+
# distributed under the License is distributed on an "AS IS" BASIS,
12+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
# See the License for the specific language governing permissions and
14+
# limitations under the License.
15+
#
16+
import proto # type: ignore
17+
18+
19+
__protobuf__ = proto.module(
20+
package="google.monitoring.dashboard.v1", manifest={"AlertChart",},
21+
)
22+
23+
24+
class AlertChart(proto.Message):
25+
r"""A chart that displays alert policy data.
26+
Attributes:
27+
name (str):
28+
Required. The resource name of the alert policy. The format
29+
is:
30+
31+
::
32+
33+
projects/[PROJECT_ID_OR_NUMBER]/alertPolicies/[ALERT_POLICY_ID]
34+
"""
35+
36+
name = proto.Field(proto.STRING, number=1,)
37+
38+
39+
__all__ = tuple(sorted(__protobuf__.manifest))

packages/google-cloud-monitoring-dashboards/google/cloud/monitoring_dashboard_v1/types/dashboards_service.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,14 @@ class CreateDashboardRequest(proto.Message):
4747
dashboard (google.cloud.monitoring_dashboard_v1.types.Dashboard):
4848
Required. The initial dashboard
4949
specification.
50+
validate_only (bool):
51+
If set, validate the request and preview the
52+
review, but do not actually save it.
5053
"""
5154

5255
parent = proto.Field(proto.STRING, number=1,)
5356
dashboard = proto.Field(proto.MESSAGE, number=2, message=gmd_dashboard.Dashboard,)
57+
validate_only = proto.Field(proto.BOOL, number=3,)
5458

5559

5660
class ListDashboardsRequest(proto.Message):
@@ -136,9 +140,13 @@ class UpdateDashboardRequest(proto.Message):
136140
dashboard (google.cloud.monitoring_dashboard_v1.types.Dashboard):
137141
Required. The dashboard that will replace the
138142
existing dashboard.
143+
validate_only (bool):
144+
If set, validate the request and preview the
145+
review, but do not actually save it.
139146
"""
140147

141148
dashboard = proto.Field(proto.MESSAGE, number=1, message=gmd_dashboard.Dashboard,)
149+
validate_only = proto.Field(proto.BOOL, number=3,)
142150

143151

144152
__all__ = tuple(sorted(__protobuf__.manifest))

packages/google-cloud-monitoring-dashboards/google/cloud/monitoring_dashboard_v1/types/widget.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#
1616
import proto # type: ignore
1717

18+
from google.cloud.monitoring_dashboard_v1.types import alertchart
1819
from google.cloud.monitoring_dashboard_v1.types import scorecard as gmd_scorecard
1920
from google.cloud.monitoring_dashboard_v1.types import text as gmd_text
2021
from google.cloud.monitoring_dashboard_v1.types import xychart
@@ -42,6 +43,8 @@ class Widget(proto.Message):
4243
content.
4344
blank (google.protobuf.empty_pb2.Empty):
4445
A blank space.
46+
alert_chart (google.cloud.monitoring_dashboard_v1.types.AlertChart):
47+
A chart of alert policy data.
4548
"""
4649

4750
title = proto.Field(proto.STRING, number=1,)
@@ -55,6 +58,9 @@ class Widget(proto.Message):
5558
blank = proto.Field(
5659
proto.MESSAGE, number=5, oneof="content", message=empty_pb2.Empty,
5760
)
61+
alert_chart = proto.Field(
62+
proto.MESSAGE, number=7, oneof="content", message=alertchart.AlertChart,
63+
)
5864

5965

6066
__all__ = tuple(sorted(__protobuf__.manifest))

packages/google-cloud-monitoring-dashboards/google/cloud/monitoring_dashboard_v1/types/xychart.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ class DataSet(proto.Message):
6464
min_alignment_period (google.protobuf.duration_pb2.Duration):
6565
Optional. The lower bound on data point frequency for this
6666
data set, implemented by specifying the minimum alignment
67-
period to use in a time series query. For example, if the
67+
period to use in a time series query For example, if the
6868
data is published once every 10 minutes, the
6969
``min_alignment_period`` should be at least 10 minutes. It
7070
would not make sense to fetch and align data at one minute

packages/google-cloud-monitoring-dashboards/scripts/fixup_dashboard_v1_keywords.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,11 @@ def partition(
3939
class dashboardCallTransformer(cst.CSTTransformer):
4040
CTRL_PARAMS: Tuple[str] = ('retry', 'timeout', 'metadata')
4141
METHOD_TO_PARAMS: Dict[str, Tuple[str]] = {
42-
'create_dashboard': ('parent', 'dashboard', ),
42+
'create_dashboard': ('parent', 'dashboard', 'validate_only', ),
4343
'delete_dashboard': ('name', ),
4444
'get_dashboard': ('name', ),
4545
'list_dashboards': ('parent', 'page_size', 'page_token', ),
46-
'update_dashboard': ('dashboard', ),
46+
'update_dashboard': ('dashboard', 'validate_only', ),
4747
}
4848

4949
def leave_Call(self, original: cst.Call, updated: cst.Call) -> cst.CSTNode:

0 commit comments

Comments
 (0)