Skip to content

Commit

Permalink
Testing: Further reduce use of DirectoryLogger (#1238)
Browse files Browse the repository at this point in the history
  • Loading branch information
martijnvans authored May 12, 2023
1 parent 73b9b08 commit fe40dbf
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 68 deletions.
10 changes: 5 additions & 5 deletions integration_test/agents/agents.go
Original file line number Diff line number Diff line change
Expand Up @@ -744,13 +744,13 @@ func InstallOpsAgent(ctx context.Context, logger *log.Logger, vm *gce.VM, locati
}

// SetupOpsAgent installs the Ops Agent and installs the given config.
func SetupOpsAgent(ctx context.Context, logger *logging.DirectoryLogger, vm *gce.VM, config string) error {
func SetupOpsAgent(ctx context.Context, logger *log.Logger, vm *gce.VM, config string) error {
return SetupOpsAgentFrom(ctx, logger, vm, config, LocationFromEnvVars())
}

// restartOpsAgent restarts the Ops Agent and waits for it to become available.
func restartOpsAgent(ctx context.Context, logger *logging.DirectoryLogger, vm *gce.VM) error {
if _, err := gce.RunRemotely(ctx, logger.ToMainLog(), vm, "", restartOpsAgentForPlatform(vm.Platform)); err != nil {
func restartOpsAgent(ctx context.Context, logger *log.Logger, vm *gce.VM) error {
if _, err := gce.RunRemotely(ctx, logger, vm, "", restartOpsAgentForPlatform(vm.Platform)); err != nil {
return fmt.Errorf("restartOpsAgent() failed to restart ops agent: %v", err)
}
// Give agents time to shut down. Fluent-Bit's default shutdown grace period
Expand All @@ -761,8 +761,8 @@ func restartOpsAgent(ctx context.Context, logger *logging.DirectoryLogger, vm *g

// SetupOpsAgentFrom is an overload of setupOpsAgent that allows the callsite to
// decide which version of the agent gets installed.
func SetupOpsAgentFrom(ctx context.Context, logger *logging.DirectoryLogger, vm *gce.VM, config string, location PackageLocation) error {
if err := InstallOpsAgent(ctx, logger.ToMainLog(), vm, location); err != nil {
func SetupOpsAgentFrom(ctx context.Context, logger *log.Logger, vm *gce.VM, config string, location PackageLocation) error {
if err := InstallOpsAgent(ctx, logger, vm, location); err != nil {
return err
}
startupDelay := 20 * time.Second
Expand Down
9 changes: 3 additions & 6 deletions integration_test/gce/gce_testing.go
Original file line number Diff line number Diff line change
Expand Up @@ -808,18 +808,16 @@ func RunRemotely(ctx context.Context, logger *log.Logger, vm *VM, stdin string,
// given permission to read from that bucket. This was accomplished by adding
// the "Compute Engine default service account" for PROJECT as
// a "Storage Object Viewer" and "Storage Object Creator" on the bucket.
func UploadContent(ctx context.Context, dirLog *logging.DirectoryLogger, vm *VM, content io.Reader, remotePath string) (err error) {
func UploadContent(ctx context.Context, logger *log.Logger, vm *VM, content io.Reader, remotePath string) (err error) {
defer func() {
dirLog.ToMainLog().Printf("Uploading file finished. For details see file_uploads.txt. err=%v", err)
logger.Printf("Uploading file finished with err=%v", err)
}()
logger := dirLog.ToFile("file_uploads.txt")
object := storageClient.Bucket(transfersBucket).Object(path.Join(vm.Name, remotePath))
writer := object.NewWriter(ctx)
_, copyErr := io.Copy(writer, content)
// We have to make sure to call Close() here in order to tell it to finish
// the upload operation.
closeErr := writer.Close()
logger.Printf("Upload to %v finished with copyErr=%v, closeErr=%v", object, copyErr, closeErr)
err = multierr.Combine(copyErr, closeErr)
if err != nil {
return fmt.Errorf("UploadContent() could not write data into storage object: %v", err)
Expand All @@ -831,7 +829,6 @@ func UploadContent(ctx context.Context, dirLog *logging.DirectoryLogger, vm *VM,
// (note that the go client libraries use resumable uploads).
defer func() {
deleteErr := object.Delete(ctx)
logger.Printf("Deleting %v finished with deleteErr=%v", object, deleteErr)
if deleteErr != nil {
err = fmt.Errorf("UploadContent() finished with err=%v, then cleanup of %v finished with err=%v", err, object.ObjectName(), deleteErr)
}
Expand Down Expand Up @@ -886,7 +883,7 @@ func RunScriptRemotely(ctx context.Context, logger *logging.DirectoryLogger, vm
// Use a UUID for the script name in case RunScriptRemotely is being
// called concurrently on the same VM.
scriptPath := "C:\\" + uuid.NewString() + ".ps1"
if err := UploadContent(ctx, logger, vm, strings.NewReader(scriptContents), scriptPath); err != nil {
if err := UploadContent(ctx, logger.ToFile("file_uploads.txt"), vm, strings.NewReader(scriptContents), scriptPath); err != nil {
return CommandOutput{}, err
}
return RunRemotely(ctx, logger.ToMainLog(), vm, "", envVarMapToPowershellPrefix(env)+"powershell -File "+scriptPath+" "+flagsStr)
Expand Down
Loading

0 comments on commit fe40dbf

Please sign in to comment.