Search in sources :

Example 51 with TimeSeries

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());
}
Also used : TimeSeries(com.google.monitoring.v3.TimeSeries) MonitoredResource(com.google.api.MonitoredResource) Test(org.junit.Test)

Example 52 with TimeSeries

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)));
        }
    }
}
Also used : TimeSeries(com.google.monitoring.v3.TimeSeries) CreateTimeSeriesRequest(com.google.monitoring.v3.CreateTimeSeriesRequest) ArrayList(java.util.ArrayList) Metric(io.opencensus.metrics.export.Metric) Span(io.opencensus.trace.Span) ApiException(com.google.api.gax.rpc.ApiException)

Aggregations

TimeSeries (com.google.monitoring.v3.TimeSeries)36 Test (org.junit.Test)21 ArrayList (java.util.ArrayList)18 ProjectName (com.google.monitoring.v3.ProjectName)17 TimeInterval (com.google.monitoring.v3.TimeInterval)14 ListTimeSeriesPagedResponse (com.google.cloud.monitoring.v3.MetricServiceClient.ListTimeSeriesPagedResponse)11 CreateTimeSeriesRequest (com.google.monitoring.v3.CreateTimeSeriesRequest)11 TimeSeries (org.spf4j.tsdb2.TimeSeries)11 ListTimeSeriesRequest (com.google.monitoring.v3.ListTimeSeriesRequest)10 MetricServiceClient (com.google.cloud.monitoring.v3.MetricServiceClient)8 ListTimeSeriesResponse (com.google.monitoring.v3.ListTimeSeriesResponse)8 AbstractMessage (com.google.protobuf.AbstractMessage)8 Point (com.google.monitoring.v3.Point)6 MonitoredResource (com.google.api.MonitoredResource)5 Empty (com.google.protobuf.Empty)5 StatusRuntimeException (io.grpc.StatusRuntimeException)5 HashMap (java.util.HashMap)5 Metric (com.google.api.Metric)4 InvalidArgumentException (com.google.api.gax.rpc.InvalidArgumentException)4 DateTime (org.joda.time.DateTime)4