use of com.google.api.ads.admanager.axis.v202111.TimeSeries 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.ads.admanager.axis.v202111.TimeSeries in project instrumentation-java by census-instrumentation.
the class CreateTimeSeriesExporter method export.
@Override
public void export(Collection<Metric> metrics) {
List<TimeSeries> timeSeriesList = new ArrayList<>(metrics.size());
for (Metric metric : metrics) {
timeSeriesList.addAll(StackdriverExportUtils.createTimeSeriesList(metric, monitoredResource, domain, projectName.getProject(), constantLabels));
}
Span span = tracer.getCurrentSpan();
for (List<TimeSeries> batchedTimeSeries : Lists.partition(timeSeriesList, MAX_BATCH_EXPORT_SIZE)) {
span.addAnnotation("Export Stackdriver TimeSeries.");
try {
CreateTimeSeriesRequest request = CreateTimeSeriesRequest.newBuilder().setName(projectName.toString()).addAllTimeSeries(batchedTimeSeries).build();
metricServiceClient.createTimeSeries(request);
span.addAnnotation("Finish exporting TimeSeries.");
} catch (ApiException e) {
logger.log(Level.WARNING, "ApiException thrown when exporting TimeSeries.", e);
span.setStatus(Status.CanonicalCode.valueOf(e.getStatusCode().getCode().name()).toStatus().withDescription("ApiException thrown when exporting TimeSeries: " + StackdriverExportUtils.exceptionMessage(e)));
} catch (Throwable e) {
logger.log(Level.WARNING, "Exception thrown when exporting TimeSeries.", e);
span.setStatus(Status.UNKNOWN.withDescription("Exception thrown when exporting TimeSeries: " + StackdriverExportUtils.exceptionMessage(e)));
}
}
}
Aggregations