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);
}
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));
}
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"));
}
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"));
}
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());
}
Aggregations