Search in sources :

Example 1 with MetricQueryResult

use of co.cask.cdap.proto.MetricQueryResult in project cdap by caskdata.

the class MetricsHandlerTestRun method verifyAggregateQueryResult.

private void verifyAggregateQueryResult(String url, long expectedValue) throws Exception {
    // todo : can refactor this to test only the new tag name queries once we deprecate queryParam using context.
    MetricQueryResult queryResult = post(url, MetricQueryResult.class);
    Assert.assertEquals(expectedValue, queryResult.getSeries()[0].getData()[0].getValue());
}
Also used : MetricQueryResult(co.cask.cdap.proto.MetricQueryResult)

Example 2 with MetricQueryResult

use of co.cask.cdap.proto.MetricQueryResult in project cdap by caskdata.

the class MetricsHandlerTestRun method verifyGroupByResult.

private void verifyGroupByResult(String url, List<TimeSeriesResult> groupByResult) throws Exception {
    MetricQueryResult result = post(url, MetricQueryResult.class);
    Assert.assertEquals(groupByResult.size(), result.getSeries().length);
    for (MetricQueryResult.TimeSeries timeSeries : result.getSeries()) {
        boolean timeSeriesMatchFound = false;
        for (TimeSeriesResult expectedTs : groupByResult) {
            if (expectedTs.getTagValues().equals(ImmutableMap.copyOf(timeSeries.getGrouping()))) {
                assertTimeValues(expectedTs, timeSeries);
                timeSeriesMatchFound = true;
            }
        }
        Assert.assertTrue(timeSeriesMatchFound);
    }
}
Also used : MetricQueryResult(co.cask.cdap.proto.MetricQueryResult)

Example 3 with MetricQueryResult

use of co.cask.cdap.proto.MetricQueryResult in project cdap by caskdata.

the class MetricsQueryHelper method executeBatchQueries.

public Map<String, MetricQueryResult> executeBatchQueries(Map<String, QueryRequestFormat> queries) throws Exception {
    LOG.trace("Received Queries {}", queries);
    Map<String, MetricQueryResult> queryFinalResponse = Maps.newHashMap();
    for (Map.Entry<String, QueryRequestFormat> query : queries.entrySet()) {
        MetricQueryRequest queryRequest = getQueryRequestFromFormat(query.getValue());
        queryFinalResponse.put(query.getKey(), executeQuery(queryRequest));
    }
    return queryFinalResponse;
}
Also used : MetricQueryResult(co.cask.cdap.proto.MetricQueryResult) ImmutableBiMap(com.google.common.collect.ImmutableBiMap) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) MetricQueryRequest(co.cask.cdap.proto.MetricQueryRequest)

Example 4 with MetricQueryResult

use of co.cask.cdap.proto.MetricQueryResult in project cdap by caskdata.

the class MetricsClient method getTotalCounter.

private long getTotalCounter(Map<String, String> tags, String metricName) {
    try {
        MetricQueryResult result = query(tags, metricName);
        if (result.getSeries().length == 0) {
            return 0;
        }
        MetricQueryResult.TimeValue[] timeValues = result.getSeries()[0].getData();
        if (timeValues.length == 0) {
            return 0;
        }
        // since it is totals, we know there's one value only
        return timeValues[0].getValue();
    } catch (Exception e) {
        throw Throwables.propagate(e);
    }
}
Also used : MetricQueryResult(co.cask.cdap.proto.MetricQueryResult) TimeoutException(java.util.concurrent.TimeoutException) IOException(java.io.IOException) UnauthenticatedException(co.cask.cdap.common.UnauthenticatedException) UnauthorizedException(co.cask.cdap.security.spi.authorization.UnauthorizedException)

Example 5 with MetricQueryResult

use of co.cask.cdap.proto.MetricQueryResult in project cdap by caskdata.

the class MetricsClientTestRun method testAll.

