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

kvstore: Fix event watcher serialization #14101

Merged

Conversation

joestringer
Copy link
Member

When using the watcher in log messages with JSON-based logging, logrus
would give up on trying to generate the log message and print this to
the logs instead:

Failed to obtain reader, failed to marshal fields to JSON, json:
unsupported type: kvstore.EventChan

Fix it by fixing the JSON serialization tags to the structure to avoid
serializing fields that don't make sense to be serialized, and to export
the fields that do make sense to be serialized.

Manually tested by applying this diff:

diff --git a/pkg/kvstore/base_test.go b/pkg/kvstore/base_test.go
index e9ee7da296bf..eb5a3548039b 100644
--- a/pkg/kvstore/base_test.go
+++ b/pkg/kvstore/base_test.go
@@ -292,3 +292,10 @@ func (s *BaseTests) TestListAndWatch(c *C) {

        w.Stop()
 }
+
+func (s *BaseTests) TestFoo(c *C) {
+       w := ListAndWatch(context.TODO(), "testWatcher2", "foo2/", 100)
+       c.Assert(c, Not(IsNil))
+
+       log.WithField(fieldWatcher, w).Fatal("Stopped watcher")
+}
diff --git a/pkg/logging/logging.go b/pkg/logging/logging.go
index 9989e8db0280..6a651c0c87f4 100644
--- a/pkg/logging/logging.go
+++ b/pkg/logging/logging.go
@@ -50,7 +50,7 @@ const (

        // DefaultLogFormat is the string representation of the default logrus.Formatter
        // we want to use (possible values: text or json)
-       DefaultLogFormat LogFormat = LogFormatText
+       DefaultLogFormat LogFormat = LogFormatJSON
 )

 var (

Fixes: #14028

When using the watcher in log messages with JSON-based logging, logrus
would give up on trying to generate the log message and print this to
the logs instead:

    Failed to obtain reader, failed to marshal fields to JSON, json:
    unsupported type: kvstore.EventChan

Fix it by fixing the JSON serialization tags to the structure to avoid
serializing fields that don't make sense to be serialized, and to export
the fields that do make sense to be serialized.

Manually tested by applying this diff:

    diff --git a/pkg/kvstore/base_test.go b/pkg/kvstore/base_test.go
    index e9ee7da296bf..eb5a3548039b 100644
    --- a/pkg/kvstore/base_test.go
    +++ b/pkg/kvstore/base_test.go
    @@ -292,3 +292,10 @@ func (s *BaseTests) TestListAndWatch(c *C) {

            w.Stop()
     }
    +
    +func (s *BaseTests) TestFoo(c *C) {
    +       w := ListAndWatch(context.TODO(), "testWatcher2", "foo2/", 100)
    +       c.Assert(c, Not(IsNil))
    +
    +       log.WithField(fieldWatcher, w).Fatal("Stopped watcher")
    +}
    diff --git a/pkg/logging/logging.go b/pkg/logging/logging.go
    index 9989e8db0280..6a651c0c87f4 100644
    --- a/pkg/logging/logging.go
    +++ b/pkg/logging/logging.go
    @@ -50,7 +50,7 @@ const (

            // DefaultLogFormat is the string representation of the default logrus.Formatter
            // we want to use (possible values: text or json)
    -       DefaultLogFormat LogFormat = LogFormatText
    +       DefaultLogFormat LogFormat = LogFormatJSON
     )

     var (

Fixes: cilium#14028

Signed-off-by: Joe Stringer <joe@cilium.io>
@joestringer joestringer added the release-note/misc This PR makes changes that have no direct user impact. label Nov 20, 2020
@joestringer joestringer requested a review from a team as a code owner November 20, 2020 06:07
@maintainer-s-little-helper maintainer-s-little-helper bot added this to In progress in 1.10.0 Nov 20, 2020
Copy link
Member

@fristonio fristonio left a comment

Choose a reason for hiding this comment

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

LGTM 🥳

@nathanjsweet
Copy link
Member

test-me-please

@aanm
Copy link
Member

aanm commented Nov 23, 2020

retest-gke

EDIT: Provisioning failure.

@joestringer
Copy link
Member Author

joestringer commented Nov 24, 2020

retest-gke

EDIT: Provisioning failure.

@joestringer
Copy link
Member Author

I don't see a way that the GKE build could fail while the others are all successful, so given the problems with running GKE CI runs right now I think it's reasonable to bypass that check and merge.

@joestringer joestringer added the ready-to-merge This PR has passed all tests and received consensus from code owners to merge. label Nov 25, 2020
@errordeveloper
Copy link
Contributor

retest-gke

@errordeveloper
Copy link
Contributor

GKE Failed again, and it definitely looks unrelated.

===================== Exiting AfterFailed =====================
15:24:30 STEP: Running AfterEach for block EntireTestsuite K8sServicesTest
FAIL: terminating containers are not deleted after timeout
Expected
    <*errors.errorString | 0xc0004bdd40>: {
        s: "Pods are still not deleted after a timeout: 4m0s timeout expired",
    }
to be nil
15:28:30 STEP: Running AfterEach for block EntireTestsuite

@errordeveloper errordeveloper merged commit 679f913 into cilium:master Nov 25, 2020
@joestringer joestringer deleted the submit/fix-watcher-marshal branch November 25, 2020 21:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ready-to-merge This PR has passed all tests and received consensus from code owners to merge. release-note/misc This PR makes changes that have no direct user impact.
Projects
No open projects
Development

Successfully merging this pull request may close these issues.

JSON based logging not applied everywhere
6 participants