Search in sources :

Example 11 with MetricDataQuery

use of co.cask.cdap.api.metrics.MetricDataQuery in project cdap by caskdata.

the class MetricQueryParserTest method testMapReduce.

@Test
public void testMapReduce() throws MetricsPathException {
    MetricDataQuery query = MetricQueryParser.parse(URI.create("/system/apps/app1/mapreduce/mapred1/mappers/reads?summary=true"));
    verifyTags(query.getSliceByTags(), Id.Namespace.DEFAULT.getId(), Tag.APP, "app1", Tag.MAPREDUCE, "mapred1", Tag.MR_TASK_TYPE, "m");
    assertMetricName("system.reads", query);
    query = MetricQueryParser.parse(URI.create("/system/apps/app1/mapreduce/mapred1/reducers/reads?summary=true"));
    verifyTags(query.getSliceByTags(), Id.Namespace.DEFAULT.getId(), Tag.APP, "app1", Tag.MAPREDUCE, "mapred1", Tag.MR_TASK_TYPE, "r");
    assertMetricName("system.reads", query);
    query = MetricQueryParser.parse(URI.create("/system/apps/app1/mapreduce/mapred1/reads?summary=true"));
    verifyTags(query.getSliceByTags(), Id.Namespace.DEFAULT.getId(), Tag.APP, "app1", Tag.MAPREDUCE, "mapred1");
    assertMetricName("system.reads", query);
    query = MetricQueryParser.parse(URI.create("/system/apps/app1/mapreduce/mapred1/runs/run123/reads?summary=true"));
    verifyTags(query.getSliceByTags(), Id.Namespace.DEFAULT.getId(), Tag.APP, "app1", Tag.MAPREDUCE, "mapred1");
    assertMetricName("system.reads", query);
    Assert.assertEquals("run123", query.getSliceByTags().get(Tag.RUN_ID));
    query = MetricQueryParser.parse(URI.create("/system/apps/app1/mapreduce/mapred1/runs/run123/mappers/reads?summary=true"));
    verifyTags(query.getSliceByTags(), Id.Namespace.DEFAULT.getId(), Tag.APP, "app1", Tag.MAPREDUCE, "mapred1", Tag.MR_TASK_TYPE, "m");
    assertMetricName("system.reads", query);
    Assert.assertEquals("run123", query.getSliceByTags().get(Tag.RUN_ID));
}
Also used : MetricDataQuery(co.cask.cdap.api.metrics.MetricDataQuery) Test(org.junit.Test)

Example 12 with MetricDataQuery

use of co.cask.cdap.api.metrics.MetricDataQuery in project cdap by caskdata.

the class MetricQueryParserTest method testHandler.

@Test
public void testHandler() throws MetricsPathException {
    MetricDataQuery query = MetricQueryParser.parse(URI.create("/system/services/appfabric/handlers/AppFabricHttpHandler/runs/123/" + "response.server-error?aggregate=true"));
    verifyTags(query.getSliceByTags(), "system", Tag.COMPONENT, "appfabric", Tag.HANDLER, "AppFabricHttpHandler");
    assertMetricName("system.response.server-error", query);
    Assert.assertEquals("123", query.getSliceByTags().get(Tag.RUN_ID));
}
Also used : MetricDataQuery(co.cask.cdap.api.metrics.MetricDataQuery) Test(org.junit.Test)

Example 13 with MetricDataQuery

use of co.cask.cdap.api.metrics.MetricDataQuery in project cdap by caskdata.

the class MetricQueryParserTest method testDataset.

