[
https://issues.apache.org/jira/browse/BEAM-11213?focusedWorklogId=543088&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-543088
]
ASF GitHub Bot logged work on BEAM-11213:
-----------------------------------------
Author: ASF GitHub Bot
Created on: 27/Jan/21 21:25
Start Date: 27/Jan/21 21:25
Worklog Time Spent: 10m
Work Description: 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]
Issue Time Tracking
-------------------
Worklog Id: (was: 543088)
Time Spent: 4h 50m (was: 4h 40m)
> Beam metrics should be displayed in Spark UI
> --------------------------------------------
>
> Key: BEAM-11213
> URL: https://issues.apache.org/jira/browse/BEAM-11213
> Project: Beam
> Issue Type: Wish
> Components: runner-spark
> Reporter: Kyle Weaver
> Assignee: Tomasz Szerszen
> Priority: P2
> Labels: portability-spark
> Time Spent: 4h 50m
> Remaining Estimate: 0h
>
> All Beam metrics are visible in the Spark UI in a single accumulator value
> (in the "Accumulators" tab), which is a large, hard-to-read blob. Originally,
> this blob was rendered in a bespoke format
> (https://github.com/apache/beam/blob/ead80b469ffeeddcd8e9e5c8dc462eec0b0ffc6b/sdks/java/core/src/main/java/org/apache/beam/sdk/metrics/MetricQueryResults.java#L63-L72).
> I changed the format to JSON so it could be easily deserialized (BEAM-9600).
> But then an issue was filed (BEAM-10294) reporting that the new JSON format
> was harder to read than the original bespoke format. The temporary fix was to
> revert to the bespoke format in Spark, while allowing Flink to continue to
> use JSON. However, if Beam metrics are only visible as an accumulator, then
> they are also unreadable because the payloads are in binary form (BEAM-10719).
> Having metrics visible in Spark's "Metrics" tab would A) make metrics easier
> to read (even compared to the bespoke accumulator string format), and closer
> to what users of Beamless Spark expect, and B) free us to use the accumulator
> however we wish for Beam internal purposes, without worrying about
> readability.
--
This message was sent by Atlassian Jira
(v8.3.4#803005)