Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Print a message if a stage is taking more than 10 seconds #185

Merged
merged 4 commits into from
Oct 22, 2024

Conversation

Itxaka
Copy link
Collaborator

@Itxaka Itxaka commented Oct 21, 2024

With a config like this:

#cloud-config

stages:
  initramfs:
    - name: "test"
      commands:
        - sleep 15
        - echo "hello"

This is the output:

$ LOGLEVEL=debug go run main.go -s initramfs .
INFO[0000] yip version -g                               
INFO[0000] Running stage: initramfs                     
DEBU[0000] Generating op for stage 'test.yaml.0'        
DEBU[0000] Generating op for stage 'test.yaml.test'     
DEBU[0000] Reading 'test.yaml'                          
DEBU[0000] Executing stage 'test.yaml.0'                
INFO[0000] Processing stage step 'test.yaml.0'. ( commands: 0, files: 0, ... ) 
DEBU[0000] Stage: schema.Stage{}                        
DEBU[0000] Device field empty, skipping layout plugin   
DEBU[0000] Reading 'test.yaml'                          
DEBU[0000] Executing stage 'test.yaml.test'             
INFO[0000] Processing stage step 'test.yaml.test'. ( commands: 2, files: 0, ... ) 
DEBU[0000] Stage: schema.Stage{
  Commands: []string{
    "sleep 15",
    "echo \"hello\"",
  },
  Name: "test",
} 
DEBU[0000] running command `sleep 15`                   
INFO[0010] Still running command 'sleep 15'             
DEBU[0015] Empty command output                         
DEBU[0015] running command `echo "hello"`               
DEBU[0015] Command output: hello                        
DEBU[0015] Device field empty, skipping layout plugin   
INFO[0015] Done executing stage 'initramfs'    

pkg/console/console.go Outdated Show resolved Hide resolved
Signed-off-by: Itxaka <[email protected]>
pkg/console/console.go Outdated Show resolved Hide resolved
@Itxaka Itxaka requested a review from mudler October 21, 2024 16:19
@Itxaka
Copy link
Collaborator Author

Itxaka commented Oct 21, 2024

$ LOGLEVEL=debug go run main.go -s initramfs .
INFO[0000] yip version -g                               
INFO[0000] Running stage: initramfs                     
DEBU[0000] Generating op for stage 'test.yaml.0'        
DEBU[0000] Generating op for stage 'test.yaml.test'     
DEBU[0000] Reading 'test.yaml'                          
DEBU[0000] Executing stage 'test.yaml.0'                
INFO[0000] Processing stage step 'test.yaml.0'. ( commands: 0, files: 0, ... ) 
DEBU[0000] Stage: schema.Stage{}                        
DEBU[0000] Device field empty, skipping layout plugin   
DEBU[0000] Reading 'test.yaml'                          
DEBU[0000] Executing stage 'test.yaml.test'             
INFO[0000] Processing stage step 'test.yaml.test'. ( commands: 2, files: 0, ... ) 
DEBU[0000] Stage: schema.Stage{
  Commands: []string{
    "sleep 15",
    "sleep 12",
  },
  Name: "test",
} 
DEBU[0000] running command `sleep 15`                   
INFO[0005] Still running command 'sleep 15'             
INFO[0010] Still running command 'sleep 15'             
INFO[0015] Still running command 'sleep 15'             
DEBU[0015] Empty command output                         
DEBU[0015] running command `sleep 12`                   
INFO[0020] Still running command 'sleep 12'             
INFO[0025] Still running command 'sleep 12'             
DEBU[0027] Empty command output                         
DEBU[0027] Device field empty, skipping layout plugin   
INFO[0027] Done executing stage 'initramfs'           

@Itxaka
Copy link
Collaborator Author

Itxaka commented Oct 21, 2024

so the problem seems that in the case of the rsync we needed the channel to pass back the info about the rsync output, but here we just need to print a info message, nothing more

out, err := c.CombinedOutput()

// Stop the timer log
cancel()
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

isn't this redundant? we do already call defer cancel()

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