@Test
public void testDataset() throws MetricsPathException {
    MetricDataQuery query = MetricQueryParser.parse(URI.create("/system/datasets/dataset1/apps/app1/flows/flow1/runs/run1/" + "flowlets/flowlet1/store.reads?summary=true"));
    verifyTags(query.getSliceByTags(), Id.Namespace.DEFAULT.getId(), Tag.APP, "app1", Tag.FLOW, "flow1", Tag.FLOWLET, "flowlet1");
    assertMetricName("system.store.reads", query);
    Assert.assertEquals("dataset1", query.getSliceByTags().get(Tag.DATASET));
    Assert.assertEquals("run1", query.getSliceByTags().get(Tag.RUN_ID));
    query = MetricQueryParser.parse(URI.create("/system/datasets/dataset1/apps/app1/flows/flow1/store.reads?summary=true"));
    verifyTags(query.getSliceByTags(), Id.Namespace.DEFAULT.getId(), Tag.APP, "app1", Tag.FLOW, "flow1");
    assertMetricName("system.store.reads", query);
    Assert.assertEquals("dataset1", query.getSliceByTags().get(Tag.DATASET));
    query = MetricQueryParser.parse(URI.create("/system/datasets/dataset1/apps/app1/flows/flow1/runs/123/store.reads?summary=true"));
    verifyTags(query.getSliceByTags(), Id.Namespace.DEFAULT.getId(), Tag.APP, "app1", Tag.FLOW, "flow1");
    assertMetricName("system.store.reads", query);
    Assert.assertEquals("dataset1", query.getSliceByTags().get(Tag.DATASET));
    Assert.assertEquals("123", query.getSliceByTags().get(Tag.RUN_ID));
    query = MetricQueryParser.parse(URI.create("/system/datasets/dataset1/apps/app1/store.reads?summary=true"));
    verifyTags(query.getSliceByTags(), Id.Namespace.DEFAULT.getId(), Tag.APP, "app1");
    assertMetricName("system.store.reads", query);
    Assert.assertEquals("dataset1", query.getSliceByTags().get(Tag.DATASET));
    query = MetricQueryParser.parse(URI.create("/system/datasets/dataset1/store.reads?summary=true"));
    verifyTags(query.getSliceByTags(), Id.Namespace.DEFAULT.getId());
    assertMetricName("system.store.reads", query);
    Assert.assertEquals("dataset1", query.getSliceByTags().get(Tag.DATASET));
}
Also used : MetricDataQuery(co.cask.cdap.api.metrics.MetricDataQuery) Test(org.junit.Test)

Example 14 with MetricDataQuery

use of co.cask.cdap.api.metrics.MetricDataQuery in project cdap by caskdata.

the class MetricStoreRequestExecutor method computeFlowletPending.

private Object computeFlowletPending(MetricDataQuery query) throws Exception {
    // Pending is processed by flowlet minus emitted into the queues it was processing from.
    // trick: get all queues and streams it was processing from using group by
    MetricDataQuery groupByQueueName = new MetricDataQuery(new MetricDataQuery(query, "system.process.events.processed", AggregationFunction.SUM), ImmutableList.of(Constants.Metrics.Tag.FLOWLET_QUEUE));
    Map<String, Long> processedPerQueue = getTotalsWithSingleGroupByTag(groupByQueueName);
    long processedTotal = 0;
    long writtenTotal = 0;
    for (Map.Entry<String, Long> entry : processedPerQueue.entrySet()) {
        String name = entry.getKey();
        // note: each has "input." prefix
        QueueName queueName = QueueName.from(URI.create(name.substring("input.".length(), name.length())));
        long written;
        if (queueName.isQueue()) {
            Map<String, String> sliceByTags = Maps.newHashMap(query.getSliceByTags());
            // we want to aggregate written to the queue by all flowlets
            sliceByTags.remove(Constants.Metrics.Tag.FLOWLET);
            // we want to narrow down to specific queue we know our flowlet was consuming from
            sliceByTags.put(Constants.Metrics.Tag.FLOWLET_QUEUE, queueName.getSimpleName());
            written = getTotals(new MetricDataQuery(new MetricDataQuery(query, sliceByTags), "system.process.events.out", AggregationFunction.SUM));
        } else if (queueName.isStream()) {
            Map<String, String> sliceByTags = Maps.newHashMap();
            // we want to narrow down to specific stream we know our flowlet was consuming from
            sliceByTags.put(Constants.Metrics.Tag.STREAM, queueName.getSimpleName());
            // note: namespace + stream uniquely define the stream
            // we know that flow can consume from stream of the same namespace only at this point
            sliceByTags.put(Constants.Metrics.Tag.NAMESPACE, query.getSliceByTags().get(Constants.Metrics.Tag.NAMESPACE));
            written = getTotals(new MetricDataQuery(new MetricDataQuery(query, sliceByTags), "system.collect.events", AggregationFunction.SUM));
        } else {
            LOG.warn("Unknown queue type: " + name);
            continue;
        }
        processedTotal += entry.getValue();
        writtenTotal += written;
    }
    long pending = writtenTotal - processedTotal;
    return new AggregateResponse(pending > 0 ? pending : 0);
}
Also used : MetricDataQuery(co.cask.cdap.api.metrics.MetricDataQuery) Map(java.util.Map) QueueName(co.cask.cdap.common.queue.QueueName)

