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

Feature/zap logging #185

Merged
merged 9 commits into from
Jun 4, 2021
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions argus.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,12 @@ prometheus:
constLabels:
development: "true"

log:
file: stdout
level: DEBUG
logging:
level: debug
development: true
encoderConfig:
messageKey: msg
levelKey: level

health:
disableLogging: false
Expand Down
14 changes: 6 additions & 8 deletions auth/capabilityCheck.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,10 @@ import (
"fmt"
"regexp"

"github.com/go-kit/kit/log/level"
"github.com/xmidt-org/bascule"
"github.com/xmidt-org/themis/xlog"
"github.com/xmidt-org/webpa-common/basculechecks"
"go.uber.org/fx"
"go.uber.org/zap"
)

type capabilityValidatorConfig struct {
Expand All @@ -31,18 +30,18 @@ type primaryCapabilityValidatorIn struct {

func newPrimaryCapabilityValidator(in primaryCapabilityValidatorIn) (bascule.Validator, error) {
if in.Profile == nil {
in.Logger.Log(level.Key(), level.WarnValue(), xlog.MessageKey(), "undefined profile. CapabilityCheck disabled.", "server", "primary")
in.Logger.Warn("undefined profile. CapabilityCheck disabled")
return nil, nil
}

config := in.Profile.CapabilityCheck
if config == nil {
in.Logger.Log(level.Key(), level.WarnValue(), xlog.MessageKey(), "config not provided. CapabilityCheck disabled.", "server", "primary")
in.Logger.Warn("config not provided. CapabilityCheck disabled")
return nil, nil
}

if config.Type != "enforce" && config.Type != "monitor" {
in.Logger.Log(level.Key(), level.WarnValue(), xlog.MessageKey(), "unsupported capability check type. CapabilityCheck disabled.", "type", config.Type, "server", "primary")
in.Logger.Warn("unsupported capability check type. CapabilityCheck disabled", zap.String("type", config.Type))
return nil, nil
}

Expand All @@ -55,7 +54,7 @@ func newPrimaryCapabilityValidator(in primaryCapabilityValidatorIn) (bascule.Val
for _, e := range config.EndpointBuckets {
r, err := regexp.Compile(e)
if err != nil {
in.Logger.Log(level.Key(), level.WarnValue(), xlog.MessageKey(), "failed to compile regular expression", "regex", e, xlog.ErrorKey(), err.Error(), "server", "primary")
in.Logger.Warn("failed to compile regular expression", zap.String("regex", e))
continue
}
endpoints = append(endpoints, r)
Expand All @@ -66,8 +65,7 @@ func newPrimaryCapabilityValidator(in primaryCapabilityValidatorIn) (bascule.Val
Measures: in.Measures,
Endpoints: endpoints,
}
in.Logger.Log(level.Key(), level.DebugValue(), xlog.MessageKey(), "building auth capability", "server", "primary", "type", config.Type)

in.Logger.Info("building auth capability", zap.String("type", config.Type))
return m.CreateValidator(config.Type == "enforce"), nil
}

Expand Down
17 changes: 7 additions & 10 deletions auth/constructor.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,6 @@ package auth
import (
"reflect"

"github.com/xmidt-org/themis/xlog"

"github.com/go-kit/kit/log/level"
"github.com/justinas/alice"
"github.com/xmidt-org/bascule"
"github.com/xmidt-org/bascule/basculehttp"
Expand Down Expand Up @@ -56,10 +53,10 @@ func providePrimaryBasculeConstructorOptions(apiBase string) fx.Option {
Group: primaryBasculeCOptionsName,
Target: func(in primaryBearerTokenFactoryIn) basculehttp.COption {
if in.Resolver == nil {
in.Logger.Log(level.Key(), level.WarnValue(), xlog.MessageKey(), "returning nil bearer token factory option as resolver was not defined", "server", "primary")
in.Logger.Warn("returning nil bearer token factory option as resolver was not defined")
return nil
}
in.Logger.Log(level.Key(), level.DebugValue(), xlog.MessageKey(), "building bearer token factory option", "server", "primary")
in.Logger.Debug("building bearer token factory option")
return basculehttp.WithTokenFactory("Bearer", accessLevelBearerTokenFactory{
DefaultKeyID: in.DefaultKeyID,
Resolver: in.Resolver,
Expand All @@ -73,14 +70,14 @@ func providePrimaryBasculeConstructorOptions(apiBase string) fx.Option {
Group: primaryBasculeCOptionsName,
Target: func(in primaryProfileIn) (basculehttp.COption, error) {
if in.Profile == nil || len(in.Profile.Basic) < 1 {
in.Logger.Log(level.Key(), level.WarnValue(), xlog.MessageKey(), "returning nil basic token factory option as config was not provided", "server", "primary")
in.Logger.Warn("returning nil basic token factory option as config was not provided")
return nil, nil
}
basicTokenFactory, err := basculehttp.NewBasicTokenFactoryFromList(in.Profile.Basic)
if err != nil {
return nil, err
}
in.Logger.Log(level.Key(), level.DebugValue(), xlog.MessageKey(), "building basic token factory option", "server", "primary")
in.Logger.Debug("building basic token factory option")
return basculehttp.WithTokenFactory("Basic", basicTokenFactory), nil
},
},
Expand Down Expand Up @@ -110,7 +107,7 @@ func providePrimaryBasculeConstructor(apiBase string) fx.Option {
fx.Annotated{
Name: "primary_alice_constructor",
Target: func(in primaryCOptionsIn) alice.Constructor {
in.Logger.Log(level.Key(), level.DebugValue(), xlog.MessageKey(), "building alice constructor from bascule constructor options", "server", "primary")
in.Logger.Debug("building alice constructor from bascule constructor options")
var filteredOptions []basculehttp.COption
for _, option := range in.Options {
if option == nil || reflect.ValueOf(option).IsNil() {
Expand All @@ -136,10 +133,10 @@ func providePrimaryTokenFactoryInput() fx.Option {
Name: "primary_bearer_key_resolver",
Target: func(in primaryProfileIn) (key.Resolver, error) {
if anyNil(in.Profile, in.Profile.Bearer) {
in.Logger.Log(level.Key(), level.WarnValue(), xlog.MessageKey(), "returning nil bearer key resolver as config wasn't provided", "server", "primary")
in.Logger.Warn("returning nil bearer key resolver as config wasn't provided")
return nil, nil
}
in.Logger.Log(level.Key(), level.DebugValue(), xlog.MessageKey(), "building bearer key resolver option", "server", "primary")
in.Logger.Debug("building bearer key resolver option")
return in.Profile.Bearer.Keys.NewResolver()
},
},
Expand Down
6 changes: 2 additions & 4 deletions auth/enforcer.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
package auth

import (
"github.com/go-kit/kit/log/level"
"github.com/justinas/alice"
"github.com/xmidt-org/bascule"
bchecks "github.com/xmidt-org/bascule/basculechecks"
"github.com/xmidt-org/bascule/basculehttp"
"github.com/xmidt-org/themis/xlog"
"github.com/xmidt-org/webpa-common/basculechecks"
"go.uber.org/fx"
)
Expand All @@ -31,7 +29,7 @@ func providePrimaryBasculeEnforcerOptions() fx.Option {
fx.Annotated{
Group: "primary_bascule_enforcer_options",
Target: func(in primaryBearerValidatorsIn) basculehttp.EOption {
in.Logger.Log(level.Key(), level.DebugValue(), xlog.MessageKey(), "building bearer rules option", "server", "primary")
in.Logger.Debug("building bearer rules option")
var validators = []bascule.Validator{in.Principal, in.Type}
if in.Capability != nil {
validators = append(validators, in.Capability)
Expand Down Expand Up @@ -74,7 +72,7 @@ func providePrimaryBasculeEnforcer() fx.Option {
fx.Annotated{
Name: "primary_alice_enforcer",
Target: func(in primaryEOptionsIn) alice.Constructor {
in.Logger.Log(level.Key(), level.DebugValue(), xlog.MessageKey(), "building alice enforcer", "server", "primary")
in.Logger.Debug("building alice enforcer")
return basculehttp.NewEnforcer(in.Options...)
},
},
Expand Down
18 changes: 7 additions & 11 deletions auth/profiles.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,11 @@ import (
"errors"
"fmt"

"github.com/go-kit/kit/log"
"github.com/go-kit/kit/log/level"
"github.com/xmidt-org/bascule"
"github.com/xmidt-org/bascule/key"
"github.com/xmidt-org/themis/config"
"github.com/xmidt-org/themis/xlog"
"go.uber.org/fx"
"go.uber.org/zap"
)

var (
Expand All @@ -25,8 +23,7 @@ var (
type LoggerIn struct {
fx.In

// Logger is the required go-kit logger that will receive logging output.
Logger log.Logger
Logger *zap.Logger
}

type profilesFactoryIn struct {
Expand Down Expand Up @@ -81,15 +78,14 @@ func (p ProfilesUnmarshaler) Unmarshal(configKey string, supportedServers ...str
servers[supportedServer] = true
}
return func(in profilesFactoryIn) (map[string]*profile, error) {
in.Logger.Log(level.Key(), level.DebugValue(), xlog.MessageKey(), "unmarshaling bascule profiles")

in.Logger.Debug("unmarshaling bascule profiles")
var sourceProfiles []profile
if err := in.Unmarshaller.UnmarshalKey(configKey, &sourceProfiles); err != nil {
return nil, fmt.Errorf("failed to unmarshal bascule profiles from config: %w", err)
}

if len(sourceProfiles) < 1 {
in.Logger.Log(level.Key(), level.InfoValue(), xlog.MessageKey(), "No bascule profiles configured.")
in.Logger.Info("no bascule profiles configured")
return nil, nil
}

Expand All @@ -101,12 +97,12 @@ func (p ProfilesUnmarshaler) Unmarshal(configKey string, supportedServers ...str

for _, targetServer := range sourceProfile.TargetServers {
if !servers[targetServer] {
in.Logger.Log(level.Key(), level.ErrorValue(), xlog.MessageKey(), "Bascule profile targetServer does not exist.", "targetServer", targetServer)
in.Logger.Error("Bascule profile targetServer does not exist.", zap.String("targetServer", targetServer))
return nil, ErrUnsupportedTargetServer
}

if _, ok := profiles[targetServer]; ok {
in.Logger.Log(level.Key(), level.InfoValue(), xlog.MessageKey(), "A previous Bascule profile was used for this server. Skipping.", "targetServer", targetServer)
in.Logger.Info("A previous Bascule profile was used for this server. Skipping.", zap.String("targetServer", targetServer))
continue
}
profiles[targetServer] = &sourceProfile
Expand All @@ -129,7 +125,7 @@ type profileFactory struct {
}

func (p profileFactory) new(in profilesIn) *profile {
in.Logger.Log(level.Key(), level.DebugValue(), xlog.MessageKey(), "returning profile", "server", p.serverName)
in.Logger.Debug("returning profile", zap.String("server", p.serverName))
return in.Profiles[p.serverName]
}

Expand Down
7 changes: 5 additions & 2 deletions deploy/packaging/argus_spruce.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,12 @@ prometheus:
defaultNamespace: xmidt
defaultSubsystem: argus

log:
file: stdout
logging:
level: (( grab $LOG_LEVEL || "INFO" ))
development: (( grab $LOG_DEVELOPMENT || false ))
encoderConfig:
messageKey: msg
levelKey: level

health:
disableLogging: false
Expand Down
3 changes: 3 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,13 @@ require (
github.com/spf13/pflag v1.0.5
github.com/spf13/viper v1.7.1
github.com/stretchr/testify v1.7.0
github.com/xmidt-org/arrange v0.1.9
github.com/xmidt-org/bascule v0.9.1-0.20210506212507-4df8762472bc
github.com/xmidt-org/candlelight v0.0.5
github.com/xmidt-org/httpaux v0.2.1
github.com/xmidt-org/sallust v0.1.5
github.com/xmidt-org/themis v0.4.7
github.com/xmidt-org/webpa-common v1.11.7
go.uber.org/fx v1.13.1
go.uber.org/zap v1.16.0
)
6 changes: 6 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -724,6 +724,8 @@ github.com/xmidt-org/httpaux v0.1.3 h1:RiA4pCwlZfu6a3CBzbvJy3F+5no1ou2UB2XLmNxzz
github.com/xmidt-org/httpaux v0.1.3/go.mod h1:mviIlg5fHGb3lAv3l0sbiwVG/q9rqvXaudEYxVrzXdE=
github.com/xmidt-org/httpaux v0.2.1 h1:SFK+Bab5c6r70VxMfJcDR49aBHIUs0uQJruC+nMpAcg=
github.com/xmidt-org/httpaux v0.2.1/go.mod h1:mviIlg5fHGb3lAv3l0sbiwVG/q9rqvXaudEYxVrzXdE=
github.com/xmidt-org/sallust v0.1.5 h1:yf95DXZUYnS+Td3w+jV3oO7XmhMbViMYK0A/WVM4QYo=
github.com/xmidt-org/sallust v0.1.5/go.mod h1:azcKBypudADIeZ3Em8zGjVq3yQ7n4ueSvM/degHMIxo=
github.com/xmidt-org/themis v0.4.4 h1:KewitRxStW1xOehDBi0YyGZyRv3PjFdYUEDvQFf1Nmk=
github.com/xmidt-org/themis v0.4.4/go.mod h1:0qRYFvKdrQhwjxH/1nAiTgBGT4cegJR76gfEYF5P7so=
github.com/xmidt-org/themis v0.4.7 h1:QAbutfysHG/UhVNzPAvWsEQIdZY0oNz9KYIkAaK7aus=
Expand Down Expand Up @@ -827,7 +829,10 @@ go.uber.org/multierr v1.6.0/go.mod h1:cdWPpRnG4AhwMwsgIHip0KRBQjJy5kYEpYjJxpXp9i
go.uber.org/tools v0.0.0-20190618225709-2cfd321de3ee h1:0mgffUl7nfd+FpvXMVz4IDEaUSmT1ysygQC7qYo7sG4=
go.uber.org/tools v0.0.0-20190618225709-2cfd321de3ee/go.mod h1:vJERXedbb3MVM5f9Ejo0C68/HhF8uaILCdgjnY+goOA=
go.uber.org/zap v1.10.0/go.mod h1:vwi/ZaCAaUcBkycHslxD9B2zi4UTXhF60s6SWpuDF0Q=
go.uber.org/zap v1.13.0 h1:nR6NoDBgAf67s68NhaXbsojM+2gxp3S1hWkHDl27pVU=
go.uber.org/zap v1.13.0/go.mod h1:zwrFLgMcdUuIBviXEYEH1YKNaOBnKXsx2IPda5bBwHM=
go.uber.org/zap v1.16.0 h1:uFRZXykJGK9lLY4HtgSw44DnIcAM+kRBP7x5m+NpAOM=
go.uber.org/zap v1.16.0/go.mod h1:MA8QOfq0BHJwdXa996Y4dYkAqRKB8/1K1QMMZVaNZjQ=
golang.org/x/crypto v0.0.0-20180904163835-0709b304e793/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
golang.org/x/crypto v0.0.0-20181029021203-45a5f77698d3/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
Expand Down Expand Up @@ -1068,6 +1073,7 @@ golang.org/x/tools v0.0.0-20191210221141-98df12377212/go.mod h1:b+2E5dAYhXwXZwtn
golang.org/x/tools v0.0.0-20191216173652-a0e659d51361/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28=
golang.org/x/tools v0.0.0-20191227053925-7b8e75db28f4/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28=
golang.org/x/tools v0.0.0-20200103221440-774c71fcf114/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28=
golang.org/x/tools v0.0.0-20200108203644-89082a384178/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28=
golang.org/x/tools v0.0.0-20200117161641-43d50277825c/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28=
golang.org/x/tools v0.0.0-20200122220014-bf1340f18c4a/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28=
golang.org/x/tools v0.0.0-20200130002326-2f3ba24bd6e7/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28=
Expand Down
Loading