diff --git a/apiserver/httpserver/i18n/translate.go b/apiserver/httpserver/i18n/translate.go index 4c306638a..8b6b59840 100644 --- a/apiserver/httpserver/i18n/translate.go +++ b/apiserver/httpserver/i18n/translate.go @@ -21,6 +21,7 @@ package i18n import ( "fmt" + "sync" "github.com/BurntSushi/toml" ii18n "github.com/nicksnyder/go-i18n/v2/i18n" @@ -28,18 +29,18 @@ import ( "golang.org/x/text/language" "github.com/polarismesh/polaris/common/log" + "github.com/polarismesh/polaris/common/utils" ) var ( bundle *ii18n.Bundle i18nMsgCache map[uint32]*ii18n.Message + once sync.Once ) func init() { bundle = ii18n.NewBundle(language.English) bundle.RegisterUnmarshalFunc("toml", toml.Unmarshal) - LoadI18nMessageFile("conf/i18n/zh.toml") - LoadI18nMessageFile("conf/i18n/en.toml") } // LoadI18nMessageFile 加载i18n配置文件 @@ -51,6 +52,10 @@ func LoadI18nMessageFile(path string) { // Translate 国际化code所对应的msg信息 func Translate(code uint32, langs ...string) (string, error) { + once.Do(func() { + LoadI18nMessageFile(utils.ConfDir + "i18n/zh.toml") + LoadI18nMessageFile(utils.ConfDir + "i18n/en.toml") + }) msg, ok := i18nMsgCache[code] if !ok { msg = &ii18n.Message{ID: fmt.Sprintf("%d", code)} diff --git a/bootstrap/server.go b/bootstrap/server.go index 9bcdb9e8d..a26cd008c 100644 --- a/bootstrap/server.go +++ b/bootstrap/server.go @@ -61,6 +61,7 @@ var ( func Start(configFilePath string) { // 加载配置 ConfigFilePath = configFilePath + utils.ConfDir = parseConfDir(configFilePath) cfg, err := boot_config.Load(configFilePath) if err != nil { fmt.Printf("[ERROR] load config fail\n") @@ -282,6 +283,14 @@ func StartDiscoverComponents(ctx context.Context, cfg *boot_config.Config, s sto return nil } +func parseConfDir(path string) string { + slashIndex := strings.LastIndex(path, "/") + if slashIndex == -1 { + return "./" + } + return path[0 : slashIndex+1] +} + // StartConfigCenterComponents 启动配置中心模块 func StartConfigCenterComponents(ctx context.Context, cfg *boot_config.Config, s store.Store, cacheMgn *cache.CacheManager, authMgn auth.AuthServer) error { diff --git a/cache/faultdetect.go b/cache/faultdetect.go index 1094b3736..09123ef39 100644 --- a/cache/faultdetect.go +++ b/cache/faultdetect.go @@ -142,7 +142,6 @@ func (f *faultDetectCache) checkServiceSpecificCache( log.Infof( "checkServiceSpecificCache name %s, namespace %s, values %v", name, namespace, f.svcSpecificRules) svcRules, ok := f.svcSpecificRules[namespace] - log.Infof("svcSpecificRules for ns %s, values %v", name, svcRules) if ok { return svcRules[name] } diff --git a/common/utils/const.go b/common/utils/const.go index 38b72490b..9382017f6 100644 --- a/common/utils/const.go +++ b/common/utils/const.go @@ -29,6 +29,8 @@ const ( var ( // LocalHost local host LocalHost = "127.0.0.1" + // ConfDir default config dir + ConfDir = "conf/" ) const ( diff --git a/service/faultdetect_config_test.go b/service/faultdetect_config_test.go index 715f24899..31ab3f728 100644 --- a/service/faultdetect_config_test.go +++ b/service/faultdetect_config_test.go @@ -18,9 +18,11 @@ package service_test import ( + "context" "fmt" "sync" "testing" + "time" "github.com/golang/protobuf/ptypes" "github.com/golang/protobuf/ptypes/wrappers" @@ -178,4 +180,19 @@ func TestCreateFaultDetectRule(t *testing.T) { } wg.Wait() }) + + t.Run("创建探测规则,并通过客户端接口查询,返回正确规则", func(t *testing.T) { + fdRules, resp := createFaultDetectRules(discoverSuit, 1) + defer cleanFaultDetectRules(discoverSuit, resp) + checkFaultDetectRuleResponse(t, fdRules, resp) + time.Sleep(5 * time.Second) + discoverResp := discoverSuit.DiscoverServer().GetFaultDetectWithCache(context.Background(), &apiservice.Service{ + Name: &wrappers.StringValue{Value: "testDestService"}, + Namespace: &wrappers.StringValue{Value: "test"}, + }) + assert.Equal(t, int(apimodel.Code_ExecuteSuccess), int(discoverResp.GetCode().GetValue())) + faultDetector := discoverResp.GetFaultDetector() + assert.NotNil(t, faultDetector) + assert.Equal(t, 1, len(faultDetector.GetRules())) + }) } diff --git a/service/healthcheck/server.go b/service/healthcheck/server.go index 3ac1c9054..582f1efd7 100644 --- a/service/healthcheck/server.go +++ b/service/healthcheck/server.go @@ -25,6 +25,7 @@ import ( "sync" "time" + "github.com/golang/protobuf/proto" apimodel "github.com/polarismesh/specification/source/go/api/v1/model" apiservice "github.com/polarismesh/specification/source/go/api/v1/service_manage" @@ -214,6 +215,9 @@ func (s *Server) RecordHistory(entry *model.RecordEntry) { // publishInstanceEvent 发布服务事件 func (s *Server) publishInstanceEvent(serviceID string, event model.InstanceEvent) { event.SvcId = serviceID + if nil != event.Instance { + event.Instance = proto.Clone(event.Instance).(*apiservice.Instance) + } eventhub.Publish(eventhub.InstanceEventTopic, event) }