Example 15 with MetricDataQuery

use of co.cask.cdap.api.metrics.MetricDataQuery in project cdap by caskdata.

the class TestFrameworkTestRun method verifyMapperJobOutput.

private void verifyMapperJobOutput(Class<?> appClass, DataSetManager<KeyValueTable> outTableManager) throws Exception {
    KeyValueTable outputTable = outTableManager.get();
    Assert.assertEquals("world", Bytes.toString(outputTable.read("hello")));
    // Verify dataset metrics
    String readCountName = "system." + Constants.Metrics.Name.Dataset.READ_COUNT;
    String writeCountName = "system." + Constants.Metrics.Name.Dataset.WRITE_COUNT;
    Collection<MetricTimeSeries> metrics = getMetricsManager().query(new MetricDataQuery(0, System.currentTimeMillis() / 1000, Integer.MAX_VALUE, ImmutableMap.of(readCountName, AggregationFunction.SUM, writeCountName, AggregationFunction.SUM), ImmutableMap.of(Constants.Metrics.Tag.NAMESPACE, DefaultId.NAMESPACE.getNamespace(), Constants.Metrics.Tag.APP, appClass.getSimpleName(), Constants.Metrics.Tag.MAPREDUCE, DatasetWithMRApp.MAPREDUCE_PROGRAM), ImmutableList.<String>of()));
    // Transform the collection of metrics into a map from metrics name to aggregated sum
    Map<String, Long> aggs = Maps.transformEntries(Maps.uniqueIndex(metrics, new Function<MetricTimeSeries, String>() {

        @Override
        public String apply(MetricTimeSeries input) {
            return input.getMetricName();
        }
    }), new Maps.EntryTransformer<String, MetricTimeSeries, Long>() {

        @Override
        public Long transformEntry(String key, MetricTimeSeries value) {
            Preconditions.checkArgument(value.getTimeValues().size() == 1, "Expected one value for aggregated sum for metrics %s", key);
            return value.getTimeValues().get(0).getValue();
        }
    });
    Assert.assertEquals(Long.valueOf(1), aggs.get(readCountName));
    Assert.assertEquals(Long.valueOf(1), aggs.get(writeCountName));
}
Also used : AggregationFunction(co.cask.cdap.api.dataset.lib.cube.AggregationFunction) Function(com.google.common.base.Function) Maps(com.google.common.collect.Maps) KeyValueTable(co.cask.cdap.api.dataset.lib.KeyValueTable) MetricTimeSeries(co.cask.cdap.api.metrics.MetricTimeSeries) MetricDataQuery(co.cask.cdap.api.metrics.MetricDataQuery)

Aggregations

MetricDataQuery (co.cask.cdap.api.metrics.MetricDataQuery)42 Test (org.junit.Test)25 MetricTimeSeries (co.cask.cdap.api.metrics.MetricTimeSeries)21 TimeValue (co.cask.cdap.api.dataset.lib.cube.TimeValue)11 IOException (java.io.IOException)5 ArrayList (java.util.ArrayList)5 Map (java.util.Map)5 KeyValueTable (co.cask.cdap.api.dataset.lib.KeyValueTable)4 ApplicationManager (co.cask.cdap.test.ApplicationManager)4 AggregationFunction (co.cask.cdap.api.dataset.lib.cube.AggregationFunction)3 ImmutableMap (com.google.common.collect.ImmutableMap)3 Collection (java.util.Collection)3 ObjectStore (co.cask.cdap.api.dataset.lib.ObjectStore)2 MetricStore (co.cask.cdap.api.metrics.MetricStore)2 QueueName (co.cask.cdap.common.queue.QueueName)2 DatasetFramework (co.cask.cdap.data2.dataset2.DatasetFramework)2 SparkAppUsingObjectStore (co.cask.cdap.spark.app.SparkAppUsingObjectStore)2 SparkManager (co.cask.cdap.test.SparkManager)2 ListenableFuture (com.google.common.util.concurrent.ListenableFuture)2 LoggerContext (ch.qos.logback.classic.LoggerContext)1