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

Fix retrieve logs in elastic-package stack dump #1252

Merged
merged 8 commits into from
May 8, 2023

Conversation

mrodm
Copy link
Contributor

@mrodm mrodm commented May 5, 2023

Closes #1251

This PR solves two issues related to logs retrieved by elastic-package stack dump command:

  • using docker-compose v2 some environment variables are missing
  • starting with 8.6.0, paths where logs can be found for elastic-agent and fleet-server has changed to be one unified log file:
    • Prior to that version those internal logs follow this pattern:
      • /usr/share/elastic-agent/state/data/logs/default/* (elastic-package copy these ones)
      • /usr/share/elastic-agent/state/data/logs/*
    • Since 8.6.0, there is no default folder
      • /usr/share/elastic-agent/state/data/logs/

Example of current failures against 8.8.0-SNAPSHOT:

  • using docker-compose v1:
    • some files cannot be copied due to the missing default folder
 $ docker-compose version --short
1.25.5

 $ elastic-package stack up -v -d --version 8.8.0-SNAPSHOT
 $ elastic-package stack dump
2023/05/05 17:49:25 ERROR can't copy internal logs (service: elastic-agent): docker copy failed: could not copy files from the container (stderr="Error response from daemon: Could not find the file /usr/share/elastic-agent/state/data/logs/default in container elastic-package-stack_elastic-agent_1\n"): exit status 1
2023/05/05 17:49:27 ERROR can't copy internal logs (service: fleet-server): docker copy failed: could not copy files from the container (stderr="Error response from daemon: Could not find the file /usr/share/elastic-agent/state/data/logs/default in container elastic-package-stack_fleet-server_1\n"): exit status 1
Path to stack dump: elastic-stack-dump
Done

 $ tree elastic-stack-dump/logs
elastic-stack-dump/logs
├── elastic-agent.log
├── elasticsearch.log
├── fleet-server.log
├── kibana.log
└── package-registry.log

0 directories, 5 files
  • using docker-compose v2
 $ docker-compose version --short
2.17.2

 $ elastic-package stack up -v -d --version 8.8.0-SNAPSHOT
 $ elastic-package stack dump
2023/05/05 17:51:57 ERROR can't fetch service logs (service: elasticsearch): running command failed: exit status 15
2023/05/05 17:51:57 ERROR can't fetch service logs (service: elastic-agent): running command failed: exit status 15
2023/05/05 17:51:57 ERROR can't copy internal logs (service: elastic-agent): docker copy failed: could not copy files from the container (stderr="Error response from daemon: Could not find the file /usr/share/elastic-agent/state/data/logs/default in container elastic-package-stack-elastic-agent-1\n"): exit status 1
2023/05/05 17:51:57 ERROR can't fetch service logs (service: fleet-server): running command failed: exit status 15
2023/05/05 17:51:57 ERROR can't copy internal logs (service: fleet-server): docker copy failed: could not copy files from the container (stderr="Error response from daemon: Could not find the file /usr/share/elastic-agent/state/data/logs/default in container elastic-package-stack-fleet-server-1\n"): exit status 1
2023/05/05 17:51:57 ERROR can't fetch service logs (service: kibana): running command failed: exit status 15
2023/05/05 17:51:57 ERROR can't fetch service logs (service: package-registry): running command failed: exit status 15
Path to stack dump: elastic-stack-dump
Done

 $ tree elastic-stack-dump/logs
elastic-stack-dump/logs/

0 directories, 0 files

 $ elastic-package stack down

Example of files present in different Elastic stack versions for elastic-agent-internal:

  • 7.17.10
 $ tree -l elastic-stack-dump-7.17.10/logs/elastic-agent-internal/
elastic-stack-dump-7.17.10/logs/elastic-agent-internal/
├── default
│   ├── filebeat-json.log
│   ├── filebeat-json.log-2023-05-05-15-1
│   ├── metricbeat-json.log
│   └── metricbeat-json.log-2023-05-05-15-1
└── elastic-agent-json.log-20230505150712

1 directory, 5 files
  • 8.0.0
 $ tree elastic-stack-dump-8.0.0/logs/elastic-agent-internal/
elastic-stack-dump-8.0.0/logs/elastic-agent-internal/
├── default
│   ├── filebeat-20230505-1.ndjson
│   ├── filebeat-20230505-2.ndjson
│   ├── filebeat-20230505-3.ndjson
│   ├── filebeat-20230505.ndjson
│   ├── metricbeat-20230505-1.ndjson
│   ├── metricbeat-20230505-2.ndjson
│   ├── metricbeat-20230505-3.ndjson
│   ├── metricbeat-20230505-4.ndjson
│   ├── metricbeat-20230505-5.ndjson
│   └── metricbeat-20230505.ndjson
└── elastic-agent-20230505.ndjson

1 directory, 11 files
  • 8.5.0
 $ tree elastic-stack-dump-8.5.0/logs/elastic-agent-internal/
elastic-stack-dump-8.5.0/logs/elastic-agent-internal/
├── default
│   ├── filebeat-20230505-1.ndjson
│   ├── filebeat-20230505-2.ndjson
│   ├── filebeat-20230505-3.ndjson
│   ├── filebeat-20230505.ndjson
│   ├── metricbeat-20230505-1.ndjson
│   └── metricbeat-20230505.ndjson
└── elastic-agent-20230505.ndjson

1 directory, 7 files
  • 8.8.0-SNAPSHOT
 $ tree elastic-stack-dump-8.8.0-SNAPSHOT/logs/elastic-agent-internal/
elastic-stack-dump-8.8.0-SNAPSHOT/logs/elastic-agent-internal/
└── elastic-agent-20230505.ndjson

0 directories, 1 file

Checklist

  • Tested using docker-compose v1
  • Tested using docker-compose v2
  • Tested with different Elastic stack versions (7.17.10, 8.0.0, 8.5.0, 8.6.0 and 8.8.0-SNAPSHOT)

How to test this change

  • Check docker-compose version installed in your system:
 $ docker-compose version --short
2.17.2
  • Start a Elastic stack using elastic-package with the desired version (e.g. 8.8.0-SNAPSHOT)
 $ elastic-package stack up -v -d --version 8.8.0-SNAPSHOT
  • Dump information from the stack command and check logs
 $ elastic-package stack dump
Path to stack dump: elastic-stack-dump
Done
 $ tree elastic-stack-dump/logs/
elastic-stack-dump/logs/
├── elastic-agent-internal
│   └── elastic-agent-20230505.ndjson
├── elastic-agent.log
├── elasticsearch.log
├── fleet-server-internal
│   ├── elastic-agent-20230505-1.ndjson
│   └── elastic-agent-20230505.ndjson
├── fleet-server.log
├── kibana.log
└── package-registry.log

@mrodm mrodm added the bug Something isn't working label May 5, 2023
@mrodm mrodm self-assigned this May 5, 2023
@mrodm mrodm marked this pull request as ready for review May 5, 2023 17:16
@mrodm mrodm requested a review from a team May 5, 2023 17:16
Copy link
Member

@kpollich kpollich left a comment

Choose a reason for hiding this comment

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

LGTM - thanks for the fix.

)

func dockerComposeLogs(serviceName string, snapshotFile string) ([]byte, error) {
func dockerComposeLogs(serviceName string, profile *profile.Profile) ([]byte, error) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Use profile as parameter instead of using snapshotFile as parameter.
Having the profile as parameter, allows us:

  • obtain the snapshot file path
  • get the needed Environment variables from the Profile for the docker-compose logs command

@mrodm mrodm requested a review from jsoriano May 5, 2023 18:28
@elasticmachine
Copy link
Collaborator

💚 Build Succeeded

History

cc @mrodm

internal/stack/logs.go Show resolved Hide resolved
@mrodm mrodm merged commit b187ad0 into elastic:main May 8, 2023
@mrodm mrodm deleted the fix_stack_dump branch May 8, 2023 15:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Container logs are not written in elastic-package stack dump using docker-compose v2
4 participants