Search in sources :

Example 1 with FilterOptions

use of org.apache.storm.metricstore.FilterOptions in project storm by apache.

the class MetricsCleaner method purgeMetrics.

void purgeMetrics() throws MetricException {
    purgeTimestamp = System.currentTimeMillis() - this.retentionHours * 60L * 60L * 1000L;
    LOG.info("Purging metrics before {}", purgeTimestamp);
    FilterOptions filter = new FilterOptions();
    long endTime = purgeTimestamp - 1L;
    filter.setEndTime(endTime);
    store.deleteMetrics(filter);
    LOG.info("Purging metadata before " + purgeTimestamp);
    store.deleteMetadataBefore(purgeTimestamp);
}
Also used : FilterOptions(org.apache.storm.metricstore.FilterOptions)

Example 2 with FilterOptions

use of org.apache.storm.metricstore.FilterOptions in project storm by apache.

the class RocksDbStoreTest method testMetricCleanup.

@Test
public void testMetricCleanup() throws Exception {
    FilterOptions filter;
    List<Metric> list;
    // Share some common metadata strings to validate they do not get deleted
    String commonTopologyId = "topology-cleanup-2";
    String commonStreamId = "stream-cleanup-5";
    String defaultS = "default";
    Metric m1 = new Metric(defaultS, 40000000L, commonTopologyId, 1.0, "component-1", defaultS, "hostname-1", commonStreamId, 1, AggLevel.AGG_LEVEL_NONE);
    Metric m2 = new Metric(defaultS, System.currentTimeMillis(), commonTopologyId, 1.0, "component-1", "executor-1", defaultS, commonStreamId, 1, AggLevel.AGG_LEVEL_NONE);
    store.insert(m1);
    store.insert(m2);
    waitForInsertFinish(m2);
    // validate at least two agg level none metrics exist
    filter = new FilterOptions();
    filter.addAggLevel(AggLevel.AGG_LEVEL_NONE);
    list = getMetricsFromScan(filter);
    Assert.assertTrue(list.size() >= 2);
    // delete anything older than an hour
    MetricsCleaner cleaner = new MetricsCleaner((RocksDbStore) store, 1, 1, null, new StormMetricsRegistry());
    cleaner.purgeMetrics();
    list = getMetricsFromScan(filter);
    Assert.assertEquals(1, list.size());
    Assert.assertTrue(list.contains(m2));
}
Also used : StormMetricsRegistry(org.apache.storm.metric.StormMetricsRegistry) Metric(org.apache.storm.metricstore.Metric) FilterOptions(org.apache.storm.metricstore.FilterOptions) Test(org.junit.Test)

Example 3 with FilterOptions

use of org.apache.storm.metricstore.FilterOptions in project storm by apache.

the class RocksDbStoreTest method testScan.

