Skip to content

Commit

Permalink
feat : only sync if kafka-connect is running (#66)
Browse files Browse the repository at this point in the history
* only sync if kafka-connect is running

Signed-off-by: Mark deVilliers <markdevilliers@gmail.com>
  • Loading branch information
mdevilliers authored Mar 20, 2020
1 parent e8bd9bb commit ded7004
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 12 deletions.
26 changes: 17 additions & 9 deletions pkg/manager/manage.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,22 +12,30 @@ import (
// Manage will start the connector manager running and managing connectors
func (c *ConnectorManager) Manage(source ConnectorSource, stopCH <-chan struct{}) error {
// mark ourselves as having an unhealthy state until we have
// tried to contact the kafka-connect instance
// successfully configured the kafka-connect instance
c.readinessState = errorState

syncChannel := time.NewTicker(c.config.SyncPeriod).C
for {
select {
case <-syncChannel:
err := c.Sync(source)
if err != nil {
// set back into an unhealthy state
c.readinessState = errorState
return errors.Wrap(err, "error synchronising connectors for source")

// we only want to try Syncing if we can contact the kafka-connect instance.
// Using the LivenessCheck as a proxy for calculating the connection
if c.livenessState == okState {
err := c.Sync(source)
if err != nil {
// set back into an unhealthy state
c.readinessState = errorState
return errors.Wrap(err, "error synchronising connectors for source")
}
// mark ourselves as being in an ok state as we have
// started syncing without any error
c.readinessState = okState
} else {
c.logger.Infof("skipping sync as livenessState == %v", c.livenessState)
}
// mark ourselves as being in an ok state as we have
// started syncing without any error
c.readinessState = okState

case <-stopCH:
return nil
}
Expand Down
10 changes: 7 additions & 3 deletions pkg/manager/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ type ConnectorManager struct {
client client
logger Logger

readinessState readinessState
readinessState healthcheckState
livenessState healthcheckState
}

// Option can be supplied that override the default ConnectorManager properties
Expand All @@ -52,6 +53,7 @@ func NewConnectorsManager(client client, config *Config, opts ...Option) (*Conne
client: client,
logger: newNoopLogger(),
readinessState: unknownState,
livenessState: unknownState,
}

for _, opt := range opts {
Expand All @@ -61,10 +63,10 @@ func NewConnectorsManager(client client, config *Config, opts ...Option) (*Conne
return cm, nil
}

type readinessState int
type healthcheckState int

const (
unknownState readinessState = iota
unknownState healthcheckState = iota
okState
errorState
)
Expand All @@ -91,9 +93,11 @@ func (c *ConnectorManager) LivenessCheck() (string, func() error) {
check := func() error {
err := healthcheck.HTTPGetCheck(c.config.ClusterURL, time.Second*2)()
if err != nil {
c.livenessState = errorState
c.logger.Infof("healthcheck: liveness : %s", err.Error())
return err
}
c.livenessState = okState
c.logger.Infof("healthcheck: liveness : ok")
return nil
}
Expand Down

0 comments on commit ded7004

Please sign in to comment.