Search in sources :

Example 16 with MetricDescriptor

use of com.google.api.MetricDescriptor in project spring-cloud-gcp by spring-cloud.

the class MetricsSampleApplicationTests method testMetricRecordedInStackdriver.

@Test
public void testMetricRecordedInStackdriver() {
    String projectId = this.projectIdProvider.getProjectId();
    String id = "integration_test_" + UUID.randomUUID().toString().replace('-', '_');
    String url = String.format("http://localhost:%s/%s", this.port, id);
    ResponseEntity<String> responseEntity = this.testRestTemplate.getForEntity(url, String.class, String.class);
    assertThat(responseEntity.getStatusCode().is2xxSuccessful()).isTrue();
    String metricType = "custom.googleapis.com/" + id;
    String metricName = "projects/" + projectId + "/metricDescriptors/" + metricType;
    await().atMost(4, TimeUnit.MINUTES).pollInterval(5, TimeUnit.SECONDS).ignoreExceptionsMatching(e -> e.getMessage().contains("Could not find descriptor for metric")).untilAsserted(() -> {
        MetricDescriptor metricDescriptor = this.metricClient.getMetricDescriptor(metricName);
        assertThat(metricDescriptor.getName()).isEqualTo(metricName);
        assertThat(metricDescriptor.getType()).isEqualTo(metricType);
    });
}
Also used : Awaitility.await(org.awaitility.Awaitility.await) Assume.assumeThat(org.junit.Assume.assumeThat) BeforeClass(org.junit.BeforeClass) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) MetricDescriptor(com.google.api.MetricDescriptor) RunWith(org.junit.runner.RunWith) MetricServiceClient(com.google.cloud.monitoring.v3.MetricServiceClient) Autowired(org.springframework.beans.factory.annotation.Autowired) IOException(java.io.IOException) Test(org.junit.Test) UUID(java.util.UUID) TimeUnit(java.util.concurrent.TimeUnit) LocalServerPort(org.springframework.boot.web.server.LocalServerPort) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) GcpProjectIdProvider(org.springframework.cloud.gcp.core.GcpProjectIdProvider) ResponseEntity(org.springframework.http.ResponseEntity) Matchers.is(org.hamcrest.Matchers.is) SpringRunner(org.springframework.test.context.junit4.SpringRunner) TestRestTemplate(org.springframework.boot.test.web.client.TestRestTemplate) Before(org.junit.Before) MetricDescriptor(com.google.api.MetricDescriptor) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Aggregations

MetricDescriptor (com.google.api.MetricDescriptor)16 Test (org.junit.Test)10 ProjectName (com.google.monitoring.v3.ProjectName)5 MetricServiceClient (com.google.cloud.monitoring.v3.MetricServiceClient)4 CreateMetricDescriptorRequest (com.google.monitoring.v3.CreateMetricDescriptorRequest)4 ListMetricDescriptorsRequest (com.google.monitoring.v3.ListMetricDescriptorsRequest)3 GeneratedMessageV3 (com.google.protobuf.GeneratedMessageV3)3 ListMetricDescriptorsPagedResponse (com.google.cloud.monitoring.v3.MetricServiceClient.ListMetricDescriptorsPagedResponse)2 ListTimeSeriesPagedResponse (com.google.cloud.monitoring.v3.MetricServiceClient.ListTimeSeriesPagedResponse)2 ListTimeSeriesRequest (com.google.monitoring.v3.ListTimeSeriesRequest)2 TimeSeries (com.google.monitoring.v3.TimeSeries)2 LabelKey (io.opencensus.metrics.LabelKey)2 IOException (java.io.IOException)2 UUID (java.util.UUID)2 Metric (com.google.api.Metric)1 ApiException (com.google.api.gax.grpc.ApiException)1 ApiException (com.google.api.gax.rpc.ApiException)1 ServiceOptions (com.google.cloud.ServiceOptions)1 BigQuery (com.google.cloud.bigquery.BigQuery)1 BigQueryOptions (com.google.cloud.bigquery.BigQueryOptions)1