use of org.apache.samza.metrics.reporter.MetricsSnapshot 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.");
}
}
use of org.apache.samza.metrics.reporter.MetricsSnapshot in project samza by apache.
the class TestMetricsSnapshotSerdeV2 method testDeserializeRawEmptySamzaEpochIdInHeader.
/**
* Helps for verifying compatibility when schemas evolve.
*/
@Test
public void testDeserializeRawEmptySamzaEpochIdInHeader() {
SamzaException samzaException = new SamzaException("this is a samza exception", new RuntimeException("cause"));
MetricsSnapshot metricsSnapshot = metricsSnapshot(samzaException, false);
MetricsSnapshotSerdeV2 metricsSnapshotSerde = new MetricsSnapshotSerdeV2();
assertEquals(metricsSnapshot, metricsSnapshotSerde.fromBytes(expectedSeralizedSnapshot(samzaException, false, false).getBytes(StandardCharsets.UTF_8)));
assertEquals(metricsSnapshot, metricsSnapshotSerde.fromBytes(expectedSeralizedSnapshot(samzaException, false, true).getBytes(StandardCharsets.UTF_8)));
}
use of org.apache.samza.metrics.reporter.MetricsSnapshot 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));
}
use of org.apache.samza.metrics.reporter.MetricsSnapshot in project samza by apache.
the class TestMetricsSnapshotSerde method testSerializeThenDeserialize.
@Test
public void testSerializeThenDeserialize() {
MetricsSnapshot snapshot = metricsSnapshot(true);
MetricsSnapshotSerde serde = new MetricsSnapshotSerde();
byte[] bytes = serde.toBytes(snapshot);
assertEquals(snapshot, serde.fromBytes(bytes));
}
use of org.apache.samza.metrics.reporter.MetricsSnapshot in project samza by apache.
the class TestMetricsSnapshotSerde 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() {
MetricsSnapshot snapshot = metricsSnapshot(true);
MetricsSnapshotSerde serde = new MetricsSnapshotSerde();
assertEquals(snapshot, serde.fromBytes(expectedSeralizedSnapshot(true, false).getBytes(StandardCharsets.UTF_8)));
assertEquals(snapshot, serde.fromBytes(expectedSeralizedSnapshot(true, true).getBytes(StandardCharsets.UTF_8)));
}
Aggregations