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

HTTP PUT output support #737

Merged
merged 32 commits into from
Feb 2, 2021
Merged

Conversation

termoose
Copy link
Contributor

Experimental feature support for HTTP ingest.

  • Tested with ingesting encrypted DASH segments against Akamai MSL4 EP's.
  • Tested with flaky ingests, disconnecting and reconnecting.

Relates and hopefully closes issue #149.

amotl and others added 26 commits October 15, 2018 14:59
prevent propagation as zero-length PUT request
to mitigate calls to File::GetFileSize
@googlebot
Copy link

Thanks for your pull request. It looks like this may be your first contribution to a Google open source project (if not, look below for help). Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

📝 Please visit https://cla.developers.google.com/ to sign.

Once you've signed (or fixed any issues), please reply here with @googlebot I signed it! and we'll verify it.


What to do if you already signed the CLA

Individual signers
Corporate signers

ℹ️ Googlers: Go here for more info.

1 similar comment
@googlebot
Copy link

Thanks for your pull request. It looks like this may be your first contribution to a Google open source project (if not, look below for help). Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

📝 Please visit https://cla.developers.google.com/ to sign.

Once you've signed (or fixed any issues), please reply here with @googlebot I signed it! and we'll verify it.


What to do if you already signed the CLA

Individual signers
Corporate signers

ℹ️ Googlers: Go here for more info.

@amotl
Copy link
Contributor

amotl commented Mar 24, 2020

Dear Ole Andre,

thanks again for taking care about this. Will you also add 8ddbbf0 into the mix?

With kind regards,
Andreas.

@amotl
Copy link
Contributor

amotl commented Mar 24, 2020

@googlebot I signed it!

@kqyang
Copy link
Contributor

kqyang commented Oct 13, 2020

I don't know what to do about the @googlebot I consent. part above. Is this an issue related to my CLA signing?

Emm... I am not sure if it is because of yours CLA signing, but the bot was complaining "one or more commits were authored or co-authored by someone other than the pull request submitter."

I'll see if I can find out.

Thanks for your effort on this PR!

@amotl
Copy link
Contributor

amotl commented Oct 21, 2020

Hi again,

seems like most of the conflicts were that you're now using a BufferWriter

AppVeyor shows different kinds of errors [1]. Is this related somehow?

Is [there still] an issue related to my CLA signing?

@kqyang promised to check. Maybe this is related to these two commits by Rintaro Kuroiwa (@rkuroiwa) somehow? At least, both commits are not directly associated with his pen.

image

With kind regards,
Andreas.

[1] https://ci.appveyor.com/project/shaka/shaka-packager/builds/35724371/job/d3va1bvda78ago4o

@kqyang
Copy link
Contributor

kqyang commented Oct 21, 2020

@kqyang promised to check. Maybe this is related to these two commits by Rintaro Kuroiwa (@rkuroiwa) somehow? At least, both commits are not directly associated with his pen.

We are still checking. Apologize for the delay.

AppVeyor shows different kinds of errors [1]. Is this related somehow?

It looks like a problem in the test.

TEST_F(HttpFileTest, PutChunkedTranser) {
  std::unique_ptr<File, FileCloser> writer(
      File::Open("put+http://127.0.0.1:8080/test_out", "w"));
  ASSERT_TRUE(writer);
  ASSERT_EQ(kWriteBufferSize, writer->Write(kWriteBuffer, kWriteBufferSize));
  writer.release()->Close();
}
[ RUN      ] HttpFileTest.PutChunkedTranser
[1013/131933:ERROR:local_file.cc(85)] Failed to create directory put+http: ErrorCode 123
c:\projects\shaka-packager\src\packager\file\http_file_unittest.cc(20): error: Value of: writer
  Actual: false
Expected: true
[  FAILED  ] HttpFileTest.PutChunkedTranser (27 ms)

Should the URL of the file open just be "http://127.0.0.1:8080/test_out"?

Also, a separate question, do we support HTTP methods other than "put"?

@kqyang
Copy link
Contributor

kqyang commented Oct 21, 2020

@amotl Here is the problem:

amotl | andreas.motl@elmyra.de | need_author_consent

We need your consent for this PR. See the instruction at #737 (comment), i.e.

Please have them confirm that by leaving a comment that contains only @googlebot I consent

@amotl
Copy link
Contributor

amotl commented Oct 21, 2020

Oh, it was me! I believed I had solved this properly already. Thanks!

@amotl
Copy link
Contributor

amotl commented Oct 21, 2020

@googlebot I consent

@googlebot
Copy link

CLAs look good, thanks!

ℹ️ Googlers: Go here for more info.

1 similar comment
@google-cla
Copy link

google-cla bot commented Oct 21, 2020

CLAs look good, thanks!

ℹ️ Googlers: Go here for more info.

@termoose
Copy link
Contributor Author

It looks like a problem in the test.

TEST_F(HttpFileTest, PutChunkedTranser) {
  std::unique_ptr<File, FileCloser> writer(
      File::Open("put+http://127.0.0.1:8080/test_out", "w"));
  ASSERT_TRUE(writer);
  ASSERT_EQ(kWriteBufferSize, writer->Write(kWriteBuffer, kWriteBufferSize));
  writer.release()->Close();
}
[ RUN      ] HttpFileTest.PutChunkedTranser
[1013/131933:ERROR:local_file.cc(85)] Failed to create directory put+http: ErrorCode 123
c:\projects\shaka-packager\src\packager\file\http_file_unittest.cc(20): error: Value of: writer
  Actual: false
Expected: true
[  FAILED  ] HttpFileTest.PutChunkedTranser (27 ms)

Should the URL of the file open just be "http://127.0.0.1:8080/test_out"?

That's a strange test, but I'm guessing it should be just http since that's the only prefix we're checking for with the kHttpFilePrefix and kHttpsFilePrefix.
It does run for me though, which doesn't make sense at all?

[----------] 1 test from HttpFileTest
[ RUN      ] HttpFileTest.PutChunkedTranser
[       OK ] HttpFileTest.PutChunkedTranser (20 ms)
[----------] 1 test from HttpFileTest (20 ms total)

It gives me a 404 if I change the test to http

[----------] 1 test from HttpFileTest
[ RUN      ] HttpFileTest.PutChunkedTranser
[1027/094205:ERROR:http_file.cc(218)] PUT request for http://127.0.0.1:8080/test_out failed. Reason: HTTP response code said error. Response code: 404.
[       OK ] HttpFileTest.PutChunkedTranser (47 ms)
[----------] 1 test from HttpFileTest (47 ms total)

It makes sense that the test is not failing anyway since it's only asserting writer and checking that kWriteBufferSize is equal to bytes written, but Writer writes to a cache_ buffer before doing the http request, so that will probably never fail. I made the change to http anyway.

Also, a separate question, do we support HTTP methods other than "put"?

It's only doing PUT for now but I see there's code for other methods added in the large commit above, does not seem to be in use.

@amotl
Copy link
Contributor

amotl commented Oct 27, 2020

Hi there,

It gives me a 404 if I change the test to http.

It will not be so easy to just remove the prefix. However, I can't remember the intrinsic details that took me to that decision to add the prefix like that - apart from only supporting PUT anyway. I believe it has something to do with that I had to use something like the put+ prefix to detect that the output should go to a non-file handler.

Will you be able to make it work after sublimating yourself into the code again, @termoose?

With kind regards,
Andreas.

P.S.: Great so see @joeyparrish is already building upon our work here, see termoose#1.

@amotl
Copy link
Contributor

amotl commented Oct 27, 2020

The innocent and rather superfluous code like 4491dee ff. has been there for a reason to be able to tell different kinds of files apart.

Otherwise, the machinery doesn't know to handle that as HTTP and will try to access the local file system

[1013/131933:ERROR:local_file.cc(85)] Failed to create directory put+http: ErrorCode 123

I can't describe more precisely what I have been going through back then but I can remember it was a bit of a brainfuck because the machinery doesn't offer a way to signal this through all the loosely coupled subsystems between ingress and egress.

I would have to review the whole bunch of changes again and compare the current state of the onion against all the commits I made in the past to get back on track with this.

@amotl
Copy link
Contributor

amotl commented Oct 27, 2020

Is it actually a good sign that AppVeyor build succeeded right now? Maybe all my ramblings above are just moot. If so, sorry for the noise!

So, will that be ready to merge?

@termoose
Copy link
Contributor Author

Ah I didn't see your GetEffectiveFileAddress function! Could it be that there are other mechanism at work in the "loosely coupled subsystem" now that makes it handle the http protocol? Whenever I tested with ingesting to Akamai MSL4 I didn't specify the output gateway to have put+http:// BTW. I will test the branch once again against Akamai's gateways for DASH and HLS and see how it behaves. This merge is getting complicated :)

But yes the test passes, so that's a bit strange, but I don't see how it could fail actually. The only way I see this test failing is if the writer is nullptr, and for some strange reason it was when the test was running with put+http. I guessing that this is because put+http is not in any of the elements in kFileTypeInfo[] and the construction fails? Anyway enough rabling from me! I'll run some tests tomorrow and see how it behaves. I'd also like to add support for multiple output gateways at some point so we can push to a backup, but that's for another time!

