Skip to content
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
3 changes: 0 additions & 3 deletions pkg/features/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,6 @@ var (
// StoreEventHashes stores the hashes of successfully processed objects we receive from Sensor into the database
StoreEventHashes = registerFeature("Store Event Hashes", "ROX_STORE_EVENT_HASHES", enabled, unchangeableInProd)

// PreventSensorRestartOnDisconnect enables a new behavior in Sensor where it avoids restarting when the gRPC connection with Central ends.
PreventSensorRestartOnDisconnect = registerFeature("Prevent Sensor restart on disconnect", "ROX_PREVENT_SENSOR_RESTART_ON_DISCONNECT", enabled, unchangeableInProd)

// ComplianceEnhancements enables APIs and UI pages for Compliance 2.0
ComplianceEnhancements = registerFeature("Compliance enhancements", "ROX_COMPLIANCE_ENHANCEMENTS", enabled)

Expand Down
49 changes: 3 additions & 46 deletions sensor/common/sensor/sensor.go
Original file line number Diff line number Diff line change
Expand Up @@ -284,9 +284,6 @@ func (s *Sensor) Start() {
}
log.Info("All components have started")

okSig := s.centralConnectionFactory.OkSignal()
errSig := s.centralConnectionFactory.StopSignal()

err = s.pubSub.Subscribe(internalmessage.SensorMessageSoftRestart, func(message *internalmessage.SensorInternalMessage) {
if message.IsExpired() {
return
Expand All @@ -306,25 +303,8 @@ func (s *Sensor) Start() {
log.Warnf("Failed to register subscription to sensor internal message: %q", err)
}

if features.PreventSensorRestartOnDisconnect.Enabled() {
log.Info("Running Sensor with connection retry: preventing sensor restart on disconnect")
go s.communicationWithCentralWithRetries(&centralReachable)
} else {
log.Info("Running Sensor without connection retries: sensor will restart on disconnect")
// This has to be checked only if retries are not enabled. With retries, this signal will be checked
// inside communicationWithCentralWithRetries since it has to be re-checked on reconnects, and not
// crash if it fails.
select {
case <-errSig.Done():
s.stoppedSig.SignalWithErrorWrap(errSig.Err(), "getting connection from connection factory")
return
case <-okSig.Done():
s.changeState(common.SensorComponentEventCentralReachableHTTP)
case <-s.stoppedSig.Done():
return
}
go s.communicationWithCentral(&centralReachable)
}
log.Info("Running Sensor with connection retry: preventing sensor restart on disconnect")
go s.communicationWithCentralWithRetries(&centralReachable)
}

// newScannerDefinitionsRoute returns a custom route that serves scanner
Expand All @@ -345,14 +325,7 @@ func (s *Sensor) newScannerDefinitionsRoute(centralEndpoint string, centralCerti

// Stop shuts down background tasks.
func (s *Sensor) Stop() {
if features.PreventSensorRestartOnDisconnect.Enabled() {
s.stoppedSig.Signal()
} else {
// Stop communication with central.
if s.centralConnection != nil {
s.centralCommunication.Stop()
}
}
s.stoppedSig.Signal()

for _, c := range s.components {
c.Stop()
Expand All @@ -377,22 +350,6 @@ func (s *Sensor) Stop() {
log.Info("Sensor shutdown complete")
}

func (s *Sensor) communicationWithCentral(centralReachable *concurrency.Flag) {
s.centralCommunication = NewCentralCommunication(s.clusterID, false, false, s.components...)

syncDone := concurrency.NewSignal()
s.centralCommunication.Start(central.NewSensorServiceClient(s.centralConnection), centralReachable, &syncDone, s.configHandler, s.detector)
go s.notifySyncDone(&syncDone, s.centralCommunication)

if err := s.centralCommunication.Stopped().Wait(); err != nil {
log.Errorf("Sensor reported an error: %v", err)
s.stoppedSig.SignalWithError(err)
} else {
log.Info("Terminating central connection.")
s.stoppedSig.Signal()
}
}

func (s *Sensor) changeState(state common.SensorComponentEvent) {
s.currentStateMtx.Lock()
defer s.currentStateMtx.Unlock()
Expand Down
7 changes: 0 additions & 7 deletions sensor/tests/connection/alerts/alert_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (

"github.com/pkg/errors"
"github.com/stackrox/rox/generated/internalapi/central"
"github.com/stackrox/rox/pkg/features"
"github.com/stackrox/rox/sensor/tests/helper"
"github.com/stackrox/rox/sensor/testutils"
"github.com/stretchr/testify/require"
Expand All @@ -19,12 +18,6 @@ var (
)

func Test_AlertsAreSentAfterConnectionRestart(t *testing.T) {
t.Setenv(features.PreventSensorRestartOnDisconnect.EnvVar(), "true")
if !features.PreventSensorRestartOnDisconnect.Enabled() {
t.Skip("Skip tests when ROX_PREVENT_SENSOR_RESTART_ON_DISCONNECT is disabled")
t.SkipNow()
}

t.Setenv("ROX_SENSOR_CONNECTION_RETRY_INITIAL_INTERVAL", "1s")
t.Setenv("ROX_SENSOR_CONNECTION_RETRY_MAX_INTERVAL", "2s")

Expand Down
2 changes: 1 addition & 1 deletion sensor/tests/connection/connection_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ func Test_SensorReconnects(t *testing.T) {
c.RunTest(t, helper.WithTestCase(func(t *testing.T, testContext *helper.TestContext, _ map[string]k8s.Object) {

// This test case will make sure that:
// 1) Sensor does not crash when ROX_PREVENT_SENSOR_RESTART_ON_DISCONNECT is set.
// 1) Sensor does not crash when connection to Central is interrupted.
// 2) After Central reconnects, events can continue streaming messages
//
// Since this a base test, which will be used to test further features in the ROX-9776 epic, there are some
Expand Down
6 changes: 0 additions & 6 deletions sensor/tests/connection/k8sreconciliation/reconcile_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,6 @@ type resourceDef struct {
}

func Test_SensorReconcilesKubernetesEvents(t *testing.T) {
t.Setenv(features.PreventSensorRestartOnDisconnect.EnvVar(), "true")
if !features.PreventSensorRestartOnDisconnect.Enabled() {
t.Skip("Skip tests when ROX_PREVENT_SENSOR_RESTART_ON_DISCONNECT is disabled")
t.SkipNow()
}

t.Setenv(features.SensorReconciliationOnReconnect.EnvVar(), "true")

t.Setenv("ROX_SENSOR_CONNECTION_RETRY_INITIAL_INTERVAL", "1s")
Expand Down
1 change: 0 additions & 1 deletion sensor/tests/connection/runtime/runtime_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ var (
)

func Test_SensorIntermediateRuntimeEvents(t *testing.T) {
t.Setenv(features.PreventSensorRestartOnDisconnect.EnvVar(), "true")
t.Setenv(features.SensorReconciliationOnReconnect.EnvVar(), "true")
t.Setenv(features.SensorCapturesIntermediateEvents.EnvVar(), "true")

Expand Down
Loading