use of com.google.api.MetricDescriptor in project google-cloud-java by GoogleCloudPlatform.
the class MetricServiceClientTest method listMetricDescriptorsTest.
@Test
@SuppressWarnings("all")
public void listMetricDescriptorsTest() {
String nextPageToken = "";
MetricDescriptor metricDescriptorsElement = MetricDescriptor.newBuilder().build();
List<MetricDescriptor> metricDescriptors = Arrays.asList(metricDescriptorsElement);
ListMetricDescriptorsResponse expectedResponse = ListMetricDescriptorsResponse.newBuilder().setNextPageToken(nextPageToken).addAllMetricDescriptors(metricDescriptors).build();
mockMetricService.addResponse(expectedResponse);
ProjectName name = ProjectName.create("[PROJECT]");
ListMetricDescriptorsPagedResponse pagedListResponse = client.listMetricDescriptors(name);
List<MetricDescriptor> resources = Lists.newArrayList(pagedListResponse.iterateAll());
Assert.assertEquals(1, resources.size());
Assert.assertEquals(expectedResponse.getMetricDescriptorsList().get(0), resources.get(0));
List<GeneratedMessageV3> actualRequests = mockMetricService.getRequests();
Assert.assertEquals(1, actualRequests.size());
ListMetricDescriptorsRequest actualRequest = (ListMetricDescriptorsRequest) actualRequests.get(0);
Assert.assertEquals(name, actualRequest.getNameAsProjectName());
}
use of com.google.api.MetricDescriptor in project google-cloud-java by GoogleCloudPlatform.
the class MetricServiceClientTest method createMetricDescriptorExceptionTest.
@Test
@SuppressWarnings("all")
public void createMetricDescriptorExceptionTest() throws Exception {
StatusRuntimeException exception = new StatusRuntimeException(Status.INVALID_ARGUMENT);
mockMetricService.addException(exception);
try {
ProjectName name = ProjectName.create("[PROJECT]");
MetricDescriptor metricDescriptor = MetricDescriptor.newBuilder().build();
client.createMetricDescriptor(name, metricDescriptor);
Assert.fail("No exception raised");
} catch (ApiException e) {
Assert.assertEquals(Status.INVALID_ARGUMENT.getCode(), e.getStatusCode());
}
}
use of com.google.api.MetricDescriptor in project google-cloud-java by GoogleCloudPlatform.
the class MetricServiceClientTest method createMetricDescriptorTest.
@Test
@SuppressWarnings("all")
public void createMetricDescriptorTest() {
String name2 = "name2-1052831874";
String type = "type3575610";
String unit = "unit3594628";
String description = "description-1724546052";
String displayName = "displayName1615086568";
MetricDescriptor expectedResponse = MetricDescriptor.newBuilder().setName(name2).setType(type).setUnit(unit).setDescription(description).setDisplayName(displayName).build();
mockMetricService.addResponse(expectedResponse);
ProjectName name = ProjectName.create("[PROJECT]");
MetricDescriptor metricDescriptor = MetricDescriptor.newBuilder().build();
MetricDescriptor actualResponse = client.createMetricDescriptor(name, metricDescriptor);
Assert.assertEquals(expectedResponse, actualResponse);
List<GeneratedMessageV3> actualRequests = mockMetricService.getRequests();
Assert.assertEquals(1, actualRequests.size());
CreateMetricDescriptorRequest actualRequest = (CreateMetricDescriptorRequest) actualRequests.get(0);
Assert.assertEquals(name, actualRequest.getNameAsProjectName());
Assert.assertEquals(metricDescriptor, actualRequest.getMetricDescriptor());
}
use of com.google.api.MetricDescriptor in project java-docs-samples by GoogleCloudPlatform.
the class Snippets method createMetricDescriptor.
/**
* Creates a metric descriptor.
* <p>
* See: https://cloud.google.com/monitoring/api/ref_v3/rest/v3/projects.metricDescriptors/create
*
* @param type The metric type
*/
void createMetricDescriptor(String type) throws IOException {
// [START monitoring_create_metric]
// Your Google Cloud Platform project ID
String projectId = System.getProperty("projectId");
String metricType = CUSTOM_METRIC_DOMAIN + "/" + type;
final MetricServiceClient client = MetricServiceClient.create();
ProjectName name = ProjectName.of(projectId);
MetricDescriptor descriptor = MetricDescriptor.newBuilder().setType(metricType).setDescription("This is a simple example of a custom metric.").setMetricKind(MetricDescriptor.MetricKind.GAUGE).setValueType(MetricDescriptor.ValueType.DOUBLE).build();
CreateMetricDescriptorRequest request = CreateMetricDescriptorRequest.newBuilder().setName(name.toString()).setMetricDescriptor(descriptor).build();
client.createMetricDescriptor(request);
// [END monitoring_create_metric]
}
use of com.google.api.MetricDescriptor in project instrumentation-java by census-instrumentation.
the class StackdriverExportUtilsTest method createMetricDescriptor_cumulative.
@Test
public void createMetricDescriptor_cumulative() {
MetricDescriptor metricDescriptor = StackdriverExportUtils.createMetricDescriptor(METRIC_DESCRIPTOR_2, PROJECT_ID, CUSTOM_OPENCENSUS_DOMAIN, DEFAULT_DISPLAY_NAME_PREFIX, DEFAULT_CONSTANT_LABELS);
assertThat(metricDescriptor.getName()).isEqualTo("projects/" + PROJECT_ID + "/metricDescriptors/custom.googleapis.com/opencensus/" + METRIC_NAME);
assertThat(metricDescriptor.getDescription()).isEqualTo(METRIC_DESCRIPTION);
assertThat(metricDescriptor.getDisplayName()).isEqualTo("OpenCensus/" + METRIC_NAME);
assertThat(metricDescriptor.getType()).isEqualTo("custom.googleapis.com/opencensus/" + METRIC_NAME);
assertThat(metricDescriptor.getUnit()).isEqualTo("1");
assertThat(metricDescriptor.getMetricKind()).isEqualTo(MetricKind.CUMULATIVE);
assertThat(metricDescriptor.getValueType()).isEqualTo(MetricDescriptor.ValueType.INT64);
assertThat(metricDescriptor.getLabelsList()).containsExactly(LabelDescriptor.newBuilder().setKey(StackdriverExportUtils.OPENCENSUS_TASK_KEY.getKey()).setDescription(StackdriverExportUtils.OPENCENSUS_TASK_KEY.getDescription()).setValueType(ValueType.STRING).build());
}
Aggregations