Skip to content
This repository has been archived by the owner on Jan 17, 2024. It is now read-only.

Commit

Permalink
feat: added validation only mode when writing dashboards (#86)
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 383440655

Source-Link: googleapis/googleapis@b5532bb

Source-Link: googleapis/googleapis-gen@f3018d0

feat: added alert chart widget
  • Loading branch information
gcf-owl-bot[bot] committed Jul 9, 2021
1 parent d9b1482 commit 509abf5
Show file tree
Hide file tree
Showing 13 changed files with 136 additions and 39 deletions.
2 changes: 2 additions & 0 deletions google/cloud/monitoring_dashboard/__init__.py
Expand Up @@ -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 (
Expand Down Expand Up @@ -63,6 +64,7 @@
__all__ = (
"DashboardsServiceClient",
"DashboardsServiceAsyncClient",
"AlertChart",
"Aggregation",
"PickTimeSeriesFilter",
"StatisticalTimeSeriesFilter",
Expand Down
2 changes: 2 additions & 0 deletions google/cloud/monitoring_dashboard_v1/__init__.py
Expand Up @@ -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
Expand Down Expand Up @@ -45,6 +46,7 @@
__all__ = (
"DashboardsServiceAsyncClient",
"Aggregation",
"AlertChart",
"ChartOptions",
"ColumnLayout",
"CreateDashboardRequest",
Expand Down
Expand Up @@ -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(
Expand Down Expand Up @@ -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 <https://cloud.google.com/monitoring/dashboards/api-dashboard>`__.
This method requires the ``monitoring.dashboards.create``
permission on the specified project. For more information about
permissions, see `Cloud Identity and Access
Management <https://cloud.google.com/iam>`__.
API </monitoring/dashboards/api-dashboard>`__. This method
requires the ``monitoring.dashboards.create`` permission on the
specified project. For more information about permissions, see
`Cloud Identity and Access Management </iam>`__.
Args:
request (:class:`google.cloud.monitoring_dashboard_v1.types.CreateDashboardRequest`):
Expand Down
Expand Up @@ -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<project>.+?)/alertPolicies/(?P<alert_policy>.+?)$", path
)
return m.groupdict() if m else {}

@staticmethod
def dashboard_path(project: str, dashboard: str,) -> str:
"""Returns a fully-qualified dashboard string."""
Expand Down Expand Up @@ -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 <https://cloud.google.com/monitoring/dashboards/api-dashboard>`__.
This method requires the ``monitoring.dashboards.create``
permission on the specified project. For more information about
permissions, see `Cloud Identity and Access
Management <https://cloud.google.com/iam>`__.
API </monitoring/dashboards/api-dashboard>`__. This method
requires the ``monitoring.dashboards.create`` permission on the
specified project. For more information about permissions, see
`Cloud Identity and Access Management </iam>`__.
Args:
request (google.cloud.monitoring_dashboard_v1.types.CreateDashboardRequest):
Expand Down
Expand Up @@ -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 <https://cloud.google.com/monitoring/dashboards/api-dashboard>`__.
This method requires the ``monitoring.dashboards.create``
permission on the specified project. For more information about
permissions, see `Cloud Identity and Access
Management <https://cloud.google.com/iam>`__.
API </monitoring/dashboards/api-dashboard>`__. This method
requires the ``monitoring.dashboards.create`` permission on the
specified project. For more information about permissions, see
`Cloud Identity and Access Management </iam>`__.
Returns:
Callable[[~.CreateDashboardRequest],
Expand Down
Expand Up @@ -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 <https://cloud.google.com/monitoring/dashboards/api-dashboard>`__.
This method requires the ``monitoring.dashboards.create``
permission on the specified project. For more information about
permissions, see `Cloud Identity and Access
Management <https://cloud.google.com/iam>`__.
API </monitoring/dashboards/api-dashboard>`__. This method
requires the ``monitoring.dashboards.create`` permission on the
specified project. For more information about permissions, see
`Cloud Identity and Access Management </iam>`__.
Returns:
Callable[[~.CreateDashboardRequest],
Expand Down
2 changes: 2 additions & 0 deletions google/cloud/monitoring_dashboard_v1/types/__init__.py
Expand Up @@ -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,
Expand Down Expand Up @@ -49,6 +50,7 @@
)

__all__ = (
"AlertChart",
"Aggregation",
"PickTimeSeriesFilter",
"StatisticalTimeSeriesFilter",
Expand Down
39 changes: 39 additions & 0 deletions 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))
Expand Up @@ -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):
Expand Down Expand Up @@ -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))
6 changes: 6 additions & 0 deletions google/cloud/monitoring_dashboard_v1/types/widget.py
Expand Up @@ -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
Expand Down Expand Up @@ -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,)
Expand All @@ -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))
2 changes: 1 addition & 1 deletion google/cloud/monitoring_dashboard_v1/types/xychart.py
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions scripts/fixup_dashboard_v1_keywords.py
Expand Up @@ -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:
Expand Down

0 comments on commit 509abf5

Please sign in to comment.