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

Make Docker.run return its stdout as a string #120

Merged
merged 1 commit into from Mar 4, 2020

Conversation

kit-ty-kate
Copy link
Contributor

After commenting on #99 (comment) I realized it was relatively easy to change Current_docker.run to do what i want and return its result as a string.

This is the current design I'm using in opam-ci where it successfully gets the list of reverse dependencies for each packages:
screenshot

@talex5
Copy link
Contributor

talex5 commented Mar 3, 2020

This looks good, but I think it should be a new function (e.g. Docker.pread), as we often don't need to use (or store) the output.

@craigfe
Copy link
Member

craigfe commented Mar 3, 2020

Thanks 🙂 Some thoughts:

  • the use of Current.Process.check_output rather than docker logs sacrifices the ability to tail the logs, which is perhaps significant for very containers with very verbose output. I'm not sure how docker logs --tail is implemented, but it seems likely to be better than loading the entire log as a string and then truncating it.

  • Current.Process.check_output seems to redirect the stdout stream to a string rather than the Current logs, which is problematic as it means those logs are no longer visible in the UI.

  • Current.Process.check_output does not capture the stderr stream, unlike the previous attempt at a docker logs solution. This seems like a considerable limitation.

  • @talex5: I think we do often need to use the output, but it happens that the Log_matcher is sufficient for this purpose right now. Once we're reporting more rich data back to the user (c.f. GitHub Checks support), it seems that most (all?) of our Docker.run's (at least in the OCaml-CI pipeline) will want to use this feature.

    Which is not to say that we shouldn't still make it opt-in for performance reasons.

edit: I accidentally posted it before finishing... 🤦‍♂️

@talex5
Copy link
Contributor

talex5 commented Mar 3, 2020

@craigfe I think this use is quite separate to log analysis. For example, Kate wants to read structured data (revdeps) from the command. This should not be mixed in with warning messages from stderr. It's also quite likely that the output being captured would be binary data, in which case it's important that we don't log it.

@craigfe
Copy link
Member

craigfe commented Mar 3, 2020

@talex5 : The use-cases I can think of would all want the data to be logged as well as captured. This includes the application to benchmarking (cc @gs0510, @MagnusS), who have been waiting for a feature like this for a while. Is it an issue if the rev-deps, in this case, are not logged to the interface? I think as a new user of OCurrent I would expect them to be.

If we have a use-case for extracting binary data from a Docker container, I suggest doing that by some other mechanism than overloading 'logs'. For instance by using docker cp (as was attempted in the other PR), or volume mounting.

Copy link
Contributor

@talex5 talex5 left a comment

Choose a reason for hiding this comment

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

LGTM, once the id is changed.

