Search in sources :

Example 1 with MetricSearchQuery

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

the class TestFrameworkTestRun method testTaskMetric.

private void testTaskMetric(String runId, boolean doesExist) throws Exception {
    List<TagValue> tags = new ArrayList<>();
    tags.add(new TagValue(Constants.Metrics.Tag.NAMESPACE, NamespaceId.DEFAULT.getNamespace()));
    tags.add(new TagValue(Constants.Metrics.Tag.APP, DatasetWithMRApp.class.getSimpleName()));
    tags.add(new TagValue(Constants.Metrics.Tag.MAPREDUCE, DatasetWithMRApp.MAPREDUCE_PROGRAM));
    tags.add(new TagValue(Constants.Metrics.Tag.RUN_ID, runId));
    Collection<String> metricNames = getMetricsManager().searchMetricNames(new MetricSearchQuery(0, Integer.MAX_VALUE, Integer.MAX_VALUE, tags));
    // we disabled task level metrics; this should return empty list
    Assert.assertEquals(doesExist, metricNames.contains("user.test.metric"));
}
Also used : MetricSearchQuery(co.cask.cdap.api.metrics.MetricSearchQuery) ArrayList(java.util.ArrayList) TagValue(co.cask.cdap.api.metrics.TagValue)

Example 2 with MetricSearchQuery

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

the class TestFrameworkTestRun method testTaskTagLevelExists.

private void testTaskTagLevelExists(String appName, String programName, String runId, String datasetName, boolean doesExist) throws Exception {
    List<TagValue> tags = new ArrayList<>();
    tags.add(new TagValue(Constants.Metrics.Tag.NAMESPACE, NamespaceId.DEFAULT.getNamespace()));
    tags.add(new TagValue(Constants.Metrics.Tag.APP, appName));
    tags.add(new TagValue(Constants.Metrics.Tag.MAPREDUCE, programName));
    tags.add(new TagValue(Constants.Metrics.Tag.RUN_ID, runId));
    tags.add(new TagValue(Constants.Metrics.Tag.DATASET, datasetName));
    tags.add(new TagValue(Constants.Metrics.Tag.MR_TASK_TYPE, "m"));
    Collection<TagValue> tagsValues = getMetricsManager().searchTags(new MetricSearchQuery(0, Integer.MAX_VALUE, Integer.MAX_VALUE, tags));
    Assert.assertEquals(doesExist, !tagsValues.isEmpty());
    if (doesExist) {
        Assert.assertEquals(Constants.Metrics.Tag.INSTANCE_ID, tagsValues.iterator().next().getName());
    }
}
Also used : MetricSearchQuery(co.cask.cdap.api.metrics.MetricSearchQuery) ArrayList(java.util.ArrayList) TagValue(co.cask.cdap.api.metrics.TagValue)

Example 3 with MetricSearchQuery

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

the class MetricsQueryHelper method getMetrics.

private Collection<String> getMetrics(List<MetricTagValue> tagValues) throws Exception {
    // we want to search the entire range, so startTimestamp is '0' and end Timestamp is Integer.MAX_VALUE and
    // limit is -1 , to include the entire search result.
    MetricSearchQuery searchQuery = new MetricSearchQuery(0, Integer.MAX_VALUE, -1, toTagValues(tagValues));
    Collection<String> metricNames = metricStore.findMetricNames(searchQuery);
    return Lists.newArrayList(Iterables.filter(metricNames, Predicates.notNull()));
}
Also used : MetricSearchQuery(co.cask.cdap.api.metrics.MetricSearchQuery)

Example 4 with MetricSearchQuery

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

the class WorkflowStatsSLAHttpHandler method getSparkDetails.

private Map<String, Long> getSparkDetails(ProgramId sparkProgram, String runId) throws Exception {
    Map<String, String> context = new HashMap<>();
    context.put(Constants.Metrics.Tag.NAMESPACE, sparkProgram.getNamespace());
    context.put(Constants.Metrics.Tag.APP, sparkProgram.getApplication());
    context.put(Constants.Metrics.Tag.SPARK, sparkProgram.getProgram());
    context.put(Constants.Metrics.Tag.RUN_ID, runId);
    List<TagValue> tags = new ArrayList<>();
    for (Map.Entry<String, String> entry : context.entrySet()) {
        tags.add(new TagValue(entry.getKey(), entry.getValue()));
    }
    MetricSearchQuery metricSearchQuery = new MetricSearchQuery(0, 0, Integer.MAX_VALUE, tags);
    Collection<String> metricNames = metricStore.findMetricNames(metricSearchQuery);
    Map<String, Long> overallResult = new HashMap<>();
    for (String metricName : metricNames) {
        Collection<MetricTimeSeries> resultPerQuery = metricStore.query(new MetricDataQuery(0, 0, Integer.MAX_VALUE, metricName, AggregationFunction.SUM, context, new ArrayList<String>()));
        for (MetricTimeSeries metricTimeSeries : resultPerQuery) {
            overallResult.put(metricTimeSeries.getMetricName(), metricTimeSeries.getTimeValues().get(0).getValue());
        }
    }
    return overallResult;
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) MetricTimeSeries(co.cask.cdap.api.metrics.MetricTimeSeries) MetricSearchQuery(co.cask.cdap.api.metrics.MetricSearchQuery) TagValue(co.cask.cdap.api.metrics.TagValue) MetricDataQuery(co.cask.cdap.api.metrics.MetricDataQuery) HashMap(java.util.HashMap) Map(java.util.Map)

Aggregations

MetricSearchQuery (co.cask.cdap.api.metrics.MetricSearchQuery)4 TagValue (co.cask.cdap.api.metrics.TagValue)3 ArrayList (java.util.ArrayList)3 MetricDataQuery (co.cask.cdap.api.metrics.MetricDataQuery)1 MetricTimeSeries (co.cask.cdap.api.metrics.MetricTimeSeries)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1