Skip to content

Commit

Permalink
RegistrationId => RegistrationID
Browse files Browse the repository at this point in the history
  • Loading branch information
RebeccaMahany committed Dec 6, 2024
1 parent 7863996 commit 7aa6930
Show file tree
Hide file tree
Showing 9 changed files with 67 additions and 67 deletions.
4 changes: 2 additions & 2 deletions ee/agent/knapsack/knapsack.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,8 @@ func (k *knapsack) SetInstanceQuerier(q types.InstanceQuerier) {
}

// RegistrationTracker interface methods
func (k *knapsack) RegistrationIds() []string {
return []string{types.DefaultRegistrationId}
func (k *knapsack) RegistrationIDs() []string {
return []string{types.DefaultRegistrationID}
}

// InstanceStatuses returns the current status of each osquery instance.
Expand Down
6 changes: 3 additions & 3 deletions ee/agent/types/mocks/knapsack.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions ee/agent/types/registration.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package types

const (
DefaultRegistrationId = "default"
DefaultRegistrationID = "default"
)

// RegistrationTracker manages the current set of registrations for this launcher installation.
// Right now, the list is hardcoded to only the default registration ID. In the future, this
// data may be provided by e.g. a control server subsystem.
type RegistrationTracker interface {
RegistrationIds() []string
RegistrationIDs() []string
}
2 changes: 1 addition & 1 deletion pkg/osquery/runtime/osqueryinstance.go
Original file line number Diff line number Diff line change
Expand Up @@ -708,7 +708,7 @@ func calculateOsqueryPaths(rootDirectory string, registrationId string, runId st
}

// Keep default database path for default instance
if registrationId == types.DefaultRegistrationId {
if registrationId == types.DefaultRegistrationID {
osqueryFilePaths.databasePath = filepath.Join(rootDirectory, "osquery.db")
}

Expand Down
16 changes: 8 additions & 8 deletions pkg/osquery/runtime/osqueryinstance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ func TestCalculateOsqueryPaths(t *testing.T) {
rootDir := t.TempDir()

runId := ulid.New()
paths, err := calculateOsqueryPaths(rootDir, types.DefaultRegistrationId, runId, osqueryOptions{})
paths, err := calculateOsqueryPaths(rootDir, types.DefaultRegistrationID, runId, osqueryOptions{})

require.NoError(t, err)

Expand Down Expand Up @@ -62,7 +62,7 @@ func TestCreateOsqueryCommand(t *testing.T) {
k.On("OsqueryFlags").Return([]string{})
k.On("Slogger").Return(multislogger.NewNopLogger())

i := newInstance(types.DefaultRegistrationId, k, mockServiceClient(), WithStdout(os.Stdout), WithStderr(os.Stderr))
i := newInstance(types.DefaultRegistrationID, k, mockServiceClient(), WithStdout(os.Stdout), WithStderr(os.Stderr))

cmd, err := i.createOsquerydCommand(osquerydPath, paths)
require.NoError(t, err)
Expand All @@ -84,7 +84,7 @@ func TestCreateOsqueryCommandWithFlags(t *testing.T) {
k.On("OsqueryVerbose").Return(true)
k.On("Slogger").Return(multislogger.NewNopLogger())

i := newInstance(types.DefaultRegistrationId, k, mockServiceClient())
i := newInstance(types.DefaultRegistrationID, k, mockServiceClient())

cmd, err := i.createOsquerydCommand(
testOsqueryBinaryDirectory,
Expand Down Expand Up @@ -117,7 +117,7 @@ func TestCreateOsqueryCommand_SetsEnabledWatchdogSettingsAppropriately(t *testin
k.On("OsqueryVerbose").Return(true)
k.On("OsqueryFlags").Return([]string{})

i := newInstance(types.DefaultRegistrationId, k, mockServiceClient())
i := newInstance(types.DefaultRegistrationID, k, mockServiceClient())

cmd, err := i.createOsquerydCommand(
testOsqueryBinaryDirectory,
Expand Down Expand Up @@ -166,7 +166,7 @@ func TestCreateOsqueryCommand_SetsDisabledWatchdogSettingsAppropriately(t *testi
k.On("OsqueryVerbose").Return(true)
k.On("OsqueryFlags").Return([]string{})

i := newInstance(types.DefaultRegistrationId, k, mockServiceClient())
i := newInstance(types.DefaultRegistrationID, k, mockServiceClient())

cmd, err := i.createOsquerydCommand(
testOsqueryBinaryDirectory,
Expand Down Expand Up @@ -207,7 +207,7 @@ func TestHealthy_DoesNotPassForUnlaunchedInstance(t *testing.T) {
k := typesMocks.NewKnapsack(t)
k.On("Slogger").Return(multislogger.NewNopLogger())

i := newInstance(types.DefaultRegistrationId, k, mockServiceClient())
i := newInstance(types.DefaultRegistrationID, k, mockServiceClient())

require.Error(t, i.Healthy(), "unlaunched instance should not return healthy status")
}
Expand All @@ -218,7 +218,7 @@ func TestQuery_ReturnsErrorForUnlaunchedInstance(t *testing.T) {
k := typesMocks.NewKnapsack(t)
k.On("Slogger").Return(multislogger.NewNopLogger())

i := newInstance(types.DefaultRegistrationId, k, mockServiceClient())
i := newInstance(types.DefaultRegistrationID, k, mockServiceClient())

_, err := i.Query("select * from osquery_info;")
require.Error(t, err, "should not be able to query unlaunched instance")
Expand All @@ -229,7 +229,7 @@ func Test_healthcheckWithRetries(t *testing.T) {

k := typesMocks.NewKnapsack(t)
k.On("Slogger").Return(multislogger.NewNopLogger())
i := newInstance(types.DefaultRegistrationId, k, mockServiceClient())
i := newInstance(types.DefaultRegistrationID, k, mockServiceClient())

// No client available, so healthcheck should fail despite retries
require.Error(t, i.healthcheckWithRetries(context.TODO(), 5, 100*time.Millisecond))
Expand Down
2 changes: 1 addition & 1 deletion pkg/osquery/runtime/osqueryinstance_windows_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ func TestCreateOsqueryCommandEnvVars(t *testing.T) {
k.On("OsqueryFlags").Return([]string{})
k.On("Slogger").Return(multislogger.NewNopLogger())

i := newInstance(types.DefaultRegistrationId, k, mockServiceClient())
i := newInstance(types.DefaultRegistrationID, k, mockServiceClient())

cmd, err := i.createOsquerydCommand(osquerydPath, &osqueryFilePaths{
pidfilePath: "/foo/bar/osquery-abcd.pid",
Expand Down
4 changes: 2 additions & 2 deletions pkg/osquery/runtime/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ type Runner struct {

func New(k types.Knapsack, serviceClient service.KolideService, opts ...OsqueryInstanceOption) *Runner {
runner := &Runner{
registrationIds: k.RegistrationIds(),
registrationIds: k.RegistrationIDs(),
instances: make(map[string]*OsqueryInstance),
slogger: k.Slogger().With("component", "osquery_runner"),
knapsack: k,
Expand Down Expand Up @@ -177,7 +177,7 @@ func (r *Runner) Query(query string) ([]map[string]string, error) {
defer r.instanceLock.Unlock()

// For now, grab the default (i.e. only) instance
instance, ok := r.instances[types.DefaultRegistrationId]
instance, ok := r.instances[types.DefaultRegistrationID]
if !ok {
return nil, errors.New("no default instance exists, cannot query")
}
Expand Down
16 changes: 8 additions & 8 deletions pkg/osquery/runtime/runtime_posix_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func TestOsquerySlowStart(t *testing.T) {
logBytes, slogger, opts := setUpTestSlogger(rootDirectory)

k := typesMocks.NewKnapsack(t)
k.On("RegistrationIds").Return([]string{types.DefaultRegistrationId})
k.On("RegistrationIDs").Return([]string{types.DefaultRegistrationID})
k.On("OsqueryHealthcheckStartupDelay").Return(0 * time.Second).Maybe()
k.On("WatchdogEnabled").Return(false)
k.On("RootDirectory").Return(rootDirectory).Maybe()
Expand Down Expand Up @@ -91,7 +91,7 @@ func TestExtensionSocketPath(t *testing.T) {
logBytes, slogger, opts := setUpTestSlogger(rootDirectory)

k := typesMocks.NewKnapsack(t)
k.On("RegistrationIds").Return([]string{types.DefaultRegistrationId})
k.On("RegistrationIDs").Return([]string{types.DefaultRegistrationID})
k.On("OsqueryHealthcheckStartupDelay").Return(0 * time.Second).Maybe()
k.On("WatchdogEnabled").Return(false)
k.On("RegisterChangeObserver", mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything)
Expand Down Expand Up @@ -137,24 +137,24 @@ func TestRestart(t *testing.T) {
runner, logBytes, teardown := setupOsqueryInstanceForTests(t)
defer teardown()

previousStats := runner.instances[types.DefaultRegistrationId].stats
previousStats := runner.instances[types.DefaultRegistrationID].stats

require.NoError(t, runner.Restart())
waitHealthy(t, runner, logBytes)

require.NotEmpty(t, runner.instances[types.DefaultRegistrationId].stats.StartTime, "start time should be set on latest instance stats after restart")
require.NotEmpty(t, runner.instances[types.DefaultRegistrationId].stats.ConnectTime, "connect time should be set on latest instance stats after restart")
require.NotEmpty(t, runner.instances[types.DefaultRegistrationID].stats.StartTime, "start time should be set on latest instance stats after restart")
require.NotEmpty(t, runner.instances[types.DefaultRegistrationID].stats.ConnectTime, "connect time should be set on latest instance stats after restart")

require.NotEmpty(t, previousStats.ExitTime, "exit time should be set on last instance stats when restarted")
require.NotEmpty(t, previousStats.Error, "stats instance should have an error on restart")

previousStats = runner.instances[types.DefaultRegistrationId].stats
previousStats = runner.instances[types.DefaultRegistrationID].stats

require.NoError(t, runner.Restart())
waitHealthy(t, runner, logBytes)

require.NotEmpty(t, runner.instances[types.DefaultRegistrationId].stats.StartTime, "start time should be added to latest instance stats after restart")
require.NotEmpty(t, runner.instances[types.DefaultRegistrationId].stats.ConnectTime, "connect time should be added to latest instance stats after restart")
require.NotEmpty(t, runner.instances[types.DefaultRegistrationID].stats.StartTime, "start time should be added to latest instance stats after restart")
require.NotEmpty(t, runner.instances[types.DefaultRegistrationID].stats.ConnectTime, "connect time should be added to latest instance stats after restart")

require.NotEmpty(t, previousStats.ExitTime, "exit time should be set on instance stats when restarted")
require.NotEmpty(t, previousStats.Error, "stats instance should have an error on restart")
Expand Down
Loading

0 comments on commit 7aa6930

Please sign in to comment.