Skip to content

Commit

Permalink
HBASE-27762 Include EventType and ProcedureV2 pid in logging via MDC (a…
Browse files Browse the repository at this point in the history
…pache#5145)

Signed-off-by: Duo Zhang <[email protected]>
(cherry picked from commit 1d3d900)
Change-Id: Id2271f761dc7e858068d42f46e55a40eda4c5e36
  • Loading branch information
ndimiduk authored and anmolnar committed May 3, 2023
1 parent 05efa70 commit 6edcc14
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 1 deletion.
2 changes: 1 addition & 1 deletion hbase-logging/src/test/resources/log4j.properties
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ log4j.appender.DRFA.layout.ConversionPattern=%d{ISO8601} %-5p [%t] %C{2}(%L): %m
log4j.appender.console=org.apache.log4j.ConsoleAppender
log4j.appender.console.target=System.err
log4j.appender.console.layout=org.apache.log4j.PatternLayout
log4j.appender.console.layout.ConversionPattern=%d{ISO8601} %-5p [%t] %C{2}(%L): %m%n
log4j.appender.console.layout.ConversionPattern=%d{ISO8601} %-5p [%t (%X)] %C{2}(%L): %m%n

# Custom Logging levels

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import org.apache.yetus.audience.InterfaceAudience;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.slf4j.MDC;

/**
* Abstract base class for all HBase event handlers. Subclasses should implement the
Expand Down Expand Up @@ -94,14 +95,18 @@ public EventHandler prepare() throws Exception {

@Override
public void run() {
// assume that this is the top of an execution on a new or reused thread, that we're safe to
// blast any existing MDC state.
Span span = TraceUtil.getGlobalTracer().spanBuilder(getClass().getSimpleName())
.setParent(Context.current().with(parent)).startSpan();
try (Scope scope = span.makeCurrent()) {
MDC.put("event_type", eventType.toString());
process();
} catch (Throwable t) {
handleException(t);
} finally {
span.end();
MDC.clear();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
import org.apache.yetus.audience.InterfaceAudience;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.slf4j.MDC;

import org.apache.hadoop.hbase.shaded.protobuf.generated.RegionServerStatusProtos.RegionStateTransition.TransitionCode;

Expand Down Expand Up @@ -93,6 +94,7 @@ private void cleanUpAndReportFailure(IOException error) throws IOException {

@Override
public void process() throws IOException {
MDC.put("pid", Long.toString(openProcId));
HRegionServer rs = getServer();
String encodedName = regionInfo.getEncodedName();
byte[] encodedNameBytes = regionInfo.getEncodedNameAsBytes();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import org.apache.yetus.audience.InterfaceAudience;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.slf4j.MDC;

/**
* A event handler for running procedure.
Expand All @@ -46,6 +47,7 @@ public RSProcedureHandler(HRegionServer rs, long procId, RSProcedureCallable cal
public void process() {
Throwable error = null;
try {
MDC.put("pid", Long.toString(procId));
callable.call();
} catch (Throwable t) {
LOG.error("pid=" + this.procId, t);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import org.apache.yetus.audience.InterfaceAudience;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.slf4j.MDC;

import org.apache.hadoop.hbase.shaded.protobuf.generated.RegionServerStatusProtos.RegionStateTransition.TransitionCode;

Expand Down Expand Up @@ -86,6 +87,7 @@ private HRegionServer getServer() {

@Override
public void process() throws IOException {
MDC.put("pid", Long.toString(closeProcId));
HRegionServer rs = getServer();
byte[] encodedNameBytes = Bytes.toBytes(encodedName);
Boolean previous = rs.getRegionsInTransitionInRS().putIfAbsent(encodedNameBytes, Boolean.FALSE);
Expand Down

0 comments on commit 6edcc14

Please sign in to comment.