use of org.apache.samza.metrics.reporter.MetricsSnapshot in project samza by apache.
the class TestMetricsSnapshotSerde method metricsSnapshot.
private static MetricsSnapshot metricsSnapshot(boolean includeSamzaEpochId) {
MetricsHeader metricsHeader;
if (includeSamzaEpochId) {
metricsHeader = new MetricsHeader("test-jobName", "testjobid", "samza-container-0", "test exec env container id", Optional.of("epoch-123"), "test source", "version", "samzaversion", "host", 1L, 2L);
} else {
metricsHeader = new MetricsHeader("test-jobName", "testjobid", "samza-container-0", "test exec env container id", "test source", "version", "samzaversion", "host", 1L, 2L);
}
Map<String, Object> metricsMap = new HashMap<>();
metricsMap.put("test2", "foo");
Map<String, Map<String, Object>> metricsGroupMap = new HashMap<>();
metricsGroupMap.put("test", metricsMap);
return new MetricsSnapshot(metricsHeader, Metrics.fromMap(metricsGroupMap));
}
use of org.apache.samza.metrics.reporter.MetricsSnapshot in project samza by apache.
the class TestDiagnosticsManager method testSecondPublishWithProcessorStopInSecondMessage.
@Test
public void testSecondPublishWithProcessorStopInSecondMessage() {
// Across two successive run() invocations two messages should be published if stop events are added
this.diagnosticsManager.start();
this.diagnosticsManager.addProcessorStopEvent("0", EXECUTION_ENV_CONTAINER_ID, HOSTNAME, 102);
this.diagnosticsManager.start();
Assert.assertEquals("Two messages should have been published", 2, mockSystemProducer.getEnvelopeList().size());
// Validate the first message
OutgoingMessageEnvelope outgoingMessageEnvelope = mockSystemProducer.getEnvelopeList().get(0);
validateMetricsHeader(outgoingMessageEnvelope, FIRST_SEND_TIME);
validateOutgoingMessageEnvelope(outgoingMessageEnvelope);
// Validate the second message's header
outgoingMessageEnvelope = mockSystemProducer.getEnvelopeList().get(1);
validateMetricsHeader(outgoingMessageEnvelope, SECOND_SEND_TIME);
// Validate the second message's body (should be all empty except for the processor-stop-event)
MetricsSnapshot metricsSnapshot = new MetricsSnapshotSerdeV2().fromBytes((byte[]) outgoingMessageEnvelope.getMessage());
DiagnosticsStreamMessage diagnosticsStreamMessage = DiagnosticsStreamMessage.convertToDiagnosticsStreamMessage(metricsSnapshot);
Assert.assertNull(diagnosticsStreamMessage.getContainerMb());
Assert.assertNull(diagnosticsStreamMessage.getExceptionEvents());
Assert.assertEquals(diagnosticsStreamMessage.getProcessorStopEvents(), Arrays.asList(new ProcessorStopEvent("0", EXECUTION_ENV_CONTAINER_ID, HOSTNAME, 102)));
Assert.assertNull(diagnosticsStreamMessage.getContainerModels());
Assert.assertNull(diagnosticsStreamMessage.getContainerNumCores());
Assert.assertNull(diagnosticsStreamMessage.getNumPersistentStores());
}
use of org.apache.samza.metrics.reporter.MetricsSnapshot in project samza by apache.
the class TestDiagnosticsManager method validateOutgoingMessageEnvelope.
private void validateOutgoingMessageEnvelope(OutgoingMessageEnvelope outgoingMessageEnvelope) {
MetricsSnapshot metricsSnapshot = new MetricsSnapshotSerdeV2().fromBytes((byte[]) outgoingMessageEnvelope.getMessage());
// Validate the diagnostics stream message
DiagnosticsStreamMessage diagnosticsStreamMessage = DiagnosticsStreamMessage.convertToDiagnosticsStreamMessage(metricsSnapshot);
Assert.assertEquals(CONTAINER_MB, diagnosticsStreamMessage.getContainerMb().intValue());
Assert.assertEquals(MAX_HEAP_SIZE, diagnosticsStreamMessage.getMaxHeapSize().longValue());
Assert.assertEquals(CONTAINER_THREAD_POOL_SIZE, diagnosticsStreamMessage.getContainerThreadPoolSize().intValue());
Assert.assertEquals(exceptionEventList, diagnosticsStreamMessage.getExceptionEvents());
Assert.assertEquals(diagnosticsStreamMessage.getProcessorStopEvents(), Arrays.asList(new ProcessorStopEvent("0", EXECUTION_ENV_CONTAINER_ID, HOSTNAME, 101)));
Assert.assertEquals(containerModels, diagnosticsStreamMessage.getContainerModels());
Assert.assertEquals(CONTAINER_NUM_CORES, diagnosticsStreamMessage.getContainerNumCores().intValue());
Assert.assertEquals(NUM_PERSISTENT_STORES, diagnosticsStreamMessage.getNumPersistentStores().intValue());
Assert.assertEquals(AUTOSIZING_ENABLED, diagnosticsStreamMessage.getAutosizingEnabled());
Assert.assertEquals(config, diagnosticsStreamMessage.getConfig());
}
use of org.apache.samza.metrics.reporter.MetricsSnapshot in project samza by apache.
the class TestDiagnosticsManager method testSecondPublishWithExceptionInSecondMessage.
@Test
public void testSecondPublishWithExceptionInSecondMessage() {
// Across two successive run() invocations two messages should be published if stop events are added
this.diagnosticsManager.start();
DiagnosticsExceptionEvent diagnosticsExceptionEvent = new DiagnosticsExceptionEvent(System.currentTimeMillis(), new RuntimeException("exception"), new HashMap());
this.diagnosticsManager.addExceptionEvent(diagnosticsExceptionEvent);
this.diagnosticsManager.start();
Assert.assertEquals("Two messages should have been published", 2, mockSystemProducer.getEnvelopeList().size());
// Validate the first message
OutgoingMessageEnvelope outgoingMessageEnvelope = mockSystemProducer.getEnvelopeList().get(0);
validateMetricsHeader(outgoingMessageEnvelope, FIRST_SEND_TIME);
validateOutgoingMessageEnvelope(outgoingMessageEnvelope);
// Validate the second message's header
outgoingMessageEnvelope = mockSystemProducer.getEnvelopeList().get(1);
validateMetricsHeader(outgoingMessageEnvelope, SECOND_SEND_TIME);
// Validate the second message's body (should be all empty except for the processor-stop-event)
MetricsSnapshot metricsSnapshot = new MetricsSnapshotSerdeV2().fromBytes((byte[]) outgoingMessageEnvelope.getMessage());
DiagnosticsStreamMessage diagnosticsStreamMessage = DiagnosticsStreamMessage.convertToDiagnosticsStreamMessage(metricsSnapshot);
Assert.assertNull(diagnosticsStreamMessage.getContainerMb());
Assert.assertEquals(Arrays.asList(diagnosticsExceptionEvent), diagnosticsStreamMessage.getExceptionEvents());
Assert.assertNull(diagnosticsStreamMessage.getProcessorStopEvents());
Assert.assertNull(diagnosticsStreamMessage.getContainerModels());
Assert.assertNull(diagnosticsStreamMessage.getContainerNumCores());
Assert.assertNull(diagnosticsStreamMessage.getNumPersistentStores());
}
use of org.apache.samza.metrics.reporter.MetricsSnapshot in project samza by apache.
the class TestMetricsSnapshotSerdeV2 method testDeserializeRaw.
/**
* Helps for verifying compatibility when schemas evolve.
*
* Maps have non-deterministic ordering when serialized, so it is difficult to check exact serialized results. It
* isn't really necessary to check the serialized results anyways. We just need to make sure serialized data can be
* read by old and new systems.
*/
@Test
public void testDeserializeRaw() {
SamzaException samzaException = new SamzaException("this is a samza exception", new RuntimeException("cause"));
MetricsSnapshot metricsSnapshot = metricsSnapshot(samzaException, true);
MetricsSnapshotSerdeV2 metricsSnapshotSerde = new MetricsSnapshotSerdeV2();
assertEquals(metricsSnapshot, metricsSnapshotSerde.fromBytes(expectedSeralizedSnapshot(samzaException, true, false).getBytes(StandardCharsets.UTF_8)));
assertEquals(metricsSnapshot, metricsSnapshotSerde.fromBytes(expectedSeralizedSnapshot(samzaException, true, true).getBytes(StandardCharsets.UTF_8)));
}
Aggregations