Search in sources :

Example 6 with MetricsSnapshot

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));
}
Also used : MetricsHeader(org.apache.samza.metrics.reporter.MetricsHeader) HashMap(java.util.HashMap) MetricsSnapshot(org.apache.samza.metrics.reporter.MetricsSnapshot) Map(java.util.Map) HashMap(java.util.HashMap)

Example 7 with MetricsSnapshot

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());
}
Also used : MetricsSnapshot(org.apache.samza.metrics.reporter.MetricsSnapshot) MetricsSnapshotSerdeV2(org.apache.samza.serializers.MetricsSnapshotSerdeV2) OutgoingMessageEnvelope(org.apache.samza.system.OutgoingMessageEnvelope) Test(org.junit.Test)

Example 8 with MetricsSnapshot

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());
}
Also used : MetricsSnapshot(org.apache.samza.metrics.reporter.MetricsSnapshot) MetricsSnapshotSerdeV2(org.apache.samza.serializers.MetricsSnapshotSerdeV2)

Example 9 with MetricsSnapshot

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());
}
Also used : HashMap(java.util.HashMap) MetricsSnapshot(org.apache.samza.metrics.reporter.MetricsSnapshot) MetricsSnapshotSerdeV2(org.apache.samza.serializers.MetricsSnapshotSerdeV2) OutgoingMessageEnvelope(org.apache.samza.system.OutgoingMessageEnvelope) Test(org.junit.Test)

Example 10 with MetricsSnapshot

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)));
}
Also used : MetricsSnapshot(org.apache.samza.metrics.reporter.MetricsSnapshot) MetricsSnapshotSerdeV2(org.apache.samza.serializers.MetricsSnapshotSerdeV2) SamzaException(org.apache.samza.SamzaException) Test(org.junit.Test)

Aggregations

MetricsSnapshot (org.apache.samza.metrics.reporter.MetricsSnapshot)17 Test (org.junit.Test)12 MetricsSnapshotSerdeV2 (org.apache.samza.serializers.MetricsSnapshotSerdeV2)9 MetricsHeader (org.apache.samza.metrics.reporter.MetricsHeader)6 HashMap (java.util.HashMap)4 SamzaException (org.apache.samza.SamzaException)4 Map (java.util.Map)3 Metrics (org.apache.samza.metrics.reporter.Metrics)2 OutgoingMessageEnvelope (org.apache.samza.system.OutgoingMessageEnvelope)2 ImmutableMap (com.google.common.collect.ImmutableMap)1 File (java.io.File)1 BoundedList (org.apache.samza.diagnostics.BoundedList)1 DiagnosticsExceptionEvent (org.apache.samza.diagnostics.DiagnosticsExceptionEvent)1 LocalContainerRunner (org.apache.samza.runtime.LocalContainerRunner)1