@Test
public void testAll() throws Exception {
    appClient.deploy(NamespaceId.DEFAULT, createAppJarFile(FakeApp.class));
    ApplicationId app = NamespaceId.DEFAULT.app(FakeApp.NAME);
    ProgramId flow = app.flow(FakeFlow.NAME);
    StreamId stream = NamespaceId.DEFAULT.stream(FakeApp.STREAM_NAME);
    try {
        programClient.start(flow);
        streamClient.sendEvent(stream, "hello world");
        // TODO: remove arbitrary sleep
        TimeUnit.SECONDS.sleep(5);
        FlowletId flowletId = flow.flowlet(FakeFlow.FLOWLET_NAME);
        MetricQueryResult result = metricsClient.query(MetricsTags.flowlet(flowletId), Constants.Metrics.Name.Flow.FLOWLET_INPUT);
        Assert.assertEquals(1, result.getSeries()[0].getData()[0].getValue());
        result = metricsClient.query(MetricsTags.flowlet(flowletId), ImmutableList.of(Constants.Metrics.Name.Flow.FLOWLET_INPUT), ImmutableList.<String>of(), ImmutableMap.of("aggregate", "true"));
        Assert.assertEquals(1, result.getSeries()[0].getData()[0].getValue());
        result = metricsClient.query(MetricsTags.flowlet(flowletId), ImmutableList.of(Constants.Metrics.Name.Flow.FLOWLET_INPUT), ImmutableList.<String>of(), ImmutableMap.of("start", "now-20s", "end", "now"));
        Assert.assertEquals(1, result.getSeries()[0].getData()[0].getValue());
        List<MetricTagValue> tags = metricsClient.searchTags(MetricsTags.flowlet(flowletId));
        Assert.assertEquals(1, tags.size());
        Assert.assertEquals("run", tags.get(0).getName());
        List<String> metrics = metricsClient.searchMetrics(MetricsTags.flowlet(flowletId));
        Assert.assertTrue(metrics.contains(Constants.Metrics.Name.Flow.FLOWLET_INPUT));
    } finally {
        programClient.stop(flow);
        assertProgramRuns(programClient, flow, ProgramRunStatus.KILLED, 1, 10);
        appClient.delete(app);
    }
}
Also used : FakeApp(co.cask.cdap.client.app.FakeApp) StreamId(co.cask.cdap.proto.id.StreamId) FlowletId(co.cask.cdap.proto.id.FlowletId) MetricTagValue(co.cask.cdap.proto.MetricTagValue) MetricQueryResult(co.cask.cdap.proto.MetricQueryResult) ApplicationId(co.cask.cdap.proto.id.ApplicationId) ProgramId(co.cask.cdap.proto.id.ProgramId) Test(org.junit.Test)

Aggregations

MetricQueryResult (co.cask.cdap.proto.MetricQueryResult)13 ImmutableMap (com.google.common.collect.ImmutableMap)2 Map (java.util.Map)2 Test (org.junit.Test)2 TimeValue (co.cask.cdap.api.dataset.lib.cube.TimeValue)1 MetricTimeSeries (co.cask.cdap.api.metrics.MetricTimeSeries)1 RowMaker (co.cask.cdap.cli.util.RowMaker)1 Table (co.cask.cdap.cli.util.table.Table)1 FakeApp (co.cask.cdap.client.app.FakeApp)1 UnauthenticatedException (co.cask.cdap.common.UnauthenticatedException)1 MetricQueryRequest (co.cask.cdap.proto.MetricQueryRequest)1 MetricTagValue (co.cask.cdap.proto.MetricTagValue)1 ApplicationId (co.cask.cdap.proto.id.ApplicationId)1 FlowletId (co.cask.cdap.proto.id.FlowletId)1 ProgramId (co.cask.cdap.proto.id.ProgramId)1 StreamId (co.cask.cdap.proto.id.StreamId)1 UnauthorizedException (co.cask.cdap.security.spi.authorization.UnauthorizedException)1 HttpResponse (co.cask.common.http.HttpResponse)1 ImmutableBiMap (com.google.common.collect.ImmutableBiMap)1 Gson (com.google.gson.Gson)1