Search in sources :

Example 16 with TimeSeries

use of com.google.api.ads.admanager.axis.v202111.TimeSeries in project spring-cloud-gcp by GoogleCloudPlatform.

the class HealthTrackerImplTests method noMessagesOverThresholdNoProcessing.

@Test
public void noMessagesOverThresholdNoProcessing() throws InterruptedException {
    LockSupport.parkNanos(1001 * 1000000);
    ListTimeSeriesPagedResponse listTimeSeriesPagedResponse = mock(ListTimeSeriesPagedResponse.class);
    TimeSeries timeSeries = TimeSeries.newBuilder().addPoints(Point.newBuilder().setValue(TypedValue.newBuilder().setInt64Value(100).build()).build()).build();
    ListTimeSeriesResponse timeSeriesResponse = ListTimeSeriesResponse.newBuilder().addTimeSeries(timeSeries).build();
    ListTimeSeriesPage listTimeSeriesPage = mock(ListTimeSeriesPage.class);
    when(listTimeSeriesPagedResponse.getPage()).thenReturn(listTimeSeriesPage);
    when(listTimeSeriesPage.getResponse()).thenReturn(timeSeriesResponse);
    doReturn(listTimeSeriesPagedResponse).when(metricServiceClient).listTimeSeries(any(ProjectName.class), anyString(), any(), any());
    long messagesOverThreshold = healthTracker.messagesOverThreshold();
    assertThat(messagesOverThreshold).isNegative();
}
Also used : TimeSeries(com.google.monitoring.v3.TimeSeries) ProjectName(com.google.monitoring.v3.ProjectName) ListTimeSeriesPage(com.google.cloud.monitoring.v3.MetricServiceClient.ListTimeSeriesPage) ListTimeSeriesResponse(com.google.monitoring.v3.ListTimeSeriesResponse) ListTimeSeriesPagedResponse(com.google.cloud.monitoring.v3.MetricServiceClient.ListTimeSeriesPagedResponse) Test(org.junit.Test)

Example 17 with TimeSeries

use of com.google.api.ads.admanager.axis.v202111.TimeSeries in project google-cloud-java by GoogleCloudPlatform.

the class MetricServiceClientTest method listTimeSeriesTest.

@Test
@SuppressWarnings("all")
public void listTimeSeriesTest() {
    String nextPageToken = "";
    TimeSeries timeSeriesElement = TimeSeries.newBuilder().build();
    List<TimeSeries> timeSeries = Arrays.asList(timeSeriesElement);
    ListTimeSeriesResponse expectedResponse = ListTimeSeriesResponse.newBuilder().setNextPageToken(nextPageToken).addAllTimeSeries(timeSeries).build();
    mockMetricService.addResponse(expectedResponse);
    ProjectName name = ProjectName.create("[PROJECT]");
    String filter = "filter-1274492040";
    TimeInterval interval = TimeInterval.newBuilder().build();
    ListTimeSeriesRequest.TimeSeriesView view = ListTimeSeriesRequest.TimeSeriesView.FULL;
    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<GeneratedMessageV3> actualRequests = mockMetricService.getRequests();
    Assert.assertEquals(1, actualRequests.size());
    ListTimeSeriesRequest actualRequest = (ListTimeSeriesRequest) actualRequests.get(0);
    Assert.assertEquals(name, actualRequest.getNameAsProjectName());
    Assert.assertEquals(filter, actualRequest.getFilter());
    Assert.assertEquals(interval, actualRequest.getInterval());
    Assert.assertEquals(view, actualRequest.getView());
}
Also used : TimeSeries(com.google.monitoring.v3.TimeSeries) TimeInterval(com.google.monitoring.v3.TimeInterval) ProjectName(com.google.monitoring.v3.ProjectName) ListTimeSeriesResponse(com.google.monitoring.v3.ListTimeSeriesResponse) TimeSeriesView(com.google.monitoring.v3.ListTimeSeriesRequest.TimeSeriesView) ListTimeSeriesPagedResponse(com.google.cloud.monitoring.spi.v3.PagedResponseWrappers.ListTimeSeriesPagedResponse) GeneratedMessageV3(com.google.protobuf.GeneratedMessageV3) ListTimeSeriesRequest(com.google.monitoring.v3.ListTimeSeriesRequest) Test(org.junit.Test)

Example 18 with TimeSeries

