Search in sources :

Example 26 with MetricsTable

use of io.cdap.cdap.data2.dataset2.lib.table.MetricsTable in project cdap by caskdata.

the class EntityTableTest method testGetId.

@Test
public void testGetId() throws Exception {
    InMemoryTableService.create("testGetId");
    MetricsTable table = new InMemoryMetricsTable("testGetId");
    EntityTable entityTable = new EntityTable(table);
    // Make sure it is created sequentially
    for (int i = 1; i <= 10; i++) {
        Assert.assertEquals((long) i, entityTable.getId("app", "app" + i));
    }
    // It should get the same value (from cache)
    for (int i = 1; i <= 10; i++) {
        Assert.assertEquals((long) i, entityTable.getId("app", "app" + i));
    }
    // Construct another entityTable, it should load from storage.
    entityTable = new EntityTable(table);
    for (int i = 1; i <= 10; i++) {
        Assert.assertEquals((long) i, entityTable.getId("app", "app" + i));
    }
    // ID for different type should have ID starts from 1 again.
    for (int i = 1; i <= 10; i++) {
        Assert.assertEquals((long) i, entityTable.getId("flow", "flow" + i));
    }
}
Also used : InMemoryMetricsTable(co.cask.cdap.data2.dataset2.lib.table.inmemory.InMemoryMetricsTable) MetricsTable(co.cask.cdap.data2.dataset2.lib.table.MetricsTable) InMemoryMetricsTable(co.cask.cdap.data2.dataset2.lib.table.inmemory.InMemoryMetricsTable) Test(org.junit.Test)

Example 27 with MetricsTable

use of io.cdap.cdap.data2.dataset2.lib.table.MetricsTable in project cdap by caskdata.

the class DefaultMetricDatasetFactory method getOrCreateFactTable.

// todo: figure out roll time based on resolution from config? See DefaultMetricsTableFactory for example
@Override
public FactTable getOrCreateFactTable(int resolution) {
    String v3TableName = cConf.get(Constants.Metrics.METRICS_TABLE_PREFIX, Constants.Metrics.DEFAULT_METRIC_V3_TABLE_PREFIX) + ".ts." + resolution;
    int ttl = cConf.getInt(Constants.Metrics.RETENTION_SECONDS + "." + resolution + ".seconds", -1);
    TableProperties.Builder props = TableProperties.builder();
    // don't add TTL for MAX_RESOLUTION table. CDAP-1626
    if (ttl > 0 && resolution != Integer.MAX_VALUE) {
        props.setTTL(ttl);
    }
    // for efficient counters
    props.setReadlessIncrementSupport(true);
    // configuring pre-splits
    props.add(HBaseTableAdmin.PROPERTY_SPLITS, GSON.toJson(FactTable.getSplits(DefaultMetricStore.AGGREGATIONS.size())));
    // Disable auto split
    props.add(HBaseTableAdmin.SPLIT_POLICY, cConf.get(Constants.Metrics.METRICS_TABLE_HBASE_SPLIT_POLICY));
    MetricsTable table = getOrCreateResolutionMetricsTable(v3TableName, props, resolution);
    return new FactTable(table, entityTable.get(), resolution, getRollTime(resolution));
}
Also used : FactTable(co.cask.cdap.data2.dataset2.lib.timeseries.FactTable) CombinedHBaseMetricsTable(co.cask.cdap.data2.dataset2.lib.table.hbase.CombinedHBaseMetricsTable) MetricsTable(co.cask.cdap.data2.dataset2.lib.table.MetricsTable) TableProperties(co.cask.cdap.api.dataset.table.TableProperties)

Example 28 with MetricsTable

use of io.cdap.cdap.data2.dataset2.lib.table.MetricsTable in project cdap by caskdata.

the class DefaultMetricDatasetFactory method getOrCreateMetricsTable.

protected MetricsTable getOrCreateMetricsTable(String tableName, DatasetProperties props) {
    // metrics tables are in the system namespace
    DatasetId metricsDatasetInstanceId = NamespaceId.SYSTEM.dataset(tableName);
    MetricsTable table = null;
    try {
        table = DatasetsUtil.getOrCreateDataset(dsFramework, metricsDatasetInstanceId, MetricsTable.class.getName(), props, null);
    } catch (Exception e) {
        Throwables.propagate(e);
    }
    return table;
}
Also used : CombinedHBaseMetricsTable(co.cask.cdap.data2.dataset2.lib.table.hbase.CombinedHBaseMetricsTable) MetricsTable(co.cask.cdap.data2.dataset2.lib.table.MetricsTable) DatasetManagementException(co.cask.cdap.api.dataset.DatasetManagementException) IOException(java.io.IOException) DatasetId(co.cask.cdap.proto.id.DatasetId)

Example 29 with MetricsTable

use of io.cdap.cdap.data2.dataset2.lib.table.MetricsTable in project cdap by caskdata.

the class CubeModule method register.

