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

accept Ctrl-C in cri log viewer #1972

Merged
merged 1 commit into from
Feb 8, 2023
Merged

Conversation

zhaojizhuang
Copy link
Contributor

Fixes: #1956
Signed-off-by: zhaojizhuang 571130360@qq.com

@zhaojizhuang
Copy link
Contributor Author

default:
if stop || (limitedMode && limitedNum == 0) {
logrus.Debugf("Finished parsing log file, path; %s", logPath)
return nil
Copy link
Member

Choose a reason for hiding this comment

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

nit: Finished -> finished to be consistent; and typo ; -> :.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

According to common custom,maybe it's a good idea to let log print line ( such as logrus.Debugf(“Example”) logrus.Warnf(“Example”)) start with uppercase, and error string returned (such asfmt.Errorf("example")) start with lowercase

And It seems that there is no uniformity about uppercase and lowercase
uppercase : https://github.com/containerd/nerdctl/blob/main/pkg/composer/create.go#L169

lowercase: https://github.com/containerd/nerdctl/blob/main/cmd/nerdctl/container_cp_linux.go#L259

Copy link
Contributor

Choose a reason for hiding this comment

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

For reference only: https://www.postgres-xl.org/documentation/error-style-guide.html

I think it is also necessary to unify it in our project.

Copy link
Contributor Author

@zhaojizhuang zhaojizhuang Feb 6, 2023

Choose a reason for hiding this comment

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

+1 Agree, maybe we should open a issue to track the uniformity in our registry,cc @djdongjin

Copy link
Member

@djdongjin djdongjin Feb 6, 2023

Choose a reason for hiding this comment

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

This SGTM, but personally I feel this uniformity is more a best-effort but difficult to achieve (or maintain after achieved), part because it's quite detailed and there is a lot of error/log messages, and also because there are new contributors (and reviewers) who're not aware of these.

Speaking of this PR, I'd suggest to lowercase all error/log messages :) since it has both uppercase (line 122, 146, 152, ...) and lowercase (118, 128, 135, ...). Thanks :)

Copy link
Contributor

@suyanhanx suyanhanx Feb 6, 2023

Choose a reason for hiding this comment

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

This SGTM, but personally I feel this uniformity is more a best-effort but difficult to achieve (or maintain after achieved), part because it's quite detailed and there is a lot of error/log messages, and also because there are new contributors (and reviewers) who're not aware of these.

You're right. However, we can add some related guides in the future.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ok, let me lowercase error/log message in this PR

pkg/logging/cri_logger.go Outdated Show resolved Hide resolved
@zhaojizhuang
Copy link
Contributor Author

updated @djdongjin

Copy link
Member

@djdongjin djdongjin left a comment

Choose a reason for hiding this comment

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

LGTM, thanks

@zhaojizhuang
Copy link
Contributor Author

/test

@zhaojizhuang
Copy link
Contributor Author

zhaojizhuang commented Feb 7, 2023

CI failed,retest it? @djdongjin

@djdongjin
Copy link
Member

djdongjin commented Feb 7, 2023

@zhaojizhuang sorry I'm a reviewer and don't have write permission to restart CI 😅. The PR will be merged by a committer who will restart the CI. You can try close & reopen the PR to force CI rerun.

@suyanhanx
Copy link
Contributor

You can try close & reopen the PR to force CI rerun.

This method scares me.

}

// ReadLogs read the container log and redirect into stdout and stderr.
// Note that containerID is only needed when following the log, or else
// just pass in empty string "".
func ReadLogs(ctx context.Context, opts *LogViewOptions, stdout, stderr io.Writer) error {
func ReadLogs(ctx context.Context, opts *LogViewOptions, stdout, stderr io.Writer, stopChannel chan os.Signal) error {
Copy link
Member

Choose a reason for hiding this comment

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

no need for context

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

@@ -85,7 +87,7 @@ func TestReadLogs(t *testing.T) {
t.Run(tc.name, func(t *testing.T) {
stdoutBuf := bytes.NewBuffer(nil)
stderrBuf := bytes.NewBuffer(nil)
err = ReadLogs(context.TODO(), &tc.logViewOptions, stdoutBuf, stderrBuf)
err = ReadLogs(context.TODO(), &tc.logViewOptions, stdoutBuf, stderrBuf, stopChan)
Copy link
Member

Choose a reason for hiding this comment

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

plz see above comment

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

Fixes: containerd#1956
Signed-off-by: zhaojizhuang <571130360@qq.com>
@zhaojizhuang
Copy link
Contributor Author

updated @fahedouch

@fahedouch fahedouch added this to the v1.3.0 (tentative) milestone Feb 8, 2023
Copy link
Member

@fahedouch fahedouch left a comment

Choose a reason for hiding this comment

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

Thanks

@fahedouch fahedouch merged commit a1a5a1e into containerd:main Feb 8, 2023
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.

nerdctl --namespace=k8s.io logs -f CRICONTAINER doesn't accept Ctrl-C
4 participants