Skip to content

Commit

Permalink
🧹 decouple checkin from service startup (#1487)
Browse files Browse the repository at this point in the history
Signed-off-by: Ivan Milchev <[email protected]>
  • Loading branch information
imilchev authored Nov 20, 2024
1 parent 13003d2 commit eafe0a9
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 10 deletions.
16 changes: 8 additions & 8 deletions apps/cnspec/cmd/backgroundjob/checkin.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ func newCheckinHandler(
endpoint string,
agentMrn string,
config *upstream.UpstreamConfig,
sysInfo *sysinfo.SystemInfo,
) (*CheckinHandler, error) {
if agentMrn == "" {
return nil, errors.New("could not determine agent MRN")
Expand All @@ -38,7 +37,6 @@ func newCheckinHandler(
httpClient: httpClient,
mrn: agentMrn,
creds: config.Creds,
sysInfo: sysInfo,
}, nil
}

Expand All @@ -47,15 +45,17 @@ func NewCheckInHandlerWithInfo(httpClient *http.Client,
agentMrn string,
config *upstream.UpstreamConfig,
) (*CheckinHandler, error) {
sysInfo, err := sysinfo.Get()
if err != nil {
return nil, errors.Wrap(err, "could not determine system information")
}

return newCheckinHandler(httpClient, endpoint, agentMrn, config, sysInfo)
return newCheckinHandler(httpClient, endpoint, agentMrn, config)
}

func (c *CheckinHandler) CheckIn(ctx context.Context) error {
if c.sysInfo == nil {
sysInfo, err := sysinfo.Get()
if err != nil {
return errors.Wrap(err, "could not determine system information")
}
c.sysInfo = sysInfo
}
// gather service account
plugins := []ranger.ClientPlugin{}
plugins = append(plugins, sysInfoHeader(c.sysInfo, cnquery.DefaultFeatures))
Expand Down
4 changes: 3 additions & 1 deletion apps/cnspec/cmd/backgroundjob/checkin_pinger.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,9 @@ func (c *checkinPinger) Start() {
}

// run check-in once on startup
runCheckIn()
go func() {
runCheckIn()
}()

jitter := time.Duration(rand.Int63n(int64(c.interval)))
ticker := time.NewTicker(c.interval + jitter)
Expand Down
2 changes: 1 addition & 1 deletion apps/cnspec/cmd/backgroundjob/serve_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import (
)

func Serve(timer time.Duration, splay time.Duration, handler JobRunner) {
isIntSess, err := svc.IsAnInteractiveSession()
isIntSess, err := svc.IsWindowsService()
if err != nil {
log.Fatal().Err(err).Msg("failed to determine if we are running in an interactive session")
}
Expand Down

0 comments on commit eafe0a9

Please sign in to comment.