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

host-ctr: exposes error level log messages to console #479

Merged
merged 1 commit into from
Oct 29, 2019

Conversation

etungsten
Copy link
Contributor

@etungsten etungsten commented Oct 29, 2019

Issue #, if available: Fixes #477

Description of changes:
Splits logrus logs to different output with LogSplit logrus hook.
Error, fatal, panic levels goes to standard error and all other log levels go to stdout

Testing:

Locally ran host-ctr with an invalid image repository:

$ sudo ./host-ctr -containerd-socket /run/containerd/containerd.sock -pull-image-only -source 328549459982.dkr.ecrus-west-2.amazonaws.com/thar-admin:0.2 > >(tee -a stdout.log) 2> >(tee -a stderr.log >&2)
time="2019-10-29T15:33:25-07:00" level=warning msg="Failed to pull image. Waiting 4.273s before retrying..." error="failed to resolve reference \"328549459982.dkr.ecrus-west-2.amazonaws.com/thar-admin:0.2\": failed to do request: Head \"https://328549459982.dkr.ecrus-west-2.amazonaws.com/v2/thar-admin/manifests/0.2\": dial tcp: lookup 328549459982.dkr.ecrus-west-2.amazonaws.com on 127.0.1.1:53: no such host"
SNIP
time="2019-10-29T15:34:16-07:00" level=error msg="retries exhausted: failed to resolve reference \"328549459982.dkr.ecrus-west-2.amazonaws.com/thar-admin:0.2\": failed to do request: Head \"https://328549459982.dkr.ecrus-west-2.amazonaws.com/v2/thar-admin/manifests/0.2\": dial tcp: lookup 328549459982.dkr.ecrus-west-2.amazonaws.com on 127.0.1.1:53: no such host" ref="328549459982.dkr.ecrus-west-2.amazonaws.com/thar-admin:0.2"

Then with valid image repository:

$ sudo ./host-ctr -containerd-socket /run/containerd/containerd.sock -pull-image-only -source 328549459982.dkr.ecr.us-west-2.amazonaws.com/thar-admin:v0.2 > >(tee -a stdout.log) 2> >(tee -a stderr.log >&2)
time="2019-10-29T16:06:17-07:00" level=info msg="Pulling with Amazon ECR Resolver" ref="ecr.aws/arn:aws:ecr:us-west-2:328549459982:repository/thar-admin:v0.2"
time="2019-10-29T16:06:20-07:00" level=info msg="Pulled successfully" img="ecr.aws/arn:aws:ecr:us-west-2:328549459982:repository/thar-admin:v0.2"
time="2019-10-29T16:06:20-07:00" level=info msg=Unpacking... img="ecr.aws/arn:aws:ecr:us-west-2:328549459982:repository/thar-admin:v0.2"
time="2019-10-29T16:06:20-07:00" level=info msg="Tagging image" imageName="328549459982.dkr.ecr.us-west-2.amazonaws.com/thar-admin:v0.2"

Verified that errors get written to stderr and everything else to stdout:

$ cat stderr.log 
time="2019-10-29T15:34:16-07:00" level=error msg="retries exhausted: failed to resolve reference \"328549459982.dkr.ecrus-west-2.amazonaws.com/thar-admin:0.2\": failed to do request: Head \"https://328549459982.dkr.ecrus-west-2.amazonaws.com/v2/thar-admin/manifests/0.2\": dial tcp: lookup 328549459982.dkr.ecrus-west-2.amazonaws.com on 127.0.1.1:53: no such host" ref="328549459982.dkr.ecrus-west-2.amazonaws.com/thar-admin:0.2"
$ cat stdout.log 
time="2019-10-29T15:33:25-07:00" level=warning msg="Failed to pull image. Waiting 4.273s before retrying..." error="failed to resolve reference \"328549459982.dkr.ecrus-west-2.amazonaws.com/thar-admin:0.2\": failed to do request: Head \"https://328549459982.dkr.ecrus-west-2.amazonaws.com/v2/thar-admin/manifests/0.2\": dial tcp: lookup 328549459982.dkr.ecrus-west-2.amazonaws.com on 127.0.1.1:53: no such host"
SNIP
time="2019-10-29T16:06:17-07:00" level=info msg="Pulling with Amazon ECR Resolver" ref="ecr.aws/arn:aws:ecr:us-west-2:328549459982:repository/thar-admin:v0.2"
time="2019-10-29T16:06:20-07:00" level=info msg="Pulled successfully" img="ecr.aws/arn:aws:ecr:us-west-2:328549459982:repository/thar-admin:v0.2"
time="2019-10-29T16:06:20-07:00" level=info msg=Unpacking... img="ecr.aws/arn:aws:ecr:us-west-2:328549459982:repository/thar-admin:v0.2"
time="2019-10-29T16:06:20-07:00" level=info msg="Tagging image" imageName="328549459982.dkr.ecr.us-west-2.amazonaws.com/thar-admin:v0.2"

On a Thar instance with the following in userdata:

[settings.host-containers.control]
enabled = true
source = "totallyvalidimagerepo.org/foo:bar"

[email protected] outputs error messages to the console:

[   59.623035] host-ctr[2621]: time="2019-10-29T23:19:00Z" level=error msg="retries exhausted: failed to resolve reference \"gibberishadmincontainer.org/foo:bar\": failed to do request: Head https://gibberishadmincontainer.org/v2/foo/manifests/bar: dial tcp: lookup gibberishadmincontainer.org on 192.168.0.2:53: no such host" ref="gibberishadmincontainer.org/foo:bar"
[   60.681191] host-ctr[2672]: time="2019-10-29T23:19:01Z" level=error msg="retries exhausted: failed to resolve reference \"totallyvalidimagerepo.org/foo:bar\": failed to do request: Head https://totallyvalidimagerepo.org/v2/foo/manifests/bar: dial tcp: lookup totallyvalidimagerepo.org on 192.168.0.2:53: no such host" ref="totallyvalidimagerepo.org/foo:bar"
[  156.734936] host-ctr[4049]: time="2019-10-29T23:20:37Z" level=error msg="retries exhausted: failed to resolve reference \"totallyvalidimagerepo.org/foo:bar\": failed to do request: Head https://totallyvalidimagerepo.org/v2/foo/manifests/bar: dial tcp: lookup totallyvalidimagerepo.org on 192.168.0.2:53: no such host" ref="totallyvalidimagerepo.org/foo:bar"
[  156.826145] host-ctr[4011]: time="2019-10-29T23:20:38Z" level=error msg="retries exhausted: failed to resolve reference \"gibberishadmincontainer.org/foo:bar\": failed to do request: Head https://gibberishadmincontainer.org/v2/foo/manifests/bar: dial tcp: lookup gibberishadmincontainer.org on 192.168.0.2:53: no such host" ref="gibberishadmincontainer.org/foo:bar"

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

workspaces/host-ctr/cmd/host-ctr/main.go Outdated Show resolved Hide resolved
Splits logrus logs to different output with logsplit hook.
Error, fatal, panic log goes to standard error and all other log levels
go to stdout
@etungsten
Copy link
Contributor Author

Addresses @jahkeup 's comment.
Sets up the logger during init(), tested and things still work.

@tjkirch tjkirch requested a review from jahkeup October 29, 2019 23:49
Copy link
Member

@jahkeup jahkeup left a comment

Choose a reason for hiding this comment

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

🖱️ 🚢 💻

@etungsten etungsten merged commit b722878 into develop Oct 29, 2019
@etungsten etungsten deleted the host-ctr-log branch October 29, 2019 23:58
@iliana iliana added this to the v0.2.0 milestone Nov 19, 2019
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.

host-ctr split error logging
4 participants