This repository has been archived by the owner on Sep 12, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 233
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
disable GooglePubSubSender if pubsub cannot be reached
Adds a `isHealthy()` method to the EventSender interface that is used to filter out any unhealthy senders at startup. This logic is done in a new class named EventSenderFactory, which extracts the identical logic for constructing Lists of EventSenders from the MasterService and the AgentService. To make this common class possible, also extracted a class for the common configuration fields between AgentConfig and MasterConfig. This new CommonConfiguration class is incomplete - more fields can be moved to this class to avoid duplication, but I left that for future commits. I created EventSenderFactory in hopes of writing a test for the logic that unhealthy senders are removed from the List, but the nature of this class makes this test to impractical - since the List-of-EventSender-building involves constructing new instances of KafkaProvider/GooglePubSubProvider/etc and calling methods on instances that those instances return, which is not really feasible to be mocked out in a test.
- Loading branch information
Showing
12 changed files
with
213 additions
and
128 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
helios-services/src/main/java/com/spotify/helios/servicescommon/CommonConfiguration.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
/* | ||
* Copyright (c) 2016 Spotify AB. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
package com.spotify.helios.servicescommon; | ||
|
||
import io.dropwizard.Configuration; | ||
|
||
import java.util.List; | ||
|
||
public class CommonConfiguration<C extends CommonConfiguration<C>> extends Configuration { | ||
|
||
private List<String> kafkaBrokers; | ||
private List<String> pubsubPrefixes; | ||
|
||
public List<String> getKafkaBrokers() { | ||
return kafkaBrokers; | ||
} | ||
|
||
@SuppressWarnings("unchecked") | ||
public C setKafkaBrokers(List<String> kafkaBrokers) { | ||
this.kafkaBrokers = kafkaBrokers; | ||
return (C) this; | ||
} | ||
|
||
public List<String> getPubsubPrefixes() { | ||
return pubsubPrefixes; | ||
} | ||
|
||
@SuppressWarnings("unchecked") | ||
public C setPubsubPrefixes(List<String> pubsubPrefixes) { | ||
this.pubsubPrefixes = pubsubPrefixes; | ||
return (C) this; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
70 changes: 70 additions & 0 deletions
70
helios-services/src/main/java/com/spotify/helios/servicescommon/EventSenderFactory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
/* | ||
* Copyright (c) 2016 Spotify AB. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
package com.spotify.helios.servicescommon; | ||
|
||
import org.apache.kafka.clients.producer.KafkaProducer; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.Optional; | ||
import java.util.function.Supplier; | ||
|
||
public class EventSenderFactory implements Supplier<List<EventSender>> { | ||
|
||
private static final Logger log = LoggerFactory.getLogger(EventSenderFactory.class); | ||
|
||
private final CommonConfiguration<?> config; | ||
private final boolean performHealthchecks; | ||
|
||
public EventSenderFactory(final CommonConfiguration<?> config, | ||
final boolean performHealthchecks) { | ||
this.config = config; | ||
this.performHealthchecks = performHealthchecks; | ||
} | ||
|
||
@Override | ||
public List<EventSender> get() { | ||
final List<EventSender> senders = new ArrayList<>(); | ||
|
||
final KafkaClientProvider kafkaClientProvider = | ||
new KafkaClientProvider(config.getKafkaBrokers()); | ||
|
||
final Optional<KafkaProducer<String, byte[]>> kafkaProducer = | ||
kafkaClientProvider.getDefaultProducer(); | ||
|
||
if (kafkaProducer.isPresent()) { | ||
senders.add(new KafkaSender(kafkaProducer)); | ||
} | ||
|
||
final GooglePubSubProvider googlePubSubProvider = | ||
new GooglePubSubProvider(config.getPubsubPrefixes()); | ||
|
||
senders.addAll(googlePubSubProvider.senders()); | ||
|
||
if (performHealthchecks) { | ||
// filter out any senders that fail the healthcheck | ||
senders.removeIf(sender -> !sender.isHealthy()); | ||
} | ||
|
||
log.info("health eventSenders: {}", senders); | ||
|
||
return senders; | ||
} | ||
} |
Oops, something went wrong.