Skip to content

Commit 4c5bd12

Browse files
mehakmeetdeepakdamri
authored andcommitted
HADOOP-17670. S3AFS and ABFS to log IOStats at DEBUG mode or optionally at INFO level in close() (apache#2963)
When the S3A and ABFS filesystems are closed, their IOStatistics are logged at debug in the log: org.apache.hadoop.fs.statistics.IOStatisticsLogging Set `fs.iostatistics.logging.level` to `info` for the statistics to be logged at info. (also: `warn` or `error` for even higher log levels). Contributed by: Mehakmeet Singh Change-Id: I56d44ad89fc1c0dd4baf701681834e7fd96c544f
1 parent e9ae2bd commit 4c5bd12

File tree

2 files changed

+85
-2
lines changed

2 files changed

+85
-2
lines changed

hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/CommonConfigurationKeys.java

Lines changed: 54 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,7 @@ public class CommonConfigurationKeys extends CommonConfigurationKeysPublic {
255255
/**
256256
* HA health monitor and failover controller.
257257
*/
258-
258+
259259
/** How often to retry connecting to the service. */
260260
public static final String HA_HM_CONNECT_RETRY_INTERVAL_KEY =
261261
"ha.health-monitor.connect-retry-interval.ms";
@@ -270,7 +270,7 @@ public class CommonConfigurationKeys extends CommonConfigurationKeysPublic {
270270
public static final String HA_HM_SLEEP_AFTER_DISCONNECT_KEY =
271271
"ha.health-monitor.sleep-after-disconnect.ms";
272272
public static final long HA_HM_SLEEP_AFTER_DISCONNECT_DEFAULT = 1000;
273-
273+
274274
/* Timeout for the actual monitorHealth() calls. */
275275
public static final String HA_HM_RPC_TIMEOUT_KEY =
276276
"ha.health-monitor.rpc-timeout.ms";
@@ -394,4 +394,56 @@ public class CommonConfigurationKeys extends CommonConfigurationKeysPublic {
394394
public static final String ZK_RETRY_INTERVAL_MS =
395395
ZK_PREFIX + "retry-interval-ms";
396396
public static final int ZK_RETRY_INTERVAL_MS_DEFAULT = 1000;
397+
/** Default domain name resolver for hadoop to use. */
398+
public static final String HADOOP_DOMAINNAME_RESOLVER_IMPL =
399+
"hadoop.domainname.resolver.impl";
400+
public static final Class<? extends DomainNameResolver>
401+
HADOOP_DOMAINNAME_RESOLVER_IMPL_DEFAULT =
402+
DNSDomainNameResolver.class;
403+
/*
404+
* Ignore KMS default URI returned from NameNode.
405+
* When set to true, kms uri is searched in the following order:
406+
* 1. If there is a mapping in Credential's secrets map for namenode uri.
407+
* 2. Fallback to local conf.
408+
* If client choose to ignore KMS uri provided by NameNode then client
409+
* should set KMS URI using 'hadoop.security.key.provider.path' to access
410+
* the right KMS for encrypted files.
411+
* */
412+
public static final String DFS_CLIENT_IGNORE_NAMENODE_DEFAULT_KMS_URI =
413+
"dfs.client.ignore.namenode.default.kms.uri";
414+
public static final boolean
415+
DFS_CLIENT_IGNORE_NAMENODE_DEFAULT_KMS_URI_DEFAULT = false;
416+
417+
/**
418+
* Whether or not ThreadMXBean is used for getting thread info in JvmMetrics,
419+
* ThreadGroup approach is preferred for better performance.
420+
*/
421+
public static final String HADOOP_METRICS_JVM_USE_THREAD_MXBEAN =
422+
"hadoop.metrics.jvm.use-thread-mxbean";
423+
public static final boolean HADOOP_METRICS_JVM_USE_THREAD_MXBEAN_DEFAULT =
424+
false;
425+
426+
/** logging level for IOStatistics (debug or info). */
427+
public static final String IOSTATISTICS_LOGGING_LEVEL
428+
= "fs.iostatistics.logging.level";
429+
430+
/** DEBUG logging level for IOStatistics logging. */
431+
public static final String IOSTATISTICS_LOGGING_LEVEL_DEBUG
432+
= "debug";
433+
434+
/** WARN logging level for IOStatistics logging. */
435+
public static final String IOSTATISTICS_LOGGING_LEVEL_WARN
436+
= "warn";
437+
438+
/** ERROR logging level for IOStatistics logging. */
439+
public static final String IOSTATISTICS_LOGGING_LEVEL_ERROR
440+
= "error";
441+
442+
/** INFO logging level for IOStatistics logging. */
443+
public static final String IOSTATISTICS_LOGGING_LEVEL_INFO
444+
= "info";
445+
446+
/** Default value for IOStatistics logging level. */
447+
public static final String IOSTATISTICS_LOGGING_LEVEL_DEFAULT
448+
= IOSTATISTICS_LOGGING_LEVEL_DEBUG;
397449
}

hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/statistics/IOStatisticsLogging.java

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
package org.apache.hadoop.fs.statistics;
2020

2121
import javax.annotation.Nullable;
22+
import java.util.Locale;
2223
import java.util.Map;
2324
import java.util.TreeMap;
2425
import java.util.function.Predicate;
@@ -30,6 +31,9 @@
3031
import org.apache.hadoop.classification.InterfaceStability;
3132
import org.apache.hadoop.fs.statistics.impl.IOStatisticsBinding;
3233

34+
import static org.apache.hadoop.fs.CommonConfigurationKeys.IOSTATISTICS_LOGGING_LEVEL_ERROR;
35+
import static org.apache.hadoop.fs.CommonConfigurationKeys.IOSTATISTICS_LOGGING_LEVEL_INFO;
36+
import static org.apache.hadoop.fs.CommonConfigurationKeys.IOSTATISTICS_LOGGING_LEVEL_WARN;
3337
import static org.apache.hadoop.fs.statistics.IOStatisticsSupport.retrieveIOStatistics;
3438

3539
/**
@@ -249,6 +253,33 @@ public static void logIOStatisticsAtDebug(
249253
logIOStatisticsAtDebug(LOG, message, source);
250254
}
251255

256+
/**
257+
* A method to log IOStatistics from a source at different levels.
258+
*
259+
* @param log Logger for logging.
260+
* @param level LOG level.
261+
* @param source Source to LOG.
262+
*/
263+
public static void logIOStatisticsAtLevel(Logger log, String level,
264+
Object source) {
265+
IOStatistics stats = retrieveIOStatistics(source);
266+
if (stats != null) {
267+
switch (level.toLowerCase(Locale.US)) {
268+
case IOSTATISTICS_LOGGING_LEVEL_INFO:
269+
LOG.info("IOStatistics: {}", ioStatisticsToPrettyString(stats));
270+
break;
271+
case IOSTATISTICS_LOGGING_LEVEL_ERROR:
272+
LOG.error("IOStatistics: {}", ioStatisticsToPrettyString(stats));
273+
break;
274+
case IOSTATISTICS_LOGGING_LEVEL_WARN:
275+
LOG.warn("IOStatistics: {}", ioStatisticsToPrettyString(stats));
276+
break;
277+
default:
278+
logIOStatisticsAtDebug(log, "IOStatistics: {}", source);
279+
}
280+
}
281+
}
282+
252283
/**
253284
* On demand stringifier.
254285
* <p>

0 commit comments

Comments
 (0)