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

Log watcher properly #2518

Merged
merged 4 commits into from
Apr 20, 2023
Merged

Conversation

michalpristas
Copy link
Contributor

@michalpristas michalpristas commented Apr 19, 2023

What does this PR do?

This PR makes watcher log into logs directory.
Logs are name in a similar manner as normal logs but with watcher suffix (see picture)
image

When rollback is performed everything except logs directory is removed. this can then be collected later.
On successful upgrade full cleanup is performed and everything except latest agent is removed.

This PR also modifies diagnostics collection.
Now logs are stored into logs/elastic-agent-{hash}
So in case of rollback watcher logs will be present in oldhash dir and agent logs will be store in newhash directory

Why is it important?

Debug-ability of agent during rollback

Checklist

  • My code follows the style guidelines of this project
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • I have made corresponding change to the default configuration files
  • I have added tests that prove my fix is effective or that my feature works
  • I have added an entry in ./changelog/fragments using the changelog tool
  • I have added an integration test or an E2E test

Fixes: #2262

@michalpristas michalpristas added bug Something isn't working Team:Elastic-Agent-Control-Plane Label for the Agent Control Plane team Team:Elastic-Agent Label for the Agent team labels Apr 19, 2023
@michalpristas michalpristas requested a review from a team as a code owner April 19, 2023 11:45
@michalpristas michalpristas self-assigned this Apr 19, 2023
@michalpristas michalpristas requested review from michel-laterman and pchila and removed request for a team April 19, 2023 11:45
@mergify
Copy link
Contributor

mergify bot commented Apr 19, 2023

This pull request does not have a backport label. Could you fix it @michalpristas? 🙏
To fixup this pull request, you need to add the backport labels for the needed
branches, such as:

  • backport-v./d./d./d is the label to automatically backport to the 8./d branch. /d is the digit

NOTE: backport-skip has been added to this pull request.

@elasticmachine
Copy link
Contributor

💚 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: 2023-04-19T11:45:17.775+0000

  • Duration: 17 min 2 sec

Test stats 🧪

Test Results
Failed 0
Passed 5535
Skipped 19
Total 5554

💚 Flaky test report

Tests succeeded.

🤖 GitHub comments

Expand to view the GitHub comments

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

  • /test : Re-trigger the build.

  • /package : Generate the packages.

  • run integration tests : Run the Elastic Agent Integration tests.

  • run end-to-end tests : Generate the packages and run the E2E Tests.

  • run elasticsearch-ci/docs : Re-trigger the docs validation. (use unformatted text in the comment!)

@elasticmachine
Copy link
Contributor

🌐 Coverage report

Name Metrics % (covered/total) Diff
Packages 98.529% (67/68) 👍
Files 68.22% (161/236) 👍
Classes 67.785% (303/447) 👍
Methods 54.111% (928/1715) 👍
Lines 39.602% (10506/26529) 👍 0.014
Conditionals 100.0% (0/0) 💚

Copy link
Member

@pchila pchila left a comment

Choose a reason for hiding this comment

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

Didn't test it yet but the change looks good
I don't see any automated testing for this, would it be possible to write some?

}

// using Data() + "/logs", for some reason default paths/Logs() is the home dir...
logPath := filepath.Join(paths.Home(), "logs") + string(filepath.Separator)
logPath := filepath.Join(pathsHome, "logs") + string(filepath.Separator)
Copy link
Member

Choose a reason for hiding this comment

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

Not introduced in this change but I am just curious: why do we need an extra separator ad the end of logPath ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

dunno, probably something with a zip writer

Copy link
Contributor

@blakerouse blakerouse left a comment

Choose a reason for hiding this comment

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

Change looks good. Hopefully we can cover this code which is hard to unit test with an upgrade integration test.

@pierrehilbert
Copy link
Contributor

Change looks good. Hopefully we can cover this code which is hard to unit test with an upgrade integration test.

You know what to add to your upgrade integration test then :-)

@michalpristas michalpristas merged commit 5f0f4f3 into elastic:main Apr 20, 2023
andrewkroh added a commit to andrewkroh/elastic-agent that referenced this pull request Apr 20, 2023
The zip file did not contain a directory entry for the elastic-agent-{commit}
directory.

Relates elastic#2518
andrewkroh added a commit to andrewkroh/elastic-agent that referenced this pull request Apr 20, 2023
This calls filepath.ToSlash on any names used in zip entries.

Relates elastic#2518
michalpristas pushed a commit that referenced this pull request Apr 21, 2023
…2523)

* internal/pkg/diagnostics - Fix creation of sub-directories in logs/

Prior to this change sub-directories within logs/ were not created properly
and resulted in unexpected directories within diagnostics files. A path separator
was missing. Before the change the new test was failing with

    -  Name: (string) (len=13) "logs/sub-dir/",
    +  Name: (string) (len=12) "logssub-dir/",

* Update test to include the versioned sub-directory

I made the test pass, but this these exposes a problem
with the newly added elastic-agent-{commit} directory in
that the zip file is missing a directory entry for it.

* Add missing directory entry for logs/elastic-agent-{commit}

The zip file did not contain a directory entry for the elastic-agent-{commit}
directory.

Relates #2518

* All files within the zip must use forward slash

This calls filepath.ToSlash on any names used in zip entries.

Relates #2518
mergify bot pushed a commit that referenced this pull request Apr 21, 2023
…2523)

* internal/pkg/diagnostics - Fix creation of sub-directories in logs/

Prior to this change sub-directories within logs/ were not created properly
and resulted in unexpected directories within diagnostics files. A path separator
was missing. Before the change the new test was failing with

    -  Name: (string) (len=13) "logs/sub-dir/",
    +  Name: (string) (len=12) "logssub-dir/",

* Update test to include the versioned sub-directory

I made the test pass, but this these exposes a problem
with the newly added elastic-agent-{commit} directory in
that the zip file is missing a directory entry for it.

* Add missing directory entry for logs/elastic-agent-{commit}

The zip file did not contain a directory entry for the elastic-agent-{commit}
directory.

Relates #2518

* All files within the zip must use forward slash

This calls filepath.ToSlash on any names used in zip entries.

Relates #2518

(cherry picked from commit 91a3122)
@joshdover
Copy link
Contributor

@michalpristas Is it possible to change the monitoring configuration to ingest these watcher log files?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working Team:Elastic-Agent Label for the Agent team Team:Elastic-Agent-Control-Plane Label for the Agent Control Plane team
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Failed upgrades that result in a version rollback cannot be debugged
7 participants