Skip to content

Commit

Permalink
added fixes to db and removed unnecessary checker statements
Browse files Browse the repository at this point in the history
  • Loading branch information
kamaev committed Dec 25, 2017
1 parent f8e6c5d commit 5fe1cc6
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 9 deletions.
2 changes: 0 additions & 2 deletions checker/check.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,6 @@ func (triggerChecker *TriggerChecker) handleErrorCheck(checkData moira.CheckData
if triggerChecker.ttl == 0 {
return checkData, nil
}
return triggerChecker.compareChecks(checkData)
case ErrTriggerHasOnlyWildcards:
triggerChecker.Logger.Debugf("Trigger %s: %s", triggerChecker.TriggerID, checkingError.Error())
if len(checkData.Metrics) == 0 && triggerChecker.ttlState != OK && triggerChecker.ttlState != DEL {
Expand All @@ -145,7 +144,6 @@ func (triggerChecker *TriggerChecker) handleErrorCheck(checkData moira.CheckData
return checkData, nil
}
}
return triggerChecker.compareChecks(checkData)
case target.ErrUnknownFunction:
triggerChecker.Logger.Warningf("Trigger %s: %s", triggerChecker.TriggerID, checkingError.Error())
checkData.State = EXCEPTION
Expand Down
13 changes: 6 additions & 7 deletions database/redis/database.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ func newRedisPool(redisURI string, dbID ...int) *redis.Pool {
return &redis.Pool{
MaxIdle: 3,
IdleTimeout: 240 * time.Second,
TestOnBorrow: func(c redis.Conn, t time.Time) error {
_, err := c.Do("PING")
return err
},
Dial: func() (redis.Conn, error) {
c, err := redis.Dial("tcp", redisURI)
if err != nil {
Expand All @@ -51,10 +55,6 @@ func newRedisPool(redisURI string, dbID ...int) *redis.Pool {
}
return c, err
},
TestOnBorrow: func(c redis.Conn, t time.Time) error {
_, err := c.Do("PING")
return err
},
}
}

Expand All @@ -81,7 +81,6 @@ func (connector *DbConnector) manageSubscriptions(tomb *tomb.Tomb, channel strin

dataChan := make(chan []byte)
go func() {
defer psc.Close()
for {
switch n := psc.Receive().(type) {
case redis.Message:
Expand All @@ -94,13 +93,13 @@ func (connector *DbConnector) manageSubscriptions(tomb *tomb.Tomb, channel strin
connector.logger.Infof("Unsubscribe from %s channel, current subscriptions is %v", n.Channel, n.Count)
if n.Count == 0 {
connector.logger.Infof("No more subscriptions, exit...")
psc.Close()
close(dataChan)
return
}
}
case *net.OpError:
connector.logger.Info("psc.Receive() returned *net.OpError, reconnecting")
connector.logger.Infof("%s failed: %s for connection from %s to %s", n.Op, n.Err.Error(), n.Source.String(), n.Addr.String())
connector.logger.Infof("psc.Receive() returned *net.OpError for %s operation: %s. Reconnecting...", n.Op, n.Err.Error())
newPsc, err := connector.makePubSubConnection(metricEventKey)
if err != nil {
connector.logger.Errorf("Failed to reconnect to subscription: %v", err)
Expand Down

0 comments on commit 5fe1cc6

Please sign in to comment.