Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensure JobActor has JobID as part of every emitted log line #384 #408

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@
import java.util.stream.Collectors;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.slf4j.MDC;
import rx.Observable;
import rx.functions.Action1;
import rx.schedulers.Schedulers;
Expand Down Expand Up @@ -600,6 +601,7 @@ private Receive buildInitializedBehavior() {
// UNEXPECTED MESSAGES END //
.match(Terminated.class, this::onTerminated)
.matchAny(x -> {
MDC.put("name", name);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doesn't this make assumptions about the thread context? Will these assumptions be held for Akka actors?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, I didn't consider it. So does it mean it is better to use ActorContext.getLog() to obtain the logger and clear the MDC after processing the current message?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we want to use MDC for this.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems I thought it the wrong way. Thank you for telling me and I will fix it after my busy final.

logger.info("unexpected message '{}' received by JobCluster actor {} in Initialized State."
+ "from class {}", x, this.name, x.getClass().getCanonicalName());
// TODO getSender().tell();
Expand All @@ -613,6 +615,7 @@ MetricGroupId getMetricGroupId(String name) {

@Override
public void preStart() throws Exception {
MDC.put("name", name);
logger.info("JobClusterActor {} started", name);
super.preStart();
}
Expand All @@ -625,17 +628,20 @@ public void postStop() throws Exception {
// de-register metrics from MetricsRegistry
MetricsRegistry.getInstance().remove(getMetricGroupId(name));
}
MDC.remove("name");
}

@Override
public void preRestart(Throwable t, Optional<Object> m) throws Exception {
MDC.put("name", name);
logger.info("{} preRestart {} (exc: {})", name, m, t.getMessage());
// do not kill all children, which is the default here
// super.preRestart(t, m);
}

@Override
public void postRestart(Throwable reason) throws Exception {
MDC.put("name", name);
logger.info("{} postRestart (exc={})", name, reason.getMessage());
super.postRestart(reason);
}
Expand Down Expand Up @@ -672,6 +678,7 @@ private void setExpiredJobsTimer(long checkAgainInSecs) {
@Override
public void onJobClusterInitialize(JobClusterProto.InitializeJobClusterRequest initReq) {
ActorRef sender = getSender();
MDC.put("name", name);
logger.info("In onJobClusterInitialize {}", this.name);
if (logger.isDebugEnabled()) {
logger.debug("Init Request {}", initReq);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@
import java.util.stream.Collectors;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.slf4j.MDC;
import rx.Observable;
import rx.schedulers.Schedulers;
import rx.subjects.BehaviorSubject;
Expand Down Expand Up @@ -236,6 +237,7 @@ MetricGroupId getMetricGroupId(String id) {
* @throws InvalidJobException
*/
void initialize(boolean isSubmit) throws Exception {
MDC.put("jobId", jobId.toString());
LOGGER.info("Initializing Job {}", jobId);

if (isSubmit) {
Expand Down Expand Up @@ -1758,6 +1760,7 @@ public void shutdown() {
jobSchedulingInfoBehaviorSubject.onCompleted();

LOGGER.trace("Exit shutdown for Job {}", jobId);
MDC.remove("jobId");
}

private void terminateAllWorkersAsync() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,6 @@ log4j.rootLogger=INFO, stdout
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.Target=System.out
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%d{ISO8601} %-5p [%t] %c{1}:%L - %m %X{akkaSource}%n
log4j.appender.stdout.layout.ConversionPattern=%d{ISO8601} %X{name} %X{jobId} %-5p [%t] %c{1}:%L - %m %X{akkaSource}%n

log4j.logger.com.netflix.fenzo=INFO