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

Removing obsolete package from metricbeat #35827

Merged
merged 17 commits into from
Jun 22, 2023

Conversation

amitkanfer
Copy link
Collaborator

@amitkanfer amitkanfer commented Jun 20, 2023

github.com/pkg/errors is deprecated since 2021.
Furthermore, it's at least 100% worse in terms of performance compared to the native errors and fmt packages, (probably due to the fact every error log comes with a stack trace)

Another interesting benchmark: https://g4s8.wtf/posts/go-errors-performance/

@botelastic botelastic bot added the needs_team Indicates that the issue/PR needs a Team:* label label Jun 20, 2023
@mergify
Copy link
Contributor

mergify bot commented Jun 20, 2023

This pull request does not have a backport label.
If this is a bug or security fix, could you label this PR @amitkanfer? 🙏.
For such, you'll need to label your PR with:

  • The upcoming major version of the Elastic Stack
  • The upcoming minor version of the Elastic Stack (if you're not pushing a breaking change)

To fixup this pull request, you need to add the backport labels for the needed
branches, such as:

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

@elasticmachine
Copy link
Collaborator

elasticmachine commented Jun 20, 2023

💚 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-06-22T16:36:26.183+0000

  • Duration: 88 min 33 sec

Test stats 🧪

Test Results
Failed 0
Passed 27454
Skipped 2023
Total 29477

💚 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 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!)

@@ -43,7 +43,7 @@ func eventMapping(r mb.ReporterV2, cont *types.Container, m *MetricSet) {

container, err := m.dockerClient.ContainerInspect(context.TODO(), cont.ID)
if err != nil {
errors.Wrapf(err, "Error inspecting container %v", cont.ID)
fmt.Errorf("Error inspecting container %v: %w", cont.ID, err)
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Special attention here

@amitkanfer amitkanfer marked this pull request as ready for review June 21, 2023 12:44
@amitkanfer amitkanfer requested review from a team as code owners June 21, 2023 12:44
@amitkanfer amitkanfer requested review from cmacknz and leehinman June 21, 2023 12:44
@amitkanfer amitkanfer changed the title removing obsolete package from metricbeat Removing obsolete package from metricbeat Jun 21, 2023
@cmacknz cmacknz added the Team:Elastic-Agent Label for the Agent team label Jun 21, 2023
@elasticmachine
Copy link
Collaborator

Pinging @elastic/elastic-agent (Team:Elastic-Agent)

@botelastic botelastic bot removed the needs_team Indicates that the issue/PR needs a Team:* label label Jun 21, 2023
Copy link
Member

@cmacknz cmacknz left a comment

Choose a reason for hiding this comment

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

Everything LGTM, the one place the error was unused feels like it is a bug that could be improved but within the scope of what this PR is trying to do it could also be left as is.

@@ -43,7 +42,7 @@ func eventMapping(r mb.ReporterV2, cont *types.Container, m *MetricSet) {

container, err := m.dockerClient.ContainerInspect(context.TODO(), cont.ID)
if err != nil {
errors.Wrapf(err, "Error inspecting container %v", cont.ID)
// errors.Wrapf(err, "Error inspecting container %v", cont.ID)
Copy link
Member

Choose a reason for hiding this comment

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

Seems like it might be a bug that this is just getting dropped.

This is called from the following function which does allow returning an error:

func (m *MetricSet) Fetch(r mb.ReporterV2) error {
// Fetch a list of all containers.
containers, err := m.dockerClient.ContainerList(context.TODO(), types.ContainerListOptions{})
if err != nil {
return errors.Wrap(err, "failed to get docker containers list")
}
eventsMapping(r, containers, m)
return nil
}

The only trick would be that you don't want to just return an error and immediately stop if one of many containers has an error.

func eventsMapping(r mb.ReporterV2, containers []types.Container, m *MetricSet) {
for _, container := range containers {
eventMapping(r, &container, m)
}
}

For this you could use https://github.com/hashicorp/go-multierror there's an example here

err = multierror.Append(err, fmt.Errorf("Config for '%s' is blacklisted", configs.Type))

This multierr package itself can probably be replaced with standard library functionality once we upgrade to Go 1.20.

If you don't want to deal with all that, you can just delete this. It isn't making the code any worse and it was unused before.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

ok, deleting. will open a follow up issue to fix this.

@amitkanfer
Copy link
Collaborator Author

Team,
We're making an exception and not going to wait for approvals from all CODEOWNERS for this "find and replace" type of PRs. @cmacknz 's review will be enough.

@cmacknz cmacknz enabled auto-merge (squash) June 22, 2023 17:07
@cmacknz cmacknz disabled auto-merge June 22, 2023 18:22
@cmacknz cmacknz merged commit 2bdc35b into main Jun 22, 2023
@cmacknz cmacknz deleted the remove_obsolete_error_package_from_metricbeat branch June 22, 2023 18:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Team:Elastic-Agent Label for the Agent team
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants