use of com.google.api.ads.admanager.axis.v202205.TimeSeries in project java-monitoring by googleapis.
the class MetricServiceClientTest method listTimeSeriesTest.
@Test
public void listTimeSeriesTest() throws Exception {
TimeSeries responsesElement = TimeSeries.newBuilder().build();
ListTimeSeriesResponse expectedResponse = ListTimeSeriesResponse.newBuilder().setNextPageToken("").addAllTimeSeries(Arrays.asList(responsesElement)).build();
mockMetricService.addResponse(expectedResponse);
FolderName name = FolderName.of("[FOLDER]");
String filter = "filter-1274492040";
TimeInterval interval = TimeInterval.newBuilder().build();
ListTimeSeriesRequest.TimeSeriesView view = ListTimeSeriesRequest.TimeSeriesView.forNumber(0);
ListTimeSeriesPagedResponse pagedListResponse = client.listTimeSeries(name, filter, interval, view);
List<TimeSeries> resources = Lists.newArrayList(pagedListResponse.iterateAll());
Assert.assertEquals(1, resources.size());
Assert.assertEquals(expectedResponse.getTimeSeriesList().get(0), resources.get(0));
List<AbstractMessage> actualRequests = mockMetricService.getRequests();
Assert.assertEquals(1, actualRequests.size());
ListTimeSeriesRequest actualRequest = ((ListTimeSeriesRequest) actualRequests.get(0));
Assert.assertEquals(name.toString(), actualRequest.getName());
Assert.assertEquals(filter, actualRequest.getFilter());
Assert.assertEquals(interval, actualRequest.getInterval());
Assert.assertEquals(view, actualRequest.getView());
Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
use of com.google.api.ads.admanager.axis.v202205.TimeSeries in project java-monitoring by googleapis.
the class QuickstartSample method quickstart.
public static void quickstart(String projectId) throws IOException {
// once, and can be reused for multiple requests.
try (MetricServiceClient metricServiceClient = MetricServiceClient.create()) {
// Prepares an individual data point
TimeInterval interval = TimeInterval.newBuilder().setEndTime(Timestamps.fromMillis(System.currentTimeMillis())).build();
TypedValue value = TypedValue.newBuilder().setDoubleValue(123.45).build();
Point point = Point.newBuilder().setInterval(interval).setValue(value).build();
List<Point> pointList = new ArrayList<>();
pointList.add(point);
ProjectName name = ProjectName.of(projectId);
// Prepares the metric descriptor
Map<String, String> metricLabels = new HashMap<String, String>();
metricLabels.put("store_id", "Pittsburg");
Metric metric = Metric.newBuilder().setType("custom.googleapis.com/stores/daily_sales").putAllLabels(metricLabels).build();
// Prepares the monitored resource descriptor
Map<String, String> resourceLabels = new HashMap<String, String>();
resourceLabels.put("project_id", projectId);
MonitoredResource resource = MonitoredResource.newBuilder().setType("global").putAllLabels(resourceLabels).build();
// Prepares the time series request
TimeSeries timeSeries = TimeSeries.newBuilder().setMetric(metric).setResource(resource).addAllPoints(pointList).build();
List<TimeSeries> timeSeriesList = new ArrayList<>();
timeSeriesList.add(timeSeries);
CreateTimeSeriesRequest request = CreateTimeSeriesRequest.newBuilder().setName(name.toString()).addAllTimeSeries(timeSeriesList).build();
// Writes time series data
metricServiceClient.createTimeSeries(request);
System.out.printf("Done writing time series data.%n");
}
}
use of com.google.api.ads.admanager.axis.v202205.TimeSeries in project instrumentation-java by census-instrumentation.
the class StackdriverExportUtilsTest method createTimeSeriesList_Distribution.
@Test
public void createTimeSeriesList_Distribution() {
List<TimeSeries> timeSeriesList = StackdriverExportUtils.createTimeSeriesList(DISTRIBUTION_METRIC, DEFAULT_RESOURCE, CUSTOM_OPENCENSUS_DOMAIN, PROJECT_ID, DEFAULT_CONSTANT_LABELS);
assertThat(timeSeriesList.size()).isEqualTo(1);
TimeSeries timeSeries = timeSeriesList.get(0);
assertThat(timeSeries.getPointsCount()).isEqualTo(1);
String expectedSpanName = "projects/id/traces/00000000000000000000000000000000/spans/0000000000000000";
assertThat(timeSeries.getPoints(0).getValue().getDistributionValue()).isEqualTo(com.google.api.Distribution.newBuilder().setCount(3).setMean(0.6666666666666666).setBucketOptions(BucketOptions.newBuilder().setExplicitBuckets(Explicit.newBuilder().addAllBounds(Arrays.asList(0.0, 1.0, 3.0, 5.0)).build()).build()).addAllBucketCounts(Arrays.asList(0L, 3L, 1L, 2L, 4L)).setSumOfSquaredDeviation(14).addAllExemplars(Arrays.<Distribution.Exemplar>asList(Distribution.Exemplar.newBuilder().setValue(1.2).setTimestamp(StackdriverExportUtils.convertTimestamp(TIMESTAMP_2)).addAttachments(Any.newBuilder().setTypeUrl(StackdriverExportUtils.EXEMPLAR_ATTACHMENT_TYPE_STRING).setValue(ByteString.copyFromUtf8("value")).build()).build(), Distribution.Exemplar.newBuilder().setValue(5.6).setTimestamp(StackdriverExportUtils.convertTimestamp(TIMESTAMP_3)).addAttachments(Any.newBuilder().setTypeUrl(StackdriverExportUtils.EXEMPLAR_ATTACHMENT_TYPE_SPAN_CONTEXT).setValue(SpanContext.newBuilder().setSpanName(expectedSpanName).build().toByteString()).build()).build())).build());
}
use of com.google.api.ads.admanager.axis.v202205.TimeSeries in project instrumentation-java by census-instrumentation.
the class StackdriverExportUtilsTest method createTimeSeriesList_Gauge.
@Test
public void createTimeSeriesList_Gauge() {
io.opencensus.metrics.export.Metric metric = io.opencensus.metrics.export.Metric.create(GAUGE_METRIC_DESCRIPTOR, Arrays.asList(GAUGE_TIME_SERIES, GAUGE_TIME_SERIES_2));
List<TimeSeries> timeSeriesList = StackdriverExportUtils.createTimeSeriesList(metric, DEFAULT_RESOURCE, CUSTOM_OPENCENSUS_DOMAIN, PROJECT_ID, DEFAULT_CONSTANT_LABELS);
assertThat(timeSeriesList).hasSize(2);
TimeSeries expected1 = TimeSeries.newBuilder().setMetricKind(MetricKind.GAUGE).setValueType(MetricDescriptor.ValueType.DOUBLE).setMetric(StackdriverExportUtils.createMetric(GAUGE_METRIC_DESCRIPTOR, LABEL_VALUE, CUSTOM_OPENCENSUS_DOMAIN, DEFAULT_CONSTANT_LABELS)).setResource(MonitoredResource.newBuilder().setType("global")).addPoints(StackdriverExportUtils.createPoint(POINT, null)).build();
TimeSeries expected2 = TimeSeries.newBuilder().setMetricKind(MetricKind.GAUGE).setValueType(MetricDescriptor.ValueType.DOUBLE).setMetric(StackdriverExportUtils.createMetric(GAUGE_METRIC_DESCRIPTOR, LABEL_VALUE_2, CUSTOM_OPENCENSUS_DOMAIN, DEFAULT_CONSTANT_LABELS)).setResource(MonitoredResource.newBuilder().setType("global")).addPoints(StackdriverExportUtils.createPoint(POINT_2, null)).build();
assertThat(timeSeriesList).containsExactly(expected1, expected2);
}
use of com.google.api.ads.admanager.axis.v202205.TimeSeries in project google-cloud-java by GoogleCloudPlatform.
the class MetricServiceClientTest method createTimeSeriesTest.
@Test
@SuppressWarnings("all")
public void createTimeSeriesTest() {
Empty expectedResponse = Empty.newBuilder().build();
mockMetricService.addResponse(expectedResponse);
ProjectName name = ProjectName.create("[PROJECT]");
List<TimeSeries> timeSeries = new ArrayList<>();
client.createTimeSeries(name, timeSeries);
List<GeneratedMessageV3> actualRequests = mockMetricService.getRequests();
Assert.assertEquals(1, actualRequests.size());
CreateTimeSeriesRequest actualRequest = (CreateTimeSeriesRequest) actualRequests.get(0);
Assert.assertEquals(name, actualRequest.getNameAsProjectName());
Assert.assertEquals(timeSeries, actualRequest.getTimeSeriesList());
}
Aggregations