Skip to content

fix: connector retries. #785

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ require (
github.com/axw/gocov v1.2.1
github.com/blang/semver v3.5.1+incompatible
github.com/briandowns/spinner v1.23.2
github.com/cenkalti/backoff v2.2.1+incompatible
github.com/cert-manager/cert-manager v1.17.1
github.com/cilium/ebpf v0.17.3
github.com/cskr/pubsub v1.0.2
Expand Down
17 changes: 3 additions & 14 deletions pkg/connector/ctok/source.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ import (
"strings"
"time"

"github.com/cenkalti/backoff"

ctv1 "github.com/flomesh-io/fsm/pkg/apis/connector/v1alpha1"
"github.com/flomesh-io/fsm/pkg/connector"
)
Expand Down Expand Up @@ -48,20 +46,11 @@ func (s *CtoKSource) Run(ctx context.Context) {
var catalogServices []ctv1.NamespacedService

if !s.controller.Purge() {
err := backoff.Retry(func() error {
var err error
catalogServices, err = s.discClient.CatalogServices(opts)
return err
}, backoff.WithContext(backoff.NewExponentialBackOff(), ctx))

// If the context is ended, then we end
if ctx.Err() != nil {
return
}

var err error
catalogServices, err = s.discClient.CatalogServices(opts)
// If there was an error, handle that
if err != nil {
log.Warn().Msgf("error querying services, will retry, err:%s", err)
log.Warn().Err(err).Msgf("error querying services, will retry")
time.Sleep(opts.WaitTime)
continue
}
Expand Down
31 changes: 12 additions & 19 deletions pkg/connector/ktoc/syncer.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,10 +150,9 @@ func (s *KtoCSyncer) watchReapableServices(ctx context.Context) {
case <-minWaitCh:
services, err = s.discClient.RegisteredServices(opts)
if err != nil {
log.Error().Msgf("error querying services, will retry err:%v", err)
log.Error().Err(err).Msgf("error querying services, will retry")
} else {
log.Debug().Msgf("[watchReapableServices] services returned from catalog services:%v",
services)
log.Debug().Msgf("[watchReapableServices] services returned from catalog services:%v", services)
}

minWaitCh = time.After(minWait)
Expand Down Expand Up @@ -188,10 +187,9 @@ func (s *KtoCSyncer) watchReapableServices(ctx context.Context) {
}

if err = s.scheduleReapServiceLocked(service.Service, svcNs); err != nil {
log.Info().Msgf("error querying service for delete service-name:%s service-namespace:%s err:%v",
log.Info().Err(err).Msgf("error querying service for delete service-name:%s service-namespace:%s",
service.Service,
svcNs,
err)
svcNs)
}
}

Expand Down Expand Up @@ -226,10 +224,9 @@ func (s *KtoCSyncer) watchService(ctx context.Context, name, namespace string) {

instances, err := s.discClient.RegisteredInstances(name, queryOpts)
if err != nil {
log.Debug().Msgf("error querying service, will retry service-name:%s service-namespace:%s err:%v",
log.Debug().Err(err).Msgf("error querying service, will retry service-name:%s service-namespace:%s",
name,
namespace, // will be "" if namespaces aren't enabled
err)
namespace)
continue
}

Expand Down Expand Up @@ -391,12 +388,10 @@ func (s *KtoCSyncer) syncFull(ctx context.Context) {
log.Info().Msgf("deregistering service service-id:%s service-namespace:%s",
r.ServiceID,
r.Namespace)
err := s.discClient.Deregister(r)
if err != nil {
log.Error().Msgf("error deregistering service service-id:%s service-namespace:%s err:%v",
if err := s.discClient.Deregister(r); err != nil {
log.Error().Err(err).Msgf("error deregistering service service-id:%s service-namespace:%s",
r.ServiceID,
r.Namespace,
err)
r.Namespace)
maxRetries--
if maxRetries > 0 {
time.Sleep(time.Second)
Expand Down Expand Up @@ -439,11 +434,9 @@ func (s *KtoCSyncer) syncFull(ctx context.Context) {
maxRetries := 1
// Register the service.
for maxRetries > 0 {
err := s.discClient.Register(r)
if err != nil {
log.Error().Msgf("error registering service service-name:%s err:%v",
r.Service.MicroService.Service,
err)
if err := s.discClient.Register(r); err != nil {
log.Error().Err(err).Msgf("error registering service service-name:%s",
r.Service.MicroService.Service)
maxRetries--
if maxRetries > 0 {
time.Sleep(time.Second)
Expand Down
Loading