Add logs for GobblinMetrics
Closes from yukuai518/hang
@@ -26,6 +26,7 @@ import java.util.Properties;
import java.util.concurrent.Callable;
import java.util.concurrent.TimeUnit;
+import org.apache.commons.lang.exception.ExceptionUtils;
import org.apache.gobblin.metrics.reporter.FileFailureEventReporter;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FileSystem;
@@ -393,6 +394,7 @@ public class GobblinMetrics {
.getProperty(ConfigurationKeys.METRICS_REPORT_INTERVAL_KEY, ConfigurationKeys.DEFAULT_METRICS_REPORT_INTERVAL));
ScheduledReporter.setReportingInterval(properties, reportInterval, reportTimeUnit);
+ try {
// Build and start the JMX reporter
buildJmxMetricReporter(properties);
if (this.jmxReporter.isPresent()) {
@@ -415,8 +417,13 @@ public class GobblinMetrics {
for (com.codahale.metrics.ScheduledReporter scheduledReporter : this.codahaleScheduledReporters) {
scheduledReporter.start(reportInterval, reportTimeUnit);
}
+ } catch (Exception e) {
+ LOGGER.error("Metrics reporting cannot be started due to {}", ExceptionUtils.getFullStackTrace(e));
+ throw e;
+ }
this.metricsReportingStarted = true;
+ LOGGER.info("Metrics reporting has been started: GobblinMetrics {}", this.hashCode());
}
/**
@@ -428,6 +435,8 @@ public class GobblinMetrics {
return;
}
+ LOGGER.info("Metrics reporting will be stopped: GobblinMetrics {}", this.hashCode());
+
// Stop the JMX reporter
if (this.jmxReporter.isPresent()) {
this.jmxReporter.get().stop();
@@ -446,9 +455,13 @@ public class GobblinMetrics {
this.codahaleReportersCloser.close();
} catch (IOException ioe) {
LOGGER.error("Failed to close metric output stream for job " + this.id, ioe);
+ } catch (Exception e) {
+ LOGGER.error("Failed to close metric output stream for job {} due to {}", this.id, ExceptionUtils.getFullStackTrace(e));
+ throw e;
}
this.metricsReportingStarted = false;
+ LOGGER.info("Metrics reporting stopped successfully");
}
private void buildFileMetricReporter(Properties properties) {
