refactor: move from io/ioutil to io and os package#998
refactor: move from io/ioutil to io and os package#998yvrhdn merged 1 commit intografana:mainfrom Juneezee:deprecate-ioutil
Conversation
|
Hi 👋🏻 Thank you for this! I'll let the CI run. Did you do this all manually or is there some kind of tool out there? |
Hi, thank you! I used the Search function in VSCode |
yvrhdn
left a comment
There was a problem hiding this comment.
Thanks for this, this is a great first contribution! Besides my comment below it all looks good 👍🏻
| } | ||
|
|
||
| start := time.Now() | ||
| level.Info(log).Log("msg", "beginning replay", "file", f.Name(), "size", f.Size()) |
There was a problem hiding this comment.
It's unfortunate we are losing this information here (but I get os.ReadDir is more performant this way). I'll check with the team to see whether we want to keep this information or not.
There was a problem hiding this comment.
Yeah, the os.DirEntry interface does not have the Size() method 😞. If we want to keep the size in the log, we would need to do something like this:
fileInfo, err := f.Info()
if err != nil {
return nil, err
}
level.Info(log).Log("msg", "beginning replay", "file", f.Name(), "size", fileInfo.Size())
|
|
||
| start := time.Now() | ||
| level.Info(log).Log("msg", "beginning replay", "file", f.Name(), "size", f.Size()) | ||
| level.Info(log).Log("msg", "beginning replay", "file", f.Name()) |
There was a problem hiding this comment.
You can grab the file size using DirEntry.Info and FileInfo.Size. Can you add the size label again? Then this PR will not change anything 🙂
The io/ioutil package has been deprecated as of Go 1.16, see https://golang.org/doc/go1.16#ioutil. This commit replaces the existing io/ioutil functions with their new definitions in io and os packages. Signed-off-by: Eng Zer Jun <engzerjun@gmail.com>
| fileInfo, err := f.Info() | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
|
|
||
| level.Info(log).Log("msg", "beginning replay", "file", f.Name(), "size", fileInfo.Size()) |
There was a problem hiding this comment.
@kvrhdn Done 😃, please take a look again. The err here is not nil when the file f is removed after os.ReadDir is called, it's a rare error but still possible sometimes.
What this PR does:
The
io/ioutilpackage has been deprecated in Go 1.16 (See https://golang.org/doc/go1.16#ioutil). Since tempo has upgraded to Go 1.17 (#953), this PR replaces the existingio/ioutilfunctions with their new definitions inioandospackages. This change is transparent to end users.Which issue(s) this PR fixes:
N/A
Checklist
[ ] Tests updated[ ] Documentation added[ ]CHANGELOG.mdupdated - the order of entries should be[CHANGE],[FEATURE],[ENHANCEMENT],[BUGFIX]