Search in sources :

Example 1 with MetricsHeader

use of org.apache.samza.metrics.reporter.MetricsHeader in project samza by apache.

the class DiagnosticsUtil method writeMetadataFile.

// Write a file in the samza.log.dir named {exec-env-container-id}.metadata that contains
// metadata about the container such as containerId, jobName, jobId, hostname, timestamp, version info, and others.
// The file contents are serialized using {@link JsonSerde}.
public static void writeMetadataFile(String jobName, String jobId, String containerId, Optional<String> execEnvContainerId, Config config) {
    Optional<File> metadataFile = JobConfig.getMetadataFile(execEnvContainerId.orElse(null));
    if (metadataFile.isPresent()) {
        MetricsHeader metricsHeader = new MetricsHeader(jobName, jobId, "samza-container-" + containerId, execEnvContainerId.orElse(""), LocalContainerRunner.class.getName(), Util.getTaskClassVersion(config), Util.getSamzaVersion(), Util.getLocalHost().getHostName(), System.currentTimeMillis(), System.currentTimeMillis());
        class MetadataFileContents {

            public final String version;

            public final String metricsSnapshot;

            public MetadataFileContents(String version, String metricsSnapshot) {
                this.version = version;
                this.metricsSnapshot = metricsSnapshot;
            }
        }
        MetricsSnapshot metricsSnapshot = new MetricsSnapshot(metricsHeader, new Metrics());
        MetadataFileContents metadataFileContents = new MetadataFileContents("1", new String(new MetricsSnapshotSerdeV2().toBytes(metricsSnapshot)));
        new FileUtil().writeToTextFile(metadataFile.get(), new String(new JsonSerde<>().toBytes(metadataFileContents)), false);
    } else {
        log.info("Skipping writing metadata file.");
    }
}
Also used : MetricsHeader(org.apache.samza.metrics.reporter.MetricsHeader) Metrics(org.apache.samza.metrics.reporter.Metrics) MetricsSnapshot(org.apache.samza.metrics.reporter.MetricsSnapshot) MetricsSnapshotSerdeV2(org.apache.samza.serializers.MetricsSnapshotSerdeV2) LocalContainerRunner(org.apache.samza.runtime.LocalContainerRunner) File(java.io.File)

Example 2 with MetricsHeader

use of org.apache.samza.metrics.reporter.MetricsHeader in project samza by apache.

the class TestMetricsSnapshotSerdeV2 method metricsSnapshot.

private static MetricsSnapshot metricsSnapshot(Exception exception, boolean includeSamzaEpochId) {
    MetricsHeader metricsHeader;
    if (includeSamzaEpochId) {
        metricsHeader = new MetricsHeader("jobName", "i001", "container 0", "test container ID", Optional.of("epoch-123"), "source", "300.14.25.1", "1", "1", 1, 1);
    } else {
        metricsHeader = new MetricsHeader("jobName", "i001", "container 0", "test container ID", "source", "300.14.25.1", "1", "1", 1, 1);
    }
    BoundedList<DiagnosticsExceptionEvent> boundedList = new BoundedList<>("exceptions");
    DiagnosticsExceptionEvent diagnosticsExceptionEvent = new DiagnosticsExceptionEvent(1, exception, new HashMap<>());
    boundedList.add(diagnosticsExceptionEvent);
    Map<String, Map<String, Object>> metricMessage = new HashMap<>();
    Map<String, Object> samzaContainerMetrics = new HashMap<>();
    samzaContainerMetrics.put("commit-calls", 1);
    metricMessage.put("org.apache.samza.container.SamzaContainerMetrics", samzaContainerMetrics);
    Map<String, Object> exceptions = new HashMap<>();
    exceptions.put("exceptions", boundedList.getValues());
    metricMessage.put("org.apache.samza.exceptions", exceptions);
    return new MetricsSnapshot(metricsHeader, new Metrics(metricMessage));
}
Also used : HashMap(java.util.HashMap) MetricsSnapshot(org.apache.samza.metrics.reporter.MetricsSnapshot) MetricsHeader(org.apache.samza.metrics.reporter.MetricsHeader) Metrics(org.apache.samza.metrics.reporter.Metrics) DiagnosticsExceptionEvent(org.apache.samza.diagnostics.DiagnosticsExceptionEvent) HashMap(java.util.HashMap) Map(java.util.Map) BoundedList(org.apache.samza.diagnostics.BoundedList)

Example 3 with MetricsHeader

use of org.apache.samza.metrics.reporter.MetricsHeader 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 4 with MetricsHeader

use of org.apache.samza.metrics.reporter.MetricsHeader in project samza by apache.

the class TestDiagnosticsStreamMessage method serdeTest.

/**
 * Tests serialization and deserialization of a {@link DiagnosticsStreamMessage}
 */
