Skip to content

Commit

Permalink
Add support for worker pool drain timeout
Browse files Browse the repository at this point in the history
This surfaces the functionality introduced in stevespringett/Alpine#508 to Dependency-Track. It was previously only integrated into Hyades.

Signed-off-by: nscuro <nscuro@protonmail.com>
  • Loading branch information
nscuro committed Apr 29, 2024
1 parent 8a5aee4 commit 7d28a1a
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 5 deletions.
7 changes: 7 additions & 0 deletions docs/_docs/getting-started/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,13 @@ alpine.worker.threads=0
# 16 worker threads. Default value is 4.
alpine.worker.thread.multiplier=4

# Required
# Defines the maximum duration for which Dependency-Track will wait for queued
# events and notifications to be processed when shutting down.
# During shutdown, newly dispatched events will not be accepted.
# The duration must be specified in ISO 8601 notation (https://en.wikipedia.org/wiki/ISO_8601#Durations).
alpine.worker.pool.drain.timeout.duration=PT5S

# Required
# Defines the path to the data directory. This directory will hold logs, keys,
# and any database or index files along with application-specific files or
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/org/dependencytrack/common/ConfigKey.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ public enum ConfigKey implements Config.Key {
REPO_META_ANALYZER_CACHE_STAMPEDE_BLOCKER_ENABLED("repo.meta.analyzer.cacheStampedeBlocker.enabled", true),
REPO_META_ANALYZER_CACHE_STAMPEDE_BLOCKER_LOCK_BUCKETS("repo.meta.analyzer.cacheStampedeBlocker.lock.buckets", 1000),
REPO_META_ANALYZER_CACHE_STAMPEDE_BLOCKER_MAX_ATTEMPTS("repo.meta.analyzer.cacheStampedeBlocker.max.attempts", 10),
SYSTEM_REQUIREMENT_CHECK_ENABLED("system.requirement.check.enabled", true);
SYSTEM_REQUIREMENT_CHECK_ENABLED("system.requirement.check.enabled", true),
ALPINE_WORKER_POOL_DRAIN_TIMEOUT_DURATION("alpine.worker.pool.drain.timeout.duration", "PT5S");

private final String propertyName;
private final Object defaultValue;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,14 @@
*/
package org.dependencytrack.event;

import alpine.Config;
import alpine.common.logging.Logger;
import alpine.event.LdapSyncEvent;
import alpine.event.framework.EventService;
import alpine.event.framework.SingleThreadedEventService;
import alpine.server.tasks.LdapSyncTask;
import org.dependencytrack.RequirementsVerifier;
import org.dependencytrack.common.ConfigKey;
import org.dependencytrack.tasks.BomUploadProcessingTaskV2;
import org.dependencytrack.tasks.CallbackTask;
import org.dependencytrack.tasks.ClearComponentAnalysisCacheTask;
Expand Down Expand Up @@ -57,6 +59,7 @@

import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
import java.time.Duration;

/**
* Initializes the event subsystem and configures event subscribers.
Expand All @@ -74,6 +77,9 @@ public class EventSubsystemInitializer implements ServletContextListener {
// Starts the SingleThreadedEventService
private static final SingleThreadedEventService EVENT_SERVICE_ST = SingleThreadedEventService.getInstance();

private static final Duration DRAIN_TIMEOUT_DURATION =
Duration.parse(Config.getInstance().getProperty(ConfigKey.ALPINE_WORKER_POOL_DRAIN_TIMEOUT_DURATION));

/**
* {@inheritDoc}
*/
Expand Down Expand Up @@ -129,7 +135,6 @@ public void contextDestroyed(final ServletContextEvent event) {
LOGGER.info("Shutting down asynchronous event subsystem");
TaskScheduler.getInstance().shutdown();


EVENT_SERVICE.unsubscribe(BomUploadProcessingTaskV2.class);
EVENT_SERVICE.unsubscribe(VexUploadProcessingTask.class);
EVENT_SERVICE.unsubscribe(LdapSyncTask.class);
Expand Down Expand Up @@ -158,9 +163,9 @@ public void contextDestroyed(final ServletContextEvent event) {
EVENT_SERVICE.unsubscribe(NistMirrorTask.class);
EVENT_SERVICE.unsubscribe(NistApiMirrorTask.class);
EVENT_SERVICE.unsubscribe(EpssMirrorTask.class);
EVENT_SERVICE.shutdown();
EVENT_SERVICE.shutdown(DRAIN_TIMEOUT_DURATION);

EVENT_SERVICE_ST.unsubscribe(IndexTask.class);
EVENT_SERVICE_ST.shutdown();
EVENT_SERVICE_ST.shutdown(DRAIN_TIMEOUT_DURATION);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,16 @@
*/
package org.dependencytrack.notification;

import alpine.Config;
import alpine.common.logging.Logger;
import alpine.notification.NotificationService;
import alpine.notification.Subscription;
import org.dependencytrack.RequirementsVerifier;
import org.dependencytrack.common.ConfigKey;

import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
import java.time.Duration;

/**
* Initializes the notification subsystem and configures the notification router
Expand All @@ -39,6 +42,9 @@ public class NotificationSubsystemInitializer implements ServletContextListener
// Starts the NotificationService
private static final NotificationService NOTIFICATION_SERVICE = NotificationService.getInstance();

private static final Duration DRAIN_TIMEOUT_DURATION =
Duration.parse(Config.getInstance().getProperty(ConfigKey.ALPINE_WORKER_POOL_DRAIN_TIMEOUT_DURATION));

/**
* {@inheritDoc}
*/
Expand All @@ -57,6 +63,6 @@ public void contextInitialized(final ServletContextEvent event) {
@Override
public void contextDestroyed(final ServletContextEvent event) {
LOGGER.info("Shutting down notification service");
NOTIFICATION_SERVICE.shutdown();
NOTIFICATION_SERVICE.shutdown(DRAIN_TIMEOUT_DURATION);
}
}
7 changes: 7 additions & 0 deletions src/main/resources/application.properties
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,13 @@ alpine.worker.threads=0
# 16 worker threads. Default value is 4.
alpine.worker.thread.multiplier=4

# Required
# Defines the maximum duration for which Dependency-Track will wait for queued
# events and notifications to be processed when shutting down.
# During shutdown, newly dispatched events will not be accepted.
# The duration must be specified in ISO 8601 notation (https://en.wikipedia.org/wiki/ISO_8601#Durations).
alpine.worker.pool.drain.timeout.duration=PT5S

# Required
# Defines the path to the data directory. This directory will hold logs,
# keys, and any database or index files along with application-specific
Expand Down

0 comments on commit 7d28a1a

Please sign in to comment.