use of com.google.api.ads.admanager.axis.v202111.TimeSeries in project google-cloud-java by GoogleCloudPlatform.

the class MetricServiceClientTest method createTimeSeriesExceptionTest.

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

Example 19 with TimeSeries

use of com.google.api.ads.admanager.axis.v202111.TimeSeries in project instrumentation-java by census-instrumentation.

the class StackdriverExportUtilsTest method createTimeSeriesList_Cumulative.

@Test
public void createTimeSeriesList_Cumulative() {
    List<TimeSeries> timeSeriesList = StackdriverExportUtils.createTimeSeriesList(METRIC, DEFAULT_RESOURCE, CUSTOM_OPENCENSUS_DOMAIN, PROJECT_ID, DEFAULT_CONSTANT_LABELS);
    assertThat(timeSeriesList).hasSize(1);
    TimeSeries expectedTimeSeries = TimeSeries.newBuilder().setMetricKind(MetricKind.CUMULATIVE).setValueType(MetricDescriptor.ValueType.DOUBLE).setMetric(StackdriverExportUtils.createMetric(METRIC_DESCRIPTOR, LABEL_VALUE, CUSTOM_OPENCENSUS_DOMAIN, DEFAULT_CONSTANT_LABELS)).setResource(MonitoredResource.newBuilder().setType("global")).addPoints(StackdriverExportUtils.createPoint(POINT, TIMESTAMP_2)).build();
    assertThat(timeSeriesList).containsExactly(expectedTimeSeries);
}
Also used : TimeSeries(com.google.monitoring.v3.TimeSeries) Test(org.junit.Test)

Example 20 with TimeSeries

use of com.google.api.ads.admanager.axis.v202111.TimeSeries in project instrumentation-java by census-instrumentation.

the class StackdriverExportUtilsTest method createTimeSeriesList_withCustomMonitoredResource.

@Test
public void createTimeSeriesList_withCustomMonitoredResource() {
    MonitoredResource resource = MonitoredResource.newBuilder().setType("global").putLabels("key", "value").build();
    List<TimeSeries> timeSeriesList = StackdriverExportUtils.createTimeSeriesList(METRIC, resource, CUSTOM_OPENCENSUS_DOMAIN, PROJECT_ID, DEFAULT_CONSTANT_LABELS);
    assertThat(timeSeriesList).containsExactly(TimeSeries.newBuilder().setMetricKind(MetricKind.CUMULATIVE).setValueType(MetricDescriptor.ValueType.DOUBLE).setMetric(StackdriverExportUtils.createMetric(METRIC_DESCRIPTOR, LABEL_VALUE, CUSTOM_OPENCENSUS_DOMAIN, DEFAULT_CONSTANT_LABELS)).setResource(resource).addPoints(StackdriverExportUtils.createPoint(POINT, TIMESTAMP_2)).build());
}
Also used : TimeSeries(com.google.monitoring.v3.TimeSeries) MonitoredResource(com.google.api.MonitoredResource) Test(org.junit.Test)

Aggregations

TimeSeries (com.google.monitoring.v3.TimeSeries)22 ProjectName (com.google.monitoring.v3.ProjectName)11 Test (org.junit.Test)11 TimeSeries (org.spf4j.tsdb2.TimeSeries)11 TimeInterval (com.google.monitoring.v3.TimeInterval)8 ArrayList (java.util.ArrayList)8 ListTimeSeriesPagedResponse (com.google.cloud.monitoring.v3.MetricServiceClient.ListTimeSeriesPagedResponse)7 MetricServiceClient (com.google.cloud.monitoring.v3.MetricServiceClient)5 ListTimeSeriesRequest (com.google.monitoring.v3.ListTimeSeriesRequest)5 CreateTimeSeriesRequest (com.google.monitoring.v3.CreateTimeSeriesRequest)4 ListTimeSeriesResponse (com.google.monitoring.v3.ListTimeSeriesResponse)4 HashMap (java.util.HashMap)4 MonitoredResource (com.google.api.MonitoredResource)3 Point (com.google.monitoring.v3.Point)3 Metric (com.google.api.Metric)2 TypedValue (com.google.monitoring.v3.TypedValue)2 BufferedWriter (java.io.BufferedWriter)2 File (java.io.File)2 OutputStreamWriter (java.io.OutputStreamWriter)2 Writer (java.io.Writer)2