@Test
public void testScan() throws Exception {
    FilterOptions filter;
    List<Metric> list;
    Metric m1 = new Metric("metricType1", 50000000L, "Topo-m1", 1.0, "component-1", "executor-2", "hostname-1", "stream-1", 1, AggLevel.AGG_LEVEL_NONE);
    Metric m2 = new Metric("metricType2", 50030000L, "Topo-m1", 1.0, "component-1", "executor-1", "hostname-2", "stream-2", 1, AggLevel.AGG_LEVEL_NONE);
    Metric m3 = new Metric("metricType3", 50200000L, "Topo-m1", 1.0, "component-2", "executor-1", "hostname-1", "stream-3", 1, AggLevel.AGG_LEVEL_NONE);
    Metric m4 = new Metric("metricType4", 50200000L, "Topo-m2", 1.0, "component-2", "executor-1", "hostname-2", "stream-4", 2, AggLevel.AGG_LEVEL_NONE);
    store.insert(m1);
    store.insert(m2);
    store.insert(m3);
    store.insert(m4);
    waitForInsertFinish(m4);
    // validate search by time
    filter = new FilterOptions();
    filter.addAggLevel(AggLevel.AGG_LEVEL_NONE);
    filter.setStartTime(50000000L);
    filter.setEndTime(50130000L);
    list = getMetricsFromScan(filter);
    Assert.assertEquals(2, list.size());
    Assert.assertTrue(list.contains(m1));
    Assert.assertTrue(list.contains(m2));
    // validate search by topology id
    filter = new FilterOptions();
    filter.addAggLevel(AggLevel.AGG_LEVEL_NONE);
    filter.setTopologyId("Topo-m2");
    list = getMetricsFromScan(filter);
    Assert.assertEquals(1, list.size());
    Assert.assertTrue(list.contains(m4));
    // validate search by metric id
    filter = new FilterOptions();
    filter.addAggLevel(AggLevel.AGG_LEVEL_NONE);
    filter.setMetricName("metricType2");
    list = getMetricsFromScan(filter);
    Assert.assertEquals(1, list.size());
    Assert.assertTrue(list.contains(m2));
    // validate search by component id
    filter = new FilterOptions();
    filter.addAggLevel(AggLevel.AGG_LEVEL_NONE);
    filter.setComponentId("component-2");
    list = getMetricsFromScan(filter);
    Assert.assertEquals(2, list.size());
    Assert.assertTrue(list.contains(m3));
    Assert.assertTrue(list.contains(m4));
    // validate search by executor id
    filter = new FilterOptions();
    filter.addAggLevel(AggLevel.AGG_LEVEL_NONE);
    filter.setExecutorId("executor-1");
    list = getMetricsFromScan(filter);
    Assert.assertEquals(3, list.size());
    Assert.assertTrue(list.contains(m2));
    Assert.assertTrue(list.contains(m3));
    Assert.assertTrue(list.contains(m4));
    // validate search by executor id
    filter = new FilterOptions();
    filter.addAggLevel(AggLevel.AGG_LEVEL_NONE);
    filter.setExecutorId("executor-1");
    list = getMetricsFromScan(filter);
    Assert.assertEquals(3, list.size());
    Assert.assertTrue(list.contains(m2));
    Assert.assertTrue(list.contains(m3));
    Assert.assertTrue(list.contains(m4));
    // validate search by host id
    filter = new FilterOptions();
    filter.addAggLevel(AggLevel.AGG_LEVEL_NONE);
    filter.setHostId("hostname-2");
    list = getMetricsFromScan(filter);
    Assert.assertEquals(2, list.size());
    Assert.assertTrue(list.contains(m2));
    Assert.assertTrue(list.contains(m4));
    // validate search by port
    filter = new FilterOptions();
    filter.addAggLevel(AggLevel.AGG_LEVEL_NONE);
    filter.setPort(1);
    list = getMetricsFromScan(filter);
    Assert.assertEquals(3, list.size());
    Assert.assertTrue(list.contains(m1));
    Assert.assertTrue(list.contains(m2));
    Assert.assertTrue(list.contains(m3));
    // validate search by stream id
    filter = new FilterOptions();
    filter.addAggLevel(AggLevel.AGG_LEVEL_NONE);
    filter.setStreamId("stream-4");
    list = getMetricsFromScan(filter);
    Assert.assertEquals(1, list.size());
    Assert.assertTrue(list.contains(m4));
    // validate 4 metrics (aggregations) found for m4 for all agglevels when searching by port
    filter = new FilterOptions();
    filter.setPort(2);
    list = getMetricsFromScan(filter);
    Assert.assertEquals(4, list.size());
    Assert.assertTrue(list.contains(m4));
    Assert.assertFalse(list.contains(m1));
    Assert.assertFalse(list.contains(m2));
    Assert.assertFalse(list.contains(m3));
    // validate search by topology id and executor id
    filter = new FilterOptions();
    filter.addAggLevel(AggLevel.AGG_LEVEL_NONE);
    filter.setTopologyId("Topo-m1");
    filter.setExecutorId("executor-1");
    list = getMetricsFromScan(filter);
    Assert.assertEquals(2, list.size());
    Assert.assertTrue(list.contains(m2));
    Assert.assertTrue(list.contains(m3));
}
Also used : Metric(org.apache.storm.metricstore.Metric) FilterOptions(org.apache.storm.metricstore.FilterOptions) Test(org.junit.Test)

Aggregations

FilterOptions (org.apache.storm.metricstore.FilterOptions)3 Metric (org.apache.storm.metricstore.Metric)2 Test (org.junit.Test)2 StormMetricsRegistry (org.apache.storm.metric.StormMetricsRegistry)1