Skip to content

Commit

Permalink
use local context
Browse files Browse the repository at this point in the history
  • Loading branch information
marcoandredinis committed Nov 4, 2024
1 parent bb4bd32 commit bdae4e4
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 11 deletions.
6 changes: 3 additions & 3 deletions lib/srv/discovery/database_watcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ func (s *Server) getCurrentDatabases() map[string]types.Database {
}

func (s *Server) onDatabaseCreate(ctx context.Context, database types.Database) error {
s.Log.DebugContext(s.ctx, "Creating database", "database", database.GetName())
s.Log.DebugContext(ctx, "Creating database", "database", database.GetName())
err := s.AccessPoint.CreateDatabase(ctx, database)
// If the database already exists but has cloud origin and an empty
// discovery group, then update it.
Expand Down Expand Up @@ -169,12 +169,12 @@ func (s *Server) onDatabaseCreate(ctx context.Context, database types.Database)
}

func (s *Server) onDatabaseUpdate(ctx context.Context, database, _ types.Database) error {
s.Log.DebugContext(s.ctx, "Updating database", "database", database.GetName())
s.Log.DebugContext(ctx, "Updating database", "database", database.GetName())
return trace.Wrap(s.AccessPoint.UpdateDatabase(ctx, database))
}

func (s *Server) onDatabaseDelete(ctx context.Context, database types.Database) error {
s.Log.DebugContext(s.ctx, "Deleting database", "database", database.GetName())
s.Log.DebugContext(ctx, "Deleting database", "database", database.GetName())
return trace.Wrap(s.AccessPoint.DeleteDatabase(ctx, database.GetName()))
}

Expand Down
14 changes: 8 additions & 6 deletions lib/srv/discovery/discovery.go
Original file line number Diff line number Diff line change
Expand Up @@ -257,8 +257,9 @@ kubernetes matchers are present.`)
c.LegacyLogger = c.LegacyLogger.WithField(teleport.ComponentKey, teleport.ComponentDiscovery)

if c.DiscoveryGroup == "" {
c.Log.Warn("discovery_service.discovery_group is not set. This field is required for the discovery service to work properly.\n" +
"Please set discovery_service.discovery_group according to the documentation: https://goteleport.com/docs/reference/config/#discovery-service")
warningMessage := "discovery_service.discovery_group is not set. This field is required for the discovery service to work properly.\n" +
"Please set discovery_service.discovery_group according to the documentation: https://goteleport.com/docs/reference/config/#discovery-service"
c.Log.WarnContext(context.Background(), warningMessage)
}

c.Matchers.Azure = services.SimplifyAzureMatchers(c.Matchers.Azure)
Expand Down Expand Up @@ -1033,11 +1034,12 @@ func (s *Server) handleEC2RemoteInstallation(instances *server.EC2Instances) err
func (s *Server) logHandleInstancesErr(err error) {
var aErr awserr.Error
if errors.As(err, &aErr) && aErr.Code() == ssm.ErrCodeInvalidInstanceId {
errorMessage := "SSM SendCommand failed with ErrCodeInvalidInstanceId. " +
"Make sure that the instances have AmazonSSMManagedInstanceCore policy assigned. " +
"Also check that SSM agent is running and registered with the SSM endpoint on that instance and try restarting or reinstalling it in case of issues. " +
"See https://docs.aws.amazon.com/systems-manager/latest/APIReference/API_SendCommand.html#API_SendCommand_Errors for more details."
s.Log.ErrorContext(s.ctx,
"SSM SendCommand failed with ErrCodeInvalidInstanceId. "+
"Make sure that the instances have AmazonSSMManagedInstanceCore policy assigned. "+
"Also check that SSM agent is running and registered with the SSM endpoint on that instance and try restarting or reinstalling it in case of issues. "+
"See https://docs.aws.amazon.com/systems-manager/latest/APIReference/API_SendCommand.html#API_SendCommand_Errors for more details.",
errorMessage,
"error", err)
} else if trace.IsNotFound(err) {
s.Log.DebugContext(s.ctx, "All discovered EC2 instances are already part of the cluster")
Expand Down
2 changes: 1 addition & 1 deletion lib/srv/discovery/kube_services_watcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ func (s *Server) onAppCreate(ctx context.Context, app types.Application) error {
},
})
if err != nil {
s.Log.DebugContext(s.ctx, "Error emitting usage event", "error", err)
s.Log.DebugContext(ctx, "Error emitting usage event", "error", err)
}
return nil
}
Expand Down
2 changes: 1 addition & 1 deletion lib/srv/discovery/kube_watcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ func (s *Server) startKubeWatchers() error {
}

func (s *Server) onKubeCreate(ctx context.Context, kubeCluster types.KubeCluster) error {
s.Log.DebugContext(s.ctx, "Creating kube_cluster", "kube_cluster_name", kubeCluster.GetName())
s.Log.DebugContext(ctx, "Creating kube_cluster", "kube_cluster_name", kubeCluster.GetName())
err := s.AccessPoint.CreateKubernetesCluster(ctx, kubeCluster)
// If the kube already exists but has an empty discovery group, update it.
if err != nil {
Expand Down

0 comments on commit bdae4e4

Please sign in to comment.