You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@beam.apache.org by GitBox <gi...@apache.org> on 2021/07/14 17:54:25 UTC
[GitHub] [beam] ajamato commented on a change in pull request #15166: [BEAM-12611] Populate instruction in LogEntry in Java SDK.
ajamato commented on a change in pull request #15166:
URL: https://github.com/apache/beam/pull/15166#discussion_r669806370
##########
File path: sdks/java/harness/src/main/java/org/apache/beam/fn/harness/logging/BeamFnLoggingClient.java
##########
@@ -211,6 +211,11 @@ public void publish(LogRecord record) {
.setSeconds(record.getMillis() / 1000)
.setNanos((int) (record.getMillis() % 1000) * 1_000_000));
+ String instructionId = BeamFnLoggingMDC.getInstructionId();
+ if (!Strings.isNullOrEmpty(instructionId)) {
+ builder.setInstructionId(instructionId);
+ }
Review comment:
Done
##########
File path: sdks/java/harness/src/test/java/org/apache/beam/fn/harness/logging/BeamFnLoggingClientTest.java
##########
@@ -78,6 +78,7 @@
Review comment:
Done. created RestoreBeamFnLoggingMDC and RestoreBeamFnLoggingMDCTest
##########
File path: sdks/java/harness/src/main/java/org/apache/beam/fn/harness/logging/BeamFnLoggingMDC.java
##########
@@ -0,0 +1,37 @@
+/*
+ * 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.beam.fn.harness.logging;
+
+/** Mapped diagnostic context to be consumed and set on LogEntry protos in BeamFnLoggingClient. */
+@SuppressWarnings({
+ "nullness" // TODO(https://issues.apache.org/jira/browse/BEAM-10402)
Review comment:
Done
##########
File path: sdks/java/harness/src/main/java/org/apache/beam/fn/harness/control/ProcessBundleHandler.java
##########
@@ -310,6 +311,9 @@ private void createRunnerAndConsumersForPTransformRecursively(
}
});
try {
+ if (!request.getInstructionId().isEmpty()) {
+ BeamFnLoggingMDC.setInstructionId(request.getInstructionId());
+ }
Review comment:
Done
##########
File path: sdks/java/harness/src/main/java/org/apache/beam/fn/harness/logging/BeamFnLoggingMDC.java
##########
@@ -0,0 +1,37 @@
+/*
+ * 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.beam.fn.harness.logging;
+
+/** Mapped diagnostic context to be consumed and set on LogEntry protos in BeamFnLoggingClient. */
+@SuppressWarnings({
+ "nullness" // TODO(https://issues.apache.org/jira/browse/BEAM-10402)
+})
+public class BeamFnLoggingMDC {
+ private static final InheritableThreadLocal<String> instructionId =
+ new InheritableThreadLocal<>();
Review comment:
Makes sense. Done
##########
File path: sdks/java/harness/src/main/java/org/apache/beam/fn/harness/control/ProcessBundleHandler.java
##########
@@ -362,8 +366,11 @@ private void createRunnerAndConsumersForPTransformRecursively(
return BeamFnApi.InstructionResponse.newBuilder().setProcessBundle(response);
} catch (Exception e) {
// Make sure we clean-up from the active set of bundle processors.
+ BeamFnLoggingMDC.setInstructionId("");
bundleProcessorCache.discard(bundleProcessor);
throw e;
+ } finally {
+ BeamFnLoggingMDC.setInstructionId("");
Review comment:
Applied suggestion. But I had a concern, which is why I didn't initially do this.
I don't think this it is true that finally will be called in all cases.
Such as if an exception is thrown from the catch block (which we do here), and the thrown exception is not handled further up the stack. (Though I suppose we would crash the program entirely? Or could the thread somehow revive).
https://stackoverflow.com/questions/1555567/when-is-finally-run-if-you-throw-an-exception-from-the-catch-block/1555578
Am I wrong? Do we need to be concerned about this scenario?
--
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.
To unsubscribe, e-mail: github-unsubscribe@beam.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org