diff options
author | Eirik Nygaard <eirik.nygaard@yahooinc.com> | 2022-05-02 10:49:42 +0200 |
---|---|---|
committer | Eirik Nygaard <eirik.nygaard@yahooinc.com> | 2022-05-02 10:56:31 +0200 |
commit | 022073f17226d09623bde6d1f781ca2d615dfe47 (patch) | |
tree | db1d5fd812f4c40b7cee91691d8dc172833adf9f /controller-server | |
parent | 5d6d8bad4b293ff99e6bb213fad1833555310ad1 (diff) |
Add feature flag to toggle notification dispatch
Diffstat (limited to 'controller-server')
3 files changed, 20 insertions, 5 deletions
diff --git a/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/Controller.java b/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/Controller.java index 48e663e7feb..d62e960ebc7 100644 --- a/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/Controller.java +++ b/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/Controller.java @@ -123,7 +123,7 @@ public class Controller extends AbstractComponent { auditLogger = new AuditLogger(curator, clock); jobControl = new JobControl(new JobControlFlags(curator, flagSource)); archiveBucketDb = new CuratorArchiveBucketDb(this); - notifier = new Notifier(curator, serviceRegistry.zoneRegistry(), serviceRegistry.mailer()); + notifier = new Notifier(curator, serviceRegistry.zoneRegistry(), serviceRegistry.mailer(), flagSource); notificationsDb = new NotificationsDb(this); supportAccessControl = new SupportAccessControl(this); diff --git a/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/notify/Notifier.java b/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/notify/Notifier.java index 6b14872b07d..61fa9934f7e 100644 --- a/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/notify/Notifier.java +++ b/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/notify/Notifier.java @@ -4,6 +4,9 @@ package com.yahoo.vespa.hosted.controller.notify; import com.yahoo.config.provision.ApplicationId; import com.yahoo.config.provision.Environment; import com.yahoo.text.Text; +import com.yahoo.vespa.flags.FetchVector; +import com.yahoo.vespa.flags.FlagSource; +import com.yahoo.vespa.flags.Flags; import com.yahoo.vespa.hosted.controller.api.integration.deployment.RunId; import com.yahoo.vespa.hosted.controller.api.integration.organization.Mail; import com.yahoo.vespa.hosted.controller.api.integration.organization.Mailer; @@ -32,20 +35,22 @@ public class Notifier { private final CuratorDb curatorDb; private final ZoneRegistry zoneRegistry; private final Mailer mailer; + private final FlagSource flagSource; private static final Logger log = Logger.getLogger(Notifier.class.getName()); - public Notifier(CuratorDb curatorDb, ZoneRegistry zoneRegistry, Mailer mailer) { + public Notifier(CuratorDb curatorDb, ZoneRegistry zoneRegistry, Mailer mailer, FlagSource flagSource) { this.curatorDb = Objects.requireNonNull(curatorDb); this.zoneRegistry = Objects.requireNonNull(zoneRegistry); this.mailer = Objects.requireNonNull(mailer); + this.flagSource = Objects.requireNonNull(flagSource); } public void dispatch(List<Notification> notifications, NotificationSource source) { - if (notifications.isEmpty()) { + if (!dispatchEnabled(source) || skipSource(source)) { return; } - if (skipSource(source)) { + if (notifications.isEmpty()) { return; } var tenant = curatorDb.readTenant(source.tenant()); @@ -61,6 +66,12 @@ public class Notifier { }); } + private boolean dispatchEnabled(NotificationSource source) { + return Flags.NOTIFICATION_DISPATCH_FLAG.bindTo(flagSource) + .with(FetchVector.Dimension.TENANT_ID, source.tenant().value()) + .value(); + } + private boolean skipSource(NotificationSource source) { // Limit sources to production systems only. Dev and test systems cause too much noise at the moment. if (source.zoneId().map(z -> z.environment() != Environment.prod).orElse(false)) { diff --git a/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/notification/NotificationsDbTest.java b/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/notification/NotificationsDbTest.java index 4fbe21f11fb..f1a9bcb8cdf 100644 --- a/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/notification/NotificationsDbTest.java +++ b/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/notification/NotificationsDbTest.java @@ -9,6 +9,9 @@ import com.yahoo.config.provision.TenantName; import com.yahoo.config.provision.zone.ZoneId; import com.yahoo.path.Path; import com.yahoo.test.ManualClock; +import com.yahoo.vespa.flags.FlagSource; +import com.yahoo.vespa.flags.Flags; +import com.yahoo.vespa.flags.InMemoryFlagSource; import com.yahoo.vespa.hosted.controller.api.application.v4.model.ClusterMetrics; import com.yahoo.vespa.hosted.controller.api.identifiers.DeploymentId; import com.yahoo.vespa.hosted.controller.api.integration.deployment.RunId; @@ -70,7 +73,8 @@ public class NotificationsDbTest { private final ManualClock clock = new ManualClock(Instant.ofEpochSecond(12345)); private final MockCuratorDb curatorDb = new MockCuratorDb(SystemName.Public); private final MockMailer mailer = new MockMailer(); - private final NotificationsDb notificationsDb = new NotificationsDb(clock, curatorDb, new Notifier(curatorDb, new ZoneRegistryMock(SystemName.cd), mailer)); + private final FlagSource flagSource = new InMemoryFlagSource().withBooleanFlag(Flags.NOTIFICATION_DISPATCH_FLAG.id(), true); + private final NotificationsDb notificationsDb = new NotificationsDb(clock, curatorDb, new Notifier(curatorDb, new ZoneRegistryMock(SystemName.cd), mailer, flagSource)); @Test public void list_test() { |