Skip to content

[Spacetime] Enhance errors #2779

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

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

Supplementing
Copy link

@Supplementing Supplementing commented Jul 28, 2025

Summary

Closes https://github.com/elastic/ingest-dev/issues/5837

This is an exploratory PR aimed to improve errors displayed to the user during common commands.

The check added checks the status of Docker and ensures the daemon is running before trying to continue, which resolves issues where the CLI could 'hang' with no error output unless the user explicitly passed in the -d and or -v flags. Now we will perform a precheck and log to the user the issue.

I also explored adding a precheck for packages to be built before running install, but realized that the install command checks that already and then performs the build automatically, so the check is not needed.

Testing Instructions:

  1. Create a new package
  2. Build the package
  3. Ensure docker isnt already running (kill the desktop application and any instances)
  4. Try installing the package using elastic-package install
  5. Note that the errors are surfaced to the user telling them that Docker isnt running and it fails immediately.

@Supplementing Supplementing requested a review from jsoriano July 28, 2025 17:05
@Supplementing Supplementing added the Team:Ecosystem Label for the Packages Ecosystem team label Jul 28, 2025
@elasticmachine
Copy link
Collaborator

elasticmachine commented Jul 28, 2025

💛 Build succeeded, but was flaky

Failed CI Steps

History

// Check if Docker daemon is running
if err := CheckDockerRunning(); err != nil {
return err
}
Copy link
Member

Choose a reason for hiding this comment

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

Instead of having to check it on every operation, I think we could create a new newComposeProvider() (*composeProvider, error) constructor that could run the check, when initializing it in the factory, here:

return &composeProvider{}, nil

Copy link
Contributor

Choose a reason for hiding this comment

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

I think the other providers (Environment and Serverless) could take advantage of this check too. IIRC these two providers run also docker (docker-compose) commands.

Just thinking that doing this check in the providers makes that elastic-package test or install commands do not run this check.
Maybe it's not needed, since all these commands will require to be the Elastic stack up... WDYT?

Comment on lines +204 to +205
logger.Error(": Docker daemon is not running or not accessible")
logger.Error(": Please make sure Docker is installed and running before executing commands that require Docker")
Copy link
Member

Choose a reason for hiding this comment

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

This is an internal method. I would prefer to log closer to the user.

Suggested change
logger.Error(": Docker daemon is not running or not accessible")
logger.Error(": Please make sure Docker is installed and running before executing commands that require Docker")

Comment on lines +203 to +206
daemonError := fmt.Errorf("docker daemon is not running (stderr=%q): %w", errOutput.String(), err)
logger.Error(": Docker daemon is not running or not accessible")
logger.Error(": Please make sure Docker is installed and running before executing commands that require Docker")
return daemonError
Copy link
Member

Choose a reason for hiding this comment

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

Nit. You can directly return the error.

Suggested change
daemonError := fmt.Errorf("docker daemon is not running (stderr=%q): %w", errOutput.String(), err)
logger.Error(": Docker daemon is not running or not accessible")
logger.Error(": Please make sure Docker is installed and running before executing commands that require Docker")
return daemonError
logger.Error(": Docker daemon is not running or not accessible")
logger.Error(": Please make sure Docker is installed and running before executing commands that require Docker")
return fmt.Errorf("docker daemon is not running (stderr=%q): %w", errOutput.String(), err)

errOutput := new(bytes.Buffer)
cmd.Stderr = errOutput

logger.Debugf("running command to check Docker daemon: %s", cmd)
Copy link
Contributor

Choose a reason for hiding this comment

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

I'd use Trace level for this message

Suggested change
logger.Debugf("running command to check Docker daemon: %s", cmd)
logger.Tracef("running command to check Docker daemon: %s", cmd)

// Check if Docker daemon is running
if err := CheckDockerRunning(); err != nil {
return err
}
Copy link
Contributor

Choose a reason for hiding this comment

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

I think the other providers (Environment and Serverless) could take advantage of this check too. IIRC these two providers run also docker (docker-compose) commands.

Just thinking that doing this check in the providers makes that elastic-package test or install commands do not run this check.
Maybe it's not needed, since all these commands will require to be the Elastic stack up... WDYT?

// CheckDaemonRunning checks if the Docker daemon is running.
// Returns nil if the daemon is running, or an error if it's not.
func CheckDaemonRunning() error {
cmd := exec.Command("docker", "info")
Copy link
Contributor

@mrodm mrodm Jul 29, 2025

Choose a reason for hiding this comment

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

This commands has a large output. It should not be an issue, but maybe it could be format the output to just shown a specific value (e.g. ServerVersion).

Suggested change
cmd := exec.Command("docker", "info")
cmd := exec.Command("docker", "info", "--format", "{{ .ServerVersion }}")

@Supplementing
Copy link
Author

Got a little bogged down during the final two weeks of this iteration, and this took a backburner after ON week. Will revisit it sometime during next sprint to address requested changes! @mrodm @jsoriano

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Team:Ecosystem Label for the Packages Ecosystem team
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants