rmatharu commented on a change in pull request #1021: Adding writing of 
container.metadata file, and moving exception writing logic to 
DiagnosticsManager
URL: https://github.com/apache/samza/pull/1021#discussion_r284384684
 
 

 ##########
 File path: samza-core/src/main/java/org/apache/samza/util/DiagnosticsUtil.java
 ##########
 @@ -0,0 +1,131 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.samza.util;
+
+import java.io.File;
+import java.time.Duration;
+import java.util.Optional;
+import org.apache.samza.SamzaException;
+import org.apache.samza.config.Config;
+import org.apache.samza.config.ConfigException;
+import org.apache.samza.config.JobConfig;
+import org.apache.samza.config.MetricsConfig;
+import org.apache.samza.config.SystemConfig;
+import org.apache.samza.config.TaskConfigJava;
+import org.apache.samza.diagnostics.DiagnosticsManager;
+import org.apache.samza.metrics.MetricsRegistryMap;
+import org.apache.samza.metrics.reporter.Metrics;
+import org.apache.samza.metrics.reporter.MetricsHeader;
+import org.apache.samza.metrics.reporter.MetricsSnapshot;
+import org.apache.samza.metrics.reporter.MetricsSnapshotReporter;
+import org.apache.samza.runtime.LocalContainerRunner;
+import org.apache.samza.serializers.MetricsSnapshotSerdeV2;
+import org.apache.samza.system.SystemFactory;
+import org.apache.samza.system.SystemProducer;
+import org.apache.samza.system.SystemStream;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import scala.Option;
+import scala.Tuple2;
+import scala.runtime.AbstractFunction0;
+
+
+public class DiagnosticsUtil {
+  private static final Logger log = 
LoggerFactory.getLogger(DiagnosticsUtil.class);
+
+  // 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.
+  public static void writeMetadataFile(String jobName, String jobId, String 
containerId,
+      Optional<String> execEnvContainerId, Config config) {
+
+    Option<File> metadataFile = 
JobConfig.getMetadataFile(Option.apply(execEnvContainerId.orElse(null)));
+
+    if (metadataFile.isDefined()) {
+
+      StringBuilder metadata = new StringBuilder("Version: 1");
+      metadata.append(System.lineSeparator());
+      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());
+
+      MetricsSnapshot metricsSnapshot = new MetricsSnapshot(metricsHeader, new 
Metrics());
+      metadata.append("MetricsSnapshot: ");
 
 Review comment:
   Renamed. 
   I prefer using the serde, which internally uses objectMapper with additional 
information for typing.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

Reply via email to