Search in sources :

Example 1 with LogMetricName

use of com.google.logging.v2.LogMetricName in project gapic-generator-java by googleapis.

the class MetricsClientTest method getLogMetricTest.

@Test
public void getLogMetricTest() throws Exception {
    LogMetric expectedResponse = LogMetric.newBuilder().setName(LogMetricName.of("[PROJECT]", "[METRIC]").toString()).setDescription("description-1724546052").setFilter("filter-1274492040").setMetricDescriptor(MetricDescriptor.newBuilder().build()).setValueExtractor("valueExtractor-1867420749").putAllLabelExtractors(new HashMap<String, String>()).setBucketOptions(Distribution.BucketOptions.newBuilder().build()).setCreateTime(Timestamp.newBuilder().build()).setUpdateTime(Timestamp.newBuilder().build()).build();
    mockMetricsServiceV2.addResponse(expectedResponse);
    LogMetricName metricName = LogMetricName.of("[PROJECT]", "[METRIC]");
    LogMetric actualResponse = client.getLogMetric(metricName);
    Assert.assertEquals(expectedResponse, actualResponse);
    List<AbstractMessage> actualRequests = mockMetricsServiceV2.getRequests();
    Assert.assertEquals(1, actualRequests.size());
    GetLogMetricRequest actualRequest = ((GetLogMetricRequest) actualRequests.get(0));
    Assert.assertEquals(metricName.toString(), actualRequest.getMetricName());
    Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
Also used : AbstractMessage(com.google.protobuf.AbstractMessage) LogMetric(com.google.logging.v2.LogMetric) LogMetricName(com.google.logging.v2.LogMetricName) GetLogMetricRequest(com.google.logging.v2.GetLogMetricRequest) Test(org.junit.Test)

Example 2 with LogMetricName

use of com.google.logging.v2.LogMetricName in project gapic-generator-java by googleapis.

the class MetricsClientTest method updateLogMetricTest.

@Test
public void updateLogMetricTest() throws Exception {
    LogMetric expectedResponse = LogMetric.newBuilder().setName(LogMetricName.of("[PROJECT]", "[METRIC]").toString()).setDescription("description-1724546052").setFilter("filter-1274492040").setMetricDescriptor(MetricDescriptor.newBuilder().build()).setValueExtractor("valueExtractor-1867420749").putAllLabelExtractors(new HashMap<String, String>()).setBucketOptions(Distribution.BucketOptions.newBuilder().build()).setCreateTime(Timestamp.newBuilder().build()).setUpdateTime(Timestamp.newBuilder().build()).build();
    mockMetricsServiceV2.addResponse(expectedResponse);
    LogMetricName metricName = LogMetricName.of("[PROJECT]", "[METRIC]");
    LogMetric metric = LogMetric.newBuilder().build();
    LogMetric actualResponse = client.updateLogMetric(metricName, metric);
    Assert.assertEquals(expectedResponse, actualResponse);
    List<AbstractMessage> actualRequests = mockMetricsServiceV2.getRequests();
    Assert.assertEquals(1, actualRequests.size());
    UpdateLogMetricRequest actualRequest = ((UpdateLogMetricRequest) actualRequests.get(0));
    Assert.assertEquals(metricName.toString(), actualRequest.getMetricName());
    Assert.assertEquals(metric, actualRequest.getMetric());
    Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
Also used : AbstractMessage(com.google.protobuf.AbstractMessage) UpdateLogMetricRequest(com.google.logging.v2.UpdateLogMetricRequest) LogMetric(com.google.logging.v2.LogMetric) LogMetricName(com.google.logging.v2.LogMetricName) Test(org.junit.Test)

Example 3 with LogMetricName

use of com.google.logging.v2.LogMetricName in project gapic-generator-java by googleapis.

the class MetricsClientTest method deleteLogMetricExceptionTest.

@Test
public void deleteLogMetricExceptionTest() throws Exception {
    StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT);
    mockMetricsServiceV2.addException(exception);
    try {
        LogMetricName metricName = LogMetricName.of("[PROJECT]", "[METRIC]");
        client.deleteLogMetric(metricName);
        Assert.fail("No exception raised");
    } catch (InvalidArgumentException e) {
    // Expected exception.
    }
}
Also used : InvalidArgumentException(com.google.api.gax.rpc.InvalidArgumentException) LogMetricName(com.google.logging.v2.LogMetricName) StatusRuntimeException(io.grpc.StatusRuntimeException) Test(org.junit.Test)

Example 4 with LogMetricName

use of com.google.logging.v2.LogMetricName in project gapic-generator-java by googleapis.

the class MetricsClient method deleteLogMetric.

// AUTO-GENERATED DOCUMENTATION AND METHOD.
/**
 * Deletes a logs-based metric.
 *
 * <p>Sample code:
 *
 * <pre>{@code
 * // This snippet has been automatically generated for illustrative purposes only.
 * // It may require modifications to work in your environment.
 * try (MetricsClient metricsClient = MetricsClient.create()) {
 *   LogMetricName metricName = LogMetricName.of("[PROJECT]", "[METRIC]");
 *   metricsClient.deleteLogMetric(metricName);
 * }
 * }</pre>
 *
 * @param metricName Required. The resource name of the metric to delete:
 *     <p>"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);
}
Also used : DeleteLogMetricRequest(com.google.logging.v2.DeleteLogMetricRequest)

Example 5 with LogMetricName

use of com.google.logging.v2.LogMetricName in project gapic-generator-java by googleapis.

the class SyncDeleteLogMetricLogmetricname method syncDeleteLogMetricLogmetricname.

public static void syncDeleteLogMetricLogmetricname() throws Exception {
    // It may require modifications to work in your environment.
    try (MetricsClient metricsClient = MetricsClient.create()) {
        LogMetricName metricName = LogMetricName.of("[PROJECT]", "[METRIC]");
        metricsClient.deleteLogMetric(metricName);
    }
}
Also used : MetricsClient(com.google.cloud.logging.v2.MetricsClient) LogMetricName(com.google.logging.v2.LogMetricName)

Aggregations

LogMetricName (com.google.logging.v2.LogMetricName)15 Test (org.junit.Test)12 LogMetric (com.google.logging.v2.LogMetric)8 InvalidArgumentException (com.google.api.gax.rpc.InvalidArgumentException)6 AbstractMessage (com.google.protobuf.AbstractMessage)6 StatusRuntimeException (io.grpc.StatusRuntimeException)6 DeleteLogMetricRequest (com.google.logging.v2.DeleteLogMetricRequest)4 MetricsClient (com.google.cloud.logging.v2.MetricsClient)3 GetLogMetricRequest (com.google.logging.v2.GetLogMetricRequest)2 UpdateLogMetricRequest (com.google.logging.v2.UpdateLogMetricRequest)2 Empty (com.google.protobuf.Empty)2