-
Notifications
You must be signed in to change notification settings - Fork 4.9k
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
Conversation
This pull request does not have a backport label.
To fixup this pull request, you need to add the backport labels for the needed
|
}, | ||
"metrics": { | ||
"up": 1 | ||
} | ||
"net_conntrack_listener_conn_closed_total": 0 |
There was a problem hiding this comment.
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.)
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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>
0032bda
to
fedbe66
Compare
There was a problem hiding this 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.
t.Error(err) | ||
t.FailNow() |
There was a problem hiding this comment.
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()
t.Error(err) | |
t.FailNow() | |
t.Fatal(err) |
t.Error(err) | ||
t.FailNow() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here
t.Error(err) | |
t.FailNow() | |
t.Fatal(err) |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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.
assert.NoError(t, err) | |
require.NoError(t, err) |
There was a problem hiding this comment.
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
?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
Signed-off-by: Florian Lehner <florian.lehner@elastic.co>
Signed-off-by: Florian Lehner <florian.lehner@elastic.co>
satisfying linter is a major hurdle to get this merged. as I don't have capacity to do so, I'm closing this PR. |
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
I have commented my code, particularly in hard-to-understand areasI have made corresponding changes to the documentationI have made corresponding change to the default configuration filesI have added tests that prove my fix is effective or that my feature worksI have added an entry inCHANGELOG.next.asciidoc
orCHANGELOG-developer.next.asciidoc
.