Skip to content

Commit

Permalink
Add disabled imds client by default for integration tests (#13109)
Browse files Browse the repository at this point in the history
The instance metadata client added in #12593 significantly slows down integration tests. This change adds a disabled client to integration tests to improve performance.
  • Loading branch information
atburke authored Jun 2, 2022
1 parent 521d6c2 commit 7f730d2
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 12 deletions.
32 changes: 24 additions & 8 deletions integration/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -670,7 +670,7 @@ func (i *TeleInstance) CreateEx(t *testing.T, trustedSecrets []*InstanceSecrets,
return trace.Wrap(err)
}
i.Config = tconf
i.Process, err = service.NewTeleport(tconf)
i.Process, err = service.NewTeleport(tconf, service.WithIMDSClient(&disabledIMDSClient{}))
if err != nil {
return trace.Wrap(err)
}
Expand Down Expand Up @@ -765,7 +765,7 @@ func (i *TeleInstance) startNode(tconf *service.Config, authPort string) (*servi

// Create a new Teleport process and add it to the list of nodes that
// compose this "cluster".
process, err := service.NewTeleport(tconf)
process, err := service.NewTeleport(tconf, service.WithIMDSClient(&disabledIMDSClient{}))
if err != nil {
return nil, trace.Wrap(err)
}
Expand Down Expand Up @@ -809,7 +809,7 @@ func (i *TeleInstance) StartApp(conf *service.Config) (*service.TeleportProcess,

// Create a new Teleport process and add it to the list of nodes that
// compose this "cluster".
process, err := service.NewTeleport(conf)
process, err := service.NewTeleport(conf, service.WithIMDSClient(&disabledIMDSClient{}))
if err != nil {
return nil, trace.Wrap(err)
}
Expand Down Expand Up @@ -861,7 +861,7 @@ func (i *TeleInstance) StartApps(configs []*service.Config) ([]*service.Teleport

// Create a new Teleport process and add it to the list of nodes that
// compose this "cluster".
process, err := service.NewTeleport(cfg)
process, err := service.NewTeleport(cfg, service.WithIMDSClient(&disabledIMDSClient{}))
if err != nil {
results <- result{err: err, tmpDir: dataDir}
}
Expand Down Expand Up @@ -927,7 +927,7 @@ func (i *TeleInstance) StartDatabase(conf *service.Config) (*service.TeleportPro

// Create a new Teleport process and add it to the list of nodes that
// compose this "cluster".
process, err := service.NewTeleport(conf)
process, err := service.NewTeleport(conf, service.WithIMDSClient(&disabledIMDSClient{}))
if err != nil {
return nil, nil, trace.Wrap(err)
}
Expand Down Expand Up @@ -1013,7 +1013,7 @@ func (i *TeleInstance) StartNodeAndProxy(name string, sshPort, proxyWebPort, pro

// Create a new Teleport process and add it to the list of nodes that
// compose this "cluster".
process, err := service.NewTeleport(tconf)
process, err := service.NewTeleport(tconf, service.WithIMDSClient(&disabledIMDSClient{}))
if err != nil {
return trace.Wrap(err)
}
Expand Down Expand Up @@ -1100,7 +1100,7 @@ func (i *TeleInstance) StartProxy(cfg ProxyConfig) (reversetunnel.Server, error)

// Create a new Teleport process and add it to the list of nodes that
// compose this "cluster".
process, err := service.NewTeleport(tconf)
process, err := service.NewTeleport(tconf, service.WithIMDSClient(&disabledIMDSClient{}))
if err != nil {
return nil, trace.Wrap(err)
}
Expand Down Expand Up @@ -1149,7 +1149,7 @@ func (i *TeleInstance) Reset() (err error) {
return trace.Wrap(err)
}
}
i.Process, err = service.NewTeleport(i.Config)
i.Process, err = service.NewTeleport(i.Config, service.WithIMDSClient(&disabledIMDSClient{}))
if err != nil {
return trace.Wrap(err)
}
Expand Down Expand Up @@ -1881,3 +1881,19 @@ func getLocalIP() (string, error) {
}
return "", trace.NotFound("No non-loopback local IP address found")
}

// disabledIMDSClient is an EC2 instance metadata client that is always disabled. This is faster
// than the default client when not testing instance metadata behavior.
type disabledIMDSClient struct{}

func (d *disabledIMDSClient) IsAvailable(ctx context.Context) bool {
return false
}

func (d *disabledIMDSClient) GetTagKeys(ctx context.Context) ([]string, error) {
return nil, nil
}

func (d *disabledIMDSClient) GetTagValue(ctx context.Context, key string) (string, error) {
return "", nil
}
8 changes: 4 additions & 4 deletions integration/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3710,7 +3710,7 @@ func testRotateSuccess(t *testing.T, suite *integrationTestSuite) {
runErrCh := make(chan error, 1)
go func() {
runErrCh <- service.Run(ctx, *config, func(cfg *service.Config) (service.Process, error) {
svc, err := service.NewTeleport(cfg)
svc, err := service.NewTeleport(cfg, service.WithIMDSClient(&disabledIMDSClient{}))
if err == nil {
serviceC <- svc
}
Expand Down Expand Up @@ -3874,7 +3874,7 @@ func testRotateRollback(t *testing.T, s *integrationTestSuite) {
runErrCh := make(chan error, 1)
go func() {
runErrCh <- service.Run(ctx, *config, func(cfg *service.Config) (service.Process, error) {
svc, err := service.NewTeleport(cfg)
svc, err := service.NewTeleport(cfg, service.WithIMDSClient(&disabledIMDSClient{}))
if err == nil {
serviceC <- svc
}
Expand Down Expand Up @@ -4018,7 +4018,7 @@ func testRotateTrustedClusters(t *testing.T, suite *integrationTestSuite) {
runErrCh := make(chan error, 1)
go func() {
runErrCh <- service.Run(ctx, *config, func(cfg *service.Config) (service.Process, error) {
svc, err := service.NewTeleport(cfg)
svc, err := service.NewTeleport(cfg, service.WithIMDSClient(&disabledIMDSClient{}))
if err == nil {
serviceC <- svc
}
Expand Down Expand Up @@ -4258,7 +4258,7 @@ func testRotateChangeSigningAlg(t *testing.T, suite *integrationTestSuite) {
ctx, cancel := context.WithCancel(context.Background())
go func() {
runErrCh <- service.Run(ctx, *config, func(cfg *service.Config) (service.Process, error) {
svc, err := service.NewTeleport(cfg)
svc, err := service.NewTeleport(cfg, service.WithIMDSClient(&disabledIMDSClient{}))
if err == nil {
serviceC <- svc
}
Expand Down

0 comments on commit 7f730d2

Please sign in to comment.