Search in sources :

Example 1 with TimeSeries

use of com.google.bigtable.repackaged.com.google.monitoring.v3.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());
}
Also used : Empty(com.google.protobuf.Empty) TimeSeries(com.google.monitoring.v3.TimeSeries) ProjectName(com.google.monitoring.v3.ProjectName) CreateTimeSeriesRequest(com.google.monitoring.v3.CreateTimeSeriesRequest) ArrayList(java.util.ArrayList) GeneratedMessageV3(com.google.protobuf.GeneratedMessageV3) Test(org.junit.Test)

Example 2 with TimeSeries

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

Example 3 with TimeSeries

use of com.google.bigtable.repackaged.com.google.monitoring.v3.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());
}
Also used : TimeSeries(com.google.monitoring.v3.TimeSeries) Distribution(com.google.api.Distribution) AttachmentValueString(io.opencensus.metrics.data.AttachmentValue.AttachmentValueString) ByteString(com.google.protobuf.ByteString) Test(org.junit.Test)

Example 4 with TimeSeries

use of com.google.bigtable.repackaged.com.google.monitoring.v3.TimeSeries in project spf4j by zolyfarkas.

the class TSDBTailerTest method main.

public static void main(final String[] parameters) throws IOException {
    final MutableHolder<Integer> counter = new MutableHolder<>(0);
    TimeSeriesDatabase tsdb = new TimeSeriesDatabase(new File(parameters[0]));
    tsdb.tail(10, 0, new TSDataHandler() {

        private int count = 0;

        @Override
        public void newTable(final String tableName, final String[] columnNames) {
            LOG.info("New Table: {} columns: {}", tableName, columnNames);
        }

        @Override
        public void newData(final String tableName, final TimeSeries data) {
            LOG.debug("Table {} - {}", tableName, data);
            counter.setValue(counter.getValue() + data.getTimeStamps().length);
        }

        @Override
        public boolean finish() {
            return count++ > 400;
        }
    });
    System.exit(counter.getValue());
}
Also used : MutableHolder(org.spf4j.base.MutableHolder) TimeSeries(org.spf4j.tsdb2.TimeSeries) File(java.io.File)

Example 5 with TimeSeries

use of com.google.bigtable.repackaged.com.google.monitoring.v3.TimeSeries in project spf4j by zolyfarkas.

the class TimeSeriesDatabaseTest method testWriteTSDB.

/**
 * Test of close method, of class TimeSeriesDatabase.
 */
@Test
public void testWriteTSDB() throws Exception {
    if (new File(FILE_NAME).delete()) {
        LOG.debug("existing tsdb {} file deleted", FILE_NAME);
    }
    try (TimeSeriesDatabase instance = new TimeSeriesDatabase(new File(FILE_NAME), new byte[] {})) {
        instance.addTSTable("gr1", new byte[] {}, 5, new String[] { "a", "b" }, new byte[][] {});
        instance.write(System.currentTimeMillis(), "gr1", new long[] { 0, 1 });
        Thread.sleep(5);
        instance.write(System.currentTimeMillis(), "gr1", new long[] { 1, 2 });
        Thread.sleep(5);
        instance.write(System.currentTimeMillis(), "gr1", new long[] { 3, 4 });
        Thread.sleep(5);
        instance.addTSTable("gr2", new byte[] {}, 5, new String[] { "a", "b" }, new byte[][] {});
        instance.write(System.currentTimeMillis(), "gr2", new long[] { 7, 8 });
        instance.flush();
        instance.addTSTable("gr3", new byte[] {}, 5, new String[] { "a", "b" }, new byte[][] {});
        instance.write(System.currentTimeMillis(), "gr3", new long[] { 7, 8 });
        Thread.sleep(5);
        instance.write(System.currentTimeMillis(), "gr3", new long[] { 9, 10 });
        instance.flush();
        LOG.debug("TSTables = {}", instance.getTSTables());
        TimeSeries readAll = instance.readAll("gr1");
        Assert.assertEquals(2, readAll.getValues()[1][1]);
        LOG.debug("TimeSeries = {}", readAll);
        readAll = instance.readAll("gr2");
        Assert.assertEquals(7, readAll.getValues()[0][0]);
        LOG.debug("TimeSeries = {}", readAll);
        readAll = instance.readAll("gr3");
        Assert.assertEquals(10, readAll.getValues()[1][1]);
        LOG.debug("TimeSeries = {}", readAll);
    }
    TimeSeriesDatabase instanceRead = new TimeSeriesDatabase(new File(FILE_NAME), null);
    Collection<TSTable> tsTables = instanceRead.getTSTables();
    LOG.debug("Tables = {}", tsTables);
    Assert.assertEquals(3, tsTables.size());
    instanceRead.writeCsvTable("gr1", File.createTempFile("test", ".csv"));
    instanceRead.writeCsvTables(Arrays.asList("gr1", "gr2", "gr3"), File.createTempFile("testAll", ".csv"));
}
Also used : TimeSeries(org.spf4j.tsdb2.TimeSeries) File(java.io.File) Test(org.junit.Test)

Aggregations

TimeSeries (com.google.monitoring.v3.TimeSeries)36 Test (org.junit.Test)23 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 TypedValue (com.google.monitoring.v3.TypedValue)3