
com.google.cloud.logging.v2.MetricsClient Maven / Gradle / Ivy
Show all versions of google-cloud-logging Show documentation
/*
* Copyright 2024 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
*
* https://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.
*/
package com.google.cloud.logging.v2;
import com.google.api.core.ApiFuture;
import com.google.api.core.ApiFutures;
import com.google.api.gax.core.BackgroundResource;
import com.google.api.gax.paging.AbstractFixedSizeCollection;
import com.google.api.gax.paging.AbstractPage;
import com.google.api.gax.paging.AbstractPagedListResponse;
import com.google.api.gax.rpc.PageContext;
import com.google.api.gax.rpc.UnaryCallable;
import com.google.cloud.logging.v2.stub.MetricsServiceV2Stub;
import com.google.cloud.logging.v2.stub.MetricsServiceV2StubSettings;
import com.google.common.util.concurrent.MoreExecutors;
import com.google.logging.v2.CreateLogMetricRequest;
import com.google.logging.v2.DeleteLogMetricRequest;
import com.google.logging.v2.GetLogMetricRequest;
import com.google.logging.v2.ListLogMetricsRequest;
import com.google.logging.v2.ListLogMetricsResponse;
import com.google.logging.v2.LogMetric;
import com.google.logging.v2.LogMetricName;
import com.google.logging.v2.ProjectName;
import com.google.logging.v2.UpdateLogMetricRequest;
import com.google.protobuf.Empty;
import java.io.IOException;
import java.util.List;
import java.util.concurrent.TimeUnit;
import javax.annotation.Generated;
// AUTO-GENERATED DOCUMENTATION AND CLASS.
/**
* Service Description: Service for configuring logs-based metrics.
*
* This class provides the ability to make remote calls to the backing service through method
* calls that map to API methods. Sample code to get started:
*
*
{@code
* // This snippet has been automatically generated and should be regarded as a code template only.
* // It will require modifications to work:
* // - It may require correct/in-range values for request initialization.
* // - It may require specifying regional endpoints when creating the service client as shown in
* // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
* try (MetricsClient metricsClient = MetricsClient.create()) {
* LogMetricName metricName = LogMetricName.of("[PROJECT]", "[METRIC]");
* LogMetric response = metricsClient.getLogMetric(metricName);
* }
* }
*
* Note: close() needs to be called on the MetricsClient object to clean up resources such as
* threads. In the example above, try-with-resources is used, which automatically calls close().
*
*
* Methods
*
* Method
* Description
* Method Variants
*
*
* ListLogMetrics
* Lists logs-based metrics.
*
* Request object method variants only take one parameter, a request object, which must be constructed before the call.
*
* listLogMetrics(ListLogMetricsRequest request)
*
* "Flattened" method variants have converted the fields of the request object into function parameters to enable multiple ways to call the same method.
*
* listLogMetrics(ProjectName parent)
*
listLogMetrics(String parent)
*
* Callable method variants take no parameters and return an immutable API callable object, which can be used to initiate calls to the service.
*
* listLogMetricsPagedCallable()
*
listLogMetricsCallable()
*
*
*
*
* GetLogMetric
* Gets a logs-based metric.
*
* Request object method variants only take one parameter, a request object, which must be constructed before the call.
*
* getLogMetric(GetLogMetricRequest request)
*
* "Flattened" method variants have converted the fields of the request object into function parameters to enable multiple ways to call the same method.
*
* getLogMetric(LogMetricName metricName)
*
getLogMetric(String metricName)
*
* Callable method variants take no parameters and return an immutable API callable object, which can be used to initiate calls to the service.
*
* getLogMetricCallable()
*
*
*
*
* CreateLogMetric
* Creates a logs-based metric.
*
* Request object method variants only take one parameter, a request object, which must be constructed before the call.
*
* createLogMetric(CreateLogMetricRequest request)
*
* "Flattened" method variants have converted the fields of the request object into function parameters to enable multiple ways to call the same method.
*
* createLogMetric(ProjectName parent, LogMetric metric)
*
createLogMetric(String parent, LogMetric metric)
*
* Callable method variants take no parameters and return an immutable API callable object, which can be used to initiate calls to the service.
*
* createLogMetricCallable()
*
*
*
*
* UpdateLogMetric
* Creates or updates a logs-based metric.
*
* Request object method variants only take one parameter, a request object, which must be constructed before the call.
*
* updateLogMetric(UpdateLogMetricRequest request)
*
* "Flattened" method variants have converted the fields of the request object into function parameters to enable multiple ways to call the same method.
*
* updateLogMetric(LogMetricName metricName, LogMetric metric)
*
updateLogMetric(String metricName, LogMetric metric)
*
* Callable method variants take no parameters and return an immutable API callable object, which can be used to initiate calls to the service.
*
* updateLogMetricCallable()
*
*
*
*
* DeleteLogMetric
* Deletes a logs-based metric.
*
* Request object method variants only take one parameter, a request object, which must be constructed before the call.
*
* deleteLogMetric(DeleteLogMetricRequest request)
*
* "Flattened" method variants have converted the fields of the request object into function parameters to enable multiple ways to call the same method.
*
* deleteLogMetric(LogMetricName metricName)
*
deleteLogMetric(String metricName)
*
* Callable method variants take no parameters and return an immutable API callable object, which can be used to initiate calls to the service.
*
* deleteLogMetricCallable()
*
*
*
*
*
* See the individual methods for example code.
*
*
Many parameters require resource names to be formatted in a particular way. To assist with
* these names, this class includes a format method for each type of name, and additionally a parse
* method to extract the individual identifiers contained within names that are returned.
*
*
This class can be customized by passing in a custom instance of MetricsSettings to create().
* For example:
*
*
To customize credentials:
*
*
{@code
* // This snippet has been automatically generated and should be regarded as a code template only.
* // It will require modifications to work:
* // - It may require correct/in-range values for request initialization.
* // - It may require specifying regional endpoints when creating the service client as shown in
* // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
* MetricsSettings metricsSettings =
* MetricsSettings.newBuilder()
* .setCredentialsProvider(FixedCredentialsProvider.create(myCredentials))
* .build();
* MetricsClient metricsClient = MetricsClient.create(metricsSettings);
* }
*
* To customize the endpoint:
*
*
{@code
* // This snippet has been automatically generated and should be regarded as a code template only.
* // It will require modifications to work:
* // - It may require correct/in-range values for request initialization.
* // - It may require specifying regional endpoints when creating the service client as shown in
* // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
* MetricsSettings metricsSettings = MetricsSettings.newBuilder().setEndpoint(myEndpoint).build();
* MetricsClient metricsClient = MetricsClient.create(metricsSettings);
* }
*
* Please refer to the GitHub repository's samples for more quickstart code snippets.
*/
@Generated("by gapic-generator-java")
public class MetricsClient implements BackgroundResource {
private final MetricsSettings settings;
private final MetricsServiceV2Stub stub;
/** Constructs an instance of MetricsClient with default settings. */
public static final MetricsClient create() throws IOException {
return create(MetricsSettings.newBuilder().build());
}
/**
* Constructs an instance of MetricsClient, using the given settings. The channels are created
* based on the settings passed in, or defaults for any settings that are not set.
*/
public static final MetricsClient create(MetricsSettings settings) throws IOException {
return new MetricsClient(settings);
}
/**
* Constructs an instance of MetricsClient, using the given stub for making calls. This is for
* advanced usage - prefer using create(MetricsSettings).
*/
public static final MetricsClient create(MetricsServiceV2Stub stub) {
return new MetricsClient(stub);
}
/**
* Constructs an instance of MetricsClient, using the given settings. This is protected so that it
* is easy to make a subclass, but otherwise, the static factory methods should be preferred.
*/
protected MetricsClient(MetricsSettings settings) throws IOException {
this.settings = settings;
this.stub = ((MetricsServiceV2StubSettings) settings.getStubSettings()).createStub();
}
protected MetricsClient(MetricsServiceV2Stub stub) {
this.settings = null;
this.stub = stub;
}
public final MetricsSettings getSettings() {
return settings;
}
public MetricsServiceV2Stub getStub() {
return stub;
}
// AUTO-GENERATED DOCUMENTATION AND METHOD.
/**
* Lists logs-based metrics.
*
*
Sample code:
*
*
{@code
* // This snippet has been automatically generated and should be regarded as a code template only.
* // It will require modifications to work:
* // - It may require correct/in-range values for request initialization.
* // - It may require specifying regional endpoints when creating the service client as shown in
* // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
* try (MetricsClient metricsClient = MetricsClient.create()) {
* ProjectName parent = ProjectName.of("[PROJECT]");
* for (LogMetric element : metricsClient.listLogMetrics(parent).iterateAll()) {
* // doThingsWith(element);
* }
* }
* }
*
* @param parent Required. The name of the project containing the metrics:
* "projects/[PROJECT_ID]"
* @throws com.google.api.gax.rpc.ApiException if the remote call fails
*/
public final ListLogMetricsPagedResponse listLogMetrics(ProjectName parent) {
ListLogMetricsRequest request =
ListLogMetricsRequest.newBuilder()
.setParent(parent == null ? null : parent.toString())
.build();
return listLogMetrics(request);
}
// AUTO-GENERATED DOCUMENTATION AND METHOD.
/**
* Lists logs-based metrics.
*
*
Sample code:
*
*
{@code
* // This snippet has been automatically generated and should be regarded as a code template only.
* // It will require modifications to work:
* // - It may require correct/in-range values for request initialization.
* // - It may require specifying regional endpoints when creating the service client as shown in
* // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
* try (MetricsClient metricsClient = MetricsClient.create()) {
* String parent = ProjectName.of("[PROJECT]").toString();
* for (LogMetric element : metricsClient.listLogMetrics(parent).iterateAll()) {
* // doThingsWith(element);
* }
* }
* }
*
* @param parent Required. The name of the project containing the metrics:
* "projects/[PROJECT_ID]"
* @throws com.google.api.gax.rpc.ApiException if the remote call fails
*/
public final ListLogMetricsPagedResponse listLogMetrics(String parent) {
ListLogMetricsRequest request = ListLogMetricsRequest.newBuilder().setParent(parent).build();
return listLogMetrics(request);
}
// AUTO-GENERATED DOCUMENTATION AND METHOD.
/**
* Lists logs-based metrics.
*
*
Sample code:
*
*
{@code
* // This snippet has been automatically generated and should be regarded as a code template only.
* // It will require modifications to work:
* // - It may require correct/in-range values for request initialization.
* // - It may require specifying regional endpoints when creating the service client as shown in
* // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
* try (MetricsClient metricsClient = MetricsClient.create()) {
* ListLogMetricsRequest request =
* ListLogMetricsRequest.newBuilder()
* .setParent(ProjectName.of("[PROJECT]").toString())
* .setPageToken("pageToken873572522")
* .setPageSize(883849137)
* .build();
* for (LogMetric element : metricsClient.listLogMetrics(request).iterateAll()) {
* // doThingsWith(element);
* }
* }
* }
*
* @param request The request object containing all of the parameters for the API call.
* @throws com.google.api.gax.rpc.ApiException if the remote call fails
*/
public final ListLogMetricsPagedResponse listLogMetrics(ListLogMetricsRequest request) {
return listLogMetricsPagedCallable().call(request);
}
// AUTO-GENERATED DOCUMENTATION AND METHOD.
/**
* Lists logs-based metrics.
*
* Sample code:
*
*
{@code
* // This snippet has been automatically generated and should be regarded as a code template only.
* // It will require modifications to work:
* // - It may require correct/in-range values for request initialization.
* // - It may require specifying regional endpoints when creating the service client as shown in
* // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
* try (MetricsClient metricsClient = MetricsClient.create()) {
* ListLogMetricsRequest request =
* ListLogMetricsRequest.newBuilder()
* .setParent(ProjectName.of("[PROJECT]").toString())
* .setPageToken("pageToken873572522")
* .setPageSize(883849137)
* .build();
* ApiFuture future = metricsClient.listLogMetricsPagedCallable().futureCall(request);
* // Do something.
* for (LogMetric element : future.get().iterateAll()) {
* // doThingsWith(element);
* }
* }
* }
*/
public final UnaryCallable
listLogMetricsPagedCallable() {
return stub.listLogMetricsPagedCallable();
}
// AUTO-GENERATED DOCUMENTATION AND METHOD.
/**
* Lists logs-based metrics.
*
* Sample code:
*
*
{@code
* // This snippet has been automatically generated and should be regarded as a code template only.
* // It will require modifications to work:
* // - It may require correct/in-range values for request initialization.
* // - It may require specifying regional endpoints when creating the service client as shown in
* // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
* try (MetricsClient metricsClient = MetricsClient.create()) {
* ListLogMetricsRequest request =
* ListLogMetricsRequest.newBuilder()
* .setParent(ProjectName.of("[PROJECT]").toString())
* .setPageToken("pageToken873572522")
* .setPageSize(883849137)
* .build();
* while (true) {
* ListLogMetricsResponse response = metricsClient.listLogMetricsCallable().call(request);
* for (LogMetric element : response.getMetricsList()) {
* // doThingsWith(element);
* }
* String nextPageToken = response.getNextPageToken();
* if (!Strings.isNullOrEmpty(nextPageToken)) {
* request = request.toBuilder().setPageToken(nextPageToken).build();
* } else {
* break;
* }
* }
* }
* }
*/
public final UnaryCallable
listLogMetricsCallable() {
return stub.listLogMetricsCallable();
}
// AUTO-GENERATED DOCUMENTATION AND METHOD.
/**
* Gets a logs-based metric.
*
* Sample code:
*
*
{@code
* // This snippet has been automatically generated and should be regarded as a code template only.
* // It will require modifications to work:
* // - It may require correct/in-range values for request initialization.
* // - It may require specifying regional endpoints when creating the service client as shown in
* // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
* try (MetricsClient metricsClient = MetricsClient.create()) {
* LogMetricName metricName = LogMetricName.of("[PROJECT]", "[METRIC]");
* LogMetric response = metricsClient.getLogMetric(metricName);
* }
* }
*
* @param metricName Required. The resource name of the desired metric:
* "projects/[PROJECT_ID]/metrics/[METRIC_ID]"
* @throws com.google.api.gax.rpc.ApiException if the remote call fails
*/
public final LogMetric getLogMetric(LogMetricName metricName) {
GetLogMetricRequest request =
GetLogMetricRequest.newBuilder()
.setMetricName(metricName == null ? null : metricName.toString())
.build();
return getLogMetric(request);
}
// AUTO-GENERATED DOCUMENTATION AND METHOD.
/**
* Gets a logs-based metric.
*
*
Sample code:
*
*
{@code
* // This snippet has been automatically generated and should be regarded as a code template only.
* // It will require modifications to work:
* // - It may require correct/in-range values for request initialization.
* // - It may require specifying regional endpoints when creating the service client as shown in
* // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
* try (MetricsClient metricsClient = MetricsClient.create()) {
* String metricName = LogMetricName.of("[PROJECT]", "[METRIC]").toString();
* LogMetric response = metricsClient.getLogMetric(metricName);
* }
* }
*
* @param metricName Required. The resource name of the desired metric:
* "projects/[PROJECT_ID]/metrics/[METRIC_ID]"
* @throws com.google.api.gax.rpc.ApiException if the remote call fails
*/
public final LogMetric getLogMetric(String metricName) {
GetLogMetricRequest request =
GetLogMetricRequest.newBuilder().setMetricName(metricName).build();
return getLogMetric(request);
}
// AUTO-GENERATED DOCUMENTATION AND METHOD.
/**
* Gets a logs-based metric.
*
*
Sample code:
*
*
{@code
* // This snippet has been automatically generated and should be regarded as a code template only.
* // It will require modifications to work:
* // - It may require correct/in-range values for request initialization.
* // - It may require specifying regional endpoints when creating the service client as shown in
* // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
* try (MetricsClient metricsClient = MetricsClient.create()) {
* GetLogMetricRequest request =
* GetLogMetricRequest.newBuilder()
* .setMetricName(LogMetricName.of("[PROJECT]", "[METRIC]").toString())
* .build();
* LogMetric response = metricsClient.getLogMetric(request);
* }
* }
*
* @param request The request object containing all of the parameters for the API call.
* @throws com.google.api.gax.rpc.ApiException if the remote call fails
*/
public final LogMetric getLogMetric(GetLogMetricRequest request) {
return getLogMetricCallable().call(request);
}
// AUTO-GENERATED DOCUMENTATION AND METHOD.
/**
* Gets a logs-based metric.
*
* Sample code:
*
*
{@code
* // This snippet has been automatically generated and should be regarded as a code template only.
* // It will require modifications to work:
* // - It may require correct/in-range values for request initialization.
* // - It may require specifying regional endpoints when creating the service client as shown in
* // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
* try (MetricsClient metricsClient = MetricsClient.create()) {
* GetLogMetricRequest request =
* GetLogMetricRequest.newBuilder()
* .setMetricName(LogMetricName.of("[PROJECT]", "[METRIC]").toString())
* .build();
* ApiFuture future = metricsClient.getLogMetricCallable().futureCall(request);
* // Do something.
* LogMetric response = future.get();
* }
* }
*/
public final UnaryCallable getLogMetricCallable() {
return stub.getLogMetricCallable();
}
// AUTO-GENERATED DOCUMENTATION AND METHOD.
/**
* Creates a logs-based metric.
*
* Sample code:
*
*
{@code
* // This snippet has been automatically generated and should be regarded as a code template only.
* // It will require modifications to work:
* // - It may require correct/in-range values for request initialization.
* // - It may require specifying regional endpoints when creating the service client as shown in
* // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
* try (MetricsClient metricsClient = MetricsClient.create()) {
* ProjectName parent = ProjectName.of("[PROJECT]");
* LogMetric metric = LogMetric.newBuilder().build();
* LogMetric response = metricsClient.createLogMetric(parent, metric);
* }
* }
*
* @param parent Required. The resource name of the project in which to create the metric:
* "projects/[PROJECT_ID]"
*
The new metric must be provided in the request.
* @param metric Required. The new logs-based metric, which must not have an identifier that
* already exists.
* @throws com.google.api.gax.rpc.ApiException if the remote call fails
*/
public final LogMetric createLogMetric(ProjectName parent, LogMetric metric) {
CreateLogMetricRequest request =
CreateLogMetricRequest.newBuilder()
.setParent(parent == null ? null : parent.toString())
.setMetric(metric)
.build();
return createLogMetric(request);
}
// AUTO-GENERATED DOCUMENTATION AND METHOD.
/**
* Creates a logs-based metric.
*
*
Sample code:
*
*
{@code
* // This snippet has been automatically generated and should be regarded as a code template only.
* // It will require modifications to work:
* // - It may require correct/in-range values for request initialization.
* // - It may require specifying regional endpoints when creating the service client as shown in
* // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
* try (MetricsClient metricsClient = MetricsClient.create()) {
* String parent = ProjectName.of("[PROJECT]").toString();
* LogMetric metric = LogMetric.newBuilder().build();
* LogMetric response = metricsClient.createLogMetric(parent, metric);
* }
* }
*
* @param parent Required. The resource name of the project in which to create the metric:
* "projects/[PROJECT_ID]"
*
The new metric must be provided in the request.
* @param metric Required. The new logs-based metric, which must not have an identifier that
* already exists.
* @throws com.google.api.gax.rpc.ApiException if the remote call fails
*/
public final LogMetric createLogMetric(String parent, LogMetric metric) {
CreateLogMetricRequest request =
CreateLogMetricRequest.newBuilder().setParent(parent).setMetric(metric).build();
return createLogMetric(request);
}
// AUTO-GENERATED DOCUMENTATION AND METHOD.
/**
* Creates a logs-based metric.
*
*
Sample code:
*
*
{@code
* // This snippet has been automatically generated and should be regarded as a code template only.
* // It will require modifications to work:
* // - It may require correct/in-range values for request initialization.
* // - It may require specifying regional endpoints when creating the service client as shown in
* // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
* try (MetricsClient metricsClient = MetricsClient.create()) {
* CreateLogMetricRequest request =
* CreateLogMetricRequest.newBuilder()
* .setParent(ProjectName.of("[PROJECT]").toString())
* .setMetric(LogMetric.newBuilder().build())
* .build();
* LogMetric response = metricsClient.createLogMetric(request);
* }
* }
*
* @param request The request object containing all of the parameters for the API call.
* @throws com.google.api.gax.rpc.ApiException if the remote call fails
*/
public final LogMetric createLogMetric(CreateLogMetricRequest request) {
return createLogMetricCallable().call(request);
}
// AUTO-GENERATED DOCUMENTATION AND METHOD.
/**
* Creates a logs-based metric.
*
* Sample code:
*
*
{@code
* // This snippet has been automatically generated and should be regarded as a code template only.
* // It will require modifications to work:
* // - It may require correct/in-range values for request initialization.
* // - It may require specifying regional endpoints when creating the service client as shown in
* // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
* try (MetricsClient metricsClient = MetricsClient.create()) {
* CreateLogMetricRequest request =
* CreateLogMetricRequest.newBuilder()
* .setParent(ProjectName.of("[PROJECT]").toString())
* .setMetric(LogMetric.newBuilder().build())
* .build();
* ApiFuture future = metricsClient.createLogMetricCallable().futureCall(request);
* // Do something.
* LogMetric response = future.get();
* }
* }
*/
public final UnaryCallable createLogMetricCallable() {
return stub.createLogMetricCallable();
}
// AUTO-GENERATED DOCUMENTATION AND METHOD.
/**
* Creates or updates a logs-based metric.
*
* Sample code:
*
*
{@code
* // This snippet has been automatically generated and should be regarded as a code template only.
* // It will require modifications to work:
* // - It may require correct/in-range values for request initialization.
* // - It may require specifying regional endpoints when creating the service client as shown in
* // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
* try (MetricsClient metricsClient = MetricsClient.create()) {
* LogMetricName metricName = LogMetricName.of("[PROJECT]", "[METRIC]");
* LogMetric metric = LogMetric.newBuilder().build();
* LogMetric response = metricsClient.updateLogMetric(metricName, metric);
* }
* }
*
* @param metricName Required. The resource name of the metric to update:
* "projects/[PROJECT_ID]/metrics/[METRIC_ID]"
*
The updated metric must be provided in the request and it's `name` field must be the
* same as `[METRIC_ID]` If the metric does not exist in `[PROJECT_ID]`, then a new metric is
* created.
* @param metric Required. The updated metric.
* @throws com.google.api.gax.rpc.ApiException if the remote call fails
*/
public final LogMetric updateLogMetric(LogMetricName metricName, LogMetric metric) {
UpdateLogMetricRequest request =
UpdateLogMetricRequest.newBuilder()
.setMetricName(metricName == null ? null : metricName.toString())
.setMetric(metric)
.build();
return updateLogMetric(request);
}
// AUTO-GENERATED DOCUMENTATION AND METHOD.
/**
* Creates or updates a logs-based metric.
*
*
Sample code:
*
*
{@code
* // This snippet has been automatically generated and should be regarded as a code template only.
* // It will require modifications to work:
* // - It may require correct/in-range values for request initialization.
* // - It may require specifying regional endpoints when creating the service client as shown in
* // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
* try (MetricsClient metricsClient = MetricsClient.create()) {
* String metricName = LogMetricName.of("[PROJECT]", "[METRIC]").toString();
* LogMetric metric = LogMetric.newBuilder().build();
* LogMetric response = metricsClient.updateLogMetric(metricName, metric);
* }
* }
*
* @param metricName Required. The resource name of the metric to update:
* "projects/[PROJECT_ID]/metrics/[METRIC_ID]"
*
The updated metric must be provided in the request and it's `name` field must be the
* same as `[METRIC_ID]` If the metric does not exist in `[PROJECT_ID]`, then a new metric is
* created.
* @param metric Required. The updated metric.
* @throws com.google.api.gax.rpc.ApiException if the remote call fails
*/
public final LogMetric updateLogMetric(String metricName, LogMetric metric) {
UpdateLogMetricRequest request =
UpdateLogMetricRequest.newBuilder().setMetricName(metricName).setMetric(metric).build();
return updateLogMetric(request);
}
// AUTO-GENERATED DOCUMENTATION AND METHOD.
/**
* Creates or updates a logs-based metric.
*
*
Sample code:
*
*
{@code
* // This snippet has been automatically generated and should be regarded as a code template only.
* // It will require modifications to work:
* // - It may require correct/in-range values for request initialization.
* // - It may require specifying regional endpoints when creating the service client as shown in
* // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
* try (MetricsClient metricsClient = MetricsClient.create()) {
* UpdateLogMetricRequest request =
* UpdateLogMetricRequest.newBuilder()
* .setMetricName(LogMetricName.of("[PROJECT]", "[METRIC]").toString())
* .setMetric(LogMetric.newBuilder().build())
* .build();
* LogMetric response = metricsClient.updateLogMetric(request);
* }
* }
*
* @param request The request object containing all of the parameters for the API call.
* @throws com.google.api.gax.rpc.ApiException if the remote call fails
*/
public final LogMetric updateLogMetric(UpdateLogMetricRequest request) {
return updateLogMetricCallable().call(request);
}
// AUTO-GENERATED DOCUMENTATION AND METHOD.
/**
* Creates or updates a logs-based metric.
*
* Sample code:
*
*
{@code
* // This snippet has been automatically generated and should be regarded as a code template only.
* // It will require modifications to work:
* // - It may require correct/in-range values for request initialization.
* // - It may require specifying regional endpoints when creating the service client as shown in
* // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
* try (MetricsClient metricsClient = MetricsClient.create()) {
* UpdateLogMetricRequest request =
* UpdateLogMetricRequest.newBuilder()
* .setMetricName(LogMetricName.of("[PROJECT]", "[METRIC]").toString())
* .setMetric(LogMetric.newBuilder().build())
* .build();
* ApiFuture future = metricsClient.updateLogMetricCallable().futureCall(request);
* // Do something.
* LogMetric response = future.get();
* }
* }
*/
public final UnaryCallable updateLogMetricCallable() {
return stub.updateLogMetricCallable();
}
// AUTO-GENERATED DOCUMENTATION AND METHOD.
/**
* Deletes a logs-based metric.
*
* Sample code:
*
*
{@code
* // This snippet has been automatically generated and should be regarded as a code template only.
* // It will require modifications to work:
* // - It may require correct/in-range values for request initialization.
* // - It may require specifying regional endpoints when creating the service client as shown in
* // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
* try (MetricsClient metricsClient = MetricsClient.create()) {
* LogMetricName metricName = LogMetricName.of("[PROJECT]", "[METRIC]");
* metricsClient.deleteLogMetric(metricName);
* }
* }
*
* @param metricName Required. The resource name of the metric to delete:
* "projects/[PROJECT_ID]/metrics/[METRIC_ID]"
* @throws com.google.api.gax.rpc.ApiException if the remote call fails
*/
public final void deleteLogMetric(LogMetricName metricName) {
DeleteLogMetricRequest request =
DeleteLogMetricRequest.newBuilder()
.setMetricName(metricName == null ? null : metricName.toString())
.build();
deleteLogMetric(request);
}
// AUTO-GENERATED DOCUMENTATION AND METHOD.
/**
* Deletes a logs-based metric.
*
*
Sample code:
*
*
{@code
* // This snippet has been automatically generated and should be regarded as a code template only.
* // It will require modifications to work:
* // - It may require correct/in-range values for request initialization.
* // - It may require specifying regional endpoints when creating the service client as shown in
* // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
* try (MetricsClient metricsClient = MetricsClient.create()) {
* String metricName = LogMetricName.of("[PROJECT]", "[METRIC]").toString();
* metricsClient.deleteLogMetric(metricName);
* }
* }
*
* @param metricName Required. The resource name of the metric to delete:
* "projects/[PROJECT_ID]/metrics/[METRIC_ID]"
* @throws com.google.api.gax.rpc.ApiException if the remote call fails
*/
public final void deleteLogMetric(String metricName) {
DeleteLogMetricRequest request =
DeleteLogMetricRequest.newBuilder().setMetricName(metricName).build();
deleteLogMetric(request);
}
// AUTO-GENERATED DOCUMENTATION AND METHOD.
/**
* Deletes a logs-based metric.
*
*
Sample code:
*
*
{@code
* // This snippet has been automatically generated and should be regarded as a code template only.
* // It will require modifications to work:
* // - It may require correct/in-range values for request initialization.
* // - It may require specifying regional endpoints when creating the service client as shown in
* // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
* try (MetricsClient metricsClient = MetricsClient.create()) {
* DeleteLogMetricRequest request =
* DeleteLogMetricRequest.newBuilder()
* .setMetricName(LogMetricName.of("[PROJECT]", "[METRIC]").toString())
* .build();
* metricsClient.deleteLogMetric(request);
* }
* }
*
* @param request The request object containing all of the parameters for the API call.
* @throws com.google.api.gax.rpc.ApiException if the remote call fails
*/
public final void deleteLogMetric(DeleteLogMetricRequest request) {
deleteLogMetricCallable().call(request);
}
// AUTO-GENERATED DOCUMENTATION AND METHOD.
/**
* Deletes a logs-based metric.
*
* Sample code:
*
*
{@code
* // This snippet has been automatically generated and should be regarded as a code template only.
* // It will require modifications to work:
* // - It may require correct/in-range values for request initialization.
* // - It may require specifying regional endpoints when creating the service client as shown in
* // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
* try (MetricsClient metricsClient = MetricsClient.create()) {
* DeleteLogMetricRequest request =
* DeleteLogMetricRequest.newBuilder()
* .setMetricName(LogMetricName.of("[PROJECT]", "[METRIC]").toString())
* .build();
* ApiFuture future = metricsClient.deleteLogMetricCallable().futureCall(request);
* // Do something.
* future.get();
* }
* }
*/
public final UnaryCallable deleteLogMetricCallable() {
return stub.deleteLogMetricCallable();
}
@Override
public final void close() {
stub.close();
}
@Override
public void shutdown() {
stub.shutdown();
}
@Override
public boolean isShutdown() {
return stub.isShutdown();
}
@Override
public boolean isTerminated() {
return stub.isTerminated();
}
@Override
public void shutdownNow() {
stub.shutdownNow();
}
@Override
public boolean awaitTermination(long duration, TimeUnit unit) throws InterruptedException {
return stub.awaitTermination(duration, unit);
}
public static class ListLogMetricsPagedResponse
extends AbstractPagedListResponse<
ListLogMetricsRequest,
ListLogMetricsResponse,
LogMetric,
ListLogMetricsPage,
ListLogMetricsFixedSizeCollection> {
public static ApiFuture createAsync(
PageContext context,
ApiFuture futureResponse) {
ApiFuture futurePage =
ListLogMetricsPage.createEmptyPage().createPageAsync(context, futureResponse);
return ApiFutures.transform(
futurePage,
input -> new ListLogMetricsPagedResponse(input),
MoreExecutors.directExecutor());
}
private ListLogMetricsPagedResponse(ListLogMetricsPage page) {
super(page, ListLogMetricsFixedSizeCollection.createEmptyCollection());
}
}
public static class ListLogMetricsPage
extends AbstractPage<
ListLogMetricsRequest, ListLogMetricsResponse, LogMetric, ListLogMetricsPage> {
private ListLogMetricsPage(
PageContext context,
ListLogMetricsResponse response) {
super(context, response);
}
private static ListLogMetricsPage createEmptyPage() {
return new ListLogMetricsPage(null, null);
}
@Override
protected ListLogMetricsPage createPage(
PageContext context,
ListLogMetricsResponse response) {
return new ListLogMetricsPage(context, response);
}
@Override
public ApiFuture createPageAsync(
PageContext context,
ApiFuture futureResponse) {
return super.createPageAsync(context, futureResponse);
}
}
public static class ListLogMetricsFixedSizeCollection
extends AbstractFixedSizeCollection<
ListLogMetricsRequest,
ListLogMetricsResponse,
LogMetric,
ListLogMetricsPage,
ListLogMetricsFixedSizeCollection> {
private ListLogMetricsFixedSizeCollection(List pages, int collectionSize) {
super(pages, collectionSize);
}
private static ListLogMetricsFixedSizeCollection createEmptyCollection() {
return new ListLogMetricsFixedSizeCollection(null, 0);
}
@Override
protected ListLogMetricsFixedSizeCollection createCollection(
List pages, int collectionSize) {
return new ListLogMetricsFixedSizeCollection(pages, collectionSize);
}
}
}