@Test
public void serdeTest() {
    DiagnosticsStreamMessage diagnosticsStreamMessage = getDiagnosticsStreamMessage(Optional.of(SAMZA_EPOCH_ID));
    Collection<DiagnosticsExceptionEvent> exceptionEventList = getExceptionList();
    diagnosticsStreamMessage.addDiagnosticsExceptionEvents(exceptionEventList);
    diagnosticsStreamMessage.addProcessorStopEvents(getProcessorStopEventList());
    diagnosticsStreamMessage.addContainerModels(getSampleContainerModels());
    MetricsSnapshot metricsSnapshot = diagnosticsStreamMessage.convertToMetricsSnapshot();
    MetricsHeader expectedHeader = new MetricsHeader(JOB_NAME, JOB_ID, CONTAINER_NAME, EXECUTION_ENV_CONTAINER_ID, Optional.of(SAMZA_EPOCH_ID), DiagnosticsManager.class.getName(), TASK_CLASS_VERSION, SAMZA_VERSION, HOSTNAME, timestamp, resetTimestamp);
    Assert.assertEquals(metricsSnapshot.getHeader(), expectedHeader);
    Map<String, Map<String, Object>> metricsMap = metricsSnapshot.getMetrics().getAsMap();
    Assert.assertTrue(metricsMap.get("org.apache.samza.container.SamzaContainerMetrics").containsKey("exceptions"));
    Assert.assertTrue(metricsMap.get(DiagnosticsManager.class.getName()).containsKey("containerModels"));
    Assert.assertTrue(metricsMap.get(DiagnosticsManager.class.getName()).containsKey("numPersistentStores"));
    Assert.assertTrue(metricsMap.get(DiagnosticsManager.class.getName()).containsKey("containerNumCores"));
    Assert.assertTrue(metricsMap.get(DiagnosticsManager.class.getName()).containsKey("containerMemoryMb"));
    Assert.assertTrue(metricsMap.get(DiagnosticsManager.class.getName()).containsKey("stopEvents"));
    Assert.assertTrue(metricsMap.get(DiagnosticsManager.class.getName()).containsKey("config"));
    DiagnosticsStreamMessage convertedDiagnosticsStreamMessage = DiagnosticsStreamMessage.convertToDiagnosticsStreamMessage(metricsSnapshot);
    Assert.assertEquals(convertedDiagnosticsStreamMessage, diagnosticsStreamMessage);
}
Also used : MetricsHeader(org.apache.samza.metrics.reporter.MetricsHeader) MetricsSnapshot(org.apache.samza.metrics.reporter.MetricsSnapshot) ImmutableMap(com.google.common.collect.ImmutableMap) HashMap(java.util.HashMap) Map(java.util.Map) Test(org.junit.Test)

Example 5 with MetricsHeader

use of org.apache.samza.metrics.reporter.MetricsHeader in project samza by apache.

the class TestDiagnosticsStreamMessage method testSerdeEmptySamzaEpochIdInHeader.

@Test
public void testSerdeEmptySamzaEpochIdInHeader() {
    DiagnosticsStreamMessage diagnosticsStreamMessage = getDiagnosticsStreamMessage(Optional.empty());
    MetricsSnapshot metricsSnapshot = diagnosticsStreamMessage.convertToMetricsSnapshot();
    MetricsHeader expectedHeader = new MetricsHeader(JOB_NAME, JOB_ID, CONTAINER_NAME, EXECUTION_ENV_CONTAINER_ID, Optional.empty(), DiagnosticsManager.class.getName(), TASK_CLASS_VERSION, SAMZA_VERSION, HOSTNAME, timestamp, resetTimestamp);
    Assert.assertEquals(metricsSnapshot.getHeader(), expectedHeader);
    DiagnosticsStreamMessage convertedDiagnosticsStreamMessage = DiagnosticsStreamMessage.convertToDiagnosticsStreamMessage(metricsSnapshot);
    Assert.assertEquals(convertedDiagnosticsStreamMessage, diagnosticsStreamMessage);
}
Also used : MetricsHeader(org.apache.samza.metrics.reporter.MetricsHeader) MetricsSnapshot(org.apache.samza.metrics.reporter.MetricsSnapshot) Test(org.junit.Test)

Aggregations

MetricsHeader (org.apache.samza.metrics.reporter.MetricsHeader)6 MetricsSnapshot (org.apache.samza.metrics.reporter.MetricsSnapshot)6 HashMap (java.util.HashMap)3 Map (java.util.Map)3 Metrics (org.apache.samza.metrics.reporter.Metrics)2 MetricsSnapshotSerdeV2 (org.apache.samza.serializers.MetricsSnapshotSerdeV2)2 Test (org.junit.Test)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