Skip to content
This repository has been archived by the owner on May 21, 2024. It is now read-only.

fix/ota-2183/Enable streaming of garage-push/deploy uploads #1305

Merged

Conversation

Zee314159
Copy link
Contributor

Draft code.

@Zee314159 Zee314159 force-pushed the fix/ota-2183/enable-streaming-of-garage-tool-uploads branch 2 times, most recently from 9f3e6db to 321413c Compare August 20, 2019 12:27
@codecov-io
Copy link

codecov-io commented Aug 20, 2019

Codecov Report

Merging #1305 into master will decrease coverage by 0.02%.
The diff coverage is 84.37%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #1305      +/-   ##
==========================================
- Coverage   79.72%   79.69%   -0.03%     
==========================================
  Files         177      177              
  Lines       10475    10487      +12     
==========================================
+ Hits         8351     8358       +7     
- Misses       2124     2129       +5
Impacted Files Coverage Δ
src/sota_tools/request_pool.h 100% <ø> (ø) ⬆️
src/sota_tools/treehub_server.h 100% <ø> (ø) ⬆️
src/sota_tools/ostree_object.h 100% <ø> (ø) ⬆️
src/sota_tools/request_pool.cc 87.75% <100%> (ø) ⬆️
src/sota_tools/treehub_server.cc 100% <100%> (ø) ⬆️
src/sota_tools/ostree_http_repo.h 100% <100%> (ø) ⬆️
src/sota_tools/check.cc 61.42% <100%> (-2.86%) ⬇️
src/sota_tools/garage_deploy.cc 88.31% <25%> (-1.3%) ⬇️
src/sota_tools/ostree_object.cc 94.21% <84.61%> (-0.37%) ⬇️
... and 3 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 38f8239...ee671d5. Read the comment docs.

@Zee314159
Copy link
Contributor Author

I manually tested, using ‘t_deploy’,the output looks it didn’t work. Content_type is multipart and x-www-form-urlencoded.Maybe I was using the wrong test, or the code I added didn’t work somehow.

@pattivacek
Copy link
Collaborator

Content_type is multipart and x-www-form-urlencoded.

It's possible that there is some other way you have to specify it, perhaps forcing the header value doesn't actually stick.

However, I suspect a bigger problem is that you probably don't want to set that from the RequestPool. You only want it for uploads, so OSTreeObject::Upload in src/sota_tools/ostree_object.cc is probably a safer place to do it.

@mike-sul
Copy link
Collaborator

You only want it for uploads, so OSTreeObject::Upload in src/sota_tools/ostree_object.cc

It will require updating treehub_server.py accordingly.
Also, I am wondering what does Out of band upload described in advancedtelematic/treehub#70 exactly mean and whether there is any benefit in that upload mode for us ? My understanding is that it will help to bypass one of the OTA connect internal services (treehub ?) and stream directly to S3.

@pattivacek
Copy link
Collaborator

It will require updating treehub_server.py accordingly.

Ah, I hadn't considered that. You might be right; the tests may need to get updated once we have it working correctly with the real backend.

Also, I am wondering what does Out of band upload described in advancedtelematic/treehub#70 exactly mean and whether there is any benefit in that upload mode for us ? My understanding is that it will help to bypass one of the OTA connect internal services (treehub ?) and stream directly to S3.

To be clear, the "out of band upload" is out of scope for the current task that Liping is working on. But it's still worth understanding, and we may want to support it eventually, although I think it is somewhat more work. See https://saeljira.it.here.com/browse/OTA-1813 for some additional detail. Basically, the backend could tell us to upload directly to S3 and bypass treehub completely. The advantage is reduced load on our server and fewer points of failure.

