use of io.cdap.cdap.api.metrics.MetricTimeSeries in project cdap by cdapio.
the class WorkflowStatsSLAHttpHandler method getSparkDetails.
private Map<String, Long> getSparkDetails(ProgramId sparkProgram, String runId) throws IOException {
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);
Collection<String> metricNames = metricsSystemClient.search(context);
Collection<MetricTimeSeries> queryResult = metricsSystemClient.query(context, metricNames);
Map<String, Long> overallResult = new HashMap<>();
for (MetricTimeSeries timeSeries : queryResult) {
overallResult.put(timeSeries.getMetricName(), timeSeries.getTimeValues().get(0).getValue());
}
return overallResult;
}
use of io.cdap.cdap.api.metrics.MetricTimeSeries in project cdap by cdapio.
the class LocalMRJobInfoFetcher method getAggregates.
private void getAggregates(Map<String, String> tags, Map<String, String> metricsToCounters, Map<String, Long> result) throws IOException {
Collection<MetricTimeSeries> query = metricsSystemClient.query(tags, metricsToCounters.keySet());
// initialize elements to zero
for (String counterName : metricsToCounters.values()) {
result.put(counterName, 0L);
}
for (MetricTimeSeries metricTimeSeries : query) {
List<TimeValue> timeValues = metricTimeSeries.getTimeValues();
TimeValue timeValue = Iterables.getOnlyElement(timeValues);
result.put(metricsToCounters.get(metricTimeSeries.getMetricName()), timeValue.getValue());
}
}
use of io.cdap.cdap.api.metrics.MetricTimeSeries in project cdap by cdapio.
the class LocalMRJobInfoFetcher method queryGroupedAggregates.
// queries MetricStore for one metric across all tasks of a certain TaskType, using GroupBy InstanceId
private void queryGroupedAggregates(Map<String, String> tags, Table<String, String, Long> allTaskMetrics, Map<String, String> metricsToCounters) throws IOException {
Collection<MetricTimeSeries> query = metricsSystemClient.query(tags, metricsToCounters.keySet(), Collections.singleton(Constants.Metrics.Tag.INSTANCE_ID));
for (MetricTimeSeries metricTimeSeries : query) {
List<TimeValue> timeValues = metricTimeSeries.getTimeValues();
TimeValue timeValue = Iterables.getOnlyElement(timeValues);
String taskId = metricTimeSeries.getTagValues().get(Constants.Metrics.Tag.INSTANCE_ID);
allTaskMetrics.put(taskId, metricsToCounters.get(metricTimeSeries.getMetricName()), timeValue.getValue());
}
}
use of io.cdap.cdap.api.metrics.MetricTimeSeries in project cdap by cdapio.
the class MapReduceProgramRunnerTest method testMapreduceWithDynamicDatasets.
@Test
public void testMapreduceWithDynamicDatasets() throws Exception {
DatasetId rtInput1 = DefaultId.NAMESPACE.dataset("rtInput1");
DatasetId rtInput2 = DefaultId.NAMESPACE.dataset("rtInput2");
DatasetId rtOutput1 = DefaultId.NAMESPACE.dataset("rtOutput1");
// create the datasets here because they are not created by the app
dsFramework.addInstance("fileSet", rtInput1, FileSetProperties.builder().setBasePath("rtInput1").setInputFormat(TextInputFormat.class).setOutputFormat(TextOutputFormat.class).setOutputProperty(TextOutputFormat.SEPERATOR, ":").build());
dsFramework.addInstance("fileSet", rtOutput1, FileSetProperties.builder().setBasePath("rtOutput1").setInputFormat(TextInputFormat.class).setOutputFormat(TextOutputFormat.class).setOutputProperty(TextOutputFormat.SEPERATOR, ":").build());
// build runtime args for app
Map<String, String> runtimeArguments = Maps.newHashMap();
// Make sure there is only one mapper running at a time since this test has the Mapper writing
// to a dataset using increment and the in-memory table doesn't really support concurrent increment
runtimeArguments.put("mr.job.conf.mapreduce.local.map.tasks.maximum", "1");
runtimeArguments.put(AppWithMapReduceUsingRuntimeDatasets.INPUT_NAME, "rtInput1");
runtimeArguments.put(AppWithMapReduceUsingRuntimeDatasets.INPUT_PATHS, "abc, xyz");
runtimeArguments.put(AppWithMapReduceUsingRuntimeDatasets.OUTPUT_NAME, "rtOutput1");
runtimeArguments.put(AppWithMapReduceUsingRuntimeDatasets.OUTPUT_PATH, "a001");
// test reading and writing distinct datasets, reading more than one path
testMapreduceWithFile("rtInput1", "abc, xyz", "rtOutput1", "a001", AppWithMapReduceUsingRuntimeDatasets.class, AppWithMapReduceUsingRuntimeDatasets.ComputeSum.class, runtimeArguments, AppWithMapReduceUsingRuntimeDatasets.COUNTERS, null);
// validate that the table emitted metrics
Collection<MetricTimeSeries> metrics = metricStore.query(new MetricDataQuery(0, System.currentTimeMillis() / 1000L, Integer.MAX_VALUE, "system." + Constants.Metrics.Name.Dataset.OP_COUNT, AggregationFunction.SUM, ImmutableMap.of(Constants.Metrics.Tag.NAMESPACE, DefaultId.NAMESPACE.getNamespace(), Constants.Metrics.Tag.APP, AppWithMapReduceUsingRuntimeDatasets.APP_NAME, Constants.Metrics.Tag.MAPREDUCE, AppWithMapReduceUsingRuntimeDatasets.MR_NAME, Constants.Metrics.Tag.DATASET, "rtt"), Collections.<String>emptyList()));
Assert.assertEquals(1, metrics.size());
MetricTimeSeries ts = metrics.iterator().next();
Assert.assertEquals(1, ts.getTimeValues().size());
Assert.assertEquals(1, ts.getTimeValues().get(0).getValue());
// test reading and writing same dataset
dsFramework.addInstance("fileSet", rtInput2, FileSetProperties.builder().setBasePath("rtInput2").setInputFormat(TextInputFormat.class).setOutputFormat(TextOutputFormat.class).setOutputProperty(TextOutputFormat.SEPERATOR, ":").build());
runtimeArguments = Maps.newHashMap();
runtimeArguments.put(AppWithMapReduceUsingRuntimeDatasets.INPUT_NAME, "rtInput2");
runtimeArguments.put(AppWithMapReduceUsingRuntimeDatasets.INPUT_PATHS, "zzz");
runtimeArguments.put(AppWithMapReduceUsingRuntimeDatasets.OUTPUT_NAME, "rtInput2");
runtimeArguments.put(AppWithMapReduceUsingRuntimeDatasets.OUTPUT_PATH, "f123");
testMapreduceWithFile("rtInput2", "zzz", "rtInput2", "f123", AppWithMapReduceUsingRuntimeDatasets.class, AppWithMapReduceUsingRuntimeDatasets.ComputeSum.class, runtimeArguments, AppWithMapReduceUsingRuntimeDatasets.COUNTERS, null);
}
use of io.cdap.cdap.api.metrics.MetricTimeSeries in project cdap by cdapio.
the class PreviewDataPipelineTest method getTotalMetric.
private long getTotalMetric(Map<String, String> tags, String metricName, PreviewManager previewManager) {
MetricDataQuery query = new MetricDataQuery(0, 0, Integer.MAX_VALUE, metricName, AggregationFunction.SUM, tags, new ArrayList<>());
Collection<MetricTimeSeries> result = previewManager.getMetricsQueryHelper().getMetricStore().query(query);
if (result.isEmpty()) {
return 0;
}
List<TimeValue> timeValues = result.iterator().next().getTimeValues();
if (timeValues.isEmpty()) {
return 0;
}
return timeValues.get(0).getValue();
}
Aggregations