use of com.google.api.MonitoredResource 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());
}
use of com.google.api.MonitoredResource in project instrumentation-java by census-instrumentation.
the class StackdriverExportUtils method getDefaultResource.
/* Return a self-configured StackDriver monitored resource. */
static MonitoredResource getDefaultResource() {
MonitoredResource.Builder builder = MonitoredResource.newBuilder();
// collected.
if (MetadataConfig.getProjectId() != null) {
builder.putLabels(STACKDRIVER_PROJECT_ID_KEY, MetadataConfig.getProjectId());
}
Resource autoDetectedResource = ResourceUtils.detectResource();
if (autoDetectedResource == null || autoDetectedResource.getType() == null) {
builder.setType(GLOBAL);
return builder.build();
}
setResourceForBuilder(builder, autoDetectedResource);
return builder.build();
}
Aggregations