@Zee314159 Zee314159 force-pushed the fix/ota-2183/enable-streaming-of-garage-tool-uploads branch 3 times, most recently from 9cf5fa2 to ac6abde Compare August 27, 2019 07:03
@@ -111,6 +111,7 @@ class OSTreeObject {
std::stringstream http_response_;
CURL* curl_handle_;
struct curl_httppost* form_post_;
curl_slist* headers;
Copy link
Contributor

Choose a reason for hiding this comment

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

We should initialize this to nullptr. Otherwise, it could be anything and will segfault in destructor. This should fix some of the failing tests in CI, I think.

@@ -241,6 +245,10 @@ void OSTreeObject::Upload(const TreehubServer &push_target, CURLM *curl_multi_ha

curlEasySetoptWrapper(curl_handle_, CURLOPT_PRIVATE, this); // Used by ostree_object_from_curl

headers = nullptr;
Copy link
Contributor

Choose a reason for hiding this comment

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

If we call Upload() multiple times this will be a leak. Or is it not possible?

@Zee314159 Zee314159 force-pushed the fix/ota-2183/enable-streaming-of-garage-tool-uploads branch 2 times, most recently from b4831ca to f9cfd21 Compare August 28, 2019 04:42
@@ -79,6 +79,17 @@ def do_POST(self):
self.send_response_only(200)
self.end_headers()
return
elif ctype == 'application/octet-stream':
Copy link
Collaborator

@mike-sul mike-sul Aug 28, 2019

Choose a reason for hiding this comment

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

In case of 'application/octet-stream' we can read the posted file/body just from the socket buffer, so something like that should work

 elif ctype == 'application/octet-stream':
            length = int(self.headers['content-length'])
            body = self.rfile.read(length)
            with open("body.dat", "wb") as f:
                f.write(body)

            self.send_response_only(200)
            self.end_headers()

But, if the given implementation works then it's ok - this is just a test tool

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks Mike, I'll try your way. I was also just gonna try this:

import cgitb; cgitb.enable()

form = cgi.FieldStorage()
fileitem = form['filename']
if fileitem.filename:
with open("body.dat", "wb") as f:
f.write(fileitem.file.read())

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Tested Mike's way, t_deploy output:

diff: /tmp/aktualizr-951f-8561-2d1e-5c0a/d5ea-2beb-dir/objects/: No such file or directory
/home/liping/aktualizr/src/sota_tools/deploy_test.cc:32: Failure

Copy link
Collaborator

Choose a reason for hiding this comment

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

Interesting, I've just checked and it works for me, I missed an ending return statement at the end of the code snippet

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, I added the return statement. maybe we can see how it work out In CI test?

Copy link
Collaborator

@mike-sul mike-sul Aug 28, 2019

Choose a reason for hiding this comment

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

Oh, I think, I understand where is a problem. It's not enough just set a header that indicates a type of transferring data, actual data should be transferred according to the declared way. In this particular case we set 'application/octet-stream' header but actually transfer data as 'multipart/form-data', see OSTreeObject::Upload() code below setting the headers.

@@ -241,6 +246,10 @@ void OSTreeObject::Upload(const TreehubServer &push_target, CURLM *curl_multi_ha

curlEasySetoptWrapper(curl_handle_, CURLOPT_PRIVATE, this); // Used by ostree_object_from_curl

assert(headers_ == nullptr);
Copy link
Collaborator

Choose a reason for hiding this comment

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

If OSTreeObject::Upload is called more than one for the same class instance then it won't work. I suppose, in our case it's called only once so it shouldn't be a problem, although, perhaps makes sense to set the headers in ctor ?

@Zee314159 Zee314159 force-pushed the fix/ota-2183/enable-streaming-of-garage-tool-uploads branch 2 times, most recently from 04a1608 to 50cd80b Compare August 29, 2019 14:32
@Zee314159
Copy link
Contributor Author

Zee314159 commented Aug 29, 2019

All the tests passed except 'OstreeObject_test.UploadFail". II'll look into it tomorrow.

@Zee314159 Zee314159 force-pushed the fix/ota-2183/enable-streaming-of-garage-tool-uploads branch 4 times, most recently from 70b8a8a to 915e9cd Compare August 30, 2019 05:58
@Zee314159
Copy link
Contributor Author

I am not sure if I see where this fd is closed in case if the file is successfully opened.

I closed the file after the reading is done, but somehow it will cause a failing of the test. Any suggestion where to close the file?

@Zee314159 Zee314159 force-pushed the fix/ota-2183/enable-streaming-of-garage-tool-uploads branch 3 times, most recently from abc53fc to 12f26e1 Compare September 2, 2019 04:56
@Zee314159
Copy link
Contributor Author

See this PR: #1244 , looks there left an unsolved issue.

@Zee314159 Zee314159 force-pushed the fix/ota-2183/enable-streaming-of-garage-tool-uploads branch from 12f26e1 to 10fa383 Compare September 2, 2019 06:12
LOG_ERROR << "curl_formadd error: " << form_err;
struct stat file_info {};
fd_ = fopen(file_path_.c_str(), "rb");
if (fd_ == nullptr) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

As far as I understand, if a file opening or getting its stat fails the code control flow will end up at line #333 ?
I am just wondering if throwing an exception (like at line #229) will work in this case, at first glance it won't work (just thinking loudly :))

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Throwing an exception might be better.

@mike-sul
Copy link
Collaborator

mike-sul commented Sep 2, 2019

@patrickvacek As far as I understand some of the tests triggered by the CI pipelines do use garag-push/deploy against the prod/SIT treehub ?

@pattivacek
Copy link
Collaborator

As far as I understand some of the tests triggered by the CI pipelines do use garag-push/deploy against the prod/SIT treehub ?

Yes, that is correct. I don't think we actually push anything, though, I think it's just testing authentication. I might be misremembering.

@mike-sul
Copy link
Collaborator

mike-sul commented Sep 2, 2019

As far as I understand some of the tests triggered by the CI pipelines do use garag-push/deploy against the prod/SIT treehub ?

Yes, that is correct. I don't think we actually push anything, though, I think it's just testing authentication. I might be misremembering.

I suppose, it would be great to test this change against the real treehub, at least manually.

@pattivacek
Copy link
Collaborator

I suppose, it would be great to test this change against the real treehub, at least manually.

Absolutely, this is a requirement. Manual confirmation is enough if we have tests that effectively simulate the real backend.

@Zee314159 Zee314159 force-pushed the fix/ota-2183/enable-streaming-of-garage-tool-uploads branch 12 times, most recently from 06c1722 to 4523a85 Compare September 7, 2019 05:47
Set header from ostree_object

Fix headers initialize bug

Uploade data as 'octet-stream'

Fix bug fail ostree_object_test

Close fd and not return right away

Fix legacy issue of garage-deploy

Recieve http/204 instead of http/200

Fix headers overwriting bug

Signed-off-by: Zee314159 <252806294@qq.com>
@Zee314159 Zee314159 force-pushed the fix/ota-2183/enable-streaming-of-garage-tool-uploads branch from 4523a85 to ee671d5 Compare September 9, 2019 01:39
@@ -42,7 +42,7 @@ class RequestPool {
RateController rate_controller_;
int running_requests_;
int total_requests_made_{0};
const TreehubServer& server_;
TreehubServer& server_;
Copy link
Collaborator

Choose a reason for hiding this comment

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

It's too bad we lose this const-ness. It doesn't seem so critical, though, and I don't have a better solution available yet, though, so maybe it's fine.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, I feel sorry for the loss too. I have tried.

Copy link
Collaborator

@pattivacek pattivacek left a comment

Choose a reason for hiding this comment

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

Tested against SIT and it works! The const issue is pretty minor and we can always try to restore it another time.

@pattivacek pattivacek merged commit d6e45d2 into master Sep 9, 2019
@pattivacek pattivacek deleted the fix/ota-2183/enable-streaming-of-garage-tool-uploads branch September 9, 2019 14:25
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants