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

filestorageextension: fix panic when configured directory cannot be accessed #6103

Conversation

pmalek-sumo
Copy link
Contributor

@pmalek-sumo pmalek-sumo commented Nov 2, 2021

Description: When a configured directory cannot be accessed (due to *nix permissions) err is of type *fs.PathError and info is nil which causes a panic when calling info.IsDir() hence check for that scenario.

Link to tracking Issue: N/A

Testing: Manual testing done.

Documentation: N/A

@pmalek-sumo pmalek-sumo requested review from a team and codeboten November 2, 2021 16:17
@pmalek-sumo
Copy link
Contributor Author

It's a bit problematic to add a UT since that would require us to juggle the local file system and permissions to induce a situation described in the description but if that's what we'd want I can try to work on it.

Comment on lines 41 to 56
info, err := os.Stat(config.Directory)
if (err != nil && os.IsNotExist(err)) || !info.IsDir() {
return nil, fmt.Errorf("directory must exist: %v", err)
if err != nil {
if os.IsNotExist(err) {
return nil, fmt.Errorf("directory must exist: %v", err)
}
if fsErr, ok := err.(*fs.PathError); ok {
return nil, fmt.Errorf(
"problem accessing configured directory: %s, err: %v",
config.Directory, fsErr,
)
}

}
if !info.IsDir() {
return nil, fmt.Errorf("%s is not a directory: %v", config.Directory, err)
}
Copy link
Member

Choose a reason for hiding this comment

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

May want to have this in "validate" func on the config.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've changed it but that required more changes in tests because now the default config might not pass on machines that don't have the default dir created (hence my changes in this PR overriding the default in some tests).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Any chance that we revisit this?

It seems that load-tests / loadtest (TestBallastMemory|TestLog10kDPS) (pull_request) failed for some reason but I wouldn't connect it to this PR.

@pmalek-sumo pmalek-sumo force-pushed the fix-filestorage-extension-when-dir-cannot-be-accessed branch from 6ac822c to 05059e6 Compare November 10, 2021 20:32
@pmalek-sumo
Copy link
Contributor Author

@codeboten @bogdandrutu can we revisit this and merge it? All the tests pass now and I've changed the code structure to add this check to validate func as per : #6103 (comment)

@github-actions
Copy link
Contributor

This PR was marked stale due to lack of activity. It will be closed in 7 days.

@github-actions github-actions bot added the Stale label Nov 18, 2021
@pmalek-sumo
Copy link
Contributor Author

This is not stale.

@jpkrohling jpkrohling removed the Stale label Nov 18, 2021
Copy link
Contributor

@codeboten codeboten left a comment

Choose a reason for hiding this comment

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

@bogdandrutu it appears your comment has been address, PTAL

}

}
if !info.IsDir() {
Copy link
Contributor

Choose a reason for hiding this comment

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

Is a test covering this case?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've added an appropriate testcase, @codeboten PTAL

@github-actions
Copy link
Contributor

This PR was marked stale due to lack of activity. It will be closed in 7 days.

@jpkrohling
Copy link
Member

@bogdandrutu, this seems to be pending on you.

@pmalek-sumo pmalek-sumo force-pushed the fix-filestorage-extension-when-dir-cannot-be-accessed branch from 05059e6 to 51493c8 Compare November 29, 2021 17:04
@pmalek-sumo pmalek-sumo force-pushed the fix-filestorage-extension-when-dir-cannot-be-accessed branch from 51493c8 to dbebd65 Compare November 30, 2021 10:47
@pmalek-sumo
Copy link
Contributor Author

Unrelated UT failure https://github.com/open-telemetry/opentelemetry-collector-contrib/runs/4366230936?check_suite_focus=true

Seems there's a fix waiting to be merged: #6461

@jpkrohling
Copy link
Member

@pmalek-sumo, could you please rebase this one? I merged the PR fixing main.

@pmalek-sumo pmalek-sumo force-pushed the fix-filestorage-extension-when-dir-cannot-be-accessed branch from dbebd65 to d45068b Compare November 30, 2021 13:16
@pmalek-sumo
Copy link
Contributor Author

@pmalek-sumo, could you please rebase this one? I merged the PR fixing main.

Done

@jpkrohling
Copy link
Member

Looks good to me. I'm merging, as I believe @bogdandrutu had enough time to comment on this :-) If there are still concerns left, it can be addressed in a future PR.

@jpkrohling jpkrohling merged commit 87d9108 into open-telemetry:main Dec 1, 2021
@pmalek-sumo pmalek-sumo deleted the fix-filestorage-extension-when-dir-cannot-be-accessed branch December 1, 2021 16:07
jamesmoessis pushed a commit to atlassian-forks/opentelemetry-collector-contrib that referenced this pull request Dec 8, 2021
…ccessed (open-telemetry#6103)

* filestorageextension: fix panic when configured directory cannot be accessed

* filestorageextension: move validation to config.Validate()
povilasv referenced this pull request in coralogix/opentelemetry-collector-contrib Dec 19, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants