Skip to content
This repository has been archived by the owner on Sep 12, 2024. It is now read-only.

periodically check connectivity to Cloud Pubsub #1031

Merged
merged 4 commits into from
Dec 9, 2016

Conversation

mattnworb
Copy link
Member

This is an alternate implementation of #1030 which performs the healthchecks periodically rather than only once at process startup.

@mattnworb
Copy link
Member Author

mattnworb commented Dec 2, 2016

changes compared to #1030:

  • GooglePubSubSender checks a healthchecker interface each time that send(topic, message) is called.
    • the healthchecking logic is broken out into interface/implementation to make testing of the EventSender logic and the healthcheck logic simpler
    • the default healthchecker implementation does a check every 5 minutes to see if pubsub.getTopic(..) is successful or not.
  • EventSenderFactory registers all of the EventSenders and the PubSub client instance with the dropwizard environment lifecycle, so that everything can be cleanly shutdown when the service shuts down.
  • the EventSender interface now extends Managed from dropwizard, so that we can shut things down - I wanted to be able to shutdown the executor used for the Cloud Pubsub healthchecks, and along the way I noticed that the KafkaProvider was never cleanly shut down
  • eliminated GooglePubSubProvider as it wasn't really doing much

the CommonConfiguration stuff is unchanged from #1030.

@mattnworb
Copy link
Member Author

@davidxia @lndbrg @rohansingh

@mattnworb mattnworb force-pushed the pubsub-healthcheck-periodically branch from 956df2b to 47d8b35 Compare December 2, 2016 20:52
@codecov-io
Copy link

codecov-io commented Dec 2, 2016

Current coverage is 51.14% (diff: 35.29%)

Merging #1031 into master will increase coverage by 4.76%

@@             master      #1031   diff @@
==========================================
  Files           107        275    +168   
  Lines          5095      13157   +8062   
  Methods           0          0           
  Messages          0          0           
  Branches        858       1699    +841   
==========================================
+ Hits           2363       6729   +4366   
- Misses         2514       5925   +3411   
- Partials        218        503    +285   

Powered by Codecov. Last update 0367d6f...fbe6378

@mattnworb mattnworb force-pushed the pubsub-healthcheck-periodically branch 2 times, most recently from 6f14735 to 0e327c1 Compare December 2, 2016 21:47
Copy link
Contributor

@davidxia davidxia left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM but would like another pair of eyes.

this.healthchecker = healthchecker;
}

// public void start() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Leftover?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Delete this commented out stuff?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it is removed in a later commit

boolean isHealthy();
}

public static class DefaultHealthChecker implements HealthChecker {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nitpick: This and the constructor be package-local.

}
@Override
public void stop() throws Exception {
kafkaProducer.close();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch.

import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;

public final class EventSenderFactory {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it worth testing this class or too much of a pain?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i think it would be too cumbersome as this is constructing new instances of KafkaSender GooglePubSubSender etc directly

}

@Override
public void send(final String topic, final byte[] message) {
final String combinedTopic = topicPrefix + topic;

if (!healthchecker.isHealthy()) {
log.warn("will not publish message to pubsub topic={} as the pubsub client "
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're missing the topic for interpolation here.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good catch, thanks

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please smash that approve button now

when the GooglePubSubSender cannot connect to the pubsub service,
disable message publishing until connectivity is re-established (at the
next scheduled time).

Along the way, I refactored the common EventSender-instantiation code
from AgentService and MasterService into a new class named EventSenderFactory.
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.
make all the EventSender implementations also implement the dropwizard
Managed interface so that we can have dropwizard manage their lifecycle.

This lets us cleanly shutdown the KafkaProvider or the executor used by
GooglePubSubSender.
Add a Gauge for whether or not the GooglePubSubSender is healthy.

Refactor the builder for GooglePubSubSender to move the creation of the
healthchecker, ScheduledExecutorService etc to EventSenderFactory.
this class is only ever constructed with a non-empty Optional, so we can
simplify it by removing the Optional.
@mattnworb mattnworb force-pushed the pubsub-healthcheck-periodically branch from 0e327c1 to fbe6378 Compare December 7, 2016 15:14
@davidxia davidxia merged commit 9cb7082 into master Dec 9, 2016
@davidxia davidxia deleted the pubsub-healthcheck-periodically branch December 9, 2016 16:20
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants