Skip to content

Conversation

@mrodm
Copy link
Contributor

@mrodm mrodm commented Jul 29, 2022

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 status

Examples:

  • All services running:
 $ elastic-package stack status
elastic-package has been installed.
Status of Elastic stack services:
╭──────────────────┬─────────┬───────────────────╮
│ SERVICE          │ VERSION │ STATUS            │
├──────────────────┼─────────┼───────────────────┤
│ elastic-agent    │ 8.3.2   │ running (healthy) │
│ elasticsearch    │ 8.3.2   │ running (healthy) │
│ fleet-server     │ 8.3.2   │ running (healthy) │
│ kibana           │ 8.3.2   │ running (healthy) │
│ package-registry │ latest  │ running (healthy) │
╰──────────────────┴─────────┴───────────────────╯
  • Some containers stopped/killed:
 $ elastic-package stack status
Status of Elastic stack services:
╭──────────────────┬─────────┬───────────────────╮
│ SERVICE          │ VERSION │ STATUS            │
├──────────────────┼─────────┼───────────────────┤
│ elastic-agent    │ 8.3.2   │ exited (137)      │
│ elasticsearch    │ 8.3.2   │ running (healthy) │
│ fleet-server     │ 8.3.2   │ running (healthy) │
│ kibana           │ 8.3.2   │ running (healthy) │
│ package-registry │ latest  │ exited (137)      │
╰──────────────────┴─────────┴───────────────────╯
  • No container running (elastic-package stack down)
 $ elastic-package stack status
Status of Elastic stack services:
 - No service running
  • Just some services are started:
 $ elastic-package stack up -v -d --services=elasticsearch,kibana
...
 $ elastic-package stack status -v
Status of Elastic stack services:
╭──────────────────┬─────────┬───────────────────╮
│ SERVICE          │ VERSION │ STATUS            │
├──────────────────┼─────────┼───────────────────┤
│ elasticsearch    │ 8.3.2   │ running (healthy) │
│ kibana           │ 8.3.2   │ running (healthy) │
│ package-registry │ latest  │ running (healthy) │
╰──────────────────┴─────────┴───────────────────╯

Closes #836

@mrodm mrodm added the Team:Ecosystem Label for the Packages Ecosystem team label Jul 29, 2022
@mrodm mrodm self-assigned this Jul 29, 2022
@elasticmachine
Copy link
Collaborator

elasticmachine commented Jul 29, 2022

💚 Build Succeeded

the below badges are clickable and redirect to their specific view in the CI or DOCS
Pipeline View Test View Changes Artifacts preview preview

Expand to view the summary

Build stats

  • Start Time: 2022-08-12T11:34:10.332+0000

  • Duration: 33 min 4 sec

Test stats 🧪

Test Results
Failed 0
Passed 778
Skipped 0
Total 778

🤖 GitHub comments

To re-run your PR in the CI, just comment with:

  • /test : Re-trigger the build.

@elasticmachine
Copy link
Collaborator

elasticmachine commented Jul 29, 2022

🌐 Coverage report

Name Metrics % (covered/total) Diff
Packages 100.0% (32/32) 💚
Files 66.949% (79/118) 👍 0.282
Classes 62.424% (103/165) 👍 0.229
Methods 49.624% (330/665) 👎 -0.073
Lines 33.162% (2963/8935) 👎 -0.036
Conditionals 100.0% (0/0) 💚

Comment on lines 163 to 165
statusServices, err := p.Status(statusOptions)
if err != nil {
return nil, errors.Wrap(err, "running command failed")
Copy link
Member

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

Copy link
Contributor Author

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 ?

Copy link
Member

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

Copy link
Contributor Author

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!

@mrodm
Copy link
Contributor Author

mrodm commented Aug 11, 2022

/test

cmd/stack.go Outdated
Comment on lines 264 to 268
stackVersion, err := cmd.Flags().GetString(cobraext.StackVersionFlagName)
if err != nil {
return cobraext.FlagParsingError(err, cobraext.StackVersionFlagName)
}

Copy link
Contributor Author

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

@mrodm mrodm changed the title Add elastic-package status command - WIP Add elastic-package status command Aug 11, 2022
@mrodm mrodm marked this pull request as ready for review August 11, 2022 15:45
@mrodm mrodm requested a review from jsoriano August 11, 2022 15:45
Copy link
Member

@jsoriano jsoriano left a comment

Choose a reason for hiding this comment

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

Nice 👍

mrodm added 3 commits August 11, 2022 20:31
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.
@mrodm
Copy link
Contributor Author

mrodm commented Aug 11, 2022

Changed logic to use docker commands filtering by label instead of using docker-compose ps commands to avoid the need to set environment variables (like STACK_VERSION_VARIANT) or load the profiles. Using docker-compose it forces to define a --version parameter for this subcommand (that could have some default value (e.g. "default"))

The containers defined in a docker-compose scenario can be retrieved by filtering by the label com.docker.compose.project=<project>, example:

docker ps --filter "label=com.docker.compose.project=elastic-package-stack" --format {{.ID}}

@mrodm mrodm requested a review from jsoriano August 12, 2022 08:08
Copy link
Member

@jsoriano jsoriano left a comment

Choose a reason for hiding this comment

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

🚀

@mrodm mrodm changed the title Add elastic-package status command Add elastic-package stack status command Aug 16, 2022
@mrodm mrodm merged commit 8d676f3 into elastic:main Aug 16, 2022
@mrodm mrodm deleted the add_status_command branch August 16, 2022 08:00
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.

Add subcommand for stack status

3 participants