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

[metricbeat] replace depricated io/ioutil #36963

Closed
wants to merge 3 commits into from
Closed

Conversation

florianl
Copy link
Member

Proposed commit message

As of Go 1.16, the same functionality is now provided by package io or package os, and those implementations should be preferred. Successor functionality in io or os is more performant than the deprecated functionality in io/ioutil.

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.

@florianl florianl added cleanup release-note:skip The PR should be ignored when processing the changelog labels Oct 25, 2023
@florianl florianl requested review from a team as code owners October 25, 2023 16:51
@florianl florianl requested review from belimawr and faec October 25, 2023 16:51
@botelastic botelastic bot added the needs_team Indicates that the issue/PR needs a Team:* label label Oct 25, 2023
@florianl florianl added the Team:Elastic-Agent Label for the Agent team label Oct 25, 2023
@botelastic botelastic bot removed the needs_team Indicates that the issue/PR needs a Team:* label label Oct 25, 2023
@mergify
Copy link
Contributor

mergify bot commented Oct 25, 2023

This pull request does not have a backport label.
If this is a bug or security fix, could you label this PR @florianl? 🙏.
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

@florianl florianl added the backport-skip Skip notification from the automated backport with mergify label Oct 25, 2023
@elasticmachine
Copy link
Collaborator

elasticmachine commented Oct 25, 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-11-01T06:56:39.800+0000

  • Duration: 80 min 20 sec

Test stats 🧪

Test Results
Failed 0
Passed 5863
Skipped 1160
Total 7023

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

},
"metrics": {
"up": 1
}
"net_conntrack_listener_conn_closed_total": 0
Copy link
Contributor

Choose a reason for hiding this comment

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

Was this included by accident? Everything else in the PR looks like natural in-place substitutions, but this seems unrelated. (If the data.json changes weren't here I would approve it.)

Copy link
Member Author

Choose a reason for hiding this comment

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

sorry - I must have added them by accident and will remove them.

Copy link
Member Author

Choose a reason for hiding this comment

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

file got removed from the PR.

As of Go 1.16, the same functionality is now provided by package io or package os, and those implementations should be preferred.

Signed-off-by: Florian Lehner <florian.lehner@elastic.co>
@florianl florianl force-pushed the flo-metricbeat-ioutil branch from 0032bda to fedbe66 Compare October 26, 2023 05:51
Copy link
Contributor

@belimawr belimawr left a comment

Choose a reason for hiding this comment

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

Great job! I'm always happy to see this kin of improvements ❤️

The only blocking suggestion is the assert/require one.

Comment on lines +216 to +217
t.Error(err)
t.FailNow()
Copy link
Contributor

Choose a reason for hiding this comment

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

That can be replaced by a single t.Fatal()

Suggested change
t.Error(err)
t.FailNow()
t.Fatal(err)

Comment on lines +366 to +367
t.Error(err)
t.FailNow()
Copy link
Contributor

Choose a reason for hiding this comment

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

Same here

Suggested change
t.Error(err)
t.FailNow()
t.Fatal(err)

Copy link
Member Author

Choose a reason for hiding this comment

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

Looking at existing code, t.Error(err) followed by t.FailNow() is the most common pattern. So far, no one cared that the error was ignored so far. And the change was added, just to make linter happy.

Copy link
Contributor

Choose a reason for hiding this comment

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

Looking at existing code, t.Error(err) followed by t.FailNow() is the most common pattern.

The bits of the codebase I mostly work with follow a different pattern 😅 , anyway this one is not a blocker.

@@ -36,7 +36,8 @@ func TestFetchEventContents(t *testing.T) {
absPath, err := filepath.Abs("../_meta/testdata/")
assert.NoError(t, err)

response, err := ioutil.ReadFile(absPath + "/sample_response.json")
response, err := os.ReadFile(absPath + "/sample_response.json")
assert.NoError(t, err)
Copy link
Contributor

Choose a reason for hiding this comment

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

It's better to use require here as it will immediately fail the test. If we fail to read the file, there is no point continuing with the test.

Suggested change
assert.NoError(t, err)
require.NoError(t, err)

Copy link
Member Author

Choose a reason for hiding this comment

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

What is the difference to line 37 assert.NoError(t, err) ? Why should we use here require instead of assert?

Copy link
Contributor

Choose a reason for hiding this comment

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

require calls t.Fatal or t.FailNow which effectively interrupts the test right when the assertion fails. In that case if we continue the test after os.ReadFile fails, the test will only produce more errors that are not helpful, hence stopping the test when the file cannot be read is the best approach in my opinion.

That is the only comment/change I consider a blocker, and even that is not a hard blocker.

Copy link
Member Author

Choose a reason for hiding this comment

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

That is the only comment/change I consider a blocker, and even that is not a hard blocker.

I can't follow why this is considered a blocker. Before this change err was never checked before and the discussion assert vs require is a style discussion, that should not affect this PR.

@florianl florianl requested a review from belimawr October 27, 2023 08:33
Signed-off-by: Florian Lehner <florian.lehner@elastic.co>
Signed-off-by: Florian Lehner <florian.lehner@elastic.co>
@florianl
Copy link
Member Author

satisfying linter is a major hurdle to get this merged. as I don't have capacity to do so, I'm closing this PR.

@florianl florianl closed this Dec 14, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport-skip Skip notification from the automated backport with mergify cleanup release-note:skip The PR should be ignored when processing the changelog Team:Elastic-Agent Label for the Agent team
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants