Skip to content

Commit

Permalink
feat: add CreateServiceTimeSeries RPC (#235)
Browse files Browse the repository at this point in the history
- [ ] Regenerate this pull request now.

PiperOrigin-RevId: 401594069

Source-Link: googleapis/googleapis@3b9c98e

Source-Link: googleapis/googleapis-gen@b892911
Copy-Tag: eyJwIjoiLmdpdGh1Yi8uT3dsQm90LnlhbWwiLCJoIjoiYjg5MjkxMWNmOWY3MWQ3YmQxNTRhY2Q5MjhkOGE1ODBkZDUxOWY3MSJ9
  • Loading branch information
gcf-owl-bot[bot] authored Oct 8, 2021
1 parent 28a815e commit 04ab777
Show file tree
Hide file tree
Showing 8 changed files with 532 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,11 @@
"create_metric_descriptor"
]
},
"CreateServiceTimeSeries": {
"methods": [
"create_service_time_series"
]
},
"CreateTimeSeries": {
"methods": [
"create_time_series"
Expand Down Expand Up @@ -198,6 +203,11 @@
"create_metric_descriptor"
]
},
"CreateServiceTimeSeries": {
"methods": [
"create_service_time_series"
]
},
"CreateTimeSeries": {
"methods": [
"create_time_series"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -561,8 +561,10 @@ async def create_metric_descriptor(
timeout: float = None,
metadata: Sequence[Tuple[str, str]] = (),
) -> metric_pb2.MetricDescriptor:
r"""Creates a new metric descriptor. User-created metric descriptors
define `custom
r"""Creates a new metric descriptor. The creation is executed
asynchronously and callers may check the returned operation to
track its progress. User-created metric descriptors define
`custom
metrics <https://cloud.google.com/monitoring/custom-metrics>`__.
Args:
Expand Down Expand Up @@ -950,6 +952,100 @@ async def create_time_series(
request, retry=retry, timeout=timeout, metadata=metadata,
)

async def create_service_time_series(
self,
request: metric_service.CreateTimeSeriesRequest = None,
*,
name: str = None,
time_series: Sequence[gm_metric.TimeSeries] = None,
retry: retries.Retry = gapic_v1.method.DEFAULT,
timeout: float = None,
metadata: Sequence[Tuple[str, str]] = (),
) -> None:
r"""Creates or adds data to one or more service time series. A
service time series is a time series for a metric from a Google
Cloud service. The response is empty if all time series in the
request were written. If any time series could not be written, a
corresponding failure message is included in the error response.
This endpoint rejects writes to user-defined metrics. This
method is only for use by Google Cloud services. Use
[projects.timeSeries.create][google.monitoring.v3.MetricService.CreateTimeSeries]
instead.
Args:
request (:class:`google.cloud.monitoring_v3.types.CreateTimeSeriesRequest`):
The request object. The `CreateTimeSeries` request.
name (:class:`str`):
Required. The
`project <https://cloud.google.com/monitoring/api/v3#project_name>`__
on which to execute the request. The format is:
::
projects/[PROJECT_ID_OR_NUMBER]
This corresponds to the ``name`` field
on the ``request`` instance; if ``request`` is provided, this
should not be set.
time_series (:class:`Sequence[google.cloud.monitoring_v3.types.TimeSeries]`):
Required. The new data to be added to a list of time
series. Adds at most one data point to each of several
time series. The new data point must be more recent than
any other point in its time series. Each ``TimeSeries``
value must fully specify a unique time series by
supplying all label values for the metric and the
monitored resource.
The maximum number of ``TimeSeries`` objects per
``Create`` request is 200.
This corresponds to the ``time_series`` field
on the ``request`` instance; if ``request`` is provided, this
should not be set.
retry (google.api_core.retry.Retry): Designation of what errors, if any,
should be retried.
timeout (float): The timeout for this request.
metadata (Sequence[Tuple[str, str]]): Strings which should be
sent along with the request as metadata.
"""
# Create or coerce a protobuf request object.
# Sanity check: If we got a request object, we should *not* have
# gotten any keyword arguments that map to the request.
has_flattened_params = any([name, time_series])
if request is not None and has_flattened_params:
raise ValueError(
"If the `request` argument is set, then none of "
"the individual field arguments should be set."
)

request = metric_service.CreateTimeSeriesRequest(request)

# If we have keyword arguments corresponding to fields on the
# request, apply these.
if name is not None:
request.name = name
if time_series:
request.time_series.extend(time_series)

# Wrap the RPC method; this adds retry and timeout information,
# and friendly error handling.
rpc = gapic_v1.method_async.wrap_method(
self._client._transport.create_service_time_series,
default_timeout=None,
client_info=DEFAULT_CLIENT_INFO,
)

# Certain fields should be provided within the metadata header;
# add these here.
metadata = tuple(metadata) + (
gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)),
)

# Send the request.
await rpc(
request, retry=retry, timeout=timeout, metadata=metadata,
)

async def __aenter__(self):
return self

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -742,8 +742,10 @@ def create_metric_descriptor(
timeout: float = None,
metadata: Sequence[Tuple[str, str]] = (),
) -> metric_pb2.MetricDescriptor:
r"""Creates a new metric descriptor. User-created metric descriptors
define `custom
r"""Creates a new metric descriptor. The creation is executed
asynchronously and callers may check the returned operation to
track its progress. User-created metric descriptors define
`custom
metrics <https://cloud.google.com/monitoring/custom-metrics>`__.
Args:
Expand Down Expand Up @@ -1113,6 +1115,102 @@ def create_time_series(
request, retry=retry, timeout=timeout, metadata=metadata,
)

def create_service_time_series(
self,
request: Union[metric_service.CreateTimeSeriesRequest, dict] = None,
*,
name: str = None,
time_series: Sequence[gm_metric.TimeSeries] = None,
retry: retries.Retry = gapic_v1.method.DEFAULT,
timeout: float = None,
metadata: Sequence[Tuple[str, str]] = (),
) -> None:
r"""Creates or adds data to one or more service time series. A
service time series is a time series for a metric from a Google
Cloud service. The response is empty if all time series in the
request were written. If any time series could not be written, a
corresponding failure message is included in the error response.
This endpoint rejects writes to user-defined metrics. This
method is only for use by Google Cloud services. Use
[projects.timeSeries.create][google.monitoring.v3.MetricService.CreateTimeSeries]
instead.
Args:
request (Union[google.cloud.monitoring_v3.types.CreateTimeSeriesRequest, dict]):
The request object. The `CreateTimeSeries` request.
name (str):
Required. The
`project <https://cloud.google.com/monitoring/api/v3#project_name>`__
on which to execute the request. The format is:
::
projects/[PROJECT_ID_OR_NUMBER]
This corresponds to the ``name`` field
on the ``request`` instance; if ``request`` is provided, this
should not be set.
time_series (Sequence[google.cloud.monitoring_v3.types.TimeSeries]):
Required. The new data to be added to a list of time
series. Adds at most one data point to each of several
time series. The new data point must be more recent than
any other point in its time series. Each ``TimeSeries``
value must fully specify a unique time series by
supplying all label values for the metric and the
monitored resource.
The maximum number of ``TimeSeries`` objects per
``Create`` request is 200.
This corresponds to the ``time_series`` field
on the ``request`` instance; if ``request`` is provided, this
should not be set.
retry (google.api_core.retry.Retry): Designation of what errors, if any,
should be retried.
timeout (float): The timeout for this request.
metadata (Sequence[Tuple[str, str]]): Strings which should be
sent along with the request as metadata.
"""
# Create or coerce a protobuf request object.
# Sanity check: If we got a request object, we should *not* have
# gotten any keyword arguments that map to the request.
has_flattened_params = any([name, time_series])
if request is not None and has_flattened_params:
raise ValueError(
"If the `request` argument is set, then none of "
"the individual field arguments should be set."
)

# Minor optimization to avoid making a copy if the user passes
# in a metric_service.CreateTimeSeriesRequest.
# There's no risk of modifying the input as we've already verified
# there are no flattened fields.
if not isinstance(request, metric_service.CreateTimeSeriesRequest):
request = metric_service.CreateTimeSeriesRequest(request)
# If we have keyword arguments corresponding to fields on the
# request, apply these.
if name is not None:
request.name = name
if time_series is not None:
request.time_series = time_series

# Wrap the RPC method; this adds retry and timeout information,
# and friendly error handling.
rpc = self._transport._wrapped_methods[
self._transport.create_service_time_series
]

# Certain fields should be provided within the metadata header;
# add these here.
metadata = tuple(metadata) + (
gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)),
)

# Send the request.
rpc(
request, retry=retry, timeout=timeout, metadata=metadata,
)

def __enter__(self):
return self

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,11 @@ def _prep_wrapped_messages(self, client_info):
self.create_time_series: gapic_v1.method.wrap_method(
self.create_time_series, default_timeout=12.0, client_info=client_info,
),
self.create_service_time_series: gapic_v1.method.wrap_method(
self.create_service_time_series,
default_timeout=None,
client_info=client_info,
),
}

def close(self):
Expand Down Expand Up @@ -349,5 +354,14 @@ def create_time_series(
]:
raise NotImplementedError()

@property
def create_service_time_series(
self,
) -> Callable[
[metric_service.CreateTimeSeriesRequest],
Union[empty_pb2.Empty, Awaitable[empty_pb2.Empty]],
]:
raise NotImplementedError()


__all__ = ("MetricServiceTransport",)
Original file line number Diff line number Diff line change
Expand Up @@ -362,8 +362,10 @@ def create_metric_descriptor(
]:
r"""Return a callable for the create metric descriptor method over gRPC.
Creates a new metric descriptor. User-created metric descriptors
define `custom
Creates a new metric descriptor. The creation is executed
asynchronously and callers may check the returned operation to
track its progress. User-created metric descriptors define
`custom
metrics <https://cloud.google.com/monitoring/custom-metrics>`__.
Returns:
Expand Down Expand Up @@ -471,6 +473,40 @@ def create_time_series(
)
return self._stubs["create_time_series"]

@property
def create_service_time_series(
self,
) -> Callable[[metric_service.CreateTimeSeriesRequest], empty_pb2.Empty]:
r"""Return a callable for the create service time series method over gRPC.
Creates or adds data to one or more service time series. A
service time series is a time series for a metric from a Google
Cloud service. The response is empty if all time series in the
request were written. If any time series could not be written, a
corresponding failure message is included in the error response.
This endpoint rejects writes to user-defined metrics. This
method is only for use by Google Cloud services. Use
[projects.timeSeries.create][google.monitoring.v3.MetricService.CreateTimeSeries]
instead.
Returns:
Callable[[~.CreateTimeSeriesRequest],
~.Empty]:
A function that, when called, will call the underlying RPC
on the server.
"""
# Generate a "stub function" on-the-fly which will actually make
# the request.
# gRPC handles serialization and deserialization, so we just need
# to pass in the functions for each.
if "create_service_time_series" not in self._stubs:
self._stubs["create_service_time_series"] = self.grpc_channel.unary_unary(
"/google.monitoring.v3.MetricService/CreateServiceTimeSeries",
request_serializer=metric_service.CreateTimeSeriesRequest.serialize,
response_deserializer=empty_pb2.Empty.FromString,
)
return self._stubs["create_service_time_series"]

def close(self):
self.grpc_channel.close()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -367,8 +367,10 @@ def create_metric_descriptor(
]:
r"""Return a callable for the create metric descriptor method over gRPC.
Creates a new metric descriptor. User-created metric descriptors
define `custom
Creates a new metric descriptor. The creation is executed
asynchronously and callers may check the returned operation to
track its progress. User-created metric descriptors define
`custom
metrics <https://cloud.google.com/monitoring/custom-metrics>`__.
Returns:
Expand Down Expand Up @@ -479,6 +481,40 @@ def create_time_series(
)
return self._stubs["create_time_series"]

@property
def create_service_time_series(
self,
) -> Callable[[metric_service.CreateTimeSeriesRequest], Awaitable[empty_pb2.Empty]]:
r"""Return a callable for the create service time series method over gRPC.
Creates or adds data to one or more service time series. A
service time series is a time series for a metric from a Google
Cloud service. The response is empty if all time series in the
request were written. If any time series could not be written, a
corresponding failure message is included in the error response.
This endpoint rejects writes to user-defined metrics. This
method is only for use by Google Cloud services. Use
[projects.timeSeries.create][google.monitoring.v3.MetricService.CreateTimeSeries]
instead.
Returns:
Callable[[~.CreateTimeSeriesRequest],
Awaitable[~.Empty]]:
A function that, when called, will call the underlying RPC
on the server.
"""
# Generate a "stub function" on-the-fly which will actually make
# the request.
# gRPC handles serialization and deserialization, so we just need
# to pass in the functions for each.
if "create_service_time_series" not in self._stubs:
self._stubs["create_service_time_series"] = self.grpc_channel.unary_unary(
"/google.monitoring.v3.MetricService/CreateServiceTimeSeries",
request_serializer=metric_service.CreateTimeSeriesRequest.serialize,
response_deserializer=empty_pb2.Empty.FromString,
)
return self._stubs["create_service_time_series"]

def close(self):
return self.grpc_channel.close()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ class monitoringCallTransformer(cst.CSTTransformer):
'create_notification_channel': ('name', 'notification_channel', ),
'create_service': ('parent', 'service', 'service_id', ),
'create_service_level_objective': ('parent', 'service_level_objective', 'service_level_objective_id', ),
'create_service_time_series': ('name', 'time_series', ),
'create_time_series': ('name', 'time_series', ),
'create_uptime_check_config': ('parent', 'uptime_check_config', ),
'delete_alert_policy': ('name', ),
Expand Down
Loading

0 comments on commit 04ab777

Please sign in to comment.