diff --git a/docs/docs/configuration/inactive-topics-detection.md b/docs/docs/configuration/inactive-topics-detection.md index 4df54961c6..3a294efd63 100644 --- a/docs/docs/configuration/inactive-topics-detection.md +++ b/docs/docs/configuration/inactive-topics-detection.md @@ -9,13 +9,18 @@ and configure other options in the Hermes Management configuration. detection.inactive-topics.enabled | enable inactive topics detection | false detection.inactive-topics.inactivity-threshold | duration after which a topic is considered inactive and first notified | 60d detection.inactive-topics.next-notification-threshold | duration after previous notification after which a topic is notified again | 14d - detection.inactive-topics.whitelisted-qualified-topic-names | list of qualified topic names that will not be notified event if inactive | [] - detection.inactive-topics.leader-election-zookeeper-dc | datacenter of Zookeeper used for leader election for the detection job | dc + detection.inactive-topics.whitelisted-qualified-topic-names | list of qualified topic names that will not be notified event if inactive | [] detection.inactive-topics.cron | cron expression for the detection job | 0 0 8 * * * detection.inactive-topics.notifications-history-limit | how many notification timestamps will be kept in history | 5 The detection job runs on a single instance of Hermes Management that is a leader based on the leader election Zookeeper instance. +| Option | Description | Default Value | +|-------------------------------------|----------------------------------------------------------------------------|---------------| +| management.leadership.zookeeper-dc | Specifies the datacenter of the Zookeeper instance used for leader election in the detection job | dc | + + + To make notifying work, you need to provide an implementation of `pl.allegro.tech.hermes.management.domain.detection.InactiveTopicsNotifier` diff --git a/hermes-management/src/main/java/pl/allegro/tech/hermes/management/config/ManagementConfiguration.java b/hermes-management/src/main/java/pl/allegro/tech/hermes/management/config/ManagementConfiguration.java index 93139d4803..91f35988d7 100644 --- a/hermes-management/src/main/java/pl/allegro/tech/hermes/management/config/ManagementConfiguration.java +++ b/hermes-management/src/main/java/pl/allegro/tech/hermes/management/config/ManagementConfiguration.java @@ -10,6 +10,7 @@ import io.micrometer.core.instrument.MeterRegistry; import java.time.Clock; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; import org.springframework.boot.context.properties.EnableConfigurationProperties; import org.springframework.context.annotation.Bean; @@ -19,8 +20,11 @@ import pl.allegro.tech.hermes.common.metric.MetricsFacade; import pl.allegro.tech.hermes.common.util.InetAddressInstanceIdResolver; import pl.allegro.tech.hermes.common.util.InstanceIdResolver; +import pl.allegro.tech.hermes.infrastructure.zookeeper.ZookeeperPaths; import pl.allegro.tech.hermes.management.domain.subscription.SubscriptionLagSource; +import pl.allegro.tech.hermes.management.infrastructure.leader.ManagementLeadership; import pl.allegro.tech.hermes.management.infrastructure.metrics.NoOpSubscriptionLagSource; +import pl.allegro.tech.hermes.management.infrastructure.zookeeper.ZookeeperClientManager; import pl.allegro.tech.hermes.metrics.PathsCompiler; @Configuration @@ -29,7 +33,7 @@ HttpClientProperties.class, ConsistencyCheckerProperties.class, PrometheusProperties.class, - MicrometerRegistryProperties.class + MicrometerRegistryProperties.class, }) public class ManagementConfiguration { @@ -85,4 +89,12 @@ public SubscriptionLagSource consumerLagSource() { public Clock clock() { return new ClockFactory().provide(); } + + @Bean + ManagementLeadership inactiveTopicsDetectionLeader( + ZookeeperClientManager zookeeperClientManager, + @Value("${management.leadership.zookeeper-dc}") String leaderElectionDc, + ZookeeperPaths zookeeperPaths) { + return new ManagementLeadership(zookeeperClientManager, leaderElectionDc, zookeeperPaths); + } } diff --git a/hermes-management/src/main/java/pl/allegro/tech/hermes/management/config/detection/InactiveTopicsDetectionConfig.java b/hermes-management/src/main/java/pl/allegro/tech/hermes/management/config/detection/InactiveTopicsDetectionConfig.java index 491fa1322c..be957928dd 100644 --- a/hermes-management/src/main/java/pl/allegro/tech/hermes/management/config/detection/InactiveTopicsDetectionConfig.java +++ b/hermes-management/src/main/java/pl/allegro/tech/hermes/management/config/detection/InactiveTopicsDetectionConfig.java @@ -5,35 +5,21 @@ import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.scheduling.annotation.EnableScheduling; -import pl.allegro.tech.hermes.infrastructure.zookeeper.ZookeeperPaths; import pl.allegro.tech.hermes.management.domain.detection.InactiveTopicsDetectionJob; -import pl.allegro.tech.hermes.management.infrastructure.detection.InactiveTopicsDetectionLeader; import pl.allegro.tech.hermes.management.infrastructure.detection.InactiveTopicsDetectionScheduler; -import pl.allegro.tech.hermes.management.infrastructure.zookeeper.ZookeeperClientManager; +import pl.allegro.tech.hermes.management.infrastructure.leader.ManagementLeadership; @Configuration @EnableConfigurationProperties(InactiveTopicsDetectionProperties.class) @EnableScheduling public class InactiveTopicsDetectionConfig { - @ConditionalOnProperty( - prefix = "detection.inactive-topics", - value = "enabled", - havingValue = "true") - @Bean - InactiveTopicsDetectionLeader inactiveTopicsDetectionLeader( - ZookeeperClientManager zookeeperClientManager, - InactiveTopicsDetectionProperties properties, - ZookeeperPaths zookeeperPaths) { - return new InactiveTopicsDetectionLeader(zookeeperClientManager, properties, zookeeperPaths); - } - @ConditionalOnProperty( prefix = "detection.inactive-topics", value = "enabled", havingValue = "true") @Bean InactiveTopicsDetectionScheduler inactiveTopicsDetectionScheduler( - InactiveTopicsDetectionJob job, InactiveTopicsDetectionLeader leader) { + InactiveTopicsDetectionJob job, ManagementLeadership leader) { return new InactiveTopicsDetectionScheduler(job, leader); } } diff --git a/hermes-management/src/main/java/pl/allegro/tech/hermes/management/infrastructure/detection/InactiveTopicsDetectionScheduler.java b/hermes-management/src/main/java/pl/allegro/tech/hermes/management/infrastructure/detection/InactiveTopicsDetectionScheduler.java index f7daa1ee77..7ac7756093 100644 --- a/hermes-management/src/main/java/pl/allegro/tech/hermes/management/infrastructure/detection/InactiveTopicsDetectionScheduler.java +++ b/hermes-management/src/main/java/pl/allegro/tech/hermes/management/infrastructure/detection/InactiveTopicsDetectionScheduler.java @@ -4,16 +4,17 @@ import org.slf4j.LoggerFactory; import org.springframework.scheduling.annotation.Scheduled; import pl.allegro.tech.hermes.management.domain.detection.InactiveTopicsDetectionJob; +import pl.allegro.tech.hermes.management.infrastructure.leader.ManagementLeadership; public class InactiveTopicsDetectionScheduler { private final InactiveTopicsDetectionJob job; - private final InactiveTopicsDetectionLeader leader; + private final ManagementLeadership leader; private static final Logger logger = LoggerFactory.getLogger(InactiveTopicsDetectionScheduler.class); public InactiveTopicsDetectionScheduler( - InactiveTopicsDetectionJob job, InactiveTopicsDetectionLeader leader) { + InactiveTopicsDetectionJob job, ManagementLeadership leader) { this.leader = leader; this.job = job; } diff --git a/hermes-management/src/main/java/pl/allegro/tech/hermes/management/infrastructure/detection/InactiveTopicsDetectionLeader.java b/hermes-management/src/main/java/pl/allegro/tech/hermes/management/infrastructure/leader/ManagementLeadership.java similarity index 77% rename from hermes-management/src/main/java/pl/allegro/tech/hermes/management/infrastructure/detection/InactiveTopicsDetectionLeader.java rename to hermes-management/src/main/java/pl/allegro/tech/hermes/management/infrastructure/leader/ManagementLeadership.java index bd43663249..21c1f53a33 100644 --- a/hermes-management/src/main/java/pl/allegro/tech/hermes/management/infrastructure/detection/InactiveTopicsDetectionLeader.java +++ b/hermes-management/src/main/java/pl/allegro/tech/hermes/management/infrastructure/leader/ManagementLeadership.java @@ -1,4 +1,4 @@ -package pl.allegro.tech.hermes.management.infrastructure.detection; +package pl.allegro.tech.hermes.management.infrastructure.leader; import jakarta.annotation.PostConstruct; import java.util.Optional; @@ -7,22 +7,21 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import pl.allegro.tech.hermes.infrastructure.zookeeper.ZookeeperPaths; -import pl.allegro.tech.hermes.management.config.detection.InactiveTopicsDetectionProperties; import pl.allegro.tech.hermes.management.infrastructure.zookeeper.ZookeeperClient; import pl.allegro.tech.hermes.management.infrastructure.zookeeper.ZookeeperClientManager; -public class InactiveTopicsDetectionLeader { +public class ManagementLeadership { private final String leaderElectionDc; private final Optional leaderLatch; - private static final Logger logger = LoggerFactory.getLogger(InactiveTopicsDetectionLeader.class); + private static final Logger logger = LoggerFactory.getLogger(ManagementLeadership.class); - public InactiveTopicsDetectionLeader( + public ManagementLeadership( ZookeeperClientManager zookeeperClientManager, - InactiveTopicsDetectionProperties inactiveTopicsDetectionProperties, + String leaderElectionDc, ZookeeperPaths zookeeperPaths) { - this.leaderElectionDc = inactiveTopicsDetectionProperties.leaderElectionZookeeperDc(); + this.leaderElectionDc = leaderElectionDc; Optional leaderCuratorFramework = zookeeperClientManager.getClients().stream() .filter(it -> it.getDatacenterName().equals(leaderElectionDc)) diff --git a/hermes-management/src/main/resources/application.yaml b/hermes-management/src/main/resources/application.yaml index a01e7d47c2..feb61a2ce7 100644 --- a/hermes-management/src/main/resources/application.yaml +++ b/hermes-management/src/main/resources/application.yaml @@ -39,6 +39,8 @@ management: health: periodSeconds: 30 enabled: true + leadership: + zookeeper-dc: dc audit: isLoggingAuditEnabled: false @@ -81,6 +83,5 @@ detection: inactivity-threshold: 60d next-notification-threshold: 14d whitelisted-qualified-topic-names: [] - leader-election-zookeeper-dc: dc cron: "0 0 8 * * *" notifications-history-limit: 5