plugins/docker/pread.ml Outdated Show resolved Hide resolved
@@ -16,5 +16,5 @@
ppx_deriving_yojson.runtime
result)
(preprocess (per_module
((pps ppx_deriving.std ppx_deriving_yojson) pull build run tag push service)
((pps ppx_deriving.std ppx_deriving_yojson) pull build run pread tag push service)
Copy link
Contributor

Choose a reason for hiding this comment

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

(we could probably get rid of this per-module thing now - it was a hack for before 4.08, which we no longer support)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Should I change this in this PR or in a separate PR?

@kit-ty-kate
Copy link
Contributor Author

kit-ty-kate commented Mar 4, 2020

If the change in plugins/docker/dune can be done separately, this should be good to go.

@talex5 talex5 merged commit 8c00d1b into ocurrent:master Mar 4, 2020
@talex5
Copy link
Contributor

talex5 commented Mar 4, 2020

Thanks - I'll take a look at cleaning up the preprocessing separately...

@craigfe
Copy link
Member

craigfe commented Mar 4, 2020

I don't think this should have been merged.

  • The logging behaviour may be problematic for our other use-case, and at the very least seems to warrant further discussion.
  • plugins/docker/pread.ml duplicates all of the code from plugins/docker/run.ml, when this seems unnecessary (they share the same Key module, for instance).
  • It's missing a test in test/plugins/docker/, ideally capturing the behaviours w.r.t. logging and stderr.
  • The docstring for pread doesn't explain that the logging behaviour is not the same as run.

Are we in a rush to merge this feature as is?

@talex5
Copy link
Contributor

talex5 commented Mar 4, 2020

The behaviour of pread (returning the output instead of sending it to stdout) is pretty standard, e.g. compare lwt's version:

utop # #require "lwt.unix";;
utop # open Lwt_process;;
utop # let cmd = "", [| "echo"; "hello" |];;

utop # exec cmd;;
hello
- : Unix.process_status = Unix.WEXITED 0

utop # pread cmd;;
- : string = "hello\n"

But I do think we should make it easier to make user-defined pipeline stages using Docker, so the built-in ones don't have to cover every case.

(if you want to add an option to log the output too, or clean up the code, feel free)

talex5 added a commit to talex5/opam-repository that referenced this pull request Apr 3, 2020
…urrent_git, current_slack, current_ansi, current_rpc, current_incr and current_examples (0.2)

CHANGES:

The main new feature is that OCurrent now evaluates pipelines incrementally.
This means that services with large pipelines (such as ocaml-ci, with around
10,000 stages) can decide what they need to do without using an excessive
amount of CPU time.

- Replace changed promises with `Engine.update` (@talex5, ocurrent/ocurrent#135)
- Evaluate pipelines incrementally (@talex5, ocurrent/ocurrent#144)
- Avoid unnecessary re-evaluations in `Current.list_map` (@talex5, ocurrent/ocurrent#148)
- Change the representation of terms to support incremental evaluation (@talex5, ocurrent/ocurrent#150)

Documentation:

- Added [Internals](https://github.com/ocurrent/ocurrent/wiki/Internals) wiki
  page explaining how OCurrent works.
- Update README.md to link the [API Docs](https://ocurrent.github.io/ocurrent/index.html) (@shonfeder, ocurrent/ocurrent#145)
- Fix typo in README ("about" -> "above") (@smolck, ocurrent/ocurrent#100)

Docker plugin:

- Add support for run-arguments in docker plugin (@MagnusS, ocurrent/ocurrent#96)
- Add `?build_args` parameter to `Current_docker` build (@SquidDev, ocurrent/ocurrent#102)
- Allow alternative Dockerfile filenames in `Docker.build` (@talex5, ocurrent/ocurrent#111)
- Add `Docker.pread` to get container stdout as a string (@kit-ty-kate, ocurrent/ocurrent#120)
- Make it easier to add custom Docker commands (@talex5, ocurrent/ocurrent#130)

Git plugin:

- Git.fetch: don't take repository lock until the job starts (@talex5, ocurrent/ocurrent#116)

GitHub plugin:

- Add `Github.Api.head_of` to track individual branches (@talex5, ocurrent/ocurrent#114)
- Expose the low-level `refs` function to get access to branch names and PR
  numbers (@talex5, ocurrent/ocurrent#123)
- Add `Commit.uri` to make links back to GitHub (@talex5, ocurrent/ocurrent#131)
- Better error if setting a GitHub commit status fails (@talex5, ocurrent/ocurrent#151)
- Only refresh the repository that generated the webhook event, not all of them (@talex5, ocurrent/ocurrent#156)

Web UI:

- Use routes library to simplify routing (@talex5, ocurrent/ocurrent#160)
- Add "/jobs" page with information about active jobs (@talex5, ocurrent/ocurrent#125)
- Mark HTML pages as UTF-8 (@talex5, ocurrent/ocurrent#128)

Dependencies:

- Update to new Alcotest API (@talex5, ocurrent/ocurrent#121)
- Use mirage-crypto instead of nocrypto (@hannesm, ocurrent/ocurrent#161)

Bug fixes:

- Fix analysis with hidden `catch`/`state` nodes (@talex5, ocurrent/ocurrent#134)
- Allow cancelling a job while waiting for confirmation (@talex5 ocurrent/ocurrent#137)
- Fix merging of error states for pairs (@talex5, ocurrent/ocurrent#147)

Metrics:

- Report Prometheus metrics for pipeline stage states (@talex5, ocurrent/ocurrent#115)
- Report metric for cache evaluations (@talex5, ocurrent/ocurrent#143)

Build improvements:

- Make dune transitive dependencies explicit (@craigfe, ocurrent/ocurrent#97)
- Add OCaml-CI status badge to the README (@craigfe, ocurrent/ocurrent#107)

Other:

- Explicitly enumerate accepted `--confirm` values (@craigfe, ocurrent/ocurrent#108)
- Rename `Input` to `Primitive` and simplify the API (@talex5, ocurrent/ocurrent#154)
- Call `Lwt_main.yield` while testing log patterns (@talex5, ocurrent/ocurrent#155)
- Add `Current.collapse` to allow collapsing parts of diagrams (@talex5, ocurrent/ocurrent#152)
- Add `Current.with_context` to help with diagram layout (@talex5, ocurrent/ocurrent#159)
talex5 added a commit to talex5/opam-repository that referenced this pull request Apr 3, 2020
…urrent_git, current_slack, current_ansi, current_rpc, current_incr and current_examples (0.2)

CHANGES:

The main new feature is that OCurrent now evaluates pipelines incrementally.
This means that services with large pipelines (such as ocaml-ci, with around
10,000 stages) can decide what they need to do without using an excessive
amount of CPU time.

- Replace changed promises with `Engine.update` (@talex5, ocurrent/ocurrent#135)
- Evaluate pipelines incrementally (@talex5, ocurrent/ocurrent#144)
- Avoid unnecessary re-evaluations in `Current.list_map` (@talex5, ocurrent/ocurrent#148)
- Change the representation of terms to support incremental evaluation (@talex5, ocurrent/ocurrent#150)

Documentation:

- Added [Internals](https://github.com/ocurrent/ocurrent/wiki/Internals) wiki
  page explaining how OCurrent works.
- Update README.md to link the [API Docs](https://ocurrent.github.io/ocurrent/index.html) (@shonfeder, ocurrent/ocurrent#145)
- Fix typo in README ("about" -> "above") (@smolck, ocurrent/ocurrent#100)

Docker plugin:

- Add support for run-arguments in docker plugin (@MagnusS, ocurrent/ocurrent#96)
- Add `?build_args` parameter to `Current_docker` build (@SquidDev, ocurrent/ocurrent#102)
- Allow alternative Dockerfile filenames in `Docker.build` (@talex5, ocurrent/ocurrent#111)
- Add `Docker.pread` to get container stdout as a string (@kit-ty-kate, ocurrent/ocurrent#120)
- Make it easier to add custom Docker commands (@talex5, ocurrent/ocurrent#130)

Git plugin:

- Git.fetch: don't take repository lock until the job starts (@talex5, ocurrent/ocurrent#116)

GitHub plugin:

- Add `Github.Api.head_of` to track individual branches (@talex5, ocurrent/ocurrent#114)
- Expose the low-level `refs` function to get access to branch names and PR
  numbers (@talex5, ocurrent/ocurrent#123)
- Add `Commit.uri` to make links back to GitHub (@talex5, ocurrent/ocurrent#131)
- Better error if setting a GitHub commit status fails (@talex5, ocurrent/ocurrent#151)
- Only refresh the repository that generated the webhook event, not all of them (@talex5, ocurrent/ocurrent#156)

Web UI:

- Use routes library to simplify routing (@talex5, ocurrent/ocurrent#160)
- Add "/jobs" page with information about active jobs (@talex5, ocurrent/ocurrent#125)
- Mark HTML pages as UTF-8 (@talex5, ocurrent/ocurrent#128)

Dependencies:

- Update to new Alcotest API (@talex5, ocurrent/ocurrent#121)
- Use mirage-crypto instead of nocrypto (@hannesm, ocurrent/ocurrent#161)

Bug fixes:

- Fix analysis with hidden `catch`/`state` nodes (@talex5, ocurrent/ocurrent#134)
- Allow cancelling a job while waiting for confirmation (@talex5 ocurrent/ocurrent#137)
- Fix merging of error states for pairs (@talex5, ocurrent/ocurrent#147)

Metrics:

- Report Prometheus metrics for pipeline stage states (@talex5, ocurrent/ocurrent#115)
- Report metric for cache evaluations (@talex5, ocurrent/ocurrent#143)

Build improvements:

- Make dune transitive dependencies explicit (@craigfe, ocurrent/ocurrent#97)
- Add OCaml-CI status badge to the README (@craigfe, ocurrent/ocurrent#107)

Other:

- Explicitly enumerate accepted `--confirm` values (@craigfe, ocurrent/ocurrent#108)
- Rename `Input` to `Primitive` and simplify the API (@talex5, ocurrent/ocurrent#154)
- Call `Lwt_main.yield` while testing log patterns (@talex5, ocurrent/ocurrent#155)
- Add `Current.collapse` to allow collapsing parts of diagrams (@talex5, ocurrent/ocurrent#152)
- Add `Current.with_context` to help with diagram layout (@talex5, ocurrent/ocurrent#159)
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.

None yet

3 participants