use of org.apache.heron.spi.metricsmgr.metrics.MetricsRecord in project heron by twitter.
the class WebSinkTest method testTTLMetrics.
/**
* Testing TTL
*/
@Test
public void testTTLMetrics() throws InterruptedException {
Duration cacheTTL = Duration.ofSeconds(1);
Map<String, Object> conf = new HashMap<>(defaultConf);
conf.put("metrics-cache-ttl-sec", cacheTTL.getSeconds());
FakeTicker ticker = new FakeTicker();
WebTestSink sink = new WebTestSink(ticker);
sink.init(conf, context);
for (MetricsRecord r : records) {
sink.processRecord(r);
}
Assert.assertEquals(records.size() * 2, sink.getMetrics().size());
ticker.advance(cacheTTL.plusMillis(1));
sink.syncCache();
Assert.assertEquals(0, sink.getMetrics().size());
}
use of org.apache.heron.spi.metricsmgr.metrics.MetricsRecord in project heron by twitter.
the class MetricsManagerServerTest method testMetricsManagerServer.
/**
* Method: addSinkCommunicator(Communicator<MetricsRecord> communicator)
*/
@Test
public void testMetricsManagerServer() throws InterruptedException {
String name = "test_communicator";
CountDownLatch offersLatch = new CountDownLatch(MESSAGE_SIZE);
Communicator<MetricsRecord> sinkCommunicator = CommunicatorTestHelper.spyCommunicator(new Communicator<MetricsRecord>(), offersLatch);
metricsManagerServer.addSinkCommunicator(name, sinkCommunicator);
serverTester.start();
HeronServerTester.await(offersLatch);
int messages = 0;
while (!sinkCommunicator.isEmpty()) {
int exceptions = 0;
int metrics = 0;
MetricsRecord record = sinkCommunicator.poll();
Assert.assertEquals("hostname:0/component/instance-id", record.getSource());
Assert.assertEquals("default", record.getContext());
for (MetricsInfo info : record.getMetrics()) {
Assert.assertEquals(METRIC_NAME, info.getName());
Assert.assertEquals(METRIC_VALUE, info.getValue());
metrics++;
}
Assert.assertEquals(METRICS_COUNT, metrics);
for (ExceptionInfo info : record.getExceptions()) {
Assert.assertEquals(STACK_TRACE, info.getStackTrace());
Assert.assertEquals(LAST_TIME, info.getLastTime());
Assert.assertEquals(FIRST_TIME, info.getFirstTime());
Assert.assertEquals(LOGGING, info.getLogging());
Assert.assertEquals(EXCEPTION_COUNT, info.getCount());
exceptions++;
}
Assert.assertEquals(METRICS_COUNT, exceptions);
messages++;
}
Assert.assertEquals(MESSAGE_SIZE, messages);
}
use of org.apache.heron.spi.metricsmgr.metrics.MetricsRecord in project heron by twitter.
the class SinkExecutorTest method constructMetricsRecord.
private MetricsRecord constructMetricsRecord() {
List<MetricsInfo> metricsInfos = new ArrayList<>();
// We add EXPECTED_RECORDS MetricsInfo into a MetricsRecord
for (int i = 0; i < EXPECTED_RECORDS; i++) {
MetricsInfo metricsInfo = new MetricsInfo(METRICS_NAME + i, METRICS_VALUE + i);
metricsInfos.add(metricsInfo);
}
// We add EXPECTED_RECORDS ExceptionInfo into a MetricsRecord
List<ExceptionInfo> exceptionInfos = new ArrayList<>();
for (int i = 0; i < EXPECTED_RECORDS; i++) {
String stackTrace = EXCEPTION_STACK_TRACE + i;
String lastTime = EXCEPTION_LAST_TIME + i;
String firstTime = EXCEPTION_FIRST_TIME + i;
String logging = EXCEPTION_LOGGING + i;
ExceptionInfo info = new ExceptionInfo(stackTrace, lastTime, firstTime, i, logging);
exceptionInfos.add(info);
}
return new MetricsRecord(RECORD_SOURCE, metricsInfos, exceptionInfos, RECORD_CONTEXT);
}
use of org.apache.heron.spi.metricsmgr.metrics.MetricsRecord in project heron by twitter.
the class PrometheusSinkTests method testResponseWhenMetricNamesHaveAnInstanceId.
@Test
public void testResponseWhenMetricNamesHaveAnInstanceId() throws IOException {
Iterable<MetricsInfo> infos = Arrays.asList(new MetricsInfo("__connection_buffer_by_instanceid/container_1_word_5/packets", "1.0"), new MetricsInfo("__time_spent_back_pressure_by_compid/container_1_exclaim1_1", "1.0"), new MetricsInfo("__client_stmgr-92/__ack_tuples_to_stmgrs", "1.0"), new MetricsInfo("__instance_bytes_received/1", "1.0"));
records = Arrays.asList(newRecord("machine/__stmgr__/stmgr-1", infos, Collections.emptyList()));
PrometheusTestSink sink = new PrometheusTestSink();
sink.init(defaultConf, context);
for (MetricsRecord r : records) {
sink.processRecord(r);
}
final String topology = "testTopology";
final List<String> expectedLines = Arrays.asList(createMetric(topology, "__stmgr__", "stmgr-1", "connection_buffer_by_instanceid_packets", "container_1_word_5", "1.0"), createMetric(topology, "__stmgr__", "stmgr-1", "time_spent_back_pressure_by_compid", "container_1_exclaim1_1", "1.0"), createMetric(topology, "__stmgr__", "stmgr-1", "client_stmgr_ack_tuples_to_stmgrs", "stmgr-92", "1.0"), createMetric(topology, "__stmgr__", "stmgr-1", "instance_bytes_received", "1", "1.0"));
final Set<String> generatedLines = new HashSet<>(Arrays.asList(new String(sink.generateResponse()).split("\n")));
assertEquals(expectedLines.size(), generatedLines.size());
expectedLines.forEach((String line) -> {
assertTrue(generatedLines.contains(line));
});
}
use of org.apache.heron.spi.metricsmgr.metrics.MetricsRecord in project heron by twitter.
the class PrometheusSinkTests method testMetricsGrouping.
@Test
public void testMetricsGrouping() {
PrometheusTestSink sink = new PrometheusTestSink();
sink.init(defaultConf, context);
for (MetricsRecord r : records) {
sink.processRecord(r);
}
final Map<String, Map<String, Double>> metrics = sink.getMetrics();
assertTrue(metrics.containsKey("testTopology/component/instance_1"));
assertTrue(metrics.containsKey("testTopology/component/instance_2"));
}
Aggregations