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);
});
}
Aggregations