@Override
public void register(DatasetDefinitionRegistry registry) {
    DatasetDefinition<Table, ? extends DatasetAdmin> tableDef = registry.get("table");
    DatasetDefinition<MetricsTable, ? extends DatasetAdmin> metricsTableDef = registry.get(MetricsTable.class.getName());
    registry.add(new CubeDatasetDefinition(FULL_NAME, tableDef, metricsTableDef));
    registry.add(new CubeDatasetDefinition(SHORT_NAME, tableDef, metricsTableDef));
}
Also used : Table(co.cask.cdap.api.dataset.table.Table) CubeDatasetDefinition(co.cask.cdap.data2.dataset2.lib.cube.CubeDatasetDefinition)

Example 30 with MetricsTable

use of io.cdap.cdap.data2.dataset2.lib.table.MetricsTable in project cdap by caskdata.

the class HBaseMetricsTableTest method testDataMigration.

@Test
public void testDataMigration() throws Exception {
    MetricsTable v2Table = getTable("V2Table");
    MetricsTable v3Table = getTable("V3Table");
    v2Table.put(ImmutableSortedMap.<byte[], SortedMap<byte[], Long>>orderedBy(Bytes.BYTES_COMPARATOR).put(A, mapOf(A, Bytes.toLong(A), B, Bytes.toLong(B))).put(B, mapOf(A, Bytes.toLong(A), B, Bytes.toLong(B))).put(X, mapOf(A, Bytes.toLong(A), B, Bytes.toLong(B))).build());
    // add just column A value for key X in table v3, so this is an increment, while column B is a gauge.
    v3Table.put(ImmutableSortedMap.<byte[], SortedMap<byte[], Long>>orderedBy(Bytes.BYTES_COMPARATOR).put(X, mapOf(A, Bytes.toLong(A))).build());
    MetricsTableMigration metricsTableMigration = new MetricsTableMigration("V2Table", v2Table, "V3Table", v3Table);
    Assert.assertTrue(isMetricsDataAvailable(v2Table));
    metricsTableMigration.transferData(1);
    Assert.assertEquals(Bytes.toLong(A), Bytes.toLong(v3Table.get(A, A)));
    Assert.assertEquals(Bytes.toLong(B), Bytes.toLong(v3Table.get(A, B)));
    Assert.assertEquals(Bytes.toLong(A), Bytes.toLong(v3Table.get(B, A)));
    Assert.assertEquals(Bytes.toLong(B), Bytes.toLong(v3Table.get(B, B)));
    // this is an increment
    Assert.assertEquals(Bytes.toLong(A) * 2, Bytes.toLong(v3Table.get(X, A)));
    Assert.assertEquals(Bytes.toLong(B), Bytes.toLong(v3Table.get(X, B)));
    Assert.assertFalse(isMetricsDataAvailable(v2Table));
}
Also used : MetricsTable(co.cask.cdap.data2.dataset2.lib.table.MetricsTable) MetricsTableMigration(co.cask.cdap.metrics.process.MetricsTableMigration) MetricsTableTest(co.cask.cdap.data2.dataset2.lib.table.MetricsTableTest) Test(org.junit.Test)

Aggregations

MetricsTable (co.cask.cdap.data2.dataset2.lib.table.MetricsTable)19 Test (org.junit.Test)16 MetricsTable (io.cdap.cdap.data2.dataset2.lib.table.MetricsTable)15 DatasetId (co.cask.cdap.proto.id.DatasetId)6 AbstractModule (com.google.inject.AbstractModule)6 InMemoryMetricsTable (io.cdap.cdap.data2.dataset2.lib.table.inmemory.InMemoryMetricsTable)6 InMemoryMetricsTable (co.cask.cdap.data2.dataset2.lib.table.inmemory.InMemoryMetricsTable)5 MetricsTableTest (co.cask.cdap.data2.dataset2.lib.table.MetricsTableTest)4 CombinedHBaseMetricsTable (co.cask.cdap.data2.dataset2.lib.table.hbase.CombinedHBaseMetricsTable)4 DatasetManagementException (co.cask.cdap.api.dataset.DatasetManagementException)3 DatasetModule (co.cask.cdap.api.dataset.module.DatasetModule)3 Row (co.cask.cdap.api.dataset.table.Row)3 Scanner (co.cask.cdap.api.dataset.table.Scanner)3 Table (co.cask.cdap.api.dataset.table.Table)3 Constants (co.cask.cdap.common.conf.Constants)3 ExternalDatasetModule (co.cask.cdap.data2.dataset2.lib.external.ExternalDatasetModule)3 MetadataDatasetModule (co.cask.cdap.data2.metadata.dataset.MetadataDatasetModule)3 LineageDatasetModule (co.cask.cdap.data2.metadata.lineage.LineageDatasetModule)3 UsageDatasetModule (co.cask.cdap.data2.registry.UsageDatasetModule)3 HBaseQueueDatasetModule (co.cask.cdap.data2.transaction.queue.hbase.HBaseQueueDatasetModule)3