umm that its true, maybe I was testing this manually or something?

pkg/console/console.go Outdated Show resolved Hide resolved
@mudler
Copy link
Owner

mudler commented Oct 21, 2024

so the problem seems that in the case of the rsync we needed the channel to pass back the info about the rsync output, but here we just need to print a info message, nothing more

right, but the new changes looks good - with the first round we were keeping the goroutine alive because it was not being closed at all. Now we bind it to the context which gets canceled after we finish running the command (which makes sense).

@mudler
Copy link
Owner

mudler commented Oct 21, 2024

Just to call it out explicitly here: this covers only shell commands, not all other plugins. Can't we make at this point hook at the plugin execution? that way could cover also other cases (e.g. fetching userdata over slow network, etc)

@Itxaka
Copy link
Collaborator Author

Itxaka commented Oct 21, 2024

Just to call it out explicitly here: this covers only shell commands, not all other plugins. Can't we make at this point hook at the plugin execution? that way could cover also other cases (e.g. fetching userdata over slow network, etc)

I dont know tbh, its it possible for other sources to take this long? We are talking seconds here for a "big" delay, so maybe other sources are not prone to be this slow? While commands can be really slow, like a script that waits for a service to be up and such?

But yeah, it may be trivial to adapt this to it so maybe its possible to just plugin it in before the plugin is executed

Signed-off-by: Itxaka <[email protected]>
@Itxaka Itxaka force-pushed the progress_commands branch from 1849eee to 2cb0329 Compare October 22, 2024 07:24
@Itxaka
Copy link
Collaborator Author

Itxaka commented Oct 22, 2024

@mudler how about now?

$ LOGLEVEL=debug go run main.go -s initramfs .
INFO[0000] yip version -g                               
INFO[0000] Running stage: initramfs                     
DEBU[0000] Generating op for stage 'test.yaml.0'        
DEBU[0000] Generating op for stage 'test.yaml.test'     
DEBU[0000] Reading 'test.yaml'                          
DEBU[0000] Executing stage 'test.yaml.0'                
INFO[0000] Processing stage step 'test.yaml.0'. ( commands: 0, files: 0, ... ) 
DEBU[0000] Stage: schema.Stage{}                        
DEBU[0000] Device field empty, skipping layout plugin   
DEBU[0000] Reading 'test.yaml'                          
DEBU[0000] Executing stage 'test.yaml.test'             
INFO[0000] Processing stage step 'test.yaml.test'. ( commands: 2, files: 0, ... ) 
DEBU[0000] Stage: schema.Stage{
  Commands: []string{
    "sleep 15",
    "sleep 12",
  },
  Name: "test",
} 
DEBU[0000] running command `sleep 15`                   
INFO[0010] Still running stage 'test.yaml.test'         
DEBU[0015] Empty command output                         
DEBU[0015] running command `sleep 12`                   
INFO[0020] Still running stage 'test.yaml.test'         
DEBU[0027] Empty command output                         
DEBU[0027] Device field empty, skipping layout plugin   
INFO[0027] Done executing stage 'initramfs'             

on info:

$ go run main.go -s initramfs .
INFO[0000] yip version -g                               
INFO[0000] Running stage: initramfs                     
INFO[0000] Processing stage step 'test.yaml.0'. ( commands: 0, files: 0, ... ) 
INFO[0000] Processing stage step 'test.yaml.test'. ( commands: 2, files: 0, ... ) 
INFO[0010] Still running stage 'test.yaml.test'         
INFO[0020] Still running stage 'test.yaml.test'         
INFO[0027] Done executing stage 'initramfs'      

@Itxaka Itxaka requested a review from mudler October 22, 2024 07:25
@Itxaka Itxaka changed the title Print a message if a command is taking more than 10 seconds Print a message if a stage is taking more than 10 seconds Oct 22, 2024
Copy link
Owner

@mudler mudler left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perfect! thank you @Itxaka !

@mudler mudler merged commit cfe101e into master Oct 22, 2024
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants