-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
kvstore: Fix event watcher serialization #14101
Conversation
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>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM 🥳
test-me-please |
retest-gke EDIT: Provisioning failure. |
retest-gke EDIT: Provisioning failure. |
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. |
retest-gke |
GKE Failed again, and it definitely looks unrelated.
|
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:
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:
Fixes: #14028