@VisibleForTesting static LabelDescriptor createLabelDescriptor(LabelKey labelKey) { LabelDescriptor.Builder builder = LabelDescriptor.newBuilder(); builder.setKey(labelKey.getKey()); builder.setDescription(labelKey.getDescription()); // Now we only support String tags builder.setValueType(ValueType.STRING); return builder.build(); }
@Test public void createMetricDescriptor_cumulative() { MetricDescriptor metricDescriptor = StackdriverExportUtils.createMetricDescriptor( METRIC_DESCRIPTOR_2, PROJECT_ID, CUSTOM_OPENCENSUS_DOMAIN, DEFAULT_DISPLAY_NAME_PREFIX); 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) .setDescription(StackdriverExportUtils.OPENCENSUS_TASK_DESCRIPTION) .setValueType(ValueType.STRING) .build()); }
@Test public void createMetricDescriptor() { MetricDescriptor metricDescriptor = StackdriverExportUtils.createMetricDescriptor( METRIC_DESCRIPTOR, PROJECT_ID, "custom.googleapis.com/myorg/", "myorg/"); assertThat(metricDescriptor.getName()) .isEqualTo( "projects/" + PROJECT_ID + "/metricDescriptors/custom.googleapis.com/myorg/" + METRIC_NAME); assertThat(metricDescriptor.getDescription()).isEqualTo(METRIC_DESCRIPTION); assertThat(metricDescriptor.getDisplayName()).isEqualTo("myorg/" + METRIC_NAME); assertThat(metricDescriptor.getType()).isEqualTo("custom.googleapis.com/myorg/" + METRIC_NAME); assertThat(metricDescriptor.getUnit()).isEqualTo(METRIC_UNIT); assertThat(metricDescriptor.getMetricKind()).isEqualTo(MetricKind.CUMULATIVE); assertThat(metricDescriptor.getValueType()).isEqualTo(MetricDescriptor.ValueType.DOUBLE); assertThat(metricDescriptor.getLabelsList()) .containsExactly( LabelDescriptor.newBuilder() .setKey(LABEL_KEY.get(0).getKey()) .setDescription(LABEL_KEY.get(0).getDescription()) .setValueType(ValueType.STRING) .build(), LabelDescriptor.newBuilder() .setKey(StackdriverExportUtils.OPENCENSUS_TASK) .setDescription(StackdriverExportUtils.OPENCENSUS_TASK_DESCRIPTION) .setValueType(ValueType.STRING) .build()); }
static MetricDescriptor createMetricDescriptor( io.opencensus.metrics.export.MetricDescriptor metricDescriptor, String projectId, String domain, String displayNamePrefix) { MetricDescriptor.Builder builder = MetricDescriptor.newBuilder(); String type = generateType(metricDescriptor.getName(), domain); // Name format refers to // cloud.google.com/monitoring/api/ref_v3/rest/v3/projects.metricDescriptors/create builder.setName("projects/" + projectId + "/metricDescriptors/" + type); builder.setType(type); builder.setDescription(metricDescriptor.getDescription()); builder.setDisplayName(createDisplayName(metricDescriptor.getName(), displayNamePrefix)); for (LabelKey labelKey : metricDescriptor.getLabelKeys()) { builder.addLabels(createLabelDescriptor(labelKey)); } builder.addLabels( LabelDescriptor.newBuilder() .setKey(OPENCENSUS_TASK) .setDescription(OPENCENSUS_TASK_DESCRIPTION) .setValueType(ValueType.STRING) .build()); builder.setUnit(metricDescriptor.getUnit()); builder.setMetricKind(createMetricKind(metricDescriptor.getType())); builder.setValueType(createValueType(metricDescriptor.getType())); return builder.build(); }
com.google.api.LabelDescriptor toPb() { com.google.api.LabelDescriptor.Builder builder = com.google.api.LabelDescriptor.newBuilder().setKey(key).setValueType(valueType.toPb()); if (description != null) { builder.setDescription(description); } return builder.build(); }
com.google.api.LabelDescriptor toPb() { com.google.api.LabelDescriptor.Builder builder = com.google.api.LabelDescriptor.newBuilder() .setKey(key) .setValueType(valueType.toPb()); if (description != null) { builder.setDescription(description); } return builder.build(); }
@Test public void createLabelDescriptor() { assertThat(StackdriverExportUtils.createLabelDescriptor(LabelKey.create("key", "desc"))) .isEqualTo( LabelDescriptor.newBuilder() .setKey("key") .setDescription("desc") .setValueType(ValueType.STRING) .build()); }
com.google.api.LabelDescriptor toPb() { com.google.api.LabelDescriptor.Builder builder = com.google.api.LabelDescriptor.newBuilder().setKey(key).setValueType(valueType.toPb()); if (description != null) { builder.setDescription(description); } return builder.build(); }