Skip to content

Commit

Permalink
fix: polarismesh#672 优化日志 (polarismesh#735)
Browse files Browse the repository at this point in the history
* feat: 优化日志配置以及生成

* feat: 优化日志配置以及生成

* feat: 增加日志定时轮转备份

* feat: 增加日志定时轮转备份

* feat: 优化插件日志

* feat: 优化日志 polarismesh#672

* feat: 优化日志 polarismesh#672

* feat: polarismesh#672 优化日志

* fix: 优化单协程执行日志轮转Sync的逻辑 polarismesh#672

* fix: 修复ci测试相关错误 polarismesh#672

* feat: polarismesh#672 优化相关import分组

* feat: polarismesh#672 优化日志

* feat: #672优化日志

* fix: #672移除第三方插件日志

* fix: #672修改文件头license

* fix: #672移除plugin-platform日志相关
  • Loading branch information
hoErYu authored Oct 22, 2022
1 parent f15f6a2 commit ac7db94
Show file tree
Hide file tree
Showing 104 changed files with 756 additions and 814 deletions.
27 changes: 14 additions & 13 deletions apiserver/eurekaserver/eureka_suit_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,15 @@ import (
"github.com/polarismesh/polaris/common/utils"
"github.com/polarismesh/polaris/namespace"
"github.com/polarismesh/polaris/plugin"
"github.com/polarismesh/polaris/service"
"github.com/polarismesh/polaris/service/batch"
"github.com/polarismesh/polaris/service/healthcheck"
"github.com/polarismesh/polaris/store"
storemock "github.com/polarismesh/polaris/store/mock"

"github.com/polarismesh/polaris/testdata"

// 注册相关默认插件
_ "github.com/polarismesh/polaris/plugin/auth/defaultauth"
_ "github.com/polarismesh/polaris/plugin/cmdb/memory"
_ "github.com/polarismesh/polaris/plugin/discoverevent/local"
Expand All @@ -44,14 +53,6 @@ import (
_ "github.com/polarismesh/polaris/plugin/ratelimit/lrurate"
_ "github.com/polarismesh/polaris/plugin/ratelimit/token"
_ "github.com/polarismesh/polaris/plugin/statis/local"
"github.com/polarismesh/polaris/service"
"github.com/polarismesh/polaris/service/batch"
"github.com/polarismesh/polaris/service/healthcheck"
"github.com/polarismesh/polaris/store"
_ "github.com/polarismesh/polaris/store/boltdb"
storemock "github.com/polarismesh/polaris/store/mock"
_ "github.com/polarismesh/polaris/store/sqldb"
"github.com/polarismesh/polaris/testdata"
)

type Bootstrap struct {
Expand Down Expand Up @@ -94,11 +95,11 @@ func (d *EurekaTestSuit) initialize(t *testing.T, callback func(t *testing.T, s

_ = commonlog.Configure(d.cfg.Bootstrap.Logger)

commonlog.DefaultScope().SetOutputLevel(commonlog.ErrorLevel)
commonlog.NamingScope().SetOutputLevel(commonlog.ErrorLevel)
commonlog.CacheScope().SetOutputLevel(commonlog.ErrorLevel)
commonlog.StoreScope().SetOutputLevel(commonlog.ErrorLevel)
commonlog.AuthScope().SetOutputLevel(commonlog.ErrorLevel)
commonlog.GetScopeOrDefaultByName(commonlog.DefaultLoggerName).SetOutputLevel(commonlog.ErrorLevel)
commonlog.GetScopeOrDefaultByName(commonlog.NamingLoggerName).SetOutputLevel(commonlog.ErrorLevel)
commonlog.GetScopeOrDefaultByName(commonlog.ConfigLoggerName).SetOutputLevel(commonlog.ErrorLevel)
commonlog.GetScopeOrDefaultByName(commonlog.StoreLoggerName).SetOutputLevel(commonlog.ErrorLevel)
commonlog.GetScopeOrDefaultByName(commonlog.AuthLoggerName).SetOutputLevel(commonlog.ErrorLevel)

plugin.SetPluginConfig(&d.cfg.Plugin)

Expand Down
2 changes: 1 addition & 1 deletion apiserver/eurekaserver/log.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,4 @@ import (
commonlog "github.com/polarismesh/polaris/common/log"
)

var log = commonlog.NamingScope()
var log = commonlog.GetScopeOrDefaultByName(commonlog.NamingLoggerName)
2 changes: 1 addition & 1 deletion apiserver/grpcserver/config/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import (
)

var (
configLog = commonlog.ConfigScope()
configLog = commonlog.GetScopeOrDefaultByName(commonlog.ConfigLoggerName)
)

// ConfigGRPCServer 配置中心 GRPC API 服务器
Expand Down
2 changes: 1 addition & 1 deletion apiserver/grpcserver/discover/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ import (
)

var (
namingLog = commonlog.NamingScope()
namingLog = commonlog.GetScopeOrDefaultByName(commonlog.NamingLoggerName)

cacheTypes = map[string]struct{}{
apiv1.DiscoverResponse_INSTANCE.String(): {},
Expand Down
2 changes: 1 addition & 1 deletion apiserver/grpcserver/discover/v1/client_access.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ import (
)

var (
namingLog = commonlog.NamingScope()
namingLog = commonlog.GetScopeOrDefaultByName(commonlog.NamingLoggerName)
)

// ReportClient 客户端上报
Expand Down
2 changes: 1 addition & 1 deletion apiserver/grpcserver/discover/v2/client_access_v2.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import (
)

var (
namingLog = commonlog.NamingScope()
namingLog = commonlog.GetScopeOrDefaultByName(commonlog.NamingLoggerName)
)

// Discover 统一发现接口
Expand Down
6 changes: 3 additions & 3 deletions apiserver/httpserver/log.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import (
)

var (
log = commonlog.APIServerScope()
namingLog = commonlog.NamingScope()
configLog = commonlog.ConfigScope()
log = commonlog.GetScopeOrDefaultByName(commonlog.APIServerLoggerName)
namingLog = commonlog.GetScopeOrDefaultByName(commonlog.NamingLoggerName)
configLog = commonlog.GetScopeOrDefaultByName(commonlog.ConfigLoggerName)
)
6 changes: 3 additions & 3 deletions apiserver/httpserver/v1/log.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import (
)

var (
log = commonlog.APIServerScope()
namingLog = commonlog.NamingScope()
configLog = commonlog.ConfigScope()
log = commonlog.GetScopeOrDefaultByName(commonlog.APIServerLoggerName)
namingLog = commonlog.GetScopeOrDefaultByName(commonlog.NamingLoggerName)
configLog = commonlog.GetScopeOrDefaultByName(commonlog.ConfigLoggerName)
)
6 changes: 3 additions & 3 deletions apiserver/httpserver/v2/log.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import (
)

var (
log = commonlog.APIServerScope()
namingLog = commonlog.NamingScope()
configLog = commonlog.ConfigScope()
log = commonlog.GetScopeOrDefaultByName(commonlog.APIServerLoggerName)
namingLog = commonlog.GetScopeOrDefaultByName(commonlog.NamingLoggerName)
configLog = commonlog.GetScopeOrDefaultByName(commonlog.ConfigLoggerName)
)
2 changes: 1 addition & 1 deletion apiserver/l5pbserver/log.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,4 @@ import (
commonlog "github.com/polarismesh/polaris/common/log"
)

var log = commonlog.NamingScope()
var log = commonlog.GetScopeOrDefaultByName(commonlog.NamingLoggerName)
2 changes: 1 addition & 1 deletion apiserver/xdsserverv3/log.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,4 @@ import (
commonlog "github.com/polarismesh/polaris/common/log"
)

var log = commonlog.NamingScope()
var log = commonlog.GetScopeOrDefaultByName(commonlog.NamingLoggerName)
4 changes: 2 additions & 2 deletions apiserver/xdsserverv3/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ type XDSServer struct {
func (x *XDSServer) Initialize(ctx context.Context, option map[string]interface{},
api map[string]apiserver.APIConfig,
) error {
x.cache = cachev3.NewSnapshotCache(false, PolarisNodeHash{}, commonlog.XDSV3Scope())
x.cache = cachev3.NewSnapshotCache(false, PolarisNodeHash{}, commonlog.GetScopeOrDefaultByName(commonlog.XDSLoggerName))
x.registryInfo = make(map[string][]*ServiceInfo)
x.listenPort = uint32(option["listenPort"].(int))
x.listenIP = option["listenIP"].(string)
Expand Down Expand Up @@ -147,7 +147,7 @@ func (x *XDSServer) Initialize(ctx context.Context, option map[string]interface{
func (x *XDSServer) Run(errCh chan error) {
// 启动 grpc server
ctx := context.Background()
cb := &Callbacks{log: commonlog.XDSV3Scope()}
cb := &Callbacks{log: commonlog.GetScopeOrDefaultByName(commonlog.XDSLoggerName)}
srv := serverv3.NewServer(ctx, x.cache, cb)
var grpcOptions []grpc.ServerOption
grpcOptions = append(grpcOptions, grpc.MaxConcurrentStreams(1000))
Expand Down
5 changes: 2 additions & 3 deletions auth/defaultauth/auth_mgn.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import (

"github.com/polarismesh/polaris/auth"
"github.com/polarismesh/polaris/cache"
"github.com/polarismesh/polaris/common/log"
"github.com/polarismesh/polaris/plugin"
"github.com/polarismesh/polaris/store"
)
Expand Down Expand Up @@ -55,11 +54,11 @@ func (d *defaultAuthChecker) Initialize(options *auth.Config, cacheMgn *cache.Ca
// 获取存储层对象
s, err := store.GetStore()
if err != nil {
log.AuthScope().Errorf("[Auth][Server] can not get store, err: %s", err.Error())
log.Errorf("[Auth][Server] can not get store, err: %s", err.Error())
return errors.New("auth-checker can not get store")
}
if s == nil {
log.AuthScope().Errorf("[Auth][Server] store is null")
log.Errorf("[Auth][Server] store is null")
return errors.New("store is null")
}

Expand Down
23 changes: 11 additions & 12 deletions auth/defaultauth/auth_mgn_core.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ import (
"go.uber.org/zap"

api "github.com/polarismesh/polaris/common/api/v1"
"github.com/polarismesh/polaris/common/log"
"github.com/polarismesh/polaris/common/model"
"github.com/polarismesh/polaris/common/utils"
)
Expand Down Expand Up @@ -121,7 +120,7 @@ func (d *defaultAuthChecker) CheckPermission(authCtx *model.AcquireContext) (boo

strategies, err := d.findStrategies(operatorInfo)
if err != nil {
log.AuthScope().Error("[Auth][Checker] find strategies when check permission", utils.ZapRequestID(reqId),
log.Error("[Auth][Checker] find strategies when check permission", utils.ZapRequestID(reqId),
zap.Error(err), zap.Any("token", operatorInfo.String()))
return false, err
}
Expand All @@ -130,20 +129,20 @@ func (d *defaultAuthChecker) CheckPermission(authCtx *model.AcquireContext) (boo

noResourceNeedCheck := d.removeNoStrategyResources(authCtx)
if !noResourceNeedCheck && len(strategies) == 0 {
log.AuthScope().Error("[Auth][Checker]", utils.ZapRequestID(reqId),
log.Error("[Auth][Checker]", utils.ZapRequestID(reqId),
zap.String("msg", "need check resource is not empty, but strategies is empty"))
return false, errors.New("no permission")
}

log.AuthScope().Info("[Auth][Checker] check permission args", zap.Any("resources", authCtx.GetAccessResources()),
log.Info("[Auth][Checker] check permission args", zap.Any("resources", authCtx.GetAccessResources()),
zap.Any("strategies", strategies))

ok, err := d.authPlugin.CheckPermission(authCtx, strategies)
if err != nil {
log.AuthScope().Error("[Auth][Checker] check permission args", utils.ZapRequestID(reqId),
log.Error("[Auth][Checker] check permission args", utils.ZapRequestID(reqId),
zap.String("method", authCtx.GetMethod()), zap.Any("resources", authCtx.GetAccessResources()),
zap.Any("strategies", strategies))
log.AuthScope().Error("[Auth][Checker] check permission when request arrive", utils.ZapRequestID(reqId),
log.Error("[Auth][Checker] check permission when request arrive", utils.ZapRequestID(reqId),
zap.Error(err))
}

Expand Down Expand Up @@ -180,13 +179,13 @@ func (d *defaultAuthChecker) VerifyCredential(authCtx *model.AcquireContext) err
checkErr := func() error {
operator, err := d.decodeToken(authCtx.GetToken())
if err != nil {
log.AuthScope().Error("[Auth][Checker] decode token", zap.Error(err))
log.Error("[Auth][Checker] decode token", zap.Error(err))
return model.ErrorTokenInvalid
}

ownerId, isOwner, err := d.checkToken(&operator)
if err != nil {
log.AuthScope().Errorf("[Auth][Checker] check token err : %s", errors.WithStack(err).Error())
log.Errorf("[Auth][Checker] check token err : %s", errors.WithStack(err).Error())
return err
}

Expand All @@ -204,7 +203,7 @@ func (d *defaultAuthChecker) VerifyCredential(authCtx *model.AcquireContext) err
authCtx.SetRequestContext(ctx)
d.parseOperatorInfo(operator, authCtx)
if operator.Disable {
log.AuthScope().Warn("[Auth][Checker] token already disabled", utils.ZapRequestID(reqId),
log.Warn("[Auth][Checker] token already disabled", utils.ZapRequestID(reqId),
zap.Any("token", operator.String()))
}
return nil
Expand All @@ -214,7 +213,7 @@ func (d *defaultAuthChecker) VerifyCredential(authCtx *model.AcquireContext) err
if !canDowngradeAnonymous(authCtx, checkErr) {
return checkErr
}
log.AuthScope().Warn("[Auth][Checker] parse operator info, downgrade to anonymous", utils.ZapRequestID(reqId),
log.Warn("[Auth][Checker] parse operator info, downgrade to anonymous", utils.ZapRequestID(reqId),
zap.Error(checkErr))
// 操作者信息解析失败,降级为匿名用户
authCtx.SetAttachment(model.TokenDetailInfoKey, newAnonymous())
Expand Down Expand Up @@ -425,13 +424,13 @@ func (d *defaultAuthChecker) removeNoStrategyResources(authCtx *model.AcquireCon
newAccessRes[api.ResourceType_ConfigGroups] = newCfgRes
}

log.AuthScope().Info("[Auth][Checker] remove no link strategy final result", utils.ZapRequestID(reqId),
log.Info("[Auth][Checker] remove no link strategy final result", utils.ZapRequestID(reqId),
zap.Any("resource", newAccessRes))

authCtx.SetAccessResources(newAccessRes)
noResourceNeedCheck := authCtx.IsAccessResourceEmpty()
if noResourceNeedCheck {
log.AuthScope().Debug("[Auth][Checker]", utils.ZapRequestID(reqId),
log.Debug("[Auth][Checker]", utils.ZapRequestID(reqId),
zap.String("msg", "need check permission resource is empty"))
}

Expand Down
Loading

0 comments on commit ac7db94

Please sign in to comment.