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

'unable to get field from token' spam message #204

Closed
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
7 changes: 6 additions & 1 deletion logging/gateway_interceptor.go
Expand Up @@ -19,6 +19,10 @@ import (
"github.com/infobloxopen/atlas-app-toolkit/requestid"
)

const (
valueUndefined = "undefined"
)

type gwLogCfg struct {
dynamicLogLvl bool
noRequestID bool
Expand Down Expand Up @@ -139,7 +143,8 @@ func GatewayLoggingInterceptor(logger *logrus.Logger, opts ...GWLogOption) grpc.
if accountID, err := auth.GetAccountID(metadata.NewIncomingContext(ctx, md), cfg.acctIDKeyfunc); err == nil {
fields[auth.MultiTenancyField] = accountID
} else {
logger.Error(err)
logger.Info(err)
fields[auth.MultiTenancyField] = valueUndefined
}
}

Expand Down
13 changes: 6 additions & 7 deletions logging/interceptor.go
Expand Up @@ -170,9 +170,8 @@ func setClientInterceptorFields(ctx context.Context, fields logrus.Fields, logge

err = addAccountIDField(ctx, fields)
if err != nil {
logger.Warn(err)
logger.Info(err)
}

setInterceptorFields(ctx, fields, logger, options)
}

Expand Down Expand Up @@ -206,14 +205,14 @@ func addRequestIDField(ctx context.Context, fields logrus.Fields) error {
}

func addAccountIDField(ctx context.Context, fields logrus.Fields) error {
accountID, err := auth.GetAccountID(ctx, nil)
if err != nil {
if accountID, err := auth.GetAccountID(ctx, nil); err == nil {
fields[DefaultAccountIDKey] = accountID
} else {
fields[DefaultAccountIDKey] = valueUndefined
return fmt.Errorf("Unable to get %q from context", DefaultAccountIDKey)
}

fields[DefaultAccountIDKey] = accountID

return err
return nil
}

func addCustomField(ctx context.Context, fields logrus.Fields, customField string) error {
Expand Down
4 changes: 3 additions & 1 deletion logging/interceptor_test.go
Expand Up @@ -396,9 +396,11 @@ func TestAddAccountIDField(t *testing.T) {
func TestAddAccountID_Failed(t *testing.T) {
ctx := context.Background()

err := addAccountIDField(ctx, logrus.Fields{})
result := logrus.Fields{}
err := addAccountIDField(ctx, result)
assert.Error(t, err)
assert.Equal(t, fmt.Sprintf("Unable to get %q from context", DefaultAccountIDKey), err.Error())
assert.Equal(t, valueUndefined, result[DefaultAccountIDKey])
}

func TestAddCustomField(t *testing.T) {
Expand Down