Skip to content

Only use the last line of stdout for the JSON result - #45

Closed
mhart wants to merge 1 commit into
aws:developfrom
mhart:only-last-line-of-result
Closed

mhart wants to merge 1 commit into
aws:developfrom
mhart:only-last-line-of-result

Conversation

@mhart

@mhart mhart commented Aug 14, 2017

Copy link
Copy Markdown
Contributor

The user's function may have emitted text directly to the Docker container's stdout using System.out.println or similar – this won't parse as JSON.

As the function result is always a JSON string, and it's the last thing written to stdout, then we just want to use the last non-empty line. This is the same functionality as that used by the docker-lambda test runner: https://github.com/lambci/docker-lambda/blob/92f59a60884a1809d94046e3555a39f6e0539eab/index.js#L59-L61

cc @sanathkr

The user's function may have emitted text directly to the Docker container's stdout using System.out.println or similar – this won't parse as JSON.

As the function result is always a JSON string, and it's the last thing written to stdout, then we just want to use the last non-empty line. This is the same functionality as that used by the docker-lambda test runner: https://github.com/lambci/docker-lambda/blob/92f59a60884a1809d94046e3555a39f6e0539eab/index.js#L59-L61
@mhart

mhart commented Aug 14, 2017

Copy link
Copy Markdown
Contributor Author

Note that this will still "lose" any output to stdout that the user's function may have emitted.

If you wanted to keep that, then that will be available in the rest of the byte array (ie, result[0:lastNewlineIx]) – but the problem is how to output it. If you output to stderr, then you'll need to figure out how to intersperse it with the existing output in stderr. Could somehow inject it before the final two reporting lines... but seems messy.

@sanathkr

Copy link
Copy Markdown

Yeah, this change makes sense, given how customers can directly write to stdout. But I am concerned about loosing the other logs. We could append it to end of stderr where we send app's logs anyway.

@sanathkr

Copy link
Copy Markdown

Two missing things:

  1. Same logic is present in invoke.go. Need to duplicate there (or refactor into a separate method)
  2. Tests. I know we don't have tests for this area, but it would be good if we can start adding them one PR at a time. Unit tests would do.

@mhart

mhart commented Aug 14, 2017

Copy link
Copy Markdown
Contributor Author

I don't think there's any JSON parsing of stdout in invoke.go

@sanathkr

sanathkr commented Aug 15, 2017 •

Copy link
Copy Markdown

Yeah, you're right.

Can you add a test so we don't regress in future? LGTM otherwise

@mhart

mhart commented Aug 15, 2017

Copy link
Copy Markdown
Contributor Author

Np, where are the start tests?

@sanathkr

sanathkr commented Aug 16, 2017 •

Copy link
Copy Markdown

Sadly, they don't exists. You can fashion your tests off of the validate_test.gofile.

Thanks for doing this!

@sanathkr

Copy link
Copy Markdown

@mhart any chance you can get this implemented? thanks!

@resios

resios commented Oct 6, 2017

Copy link
Copy Markdown
Contributor

I think you can close this since #143 incorporates the changes proposed here.

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.

3 participants