ibzib commented on a change in pull request #13743:
URL: https://github.com/apache/beam/pull/13743#discussion_r565634941
##########
File path:
runners/spark/src/main/java/org/apache/beam/runners/spark/SparkPipelineRunner.java
##########
@@ -123,10 +135,66 @@ public PortablePipelineResult run(RunnerApi.Pipeline
pipeline, JobInfo jobInfo)
"Will stage {} files. (Enable logging at DEBUG level to see which
files will be staged.)",
pipelineOptions.getFilesToStage().size());
LOG.debug("Staging files: {}", pipelineOptions.getFilesToStage());
-
PortablePipelineResult result;
final JavaSparkContext jsc =
SparkContextFactory.getSparkContext(pipelineOptions);
+ EventLoggingListener eventLoggingListener = null;
+ if (pipelineOptions.getEventLogEnabled()) {
+ eventLoggingListener =
+ new EventLoggingListener(
+ jobInfo.jobId(),
+ new scala.Option<String>() {
+ @Override
+ public boolean isEmpty() {
+ return false;
+ }
+
+ @Override
+ public String get() {
+ return jobInfo.jobName();
+ }
+
+ @Override
+ public Object productElement(int i) {
+ return null;
+ }
+
+ @Override
+ public int productArity() {
+ return 0;
+ }
+
+ @Override
+ public boolean canEqual(Object o) {
+ return false;
+ }
+ },
+ new URI(pipelineOptions.getSparkHistoryDir()),
+ jsc.getConf(),
+ jsc.hadoopConfiguration());
+ eventLoggingListener.initializeLogIfNecessary(false, false);
+ eventLoggingListener.start();
+ scala.collection.immutable.Map<String, String> logUrlMap =
+ new scala.collection.immutable.HashMap<String, String>();
+ Tuple2<String, String>[] sparkConfList = jsc.getConf().getAll();
+ String sparkMaster = "";
+ String sparkExecutorID = "";
+ for (Tuple2<String, String> sparkConf : sparkConfList) {
+ if (sparkConf._1().equals("spark.master")) {
+ sparkMaster = sparkConf._2();
+ } else if (sparkConf._1().equals("spark.executor.id")) {
+ if (!sparkExecutorID.equals(sparkConf._2())) {
Review comment:
The current logic is, "if the Spark executor id is not the same as the
last executor id we saw, log it." It may be better to just log every Spark
executor id. I couldn't find any documentation on `spark.executor.id`, but I
assume there wouldn't be duplicates. And even if there are duplicates, I don't
think logging them will harm anything.
##########
File path:
runners/spark/src/main/java/org/apache/beam/runners/spark/metrics/SparkBeamMetric.java
##########
@@ -38,13 +38,11 @@
/**
* An adapter between the {@link MetricsContainerStepMap} and Codahale's
{@link Metric} interface.
*/
-class SparkBeamMetric implements Metric {
+public class SparkBeamMetric implements Metric {
private static final String ILLEGAL_CHARACTERS = "[^A-Za-z0-9-]";
- Map<String, ?> renderAll() {
+ public static Map<String, ?> renderAll(MetricResults metricResults) {
Review comment:
This method doesn't need to be public.
##########
File path:
runners/spark/src/main/java/org/apache/beam/runners/spark/SparkPipelineRunner.java
##########
@@ -123,10 +135,66 @@ public PortablePipelineResult run(RunnerApi.Pipeline
pipeline, JobInfo jobInfo)
"Will stage {} files. (Enable logging at DEBUG level to see which
files will be staged.)",
pipelineOptions.getFilesToStage().size());
LOG.debug("Staging files: {}", pipelineOptions.getFilesToStage());
-
PortablePipelineResult result;
final JavaSparkContext jsc =
SparkContextFactory.getSparkContext(pipelineOptions);
+ EventLoggingListener eventLoggingListener = null;
+ if (pipelineOptions.getEventLogEnabled()) {
+ eventLoggingListener =
+ new EventLoggingListener(
+ jobInfo.jobId(),
+ new scala.Option<String>() {
Review comment:
This can all be replaced with `scala.Option.apply(jobInfo.jobName())`
(and similar for other instances of scala.Option).
##########
File path:
runners/spark/src/main/java/org/apache/beam/runners/spark/SparkPipelineRunner.java
##########
@@ -123,10 +135,66 @@ public PortablePipelineResult run(RunnerApi.Pipeline
pipeline, JobInfo jobInfo)
"Will stage {} files. (Enable logging at DEBUG level to see which
files will be staged.)",
pipelineOptions.getFilesToStage().size());
LOG.debug("Staging files: {}", pipelineOptions.getFilesToStage());
-
PortablePipelineResult result;
final JavaSparkContext jsc =
SparkContextFactory.getSparkContext(pipelineOptions);
+ EventLoggingListener eventLoggingListener = null;
+ if (pipelineOptions.getEventLogEnabled()) {
+ eventLoggingListener =
+ new EventLoggingListener(
+ jobInfo.jobId(),
+ new scala.Option<String>() {
+ @Override
+ public boolean isEmpty() {
+ return false;
+ }
+
+ @Override
+ public String get() {
+ return jobInfo.jobName();
+ }
+
+ @Override
+ public Object productElement(int i) {
+ return null;
+ }
+
+ @Override
+ public int productArity() {
+ return 0;
+ }
+
+ @Override
+ public boolean canEqual(Object o) {
+ return false;
+ }
+ },
+ new URI(pipelineOptions.getSparkHistoryDir()),
+ jsc.getConf(),
+ jsc.hadoopConfiguration());
+ eventLoggingListener.initializeLogIfNecessary(false, false);
+ eventLoggingListener.start();
+ scala.collection.immutable.Map<String, String> logUrlMap =
+ new scala.collection.immutable.HashMap<String, String>();
+ Tuple2<String, String>[] sparkConfList = jsc.getConf().getAll();
Review comment:
Nit: instead of `getAll`, can you use `getAllWithPrefix("spark.master")`
and `getAllWithPrefix("spark.executor.id")`?
##########
File path: runners/spark/job-server/build.gradle
##########
@@ -73,6 +73,8 @@ runShadow {
args +=
["--clean-artifacts-per-job=${project.property('cleanArtifactsPerJob')}"]
if (project.hasProperty('sparkMasterUrl'))
args += ["--spark-master-url=${project.property('sparkMasterUrl')}"]
+ if (project.hasProperty('sparkHistoryDir'))
Review comment:
I still don't think `--spark-history-dir` or `--event-log-enabled`
should be arguments to the job server. Duplicating pipeline options in the job
server creates complexity without adding benefit.
##########
File path:
runners/spark/src/main/java/org/apache/beam/runners/spark/SparkPipelineRunner.java
##########
@@ -213,6 +301,97 @@ public PortablePipelineResult run(RunnerApi.Pipeline
pipeline, JobInfo jobInfo)
result);
metricsPusher.start();
+ if (eventLoggingListener != null) {
+ eventLoggingListener.onApplicationStart(
+ new SparkListenerApplicationStart(
+ jobId,
+ new scala.Option<String>() {
+ @Override
+ public boolean isEmpty() {
+ return false;
+ }
+
+ @Override
+ public String get() {
+ return jobName;
+ }
+
+ @Override
+ public Object productElement(int i) {
+ return null;
+ }
+
+ @Override
+ public int productArity() {
+ return 0;
+ }
+
+ @Override
+ public boolean canEqual(Object o) {
+ return false;
+ }
+ },
+ startTime,
+ sparkUser,
+ new scala.Option<String>() {
+ @Override
+ public boolean isEmpty() {
+ return false;
+ }
+
+ @Override
+ public String get() {
+ return jobName;
+ }
+
+ @Override
+ public Object productElement(int i) {
+ return null;
+ }
+
+ @Override
+ public int productArity() {
+ return 0;
+ }
+
+ @Override
+ public boolean canEqual(Object o) {
+ return false;
+ }
+ },
+ new scala.Option<Map<String, String>>() {
+ @Override
+ public boolean isEmpty() {
+ return false;
+ }
+
+ @Override
+ public Map<String, String> get() {
+ return JavaConverters.mapAsScalaMapConverter(
+ SparkBeamMetric.renderAll(result.metrics()))
+ .asScala();
+ }
+
+ @Override
+ public Object productElement(int i) {
+ return null;
+ }
+
+ @Override
+ public int productArity() {
+ return 0;
+ }
+
+ @Override
+ public boolean canEqual(Object o) {
+ return false;
+ }
+ }));
+ eventLoggingListener.onApplicationEnd(
+ new SparkListenerApplicationEnd(Instant.now().getMillis()));
Review comment:
I'm not sure, it's not a blocker for this PR though. Thanks for checking.
##########
File path:
runners/spark/src/test/java/org/apache/beam/runners/spark/metrics/SparkBeamMetricTest.java
##########
@@ -35,7 +35,8 @@ public void testRenderName() {
"myStep.one.two(three)", MetricName.named("myNameSpace//",
"myName()")),
123,
456);
- String renderedName = new SparkBeamMetric().renderName(metricResult);
+ new SparkBeamMetric();
Review comment:
Why is instantiating an unused `SparkBeamMetric` necessary?
----------------------------------------------------------------
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]