-
Notifications
You must be signed in to change notification settings - Fork 53
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
Create uploader actor #2302
Create uploader actor #2302
Conversation
95398c1
to
dee6615
Compare
Codecov Report
Additional details and impacted files
|
18a292a
to
9fdfd6b
Compare
Robot Results
|
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 overall code looks fine with the basic retry mechanism. But, unlike the downloader which could resume a download from the point where it was interrupted, I didn't see a similar resumption mechanism here. Is there any plan to add such a multi-part upload functionality to this uploader? It doesn't necessarily have to be in this PR, but would be a good follow-up addition.
BTW, I saw that the plan is to update the log plugin and config plugin to use this in a different PR. I'd recommend that you update one of them in this PR itself so that the functionality is well tested from a consumer as well. Else it's just a library that no one uses, relying purely on unit tests.
5cee053
to
11e80a5
Compare
I would leave the partial upload for next PR as it is more tricky than download. According to the rfc-editor this is very inconsistent and require some changes on server side. Another thing is that we would have to edit the exponential backoff mechanism because of 400 BAD REQUEST respond which at this point will not trigger retry mechanism. |
4ec8a30
to
2e7f526
Compare
5556d1a
to
e5659cc
Compare
7e685ab
to
dd070f2
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.
The main changes look fine. Just some minor niggles and I'm happy to approve once those are ironed out.
@@ -1,8 +1,13 @@ | |||
use anyhow::anyhow; |
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.
A library returning anyhow
errors is highly discouraged. You should be defining concrete error types with the use of thiserror
instead. Anyhow is usually used at the application level where the errors just need to be reported.
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.
IMO there are valid use cases for using anyhow
in a library crate. What matters the most is the intent, what do we expect users to do. We do not expect code which calls the uploader to behave differently between error variants of e.g. "this does not name a valid file" or "path is not valid unicode", we simply return these errors and show them to the user. We don't have to maintain any Rust API compatibility, we can add or remove error variants at any time.
So I think in this case using an error variant for "file error" and then using anyhow
for telling the user what exactly went wrong is acceptable.
anyhow::Error
is also like Box<dyn Error> + 'static
, but also guarantees Send
and Sync
. I originally added it to InvalidFileName
error variant because i wanted to use either io::Error
or Utf8Error
as a source, but using anyhow!("error details")
directly... I wouldn't say it's an antipattern.
I was recently reading Zero To Production In Rust and there's a free chapter about error handling. There is a dedicated section about anyhow vs thiserror, but I'd recommend reading the entire chapter for context.
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.
Thanks for the link. Gave me a new perspective. I guess the following is the key point:
Library authors cannot (or do not want to) make assumptions on the intent of their users. They steer away from being opinionated (to an extent) - enums give users more control, if they need it.
and I completely agree to your following point:
We do not expect code which calls the uploader to behave differently between error variants of e.g. "this does not name a valid file" or "path is not valid unicode", we simply return these errors and show them to the user.
Here is where I'm wondering what value anyhow
adds if all we wanted to do was to report the reason to the end-user. Why couldn't it be just a String
value? Using anyhow
instead, is just an overkill, right? As the user is less likely to introspect the source
chain any further, as that was our fundamental assumption when we picked anyhow
for "opaque" errors in the first place.
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.
Except anyhow
in a library crate, looks good to me
f982428
to
4a4de89
Compare
56916f1
to
032cdfa
Compare
82266de
to
199e214
Compare
199e214
to
0efee3f
Compare
Signed-off-by: Krzysztof Piotrowski <krzysztof.piotrowski@inetum.com>
Signed-off-by: Krzysztof Piotrowski <krzysztof.piotrowski@inetum.com>
Signed-off-by: Krzysztof Piotrowski <krzysztof.piotrowski@inetum.com>
Signed-off-by: Krzysztof Piotrowski <krzysztof.piotrowski@inetum.com>
8501559
to
dfd790d
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.
I still have my reservations against the use of anyhow
to represent a source
in error variants like InvalidFileName
where that enum variant itself was self-explanatory and I doubt if the source
would really add any more context. But, that's a parallel discussion that should not block this PR. Hence approving as the rest of the code looks fine,
QA has thoroughly checked the feature and here are the results:
|
Proposed changes
This PR adds new uploader actor that works in similar manner to
downloader_actor
. Later on it will be used in bothtedge-log-plugin
andtedge-configuration-plugin
to take responsibility for uploading content to tedge file repository. More in #2301.TODO:
Types of changes
Paste Link to the issue
Checklist
cargo fmt
as mentioned in CODING_GUIDELINEScargo clippy
as mentioned in CODING_GUIDELINESFurther comments