Skip to content

Commit

Permalink
Print the warning if amount of events in incoming queue is too big
Browse files Browse the repository at this point in the history
It should simplify troubleshooting in case of slowness in event
processing logic.
  • Loading branch information
Jimilian committed Jan 23, 2018
1 parent c9d1b4e commit fd6815e
Showing 1 changed file with 20 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,10 @@ public class GerritHandler implements Coordinator, Handler {
private final Set<GerritEventListener> gerritEventListeners = new CopyOnWriteArraySet<GerritEventListener>();
private final List<EventThread> workers;
private Map<String, String> ignoreEMails = new ConcurrentHashMap<String, String>();
/**
* The minimum size of the job-queue before monitors should begin to warn the administrator(s).
*/
public static final int WORK_QUEUE_SIZE_WARNING_THRESHOLD = 40;

/**
* Creates a GerritHandler with all the default values set.
Expand Down Expand Up @@ -177,13 +181,28 @@ private void post(Work work) {
try {
logger.trace("putting work on queue.");
workQueue.put(work);
checkQueueSize();
} catch (InterruptedException ex) {
logger.warn("Interrupted while putting work on queue!", ex);
//TODO check if shutdown
//TODO try again since it is important
}
}

/**
* Checks queue size.
*/
private void checkQueueSize() {
int queueSize = workQueue.size();
if (queueSize >= WORK_QUEUE_SIZE_WARNING_THRESHOLD) {
logger.warn("The Gerrit-trigger incoming events queue contains {} items!"
+ " Something might be stuck, or your system can't process the commands fast enough."
+ " Try to increase the number of receiving worker threads on the Gerrit configuration page."
+ " Current thread-pool size: {}",
queueSize, workers.size());
}
}

@Override
public void addListener(GerritEventListener listener) {
synchronized (this) {
Expand Down Expand Up @@ -372,12 +391,6 @@ public void shutdown(boolean join) {
*/
@Deprecated
public void triggerEvent(GerritEvent event) {
logger.debug("Internally trigger event: {}", event);
try {
logger.trace("putting work on queue.");
workQueue.put(new GerritEventWork(event));
} catch (InterruptedException ex) {
logger.error("Interrupted while putting work on queue!", ex);
}
post(event);
}
}

0 comments on commit fd6815e

Please sign in to comment.