Search in sources :

Example 6 with MetricValues

use of io.cdap.cdap.api.metrics.MetricValues in project cdap by caskdata.

the class RemoteTaskExecutorTest method testRetryMetrics.

@Test
public void testRetryMetrics() throws Exception {
    // Remove the service registration
    registered.cancel();
    RemoteTaskExecutor remoteTaskExecutor = new RemoteTaskExecutor(cConf, mockMetricsCollector, remoteClientFactory, RemoteTaskExecutor.Type.TASK_WORKER);
    RunnableTaskRequest runnableTaskRequest = RunnableTaskRequest.getBuilder(ValidRunnableClass.class.getName()).withParam("param").build();
    try {
        remoteTaskExecutor.runTask(runnableTaskRequest);
    } catch (Exception e) {
    }
    mockMetricsCollector.stopAndWait();
    Assert.assertSame(1, published.size());
    // check the metrics are present
    MetricValues metricValues = published.get(0);
    Assert.assertTrue(hasMetric(metricValues, Constants.Metrics.TaskWorker.CLIENT_REQUEST_COUNT));
    Assert.assertTrue(hasMetric(metricValues, Constants.Metrics.TaskWorker.CLIENT_REQUEST_LATENCY_MS));
    Assert.assertEquals("failure", metricValues.getTags().get(Constants.Metrics.Tag.STATUS));
    int retryCount = Integer.parseInt(metricValues.getTags().get(Constants.Metrics.Tag.TRIES));
    Assert.assertTrue(retryCount > 1);
}
Also used : MetricValues(io.cdap.cdap.api.metrics.MetricValues) RunnableTaskRequest(io.cdap.cdap.api.service.worker.RunnableTaskRequest) Test(org.junit.Test)

Example 7 with MetricValues

use of io.cdap.cdap.api.metrics.MetricValues in project cdap by caskdata.

the class RemoteTaskExecutorTest method beforeTest.

@Before
public void beforeTest() {
    published = new ArrayList<>();
    mockMetricsCollector = new AggregatedMetricsCollectionService(1000L) {

        @Override
        protected void publish(Iterator<MetricValues> metrics) {
            Iterators.addAll(published, metrics);
        }
    };
    mockMetricsCollector.startAndWait();
    registered = discoveryService.register(URIScheme.createDiscoverable(Constants.Service.TASK_WORKER, httpService));
}
Also used : AggregatedMetricsCollectionService(io.cdap.cdap.metrics.collect.AggregatedMetricsCollectionService) MetricValues(io.cdap.cdap.api.metrics.MetricValues) Before(org.junit.Before)

Example 8 with MetricValues

use of io.cdap.cdap.api.metrics.MetricValues in project cdap by caskdata.

the class RemoteTaskExecutorTest method testFailedMetrics.

@Test
public void testFailedMetrics() throws Exception {
    RemoteTaskExecutor remoteTaskExecutor = new RemoteTaskExecutor(cConf, mockMetricsCollector, remoteClientFactory, RemoteTaskExecutor.Type.TASK_WORKER);
    RunnableTaskRequest runnableTaskRequest = RunnableTaskRequest.getBuilder(InValidRunnableClass.class.getName()).withParam("param").build();
    try {
        remoteTaskExecutor.runTask(runnableTaskRequest);
    } catch (Exception e) {
    }
    mockMetricsCollector.stopAndWait();
    Assert.assertSame(1, published.size());
    // check the metrics are present
    MetricValues metricValues = published.get(0);
    Assert.assertTrue(hasMetric(metricValues, Constants.Metrics.TaskWorker.CLIENT_REQUEST_LATENCY_MS));
    Assert.assertTrue(hasMetric(metricValues, Constants.Metrics.TaskWorker.CLIENT_REQUEST_COUNT));
    // check the clz tag is set correctly
    Assert.assertEquals(InValidRunnableClass.class.getName(), metricValues.getTags().get("clz"));
}
Also used : MetricValues(io.cdap.cdap.api.metrics.MetricValues) RunnableTaskRequest(io.cdap.cdap.api.service.worker.RunnableTaskRequest) Test(org.junit.Test)

Example 9 with MetricValues

use of io.cdap.cdap.api.metrics.MetricValues in project cdap by caskdata.

the class RemoteTaskExecutorTest method testSuccessMetrics.

@Test
public void testSuccessMetrics() throws Exception {
    RemoteTaskExecutor remoteTaskExecutor = new RemoteTaskExecutor(cConf, mockMetricsCollector, remoteClientFactory, RemoteTaskExecutor.Type.TASK_WORKER);
    RunnableTaskRequest runnableTaskRequest = RunnableTaskRequest.getBuilder(ValidRunnableClass.class.getName()).withParam("param").build();
    remoteTaskExecutor.runTask(runnableTaskRequest);
    mockMetricsCollector.stopAndWait();
    Assert.assertSame(1, published.size());
    // check the metrics are present
    MetricValues metricValues = published.get(0);
    Assert.assertTrue(hasMetric(metricValues, Constants.Metrics.TaskWorker.CLIENT_REQUEST_LATENCY_MS));
    Assert.assertTrue(hasMetric(metricValues, Constants.Metrics.TaskWorker.CLIENT_REQUEST_COUNT));
    // check the clz tag is set correctly
    Assert.assertEquals(ValidRunnableClass.class.getName(), metricValues.getTags().get("clz"));
}
Also used : MetricValues(io.cdap.cdap.api.metrics.MetricValues) RunnableTaskRequest(io.cdap.cdap.api.service.worker.RunnableTaskRequest) Test(org.junit.Test)

Example 10 with MetricValues

use of io.cdap.cdap.api.metrics.MetricValues in project cdap by caskdata.

the class MessagingMetricsCollectionService method publish.

@Override
protected void publish(Iterator<MetricValues> metrics) throws Exception {
    int size = topicPayloads.size();
    while (metrics.hasNext()) {
        encoderOutputStream.reset();
        MetricValues metricValues = metrics.next();
        // Encode MetricValues into bytes
        recordWriter.encode(metricValues, encoder);
        TopicPayload topicPayload = topicPayloads.get(Math.abs(metricValues.getTags().hashCode() % size));
        // Calculate the topic number with the hashcode of MetricValues' tags and store the encoded payload in the
        // corresponding list of the topic number
        topicPayload.addPayload(encoderOutputStream.toByteArray(), metricValues.getTags(), metricValues.getMetrics().size());
    }
    publishMetric(topicPayloads.values());
}
Also used : MetricValues(io.cdap.cdap.api.metrics.MetricValues)

Aggregations

MetricValues (io.cdap.cdap.api.metrics.MetricValues)56 Test (org.junit.Test)28 MetricValue (io.cdap.cdap.api.metrics.MetricValue)20 RunnableTaskRequest (io.cdap.cdap.api.service.worker.RunnableTaskRequest)12 ArrayList (java.util.ArrayList)12 Map (java.util.Map)10 ImmutableMap (com.google.common.collect.ImmutableMap)8 DefaultHttpRequestConfig (io.cdap.cdap.common.http.DefaultHttpRequestConfig)6 HttpResponse (io.cdap.common.http.HttpResponse)6 Iterator (java.util.Iterator)6 MetricsContext (io.cdap.cdap.api.metrics.MetricsContext)4 CConfiguration (io.cdap.cdap.common.conf.CConfiguration)4 AggregatedMetricsCollectionService (io.cdap.cdap.metrics.collect.AggregatedMetricsCollectionService)4 IOException (java.io.IOException)4 HashMap (java.util.HashMap)4 LinkedBlockingQueue (java.util.concurrent.LinkedBlockingQueue)4 Before (org.junit.Before)4 Category (org.junit.experimental.categories.Category)4 MetricDeleteQuery (io.cdap.cdap.api.metrics.MetricDeleteQuery)3 LinkedHashMap (java.util.LinkedHashMap)3