Skip to content

Commit 707ccf2

Browse files
vikin91Maddosaurus
authored andcommitted
Remove duplication of initializeStream
1 parent 624fb1a commit 707ccf2

File tree

1 file changed

+1
-29
lines changed

1 file changed

+1
-29
lines changed

compliance/collection/main.go

Lines changed: 1 addition & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ func manageSendingToSensor(ctx context.Context, cli sensor.ComplianceServiceClie
114114
case <-ctx.Done():
115115
return
116116
case sc := <-sensorC:
117-
client, err := initializeSendingStream(ctx, cli)
117+
client, _, err := initializeStream(ctx, cli)
118118
if err != nil && ctx.Err() == nil {
119119
// error even after retries
120120
log.Fatalf("unable to establish send stream to sensor: %v", err)
@@ -218,34 +218,6 @@ func initialClientAndConfig(ctx context.Context, cli sensor.ComplianceServiceCli
218218
return client, config, nil
219219
}
220220

221-
// initializeSendingStream returns a client for sending the data to sensor. It ensures that the stream is open and in case not,
222-
// then the connection is being reopened with exp. back off
223-
func initializeSendingStream(ctx context.Context, cli sensor.ComplianceServiceClient) (sensor.ComplianceService_CommunicateClient, error) {
224-
eb := backoff.NewExponentialBackOff()
225-
eb.MaxInterval = 30 * time.Second
226-
eb.MaxElapsedTime = 3 * time.Minute
227-
228-
var client sensor.ComplianceService_CommunicateClient
229-
230-
operation := func() error {
231-
var err error
232-
client, err = cli.Communicate(ctx)
233-
if err != nil && ctx.Err() != nil {
234-
return backoff.Permanent(err)
235-
}
236-
return err
237-
}
238-
err := backoff.RetryNotify(operation, eb, func(err error, t time.Duration) {
239-
log.Infof("Sleeping for %0.2f seconds between attempts to connect to Sensor for sending", t.Seconds())
240-
})
241-
if err != nil {
242-
return nil, errors.Wrap(err, "Failed to initialize sensor connection for sending")
243-
}
244-
log.Infof("Successfully connected to Sensor for sending at %s", env.AdvertisedEndpoint.Setting())
245-
246-
return client, nil
247-
}
248-
249221
func initializeStream(ctx context.Context, cli sensor.ComplianceServiceClient) (sensor.ComplianceService_CommunicateClient, *sensor.MsgToCompliance_ScrapeConfig, error) {
250222
eb := backoff.NewExponentialBackOff()
251223
eb.MaxInterval = 30 * time.Second

0 commit comments

Comments
 (0)