This is an automated email from the ASF dual-hosted git repository.
sarath pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/atlas.git
The following commit(s) were added to refs/heads/master by this push:
new 5389b9b ATLAS-3147: added periodic logging of stats
5389b9b is described below
commit 5389b9bd3c9dd4bfbd1fbd881a6b4fc5fd7788cc
Author: Madhan Neethiraj <[email protected]>
AuthorDate: Wed Apr 17 17:05:05 2019 -0700
ATLAS-3147: added periodic logging of stats
Signed-off-by: Sarath Subramanian <[email protected]>
---
.../org/apache/atlas/util/AtlasMetricsCounter.java | 59 ++++++++++++----------
.../notification/NotificationHookConsumer.java | 12 +++++
2 files changed, 45 insertions(+), 26 deletions(-)
diff --git
a/repository/src/main/java/org/apache/atlas/util/AtlasMetricsCounter.java
b/repository/src/main/java/org/apache/atlas/util/AtlasMetricsCounter.java
index acf9e34..d5a4412 100644
--- a/repository/src/main/java/org/apache/atlas/util/AtlasMetricsCounter.java
+++ b/repository/src/main/java/org/apache/atlas/util/AtlasMetricsCounter.java
@@ -105,43 +105,50 @@ public class AtlasMetricsCounter {
updateForTime(clock.instant());
}
- protected void updateForTime(Instant instant) {
- if (instant.isAfter(dayEndTime)) {
- rolloverDay(instant);
- rolloverHour(instant);
- } else if (instant.isAfter(hourEndTime)) {
- rolloverHour(instant);
+ protected void updateForTime(Instant now) {
+ Instant dayEndTime = this.dayEndTime;
+ Instant hourEndTime = this.hourEndTime;
+
+ if (now.isAfter(dayEndTime)) {
+ rolloverDay(dayEndTime, now);
+ rolloverHour(hourEndTime, now);
+ } else if (now.isAfter(hourEndTime)) {
+ rolloverHour(hourEndTime, now);
}
}
- protected void rolloverDay(Instant instant) {
- Instant dayStartTime = getDayStartTime(instant);
+ protected synchronized void rolloverDay(Instant fromDayEndTime, Instant
now) {
+ if (fromDayEndTime == dayEndTime) { // only if rollover was not done
already
+ Instant dayStartTime = getDayStartTime(now);
- if (dayStartTime.equals(dayEndTime)) {
- stats.copy(CURR_DAY, PREV_DAY);
- } else {
- stats.reset(PREV_DAY);
- }
+ if (dayStartTime.equals(dayEndTime)) {
+ stats.copy(CURR_DAY, PREV_DAY);
+ } else {
+ stats.reset(PREV_DAY);
+ }
- stats.reset(CURR_DAY);
+ stats.reset(CURR_DAY);
- this.dayStartTime = dayStartTime;
- this.dayEndTime = getNextDayStartTime(instant);
+ this.dayStartTime = dayStartTime;
+ this.dayEndTime = getNextDayStartTime(now);
+ }
}
- protected void rolloverHour(Instant instant) {
- Instant hourStartTime = getHourStartTime(instant);
+ protected synchronized void rolloverHour(Instant fromHourEndTime, Instant
now) {
+ if (fromHourEndTime == hourEndTime) { // only if rollover was not done
already
+ Instant hourStartTime = getHourStartTime(now);
- if (hourStartTime.equals(hourEndTime)) {
- stats.copy(CURR_HOUR, PREV_HOUR);
- } else {
- stats.reset(PREV_HOUR);
- }
+ if (hourStartTime.equals(hourEndTime)) {
+ stats.copy(CURR_HOUR, PREV_HOUR);
+ } else {
+ stats.reset(PREV_HOUR);
+ }
- stats.reset(CURR_HOUR);
+ stats.reset(CURR_HOUR);
- this.hourStartTime = hourStartTime;
- this.hourEndTime = getNextHourStartTime(instant);
+ this.hourStartTime = hourStartTime;
+ this.hourEndTime = getNextHourStartTime(now);
+ }
}
public static LocalDateTime getLocalDateTime(Instant instant) {
diff --git
a/webapp/src/main/java/org/apache/atlas/notification/NotificationHookConsumer.java
b/webapp/src/main/java/org/apache/atlas/notification/NotificationHookConsumer.java
index fcfbd21..1f8e810 100644
---
a/webapp/src/main/java/org/apache/atlas/notification/NotificationHookConsumer.java
+++
b/webapp/src/main/java/org/apache/atlas/notification/NotificationHookConsumer.java
@@ -46,6 +46,8 @@ import
org.apache.atlas.notification.NotificationInterface.NotificationType;
import org.apache.atlas.notification.preprocessor.EntityPreprocessor;
import org.apache.atlas.notification.preprocessor.PreprocessorContext;
import
org.apache.atlas.notification.preprocessor.PreprocessorContext.PreprocessAction;
+import org.apache.atlas.util.AtlasMetricsCounter;
+import org.apache.atlas.utils.AtlasJson;
import org.apache.atlas.utils.LruCache;
import org.apache.atlas.util.AtlasMetricsUtil;
import org.apache.atlas.util.AtlasMetricsUtil.NotificationStat;
@@ -78,6 +80,7 @@ import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;
import javax.inject.Inject;
+import java.time.Instant;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
@@ -160,6 +163,7 @@ public class NotificationHookConsumer implements Service,
ActiveStateChangeHandl
private final NotificationInterface notificationInterface;
private final Configuration applicationProperties;
private ExecutorService executors;
+ private Instant nextStatsLogTime =
AtlasMetricsCounter.getNextHourStartTime(Instant.now());
@VisibleForTesting
final int consumerRetryInterval;
@@ -712,6 +716,14 @@ public class NotificationHookConsumer implements Service,
ActiveStateChangeHandl
AuditFilter.audit(auditLog);
}
+
+ Instant now = Instant.now();
+
+ if (now.isAfter(nextStatsLogTime)) {
+ LOG.info("STATS: {}",
AtlasJson.toJson(metricsUtil.getStats()));
+
+ nextStatsLogTime =
AtlasMetricsCounter.getNextHourStartTime(now);
+ }
}
}