-
Notifications
You must be signed in to change notification settings - Fork 14
fix: local file upload client fix for paths [PS-87] #502
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
fix: local file upload client fix for paths [PS-87] #502
Conversation
✅ Snyk checks have passed. No issues have been found so far.
💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse. |
✅ Snyk checks have passed. No issues have been found so far.
💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse. |
368f772 to
497bbde
Compare
497bbde to
187f6c6
Compare
pkg/apiclients/fileupload/client.go
Outdated
| info, statErr := os.Stat(pth) | ||
| if statErr != nil { | ||
| c.logger.Error().Err(statErr).Str("path", pth).Msg("failed to stat path") | ||
| return uploadrevision2.NewFileAccessError(pth, statErr) |
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.
Should we maybe be lenient and just upload the files that are there instead of failing the whole upload ?
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.
I kept the previous logic here and for now this is the behaviour we also want, scan everything or nothing at all because we don't have a way to specify to the user which files we were able to scan and which not. This is something we wanted to consider further on (partial scans).
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.
From a framework/sdk perspective, which GAF is, I think what @bastiandoetsch said is correct. the library function should be implemented independent of constraints of a specific consumer.
The library needs to make errors clear and the consumer, like a specific extension can react the way they want to or are able to.
From a library perspective a possible futrue performance improvement could then be to support a configuration value that defines to fail early,
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.
Got it. I think it would be quite straightforward to extend uploadOptions with this config value and extend the interface (either way we are doing it to add the rootPath), wdyt?
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.
Taking a closer look at the code and this functionality, if we want to be more lenient we'll also need to update how
batchPaths works since right now it fails if there's any error related to one of the files it batches.
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.
@bastiandoetsch, I had a quick sync with @PeterSchafer and decided we can have another iteration for the client in order to enable partial scans & be lenient about individual file errors (upload the files that don't error out instead of failing the whole upload).
pkg/apiclients/fileupload/client.go
Outdated
| // Client defines the interface for the high level file upload client. | ||
| type Client interface { | ||
| CreateRevisionFromPaths(ctx context.Context, paths []string) (UploadResult, error) | ||
| CreateRevisionFromPaths(ctx context.Context, paths []string, rootPath string) (UploadResult, error) |
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.
@alina-d-m quick thought/question, will you be using any of these other Create functions? Or will you be working with CreateRevisionFromChan()?
If you will be using CreateRevisionFromChan(), I would propose to remove these convenience functions actually.
Everything can be achieved through CreateRevisionFromChan and it is not clear if any of them is actually helpful/required.
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.
We will be using CreateRevisionFromChan(), I can remove the other ones if you think it's not worth having them here (I tried to make them work just to align with the previous iteration of the client).
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.
Okay, this sounds awesome. Thank you for making them work! I only left them there because of the missing channel version, so now that you have it, I think we can make this implementation even more focussed and slim, which will make it easier to test and maintain.
Sorry that this approach created some extra iterations and work. But I think CreateRevisionFromChan() is the perfect minimal interface and we should encourage its usage!
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.
However, I think the cli-extension-os-flows uses CreateRevisionFromDir which would make it a bit difficult for them to migrate to the GAF client 🤔
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.
The migration will not work 1:1 anyways, since we will exclude filtering from the fileupload API. This means, they will use channel based API anyways.
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.
Removed the other convenience functions & cleaned-up the client + tests, if you could take another look 🙏
Updated the local file upload with the following fixes:
CreateRevisionFromPathswas previously creating single file batches which limited the client to uploading only 50 files using this method, updated the method to correctly read from a chan of files and correctly spread the files over the 50 batch (part) limit per revision, this prompted the refactor ofCreateRevisionFromPathsusing a producer - consumer design: producer walks the dir/reads the files from input and adds them to a chan, the consumer (batchPaths) reads from the chan and creates batches to be uploaded, error contexts are synced between the 2 (if producer fails, consumer will also stop and not hang indefinitely, if consumer fails, the producer stops adding file paths to the chan)addPathsToRevisionrootPathargument for all client methods such that the relative path of the files that are uploaded is correctly computed relative to the desiredrootPathbatchPathsconsumer errored and the entire upload failedAdded a new method on the client for creating a revision given as input a chan of file paths:
CreateRevisionFromChan.Jira: https://snyksec.atlassian.net/browse/PS-87