fleet/orbit/pkg/update/disk_encryption.go
Lucas Manuel Rodriguez 58d882b684
Reduce orbit logging when the server is down (#16968)
Orbit changes for #16423. 
Should also fix #16326 (in case of network errors).

Orbit will log the following every 5 minutes:
```
2024-02-20T14:27:40-03:00 INF network error error="Post \"https://localhost:8080/api/fleet/orbit/config\": dial tcp [::1]:8080: connect: connection refused"
```

- [X] Changes file added for user-visible changes in `changes/` or
`orbit/changes/`.
See [Changes
files](https://fleetdm.com/docs/contributing/committing-changes#changes-files)
for more information.
- [x] Manual QA for all new/changed functionality
  - For Orbit and Fleet Desktop changes:
- [x] Manual QA must be performed in the three main OSs, macOS, Windows
and Linux.
- [x] Auto-update manual QA, from released version of component to new
version (see [tools/tuf/test](../tools/tuf/test/README.md)).
2024-02-21 15:36:15 -03:00

41 lines
1.1 KiB
Go

package update
import (
"sync/atomic"
"github.com/fleetdm/fleet/v4/orbit/pkg/useraction"
"github.com/fleetdm/fleet/v4/server/fleet"
"github.com/rs/zerolog/log"
)
const maxRetries = 2
type DiskEncryptionRunner struct {
fetcher OrbitConfigFetcher
isRunning atomic.Bool
}
func ApplyDiskEncryptionRunnerMiddleware(f OrbitConfigFetcher) *DiskEncryptionRunner {
return &DiskEncryptionRunner{fetcher: f}
}
func (d *DiskEncryptionRunner) GetConfig() (*fleet.OrbitConfig, error) {
cfg, err := d.fetcher.GetConfig()
if err != nil {
log.Debug().Err(err).Msg("calling GetConfig from DiskEncryptionFetcher")
return nil, err
}
log.Debug().Msgf("running disk encryption fetcher middleware, notification: %v, isIdle: %v", cfg.Notifications.RotateDiskEncryptionKey, d.isRunning.Load())
if cfg.Notifications.RotateDiskEncryptionKey && !d.isRunning.Swap(true) {
go func() {
defer d.isRunning.Store(false)
if err := useraction.RotateDiskEncryptionKey(maxRetries); err != nil {
log.Error().Err(err).Msg("rotating encryption key")
}
}()
}
return cfg, nil
}