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

{,x-pack/}auditbeat: replace uses of github.com/pkg/errors with stdlib equivalents #30321

Merged
merged 4 commits into from
Feb 21, 2022

Conversation

efd6
Copy link
Contributor

@efd6 efd6 commented Feb 10, 2022

What does this PR do?

This replaces uses of github.com/pkg/errors with their standard library equivalents.

Why is it important?

github.com/pkg/errors is now archived and additionally does work that we almost never use (see elastic/go-libaudit#99 for background); the one place where this work is used is replaced with a stdlib call.

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.next.asciidoc or CHANGELOG-developer.next.asciidoc.

Author's Checklist

  • Run the commands in the first commit in auditbeat and x-pack/auditbeat to confirm mechanical changes.
  • Check first commit for uses of %w in fmt.Errorf calls where the error has not been confirmed to be non-nil.
  • Check the semantics remain unaltered or corrected in the second commit.

How to test this PR locally

Related issues

Use cases

Screenshots

Logs

…error handling

This is not completely automatable here due to some semantic differences between
errors.Wrap and fmt.Errorf with the %w verb; the latter will convert a nil error
into a non-nil error, so this must be guarded with a nil error check.

The mechanical transformation was done by running the following commands:
	gofmt -w -r 'errors.Errorf -> fmt.Errorf' .
	gofmt -w -r 'errors.Wrap(e, m) -> fmt.Errorf(m+": %w", e)' .
	gofmt -w -r 'errors.Wrapf(e, m) -> fmt.Errorf(m+": %w", e)' .
	gofmt -w -r 'errors.Wrapf(e, m, a) -> fmt.Errorf(m+": %w", a, e)' .
	gofmt -w -r 'errors.Wrapf(e, m, a, b) -> fmt.Errorf(m+": %w", a, b, e)' .
	gofmt -w -r 'errors.Wrapf(e, m, a, b, c) -> fmt.Errorf(m+": %w", a, b, c, e)' .
	find . -name '*.go' -exec gsed -i -e 's/"+": %w",/: %w",/g' '{}' \;
	find . -name '*.go' -exec gsed -i -e 's!"github.com/pkg/errors"$!"errors"!g' '{}' \;
	goimports -w .
	go mod tidy
	gofumpt -w .

Replaying that will give the changes here modulo some manual changes that are
made in the next commit. There should be no uses of %w in this change that are
not guarded by a nil-check.
@efd6 efd6 added enhancement cleanup Team:Security-External Integrations backport-skip Skip notification from the automated backport with mergify 8.2-candidate labels Feb 10, 2022
@efd6 efd6 requested review from andrewkroh and adriansr February 10, 2022 01:31
@botelastic botelastic bot added needs_team Indicates that the issue/PR needs a Team:* label and removed needs_team Indicates that the issue/PR needs a Team:* label labels Feb 10, 2022
@efd6 efd6 changed the title Auditbeat/ununwrap {,x-pack}/auditbeat: replace uses of github.com/pkg/errors with stdlib equivalents Feb 10, 2022
@mergify mergify bot assigned efd6 Feb 10, 2022
@elasticmachine
Copy link
Collaborator

elasticmachine commented Feb 10, 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-02-21T00:32:57.664+0000

  • Duration: 73 min 24 sec

Test stats 🧪

Test Results
Failed 0
Passed 862
Skipped 162
Total 1024

💚 Flaky test report

Tests succeeded.

🤖 GitHub comments

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

  • /test : Re-trigger the build.

  • /package : Generate the packages and run the E2E tests.

  • /beats-tester : Run the installation tests with beats-tester.

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

…r handling

This is the manual part of the change and includes some complete removal of errors
and some silently passed bugs resulting from the use of Wrap.

In one place the exact semantics of errors.Cause is implemented to fit in with a
testing strategy.
@efd6 efd6 force-pushed the auditbeat/ununwrap branch from a0345f6 to 5a53f65 Compare February 10, 2022 03:00
@efd6 efd6 changed the title {,x-pack}/auditbeat: replace uses of github.com/pkg/errors with stdlib equivalents {,x-pack/}auditbeat: replace uses of github.com/pkg/errors with stdlib equivalents Feb 10, 2022
@efd6 efd6 marked this pull request as ready for review February 10, 2022 04:18
@efd6 efd6 requested a review from a team as a code owner February 10, 2022 04:18
@elasticmachine
Copy link
Collaborator

Pinging @elastic/security-external-integrations (Team:Security-External Integrations)

Copy link
Member

@andrewkroh andrewkroh left a comment

Choose a reason for hiding this comment

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

LGTM. Just one question.

x-pack/auditbeat/module/system/socket/guess/guess.go Outdated Show resolved Hide resolved
@efd6 efd6 requested a review from andrewkroh February 21, 2022 00:16
Copy link
Member

@andrewkroh andrewkroh left a comment

Choose a reason for hiding this comment

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

LGTM

@efd6 efd6 merged commit 4ab90f9 into elastic:main Feb 21, 2022
@efd6 efd6 deleted the auditbeat/ununwrap branch February 21, 2022 02:54
v1v added a commit to v1v/beats that referenced this pull request Feb 21, 2022
…nd-k8s-env

* upstream/main:
  fix typos and improve sentences (elastic#30432)
  Add drop and explicit tests to avoid duplicate ingest of elasticsearch logs (elastic#30440)
  {,x-pack/}auditbeat: replace uses of github.com/pkg/errors with stdlib equivalents (elastic#30321)
  Spelling fix (elastic#30439)
  packetbeat/beater: make sure Npcap installation runs before interfaces are needed in all cases (elastic#30438)
  Add BC about Homebrew no longer being available in 8.0 (elastic#30419)
  Install gawk as a replacement for mawk in Docker containers. (elastic#30452)
  Clean up python-related system tests (elastic#30415)
  Fix TestNewModuleRegistry flakiness (elastic#30453)
  [Filebeat] [auditd]: Support EXECVE events with truncated argument list (elastic#30382)
  Set `log.offset` to the start of the reported line in filestream (elastic#30445)
  clarify SelectedPackageTypes meaning and improve its usage (elastic#30142)
  [elasticsearch module] serialize shards properties (elastic#30408)
  Add docs about hints and templates autodiscovery priority (elastic#30343)
v1v added a commit to v1v/beats that referenced this pull request Feb 22, 2022
…ckaging-docker

* upstream/main: (26 commits)
  Update docker/distribution to 2.8.0 (elastic#30462)
  Add `parsers` examples to `filestream` reference configuration (elastic#30529)
  extend documentation about setting orchestrator.cluster fields (elastic#30518)
  Forward-port 8.0.1 changelog to main (elastic#30522)
  Switch skip to use `CI` (elastic#30512)
  packetbeat/beater: don't attempt to install npcap when already installed (elastic#30509)
  Fix Docker module: rename fields on dashboards (elastic#30500)
  fix typos and improve sentences (elastic#30432)
  Add drop and explicit tests to avoid duplicate ingest of elasticsearch logs (elastic#30440)
  {,x-pack/}auditbeat: replace uses of github.com/pkg/errors with stdlib equivalents (elastic#30321)
  Spelling fix (elastic#30439)
  packetbeat/beater: make sure Npcap installation runs before interfaces are needed in all cases (elastic#30438)
  Add BC about Homebrew no longer being available in 8.0 (elastic#30419)
  Install gawk as a replacement for mawk in Docker containers. (elastic#30452)
  Clean up python-related system tests (elastic#30415)
  Fix TestNewModuleRegistry flakiness (elastic#30453)
  [Filebeat] [auditd]: Support EXECVE events with truncated argument list (elastic#30382)
  Set `log.offset` to the start of the reported line in filestream (elastic#30445)
  clarify SelectedPackageTypes meaning and improve its usage (elastic#30142)
  [elasticsearch module] serialize shards properties (elastic#30408)
  ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
8.2-candidate backport-skip Skip notification from the automated backport with mergify cleanup enhancement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants