Skip to content

Commit

Permalink
refactor:添加日志打印增强问题定位
Browse files Browse the repository at this point in the history
  • Loading branch information
chuntaojun authored Dec 26, 2023
1 parent b8c406a commit 07a2f60
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 15 deletions.
10 changes: 1 addition & 9 deletions common/log/type.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@ package log

// logger type
const (
// NamingLoggerName sync logger name, can use FindScope function to get the logger
SyncLoggerName = "sync"
// ConfigLoggerName config logger name, can use FindScope function to get the logger
InjectLoggerName = "inject"
// SyncNamingLoggerName naming sync logger name, can use FindScope function to get the logger
Expand All @@ -32,7 +30,6 @@ const (
)

var (
syncScope = RegisterScope(SyncLoggerName, "sync logging messages.", 0)
injectScope = RegisterScope(InjectLoggerName, "pod inject logging messages.", 0)
syncNamingScope = RegisterScope(SyncNamingLoggerName, "naming sync logging messages.", 0)
syncConfigScope = RegisterScope(SyncConfigLoggerName, "config sync logging messages.", 0)
Expand All @@ -41,7 +38,7 @@ var (
)

func allLoggerTypes() []string {
return []string{SyncLoggerName, SyncNamingLoggerName, SyncConfigLoggerName,
return []string{SyncNamingLoggerName, SyncConfigLoggerName,
SyncConfigMapLoggerName, InjectLoggerName, DefaultLoggerName}
}

Expand All @@ -50,11 +47,6 @@ func DefaultScope() *Scope {
return defaultScope
}

// SyncScope naming logging scope handler
func SyncScope() *Scope {
return syncScope
}

// SyncNamingScope naming logging scope handler
func SyncNamingScope() *Scope {
return syncNamingScope
Expand Down
12 changes: 6 additions & 6 deletions pkg/controller/configmap.go
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,6 @@ func (p *PolarisController) watchPolarisConfig() error {

ctx, cancel := context.WithCancel(context.Background())

//
watcher := &PolarisConfigWatcher{
controller: p,
k8sClient: p.client,
Expand Down Expand Up @@ -388,10 +387,13 @@ func (p *PolarisConfigWatcher) doRecv(ctx context.Context) {
default:
msg, err := discoverClient.Recv()
if err != nil {
log.SyncConfigMapScope().Info("receive fetch config resource fail", zap.Error(err))
continue
}

if msg.Code == uint32(apimodel.Code_DataNoChange) {
log.SyncConfigMapScope().Infof("receive fetch config resource for type(%v) code(%d)",
msg.GetType().String(), msg.GetCode())
if msg.Code != uint32(apimodel.Code_ExecuteSuccess) {
continue
}

Expand Down Expand Up @@ -439,6 +441,7 @@ func (p *PolarisConfigWatcher) fetchResources(ctx context.Context) {
}

func (p *PolarisConfigWatcher) fetchGroups(ns string) {
log.SyncConfigMapScope().Infof("begin fetch config groups for namespace(%v)", ns)
p.groups.ComputeIfAbsent(ns, func(k string) *util.SyncSet[string] {
return util.NewSyncSet[string]()
})
Expand Down Expand Up @@ -481,6 +484,7 @@ func (p *PolarisConfigWatcher) receiveGroups(resp *config_manage.ConfigDiscoverR
}

func (p *PolarisConfigWatcher) fetchConfigFiles(namespace, group string) {
log.SyncConfigMapScope().Infof("begin fetch config files for namespace(%v) group(%s)", namespace, group)
key := namespace + "/" + group
preRevision, _ := p.filesRevisions.Load(key)
discoverClient := p.discoverClient
Expand Down Expand Up @@ -597,10 +601,6 @@ const (
)

func (p *PolarisConfigWatcher) allowSyncToConfigMap(file *config_manage.ClientConfigFileInfo) bool {
// 如果是加密配置,目前不支持,跳过同步
if file.GetEncrypted().GetValue() {
return false
}
var (
allowSync bool
isSourceFromK8s bool
Expand Down
2 changes: 2 additions & 0 deletions pkg/controller/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (

"github.com/polarismesh/polaris-go/api"
"go.uber.org/atomic"
"go.uber.org/zap"
v1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/labels"
"k8s.io/apimachinery/pkg/util/runtime"
Expand Down Expand Up @@ -199,6 +200,7 @@ func NewPolarisController(
p.provider = providerAPI

p.config = config
log.Info("controller config", zap.Any("info", p.config.PolarisController))
return p, p.watchPolarisConfig()
}

Expand Down

0 comments on commit 07a2f60

Please sign in to comment.