-
Notifications
You must be signed in to change notification settings - Fork 127
Add elastic-package stack status command #917
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
Conversation
🌐 Coverage report
|
internal/stack/compose.go
Outdated
| statusServices, err := p.Status(statusOptions) | ||
| if err != nil { | ||
| return nil, errors.Wrap(err, "running command failed") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
While running locally, I see the following error, even when all the containers are up and healthy 🤔
Error: failed updating the stack images: stack status failed: running command failed: container not recognised: /elastic-package-stack-elastic-agent-1
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What command did you use to boot the stack ?
I think maybe the docker output is using different name patterns. For instance, when I run locally the stack and check the containers running these are their names:
$ docker ps --format '{{.ID}} {{ .Names}}'
f2548695fda4 elastic-package-stack_elastic-agent_1
cd053207a69a elastic-package-stack_fleet-server_1
e5ae9f4a9ec8 elastic-package-stack_kibana_1
9f81003784b6 elastic-package-stack_elasticsearch_1
23a56affd189 elastic-package-stack_package-registry_1@jsoriano What is your output of this command when you have the stack up and running ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What command did you use to boot the stack ?
elastic-package stack up -v -d, with docker-compose 2.3.3.
What is your output of this command when you have the stack up and running ?
$ docker ps --format '{{.ID}} {{ .Names}}'
7bcbf178400d elastic-package-stack-elastic-agent-1
3e4549a3fae3 elastic-package-stack-fleet-server-1
f84559da2eeb elastic-package-stack-kibana-1
64a987ed7d99 elastic-package-stack-package-registry-1
b1af47e723d5 elastic-package-stack-elasticsearch-1
There are - where you have _.
Maybe using the docker compose labels is more predictable:
$ docker ps --format '{{.ID}} {{.Label "com.docker.compose.service"}}'
7bcbf178400d elastic-agent
3e4549a3fae3 fleet-server
f84559da2eeb kibana
64a987ed7d99 package-registry
b1af47e723d5 elasticsearch
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For completeness, in my case the docker-compose version is 1.29.2.
Keeping the regex could be eventually problematic if there are those differences between versions. I'm going to change the implementation and get the service name from the labels, as you suggested. Thanks!
|
/test |
cmd/stack.go
Outdated
| stackVersion, err := cmd.Flags().GetString(cobraext.StackVersionFlagName) | ||
| if err != nil { | ||
| return cobraext.FlagParsingError(err, cobraext.StackVersionFlagName) | ||
| } | ||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
--version parameter is needed in order to be able to load the needed environment variables.
$ elastic-package stack status -v
2022/08/11 12:35:13 DEBUG Enable verbose logging
2022/08/11 12:35:13 DEBUG Distribution built without a version tag, can't determine release chronology. Please consider using official releases at https://github.com/elastic/elastic-package/releases
2022/08/11 12:35:13 DEBUG running command: /home/mariorodriguez/bin/docker-compose version --short
2022/08/11 12:35:14 DEBUG Determined Docker Compose version: 1.29.2, the tool will use Compose V1
2022/08/11 12:35:14 DEBUG running command: /home/mariorodriguez/bin/docker-compose -f /home/mariorodriguez/.elastic-package/profiles/default/stack/snapshot.yml -p elastic-package-stack ps -q
ERROR: Couldn't find env file: /home/mariorodriguez/.elastic-package/profiles/default/stack/elastic-agent..env
2022/08/11 12:35:14 ERROR is Elastic stack created/running?
Error: failed getting stack status: running command failed: exit status 1
This fails when running docker-compose v1.
In case of docker-compose v2 it does not fail, not sure yet what it is the difference
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice 👍
Use docker ps with filter parameter to get the containers related to a docker-compose scenario. This allows us to avoid loading environment variables and the profiles to get this information.
|
Changed logic to use The containers defined in a docker-compose scenario can be retrieved by filtering by the label docker ps --filter "label=com.docker.compose.project=elastic-package-stack" --format {{.ID}} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🚀
This PR adds a new subcommand under "stack" to show the Elastic stack containers status.
The command to show this information is:
elastic-package stack statusExamples:
Closes #836