Search in sources :

Example 16 with TimeSeries

use of com.google.bigtable.repackaged.com.google.monitoring.v3.TimeSeries in project spring-cloud-gcp by GoogleCloudPlatform.

the class HealthTrackerImpl method getBackLogMessages.

private Optional<Long> getBackLogMessages(long currentMillis) {
    TimeInterval timeInterval = timeInterval(currentMillis);
    ListTimeSeriesResponse timeSeriesResponse = metricServiceClient.listTimeSeries(ProjectName.of(projectSubscriptionName.getProject()), undeliveredFilter, timeInterval, FULL).getPage().getResponse();
    if (timeSeriesResponse.getTimeSeriesCount() > 0) {
        TimeSeries timeSeries = timeSeriesResponse.getTimeSeries(0);
        if (timeSeries.getPointsCount() > 0) {
            return Optional.of(timeSeries.getPoints(0).getValue().getInt64Value());
        }
    }
    return Optional.empty();
}
Also used : TimeSeries(com.google.monitoring.v3.TimeSeries) TimeInterval(com.google.monitoring.v3.TimeInterval) ListTimeSeriesResponse(com.google.monitoring.v3.ListTimeSeriesResponse)

Example 17 with TimeSeries

use of com.google.bigtable.repackaged.com.google.monitoring.v3.TimeSeries in project java-monitoring by googleapis.

the class MetricServiceClientTest method createServiceTimeSeriesExceptionTest2.

@Test
public void createServiceTimeSeriesExceptionTest2() throws Exception {
    StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT);
    mockMetricService.addException(exception);
    try {
        String name = "name3373707";
        List<TimeSeries> timeSeries = new ArrayList<>();
        client.createServiceTimeSeries(name, timeSeries);
        Assert.fail("No exception raised");
    } catch (InvalidArgumentException e) {
    // Expected exception.
    }
}
Also used : TimeSeries(com.google.monitoring.v3.TimeSeries) InvalidArgumentException(com.google.api.gax.rpc.InvalidArgumentException) StatusRuntimeException(io.grpc.StatusRuntimeException) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 18 with TimeSeries

use of com.google.bigtable.repackaged.com.google.monitoring.v3.TimeSeries in project java-monitoring by googleapis.

the class MetricServiceClientTest method listTimeSeriesTest2.

@Test
public void listTimeSeriesTest2() throws Exception {
    TimeSeries responsesElement = TimeSeries.newBuilder().build();
    ListTimeSeriesResponse expectedResponse = ListTimeSeriesResponse.newBuilder().setNextPageToken("").addAllTimeSeries(Arrays.asList(responsesElement)).build();
    mockMetricService.addResponse(expectedResponse);
    OrganizationName name = OrganizationName.of("[ORGANIZATION]");
    String filter = "filter-1274492040";
    TimeInterval interval = TimeInterval.newBuilder().build();
    ListTimeSeriesRequest.TimeSeriesView view = ListTimeSeriesRequest.TimeSeriesView.forNumber(0);
    ListTimeSeriesPagedResponse pagedListResponse = client.listTimeSeries(name, filter, interval, view);
    List<TimeSeries> resources = Lists.newArrayList(pagedListResponse.iterateAll());
    Assert.assertEquals(1, resources.size());
    Assert.assertEquals(expectedResponse.getTimeSeriesList().get(0), resources.get(0));
    List<AbstractMessage> actualRequests = mockMetricService.getRequests();
    Assert.assertEquals(1, actualRequests.size());
    ListTimeSeriesRequest actualRequest = ((ListTimeSeriesRequest) actualRequests.get(0));
    Assert.assertEquals(name.toString(), actualRequest.getName());
    Assert.assertEquals(filter, actualRequest.getFilter());
    Assert.assertEquals(interval, actualRequest.getInterval());
    Assert.assertEquals(view, actualRequest.getView());
    Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
Also used : OrganizationName(com.google.monitoring.v3.OrganizationName) TimeSeries(com.google.monitoring.v3.TimeSeries) AbstractMessage(com.google.protobuf.AbstractMessage) TimeInterval(com.google.monitoring.v3.TimeInterval) ListTimeSeriesResponse(com.google.monitoring.v3.ListTimeSeriesResponse) ListTimeSeriesPagedResponse(com.google.cloud.monitoring.v3.MetricServiceClient.ListTimeSeriesPagedResponse) ListTimeSeriesRequest(com.google.monitoring.v3.ListTimeSeriesRequest) Test(org.junit.Test)

Example 19 with TimeSeries

use of com.google.bigtable.repackaged.com.google.monitoring.v3.TimeSeries in project java-monitoring by googleapis.

the class MetricServiceClientTest method listTimeSeriesTest4.

@Test
public void listTimeSeriesTest4() throws Exception {
    TimeSeries responsesElement = TimeSeries.newBuilder().build();
    ListTimeSeriesResponse expectedResponse = ListTimeSeriesResponse.newBuilder().setNextPageToken("").addAllTimeSeries(Arrays.asList(responsesElement)).build();
    mockMetricService.addResponse(expectedResponse);
    String name = "name3373707";
    String filter = "filter-1274492040";
    TimeInterval interval = TimeInterval.newBuilder().build();
    ListTimeSeriesRequest.TimeSeriesView view = ListTimeSeriesRequest.TimeSeriesView.forNumber(0);
    ListTimeSeriesPagedResponse pagedListResponse = client.listTimeSeries(name, filter, interval, view);
    List<TimeSeries> resources = Lists.newArrayList(pagedListResponse.iterateAll());
    Assert.assertEquals(1, resources.size());
    Assert.assertEquals(expectedResponse.getTimeSeriesList().get(0), resources.get(0));
    List<AbstractMessage> actualRequests = mockMetricService.getRequests();
    Assert.assertEquals(1, actualRequests.size());
    ListTimeSeriesRequest actualRequest = ((ListTimeSeriesRequest) actualRequests.get(0));
    Assert.assertEquals(name, actualRequest.getName());
    Assert.assertEquals(filter, actualRequest.getFilter());
    Assert.assertEquals(interval, actualRequest.getInterval());
    Assert.assertEquals(view, actualRequest.getView());
    Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
Also used : TimeSeries(com.google.monitoring.v3.TimeSeries) AbstractMessage(com.google.protobuf.AbstractMessage) TimeInterval(com.google.monitoring.v3.TimeInterval) ListTimeSeriesResponse(com.google.monitoring.v3.ListTimeSeriesResponse) ListTimeSeriesPagedResponse(com.google.cloud.monitoring.v3.MetricServiceClient.ListTimeSeriesPagedResponse) ListTimeSeriesRequest(com.google.monitoring.v3.ListTimeSeriesRequest) Test(org.junit.Test)

Example 20 with TimeSeries

use of com.google.bigtable.repackaged.com.google.monitoring.v3.TimeSeries in project java-monitoring by googleapis.

the class MetricServiceClientTest method createTimeSeriesExceptionTest.

@Test
public void createTimeSeriesExceptionTest() throws Exception {
    StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT);
    mockMetricService.addException(exception);
    try {
        ProjectName name = ProjectName.of("[PROJECT]");
        List<TimeSeries> timeSeries = new ArrayList<>();
        client.createTimeSeries(name, timeSeries);
        Assert.fail("No exception raised");
    } catch (InvalidArgumentException e) {
    // Expected exception.
    }
}
Also used : TimeSeries(com.google.monitoring.v3.TimeSeries) InvalidArgumentException(com.google.api.gax.rpc.InvalidArgumentException) ProjectName(com.google.monitoring.v3.ProjectName) StatusRuntimeException(io.grpc.StatusRuntimeException) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Aggregations

TimeSeries (com.google.monitoring.v3.TimeSeries)36 Test (org.junit.Test)23 ArrayList (java.util.ArrayList)18 ProjectName (com.google.monitoring.v3.ProjectName)17 TimeInterval (com.google.monitoring.v3.TimeInterval)14 ListTimeSeriesPagedResponse (com.google.cloud.monitoring.v3.MetricServiceClient.ListTimeSeriesPagedResponse)11 CreateTimeSeriesRequest (com.google.monitoring.v3.CreateTimeSeriesRequest)11 TimeSeries (org.spf4j.tsdb2.TimeSeries)11 ListTimeSeriesRequest (com.google.monitoring.v3.ListTimeSeriesRequest)10 MetricServiceClient (com.google.cloud.monitoring.v3.MetricServiceClient)8 ListTimeSeriesResponse (com.google.monitoring.v3.ListTimeSeriesResponse)8 AbstractMessage (com.google.protobuf.AbstractMessage)8 Point (com.google.monitoring.v3.Point)6 MonitoredResource (com.google.api.MonitoredResource)5 Empty (com.google.protobuf.Empty)5 StatusRuntimeException (io.grpc.StatusRuntimeException)5 HashMap (java.util.HashMap)5 Metric (com.google.api.Metric)4 InvalidArgumentException (com.google.api.gax.rpc.InvalidArgumentException)4 TypedValue (com.google.monitoring.v3.TypedValue)3