@amotl
Copy link
Contributor

amotl commented Oct 27, 2020

Dear Ole Andre,

Could it be that there are other mechanism at work in the "loosely coupled subsystem" now that makes it handle the http protocol?

That might well be the case. Magic happens sometimes. ;] Maybe also I was just too stupid back then. Thanks for the fix through a1e5a40. If we need to support other HTTP methods than PUT, we will be able to revisit this later.

I will test the branch once again against Akamai's gateways for DASH and HLS and see how it behaves.

Thank you so much! I believe if that will succeed, we will be ready to merge and address other things related to the tests later.

With kind regards,
Andreas.

packager/file/http_file.h Outdated Show resolved Hide resolved
packager/file/http_file.h Outdated Show resolved Hide resolved
packager/file/http_file.h Outdated Show resolved Hide resolved
packager/file/http_file.h Outdated Show resolved Hide resolved
packager/file/http_file.h Outdated Show resolved Hide resolved
bool Open() override;

private:
enum HttpMethod {
Copy link
Contributor

Choose a reason for hiding this comment

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

It's better to use a C++11 enum class instead. Also, the names should be kGet, kPost, etc.

std::string cert_private_key_file_;
std::string cert_private_key_pass_;

const uint32_t timeout_in_seconds_;
Copy link
Contributor

Choose a reason for hiding this comment

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

This isn't really used. It can be added later once support is added. Also, a timeout for a streaming upload isn't that useful since we're streaming in real-time, so it can take a while.

headers = curl_slist_append(headers, "Content-Type: application/octet-stream");
headers = curl_slist_append(headers, "Transfer-Encoding: chunked");

// Don't stop on 200 OK responses.
Copy link
Contributor

Choose a reason for hiding this comment

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

Don't wait for a 100-continue


private:
enum HttpMethod {
GET,
Copy link
Contributor

Choose a reason for hiding this comment

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

Since this is an upload-only type, using GET won't make sense. I suggest removing it.


// Perform HTTP request
Status HttpFile::Request(HttpMethod http_method,
const std::string& url,
Copy link
Contributor

Choose a reason for hiding this comment

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

The URL is in a field, so no need to pass as an argument.

@amotl
Copy link
Contributor

amotl commented Nov 6, 2020

Dear Jacob,

@TheModMaker requested changes 8 hours ago.

Thanks a bunch for your thorough review. Sorry that most of these shortcomings are coming from the fact that I am not a native C++ speaker. I have been happy that @kqyang and @rkuroiwa guided me the other day when doing the initial work on this.

I also want to apologize that I am currently busy with other obligations, so I am humbly asking if you will be able to address these adjustments suggested by Jacob, @termoose?

With kind regards,
Andreas.

@termoose
Copy link
Contributor Author

Thanks for the very thorough review @TheModMaker! I just started at the top and can continue when time allows, think we should be able to get through these. Most of these changes are not done by me so it's a bit challenging to amend them.

@amotl
Copy link
Contributor

amotl commented Nov 26, 2020

Hi again,

I just wanted to ping you about this again. Because @termoose stated:

Most of these changes are not done by me so it's a bit challenging to amend them.

I believe most of them are coming from my pen while working on this the other day. However, as I currently don't see any chance to continue working on those, I want to humbly ask if one of the core developers might be able to take over addressing the issues reported by @TheModMaker?

With kind regards,
Andreas.

@CaitlinOCallaghan
Copy link
Contributor

Hi everyone, @amotl @termoose @TheModMaker @joeyparrish! I was wondering what the status is on this PR? My work uses the HTTP upload feature, and I would love to see it get pulled into master soon. Please let me know if I can help in any way.

Cheers,
Caitlin

@TheModMaker TheModMaker merged commit aa17521 into shaka-project:master Feb 2, 2021
@TheModMaker
Copy link
Contributor

We've decided to merge this as-is and I'll make the requested changes. Thanks for the contribution.

@amotl
Copy link
Contributor

amotl commented Feb 28, 2021

Hi Jacob,

thank you very much for integrating this feature and for taking over development.

With kind regards,
Andreas.

@amotl amotl mentioned this pull request Feb 28, 2021
@Canta Canta mentioned this pull request Apr 28, 2021
@github-actions github-actions bot added the status: archived Archived and locked; will not be updated label Jul 24, 2023
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jul 24, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
status: archived Archived and locked; will not be updated
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants