diff --git a/common/src/java/org/apache/hadoop/hive/conf/HiveConf.java b/common/src/java/org/apache/hadoop/hive/conf/HiveConf.java index 90e9b2b7094b..47368c397660 100644 --- a/common/src/java/org/apache/hadoop/hive/conf/HiveConf.java +++ b/common/src/java/org/apache/hadoop/hive/conf/HiveConf.java @@ -5759,7 +5759,10 @@ public static enum ConfVars { HIVE_OTEL_RETRY_BACKOFF_MULTIPLIER("hive.otel.retry.backoff.multiplier", 5f, "The multiplier applied to the backoff interval for retries in the OTEL exporter." - + "This determines how much the backoff interval increases after each failed attempt, following an exponential backoff strategy."); + + "This determines how much the backoff interval increases after each failed attempt, following an exponential backoff strategy."), + + HIVE_OTEL_EXPOSE_TEZ_COUNTERS("hive.otel.expose.tez.counters", false, + "Enables the inclusion of Tez counters in OTEL output for a particular query. Default is false."); public final String varname; public final String altName; diff --git a/ql/src/java/org/apache/hadoop/hive/ql/Driver.java b/ql/src/java/org/apache/hadoop/hive/ql/Driver.java index 4ad2c82c5686..18973b4413e6 100644 --- a/ql/src/java/org/apache/hadoop/hive/ql/Driver.java +++ b/ql/src/java/org/apache/hadoop/hive/ql/Driver.java @@ -203,7 +203,10 @@ private void runInternal(String command, boolean alreadyCompiled) throws Command driverContext.getQueryDisplay().setPerfLogStarts(QueryDisplay.Phase.EXECUTION, perfLogger.getStartTimes()); driverContext.getQueryDisplay().setPerfLogEnds(QueryDisplay.Phase.EXECUTION, perfLogger.getEndTimes()); - + if (driverContext.getRuntimeContext() != null && + driverContext.getConf().getBoolVar(HiveConf.ConfVars.HIVE_OTEL_EXPOSE_TEZ_COUNTERS)) { + driverContext.getQueryDisplay().setTezCounters(driverContext.getRuntimeContext().getCounters()); + } runPostDriverHooks(hookContext); isFinishedWithError = false; } finally { diff --git a/ql/src/java/org/apache/hadoop/hive/ql/QueryDisplay.java b/ql/src/java/org/apache/hadoop/hive/ql/QueryDisplay.java index 35eccd2909a1..6dc41c6c2432 100644 --- a/ql/src/java/org/apache/hadoop/hive/ql/QueryDisplay.java +++ b/ql/src/java/org/apache/hadoop/hive/ql/QueryDisplay.java @@ -21,6 +21,9 @@ import org.apache.hadoop.hive.ql.exec.Task; import org.apache.hadoop.hive.ql.exec.TaskResult; import org.apache.hadoop.hive.ql.plan.api.StageType; +import org.apache.tez.common.counters.CounterGroup; +import org.apache.tez.common.counters.TezCounter; +import org.apache.tez.common.counters.TezCounters; import java.io.IOException; import java.util.*; @@ -58,6 +61,7 @@ public class QueryDisplay { private String explainPlan; private String errorMessage; private String queryId; + private TezCounters tezCounters; private long queryStartTime = System.currentTimeMillis(); private final Map> hmsTimingMap = new HashMap>(); @@ -305,6 +309,26 @@ public synchronized void setExplainPlan(String explainPlan) { this.explainPlan = explainPlan; } + public synchronized void setTezCounters(TezCounters tc) { + this.tezCounters = tc; + } + + public synchronized TezCounters getTezCounters() { + return this.tezCounters; + } + + public synchronized String getCountersAsString() { + JSONObject countersJson = new JSONObject(); + if (tezCounters != null){ + for (CounterGroup group : tezCounters) { + for (TezCounter counter : group) { + countersJson.put(group.getName() + " - " + counter.getDisplayName(), counter.getValue()); + } + } + } + return countersJson.toString(); + } + /** * @param phase phase of query * @return map of HMS Client method-calls and duration in milliseconds, during given phase. diff --git a/service/src/java/org/apache/hive/service/servlet/OTELExporter.java b/service/src/java/org/apache/hive/service/servlet/OTELExporter.java index 1fb53715ed0a..b5138e997725 100644 --- a/service/src/java/org/apache/hive/service/servlet/OTELExporter.java +++ b/service/src/java/org/apache/hive/service/servlet/OTELExporter.java @@ -214,6 +214,7 @@ private AttributesMap addQueryAttributes(QueryInfo query){ attributes.put(AttributeKey.stringKey("UserName"), query.getUserName()); attributes.put(AttributeKey.stringKey("State"), query.getState()); attributes.put(AttributeKey.stringKey("SessionId"), query.getSessionId()); + attributes.put(AttributeKey.stringKey("TezCounters"), query.getQueryDisplay().getCountersAsString()); return attributes; }