Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@cyphar
Copy link
Contributor

@cyphar cyphar commented Oct 18, 2016

This adds a very simple implementation of logging within conmon, where
every buffer read from the masterfd of the container is also written to
the log file (with errors during writing to the log file ignored). It also
includes changes to how we compute the logPath for a container.

The WIP part of this PR is that conmon currently doesn't really handle
containers where terminal: false. This is going to be not-very-nice to
fix because the current runC API is broken (which is why we need to
make sure that the current state of opencontainers/runtime-spec#513
is fixed). However, while that's being sorted (and I work on the
relevant console changes in runC) we can solve it with a fork+execve
though no doubt there will be some fun issues with the exit code.

Closes #24.

Signed-off-by: Aleksa Sarai [email protected]

@cyphar
Copy link
Contributor Author

cyphar commented Oct 18, 2016

Yeah, the CLA still isn't signed but I though I'd open a PR so nobody else re-does work I've already done. It also opens the door for testing.

@mrunalp
Copy link
Member

mrunalp commented Oct 18, 2016

Sweet! I'll test this out.

@cyphar
Copy link
Contributor Author

cyphar commented Oct 19, 2016

I've just pushed a version where terminal=false logging actually works. It's all a little bit dodgy at the moment, but now (for the first time) we actually have full logging to a file. :D

@mrunalp
Copy link
Member

mrunalp commented Oct 19, 2016

@cyphar Fails tests. I will try manual testing next.

1..10
not ok 1 ctr remove
# (in test file ./ctr.bats, line 35)
#   `[ "$status" -eq 0 ]' failed
# time="2016-10-19T10:54:45-07:00" level=info msg="Starting reaper" 
# E1019 10:54:45.599650    7480 ocicni.go:136] error updating cni config: No networks found in /etc/cni/net.d
# time="2016-10-19T10:54:45-07:00" level=debug msg="sandboxes: map[]" 
# time="2016-10-19T10:54:45-07:00" level=debug msg="containers: &{map[] {{0 0} 0 0 0 0}}" 
# time="2016-10-19T10:54:45-07:00" level=info msg="Signal received: child exited" 
# time="2016-10-19T10:54:45-07:00" level=info msg="Signal received: child exited" 
# time="2016-10-19T10:54:45-07:00" level=debug msg="setting sandbox infra container's log_path" ctr.logfile=d35e7bc3a1bd8111f6c904dd72a5c65c6ffbde65ab170f08118391b2a7d8c46d log_path="/var/log/ocid/pods/5322d4b3450a79798e1a34f9c676fc2005bac828d09fbf7ba382
1b5cac6fc075/d35e7bc3a1bd8111f6c904dd72a5c65c6ffbde65ab170f08118391b2a7d8c46d.log" sbox.logdir="/var/log/ocid/pods/5322d4b3450a79798e1a34f9c676fc2005bac828d09fbf7ba3821b5cac6fc075" 
# time="2016-10-19T10:54:45-07:00" level=debug msg="copying infra rootfs binary: /root/gosrc/src/github.com/kubernetes-incubator/cri-o/pause/pause -> /tmp/tmp.3Qj9yykBiS/ocid/graph/vfs/pause/rootfs/pause" 
# time="2016-10-19T10:54:45-07:00" level=debug msg="running conmon: /root/gosrc/src/github.com/kubernetes-incubator/cri-o/conmon/conmon" args=[-c default-podsandbox1-0-infra -r /usr/local/sbin/runc -l /var/log/ocid/pods/5322d4b3450a79798e1a34f9c676fc2005
bac828d09fbf7ba3821b5cac6fc075/d35e7bc3a1bd8111f6c904dd72a5c65c6ffbde65ab170f08118391b2a7d8c46d.log] 
# [conmon:i]: container PID: 7612
# [conmon:e] Failed to add stdin to epoll Operation not permitted

@mrunalp
Copy link
Member

mrunalp commented Oct 19, 2016

pod create/ctr create/ctr start work fine. However I don't see any logs in the container.log file :/
Also ctr stop hangs..

@cyphar
Copy link
Contributor Author

cyphar commented Oct 20, 2016

@mrunalp How did you run it? You need to give an absolute path to the log directory in your configs -- otherwise odd things happen to the cwd that I haven't figured out yet. For example, the test data is currently broken (though I think I included a fix) because it sets the log_directory to ".".

@mrunalp
Copy link
Member

mrunalp commented Oct 20, 2016

@cyphar I'll try with setting the log_directory. Thanks!

@cyphar
Copy link
Contributor Author

cyphar commented Oct 20, 2016

@mrunalp Note: if you set log_directory: "" then my code will automatically put all of the logs inside /var/log/ocid/pod/<pod id>/<ctr id>.log. The kubelet will always tell us a log path, but I thought this might be useful just for our own testing.

@mrunalp
Copy link
Member

mrunalp commented Oct 20, 2016

@cyphar I set pod log_directory to /var/log/podsandbox1 and container log_path to container.log The files do get created but I don't see any logs in /var/log/podsandbox1/container.log.

@cyphar
Copy link
Contributor Author

cyphar commented Oct 21, 2016

@mrunalp Just to make sure, you did this right (I actually made this mistake a few times):

% sbox_id=$(sudo ./ocic pod create --config test/testdata/sandbox_config.json --name sandbox1)
% ctr_id=$(sudo ./ocic ctr create --config test/testdata/container_config.json --pod $sbox_id)
% sudo ./ocic ctr start --id $ctr_id # I forgot to do this a few times.

After making the changes you mentioned. It works for me:

% sudo cat /var/log/ocid/podsandbox1/container.log
bin
boot
data
dev
etc
home
lib
lib64
media
mnt
opt
proc
root
run
sbin
srv
sys
tmp
usr
var

@mrunalp
Copy link
Member

mrunalp commented Oct 21, 2016

@cyphar I have been testing container_redis.json. I'll try with the other config and check whether redis is writing to stdout or stderr.

@mrunalp
Copy link
Member

mrunalp commented Oct 25, 2016

@cyphar I just got around to testing this again. Your example with ls works fine but redis-server doesn't work with or without tty.

@cyphar cyphar changed the title [wip] conmon: implement logging conmon: implement logging Nov 4, 2016
@cyphar
Copy link
Contributor Author

cyphar commented Nov 4, 2016

@mrunalp I've got a branch with the --console-socket implementation, and found some bugs in the runC --console-socket stuff (nothing major). Currently this branch works with conmon if you run it by itself, but for some reason it doesn't work under ocid.

@mrunalp
Copy link
Member

mrunalp commented Nov 9, 2016

Okay, just retested this. redis works without tty but no logs with tty.

@runcom
Copy link
Member

runcom commented Nov 24, 2016

Ping @cyphar any update?

@mrunalp
Copy link
Member

mrunalp commented Nov 24, 2016 via email

@runcom
Copy link
Member

runcom commented Nov 24, 2016

@mrunalp thanks, wasn't aware of that

@feiskyer
Copy link
Contributor

feiskyer commented Dec 6, 2016

What's the status of this?

@cyphar
Copy link
Contributor Author

cyphar commented Dec 6, 2016

The same as above. There is a console rewrite PR in runC pending to be merged (opencontainers/runc#1018) -- when you apply that patch to runC this PR works properly. Otherwise there are issues with tty: false containers and I don't really want to debug old code that is going to be replaced soon.

@cyphar
Copy link
Contributor Author

cyphar commented Dec 7, 2016

opencontainers/runc#1018 has been merged. I will rebase this soon.

@runcom
Copy link
Member

runcom commented Dec 17, 2016

@cyphar any update on this one 👼

@runcom runcom modified the milestones: 0.0.1, 0.0.2 Dec 17, 2016
@cyphar
Copy link
Contributor Author

cyphar commented Dec 18, 2016

@runcom Sorry, umoci got in the way. I will work on this today / tomorrow. Promise. If not, I give you permission to spam me on twitter. 😸

@cyphar
Copy link
Contributor Author

cyphar commented Dec 18, 2016

Hmmm. I need to figure out where all of my logDir code changes need to be moved to now.

@mrunalp
Copy link
Member

mrunalp commented Apr 4, 2017

@sameo Can you retest with etcd?

@mrunalp
Copy link
Member

mrunalp commented Apr 4, 2017

okay, retested with latest and looks good 👍 :) will wait for tests to go green and @sameo retest.

@sameo
Copy link

sameo commented Apr 4, 2017

@mrunalp re-testing...

@sameo
Copy link

sameo commented Apr 4, 2017

@mrunalp @cyphar Works with etcd and an nginx deployment.

@mrunalp
Copy link
Member

mrunalp commented Apr 4, 2017

LGTM (we can merge once tests are green)

@runcom
Copy link
Member

runcom commented Apr 4, 2017

works for me as well

@cyphar
Copy link
Contributor Author

cyphar commented Apr 4, 2017

EUGH. I made a typo in the lint command. The actual tests pass though. I'll push a fix.

@runcom
Copy link
Member

runcom commented Apr 4, 2017

(Travis isn't giving a single fu*k about our tests apparently)

@cyphar
Copy link
Contributor Author

cyphar commented Apr 4, 2017

I think it's because Travis limits the number of jobs for each organisation not repo, so there's some other job being run on behalf of @kubernetes-incubator that is blocking us. FFS.

@cyphar
Copy link
Contributor Author

cyphar commented Apr 4, 2017

Oh goddammit. go vet changed their output format between Go releases. Why are lint tests breaking things...

cyphar and others added 9 commits April 5, 2017 02:45
  checking lint
  oci/oci.go:372::warning: declaration of err shadows declaration at oci.go:240:  (vetshadow)
  oci/oci.go:265:15:warning: error return value not checked (os.RemoveAll(logPath)) (errcheck)

Signed-off-by: Aleksa Sarai <[email protected]>
The runtimeversion test was incorrectly written and would fail for no
good reason if setup_ocid happened to run a command that failed (even if
it was handled).

Signed-off-by: Aleksa Sarai <[email protected]>
This is necessary for --console-socket.

Signed-off-by: Aleksa Sarai <[email protected]>
This adds a very simple implementation of logging within conmon, where
every buffer read from the masterfd of the container is also written to
the log file (with errors during writing to the log file ignored).

Signed-off-by: Aleksa Sarai <[email protected]>
While pipes have their downsides, it turns out that socketpair(2) will
break any program that tries to open /dev/std{out,err} for writing
(because they're symlinked to /proc/1/fd/{1,2} which will cause lots of
fun issues with sockets).

Signed-off-by: Mrunal Patel <[email protected]>
Signed-off-by: Aleksa Sarai <[email protected]>
CRI requires us to timestamp our logs line-by-line by specifying whether
the line came from std{out,err} and the time at which the log was
recieved. This is a preliminary implementation of said behaviour
(without explicit newline handling at the moment).

Signed-off-by: Mrunal Patel <[email protected]>
Signed-off-by: Aleksa Sarai <[email protected]>
This is necessary, as otherwise ocid will use its own current directory
as a log_directory, which is not the best idea in the world. The same
applies for log_path.

Signed-off-by: Aleksa Sarai <[email protected]>
The main purpose of these tests is to make sure that the log actually
contains output from the container. We don't test the timestamps or the
stream that's stated at the moment.

Signed-off-by: Aleksa Sarai <[email protected]>
Because kubelet will create broken symlinks for logPath it is necessary
to remove those symlinks before we attempt to write to them. This is a
temporary workaround while the issue is fixed upstream.

Ref: https://issues.k8s.io/44043
Signed-off-by: Aleksa Sarai <[email protected]>
@cyphar
Copy link
Contributor Author

cyphar commented Apr 4, 2017

🎉 The tests are green! 🦎 💚

@cyphar
Copy link
Contributor Author

cyphar commented Apr 4, 2017

Merging.

@cyphar cyphar merged commit 7679a84 into cri-o:master Apr 4, 2017
cyphar added a commit that referenced this pull request Apr 4, 2017
@cyphar cyphar deleted the conmon-logging branch April 4, 2017 18:51
@mrunalp
Copy link
Member

mrunalp commented Apr 4, 2017

@cyphar Yay 🎉

@runcom
Copy link
Member

runcom commented Apr 4, 2017

🎉

@rhatdan
Copy link
Contributor

rhatdan commented Apr 8, 2017

Does this help our k8s test matrix?

@mrunalp
Copy link
Member

mrunalp commented Apr 8, 2017 via email

egernst pushed a commit to egernst/cri-o that referenced this pull request Nov 26, 2018
obs: qemu-vanilla: point to qemu repository.
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.

conmon: Handle logs

8 participants