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

databroker: use contextual logging for errors, use original record type for encryption #3096

Merged
merged 2 commits into from
Mar 4, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 7 additions & 7 deletions internal/log/log.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,13 @@ func Warn(ctx context.Context) *zerolog.Event {
return contextLogger(ctx).Warn()
}

// Error starts a new message with error level.
//
// You must call Msg on the returned event in order to send the event.
func Error(ctx context.Context) *zerolog.Event {
return contextLogger(ctx).Error()
}

func contextLogger(ctx context.Context) *zerolog.Logger {
global := Logger()
if global.GetLevel() == zerolog.Disabled {
Expand All @@ -133,13 +140,6 @@ func WithContext(ctx context.Context, update func(c zerolog.Context) zerolog.Con
return l.WithContext(ctx)
}

// Error starts a new message with error level.
//
// You must call Msg on the returned event in order to send the event.
func Error(ctx context.Context) *zerolog.Event {
return Logger().Error()
}

// Fatal starts a new message with fatal level. The os.Exit(1) function
// is called by the Msg method.
//
Expand Down
2 changes: 1 addition & 1 deletion pkg/storage/encrypted.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ func (e *encryptedBackend) decryptRecord(in *databroker.Record) (out *databroker
// Create a new record so that we don't re-use any internal state
return &databroker.Record{
Version: in.Version,
Type: data.TypeUrl,
Type: in.Type,
Id: in.Id,
Data: data,
ModifiedAt: in.ModifiedAt,
Expand Down
4 changes: 2 additions & 2 deletions pkg/storage/encrypted_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ func TestEncryptedBackend(t *testing.T) {
}
assert.Equal(t, any.TypeUrl, record.Data.TypeUrl, "type should be preserved")
assert.Equal(t, any.Value, record.Data.Value, "value should be preserved")
assert.Equal(t, any.TypeUrl, record.Type, "record type should be preserved")
assert.NotEqual(t, any.TypeUrl, record.Type, "record type should be preserved")

records, _, err := e.GetAll(ctx)
if !assert.NoError(t, err) {
Expand All @@ -90,6 +90,6 @@ func TestEncryptedBackend(t *testing.T) {
if assert.Len(t, records, 1) {
assert.Equal(t, any.TypeUrl, records[0].Data.TypeUrl, "type should be preserved")
assert.Equal(t, any.Value, records[0].Data.Value, "value should be preserved")
assert.Equal(t, any.TypeUrl, records[0].Type, "record type should be preserved")
assert.NotEqual(t, any.TypeUrl, records[0].Type, "record type should be preserved")
}
}