Search in sources :

Example 6 with MetricDeleteQuery

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

the class MetricQueryParser method parseDelete.

static MetricDeleteQuery parseDelete(URI requestURI, String metricPrefix) throws MetricsPathException {
    MetricDataQueryBuilder builder = new MetricDataQueryBuilder();
    parseContext(requestURI.getPath(), builder);
    builder.setStartTs(0);
    builder.setEndTs(Integer.MAX_VALUE - 1);
    builder.setMetricName(metricPrefix);
    MetricDataQuery query = builder.build();
    return new MetricDeleteQuery(query.getStartTs(), query.getEndTs(), query.getMetrics().keySet(), query.getSliceByTags());
}
Also used : MetricDeleteQuery(co.cask.cdap.api.metrics.MetricDeleteQuery) MetricDataQuery(co.cask.cdap.api.metrics.MetricDataQuery)

Example 7 with MetricDeleteQuery

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

the class ApplicationLifecycleService method deleteMetrics.

/**
   * Delete the metrics for an application.
   *
   * @param applicationId the application to delete metrics for.
   */
private void deleteMetrics(ApplicationId applicationId) throws Exception {
    ApplicationSpecification spec = this.store.getApplication(applicationId);
    long endTs = System.currentTimeMillis() / 1000;
    Map<String, String> tags = Maps.newHashMap();
    tags.put(Constants.Metrics.Tag.NAMESPACE, applicationId.getNamespace());
    // add or replace application name in the tagMap
    tags.put(Constants.Metrics.Tag.APP, spec.getName());
    MetricDeleteQuery deleteQuery = new MetricDeleteQuery(0, endTs, tags);
    metricStore.delete(deleteQuery);
}
Also used : ApplicationSpecification(co.cask.cdap.api.app.ApplicationSpecification) MetricDeleteQuery(co.cask.cdap.api.metrics.MetricDeleteQuery)

Example 8 with MetricDeleteQuery

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

the class MetricsHandlerTestRun method testInterpolate.

@Test
public void testInterpolate() throws Exception {
    long start = System.currentTimeMillis() / 1000;
    long end = start + 3;
    Map<String, String> sliceBy = getFlowletContext("interspace", "WordCount1", "WordCounter", "run1", "splitter");
    MetricValues value = new MetricValues(sliceBy, "reads", start, 100, MetricType.COUNTER);
    metricStore.add(value);
    value = new MetricValues(sliceBy, "reads", end, 400, MetricType.COUNTER);
    metricStore.add(value);
    verifyRangeQueryResult("/v3/metrics/query?" + getTags("interspace", "WordCount1", "WordCounter", "splitter") + "&metric=system.reads&interpolate=step&start=" + start + "&end=" + end, 4, 700);
    verifyRangeQueryResult("/v3/metrics/query?" + getTags("interspace", "WordCount1", "WordCounter", "splitter") + "&metric=system.reads&interpolate=linear&start=" + start + "&end=" + end, 4, 1000);
    // delete the added metrics for testing interpolator
    MetricDeleteQuery deleteQuery = new MetricDeleteQuery(start, end, sliceBy);
    metricStore.delete(deleteQuery);
}
Also used : MetricDeleteQuery(co.cask.cdap.api.metrics.MetricDeleteQuery) MetricValues(co.cask.cdap.api.metrics.MetricValues) Test(org.junit.Test)

Aggregations

MetricDeleteQuery (co.cask.cdap.api.metrics.MetricDeleteQuery)8 MetricValues (co.cask.cdap.api.metrics.MetricValues)2 Test (org.junit.Test)2 ApplicationSpecification (co.cask.cdap.api.app.ApplicationSpecification)1 MetricDataQuery (co.cask.cdap.api.metrics.MetricDataQuery)1 HashMap (java.util.HashMap)1