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

refactor: replace deprecated io/ioutil package #37467

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

blue-troy
Copy link

io/ioutil package is deprecated

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 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.

Related issues

io/ioutil package is deprecated

Signed-off-by: blue-troy <12729455+blue-troy@users.noreply.github.com>
@blue-troy blue-troy requested review from a team as code owners December 20, 2023 07:46
@botelastic botelastic bot added the needs_team Indicates that the issue/PR needs a Team:* label label Dec 20, 2023
Copy link

cla-checker-service bot commented Dec 20, 2023

💚 CLA has been signed

Copy link
Contributor

mergify bot commented Dec 20, 2023

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

❕ Build Aborted

The PR is not allowed to run in the CI yet

the below badges are clickable and redirect to their specific view in the CI or DOCS
Pipeline View Test View Changes Artifacts preview

Expand to view the summary

Build stats

  • Start Time: 2023-12-20T07:46:50.024+0000

  • Duration: 6 min 35 sec

Steps errors 2

Expand to view the steps failures

Load a resource file from a library
  • Took 0 min 0 sec . View more details here
  • Description: approval-list/elastic/beats.yml
Error signal
  • Took 0 min 0 sec . View more details here
  • Description: githubApiCall: The REST API call https://api.github.com/orgs/elastic/members/blue-troy return the message : java.lang.Exception: httpRequest: Failure connecting to the service https://api.github.com/orgs/elastic/members/blue-troy : httpRequest: Failure connecting to the service https://api.github.com/orgs/elastic/members/blue-troy : Code: 404Error: {"message":"User does not exist or is not a member of the organization","documentation_url":"https://docs.github.com/rest/orgs/members#check-organization-membership-for-a-user"}

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

@pierrehilbert pierrehilbert added Team:Security-External Integrations Team:Elastic-Agent Label for the Agent team Team:Cloud-Monitoring Label for the Cloud Monitoring team Team:Cloudnative-Monitoring Label for the Cloud Native Monitoring team labels Dec 20, 2023
@elasticmachine
Copy link
Collaborator

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

@botelastic botelastic bot removed the needs_team Indicates that the issue/PR needs a Team:* label label Dec 20, 2023
@blue-troy
Copy link
Author

There is some lint issue right now, but not caused by this pr.

@belimawr
Copy link
Contributor

@blue-troy thanks for the PR!

There is some lint issue right now, but not caused by this pr.

If the lint issues are not from your code, you can ignore them.

@belimawr
Copy link
Contributor

/test

@belimawr belimawr added the backport-skip Skip notification from the automated backport with mergify label Dec 21, 2023
@elasticmachine
Copy link
Collaborator

💚 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

  • Duration: 191 min 1 sec

❕ Flaky test report

No test was executed to be analysed.

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

Copy link
Contributor

@miltonhultgren miltonhultgren left a comment

Choose a reason for hiding this comment

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

Stack Monitoring modules LGTM

@blue-troy blue-troy requested a review from belimawr December 26, 2023 01:47
Copy link
Contributor

@efd6 efd6 left a comment

Choose a reason for hiding this comment

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

It would be helpful for review to have a description of how the mutations here were performed. If it was done purely mechanically (hopefully it was), for example with a set of gofmt rewrites and a goimports cleanup, then the code used to make the changes can be included in the commit message to make use of git-generate.

@blue-troy
Copy link
Author

It would be helpful for review to have a description of how the mutations here were performed. If it was done purely mechanically (hopefully it was), for example with a set of gofmt rewrites and a goimports cleanup, then the code used to make the changes can be included in the commit message to make use of git-generate.

For most of the case is just replace ioutil package to other package. but ioutil.ReadDir replaced with os.ReadDir returns a different struct:

before:

	contents, err := ioutil.ReadDir(src)
	if err != nil {
		return fmt.Errorf("failed to read dir %v: %w", src, err)
	}

after:

	contents := make([]fs.FileInfo, 0, len(contentEntries))
	for _, entry := range contentEntries {
		content, err := entry.Info()
		if err != nil {
			return fmt.Errorf("failed to stat %v: %w", entry.Name(), err)
		}
		contents = append(contents, content)
	}

this pr is not generate by script for some import package issue.

@efd6
Copy link
Contributor

efd6 commented Jan 15, 2024

@blue-troy Ideally, the mechanical and manual changes would be separate. I took a look at the break down of changes and the mechanical changes touch 195 files while the manual changes only alter 15. If they are separate greater care can be applied to the review of the manual changes.

In cases where stdout and stderr are assigned io.Discard the assignment can either be removed (if first assignment) or replaced with nil since nil exec.Cmd.{Stdout,Stderr} are already the bit bucket.

@miltonhultgren miltonhultgren changed the title refactor: replace depricated io/ioutil package refactor: replace deprecated io/ioutil package Jan 16, 2024
Copy link
Contributor

mergify bot commented Jan 25, 2024

This pull request is now in conflicts. Could you fix it? 🙏
To fixup this pull request, you can check out it locally. See documentation: https://help.github.com/articles/checking-out-pull-requests-locally/

git fetch upstream
git checkout -b refactor/ioutil upstream/refactor/ioutil
git merge upstream/main
git push upstream refactor/ioutil

1 similar comment
Copy link
Contributor

mergify bot commented Feb 5, 2024

This pull request is now in conflicts. Could you fix it? 🙏
To fixup this pull request, you can check out it locally. See documentation: https://help.github.com/articles/checking-out-pull-requests-locally/

git fetch upstream
git checkout -b refactor/ioutil upstream/refactor/ioutil
git merge upstream/main
git push upstream refactor/ioutil

@narph narph added Team:Security-Service Integrations Security Service Integrations Team and removed Team:Security-External Integrations labels Feb 8, 2024
@elasticmachine
Copy link
Collaborator

Pinging @elastic/security-service-integrations (Team:Security-Service Integrations)

@pierrehilbert
Copy link
Collaborator

Setting back to draft until the conflict are fixed.

@pierrehilbert pierrehilbert marked this pull request as draft March 7, 2024 15:31
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 Team:Cloud-Monitoring Label for the Cloud Monitoring team Team:Cloudnative-Monitoring Label for the Cloud Native Monitoring team Team:Elastic-Agent Label for the Agent team Team:Security-Service Integrations Security Service Integrations Team
Projects
None yet
Development

Successfully merging this pull request may close these issues.

replace depricated io/ioutil
7 participants