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

Zap logger in CNI does not log the store lock related logs #2148

Closed
wants to merge 2 commits into from

Conversation

paulyufan2
Copy link
Contributor

@paulyufan2 paulyufan2 commented Aug 15, 2023

Reason for Change:

Some of the log messages that are related to Store packages such as "Acquiring lock", "release lock" or the related error msgs within the store package are not getting logged in CNI ZAP

Issue Fixed:

Example Linux Logs:
2023/08/15 20:46:09 [3142512] Released process lock
2023/08/15 20:46:38 [3143037] Acquiring process lock
2023/08/15 20:46:38 [3143037] Acquired process lock with timeout value of 10s
2023/08/15 20:46:38 [3143052] Released process lock
{"level":"info","ts":"2023-08-15T21:19:28.289Z","msg":"Acquiring process lock","pid":3184054}
{"level":"info","ts":"2023-08-15T21:19:28.289Z","msg":"Acquired process lock with value of ","pid":3184054,"timeout":10}

Example Windows Logs:
{"level":"info","ts":"2023-08-15T21:12:03.248Z","msg":"Acquiring process lock","pid":18144}
{"level":"info","ts":"2023-08-15T21:12:03.735Z","msg":"Acquired process lock with value of ","pid":17908,"timeout":60}
{"level":"info","ts":"2023-08-15T21:12:04.051Z","msg":"Released process lock","pid":17908}

Requirements:

Notes:

@paulyufan2 paulyufan2 requested a review from a team as a code owner August 15, 2023 21:08
@paulyufan2 paulyufan2 force-pushed the zaplocklog branch 2 times, most recently from b6e1d49 to 805c7b7 Compare August 16, 2023 15:01
@@ -197,7 +198,7 @@ func (kvs *jsonFileStore) Lock(timeout time.Duration) error {
return errors.Wrap(err, "processLock acquire error")
}

log.Printf("Acquired process lock with timeout value of %v ", timeout)
log.Logger.Info("Acquired process lock with value of ", zap.Duration("timeout", timeout))
Copy link
Member

Choose a reason for hiding this comment

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

can it be like previous message "Acquired process lock with timeout value of"

Copy link
Contributor

Choose a reason for hiding this comment

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

The message should just be Acquired process lock. The rest of the context is provided by the zap parameter.

@tamilmani1989 tamilmani1989 added the cni Related to CNI. label Aug 16, 2023
@@ -82,7 +83,7 @@ func (kvs *jsonFileStore) Read(key string, value interface{}) error {
}

if len(b) == 0 {
log.Printf("Unable to read file %s, was empty", kvs.fileName)
log.Logger.Info("Unable to read was empty", zap.String("file", kvs.fileName))
Copy link
Contributor

Choose a reason for hiding this comment

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

  • This sentence reads a bit odd. Should just be File is empty.
  • Should be logged as an error. Does Logger have an Error method?

@@ -222,7 +223,7 @@ func (kvs *jsonFileStore) GetModificationTime() (time.Time, error) {

info, err := os.Stat(kvs.fileName)
if err != nil {
log.Printf("os.stat() for file %v failed: %v", kvs.fileName, err)
log.Logger.Error("os.stat() for", zap.String("file", kvs.fileName), zap.Error(err))
Copy link
Contributor

Choose a reason for hiding this comment

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

Message should be Could not get file info.

@@ -232,7 +233,7 @@ func (kvs *jsonFileStore) GetModificationTime() (time.Time, error) {
func (kvs *jsonFileStore) Remove() {
kvs.Mutex.Lock()
if err := os.Remove(kvs.fileName); err != nil {
log.Errorf("could not remove file %s. Error: %v", kvs.fileName, err)
log.Logger.Error("could not remove", zap.String("file", kvs.fileName), zap.Error(err))
Copy link
Contributor

Choose a reason for hiding this comment

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

Could not remove file

@paulyufan2
Copy link
Contributor Author

use this PR #2231 to track this issue

@paulyufan2 paulyufan2 closed this Sep 20, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cni Related to CNI.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants