From 21a15e77cf652bfb65761719c6ec599721779962 Mon Sep 17 00:00:00 2001 From: chuntaojun Date: Thu, 11 Jan 2024 11:54:51 +0800 Subject: [PATCH] =?UTF-8?q?fix:=E4=BF=AE=E5=A4=8Dnacos=E5=8D=8F=E8=AE=AE?= =?UTF-8?q?=E5=85=BC=E5=AE=B9=E4=B8=AD=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apiserver/nacosserver/model/constant.go | 6 ++++- .../nacosserver/v1/config/config_file.go | 8 ++++++- apiserver/nacosserver/v1/discover/instance.go | 24 +++++++++++++++++++ apiserver/nacosserver/v2/access.go | 17 +++---------- .../nacosserver/v2/config/config_file.go | 24 ++++++++++++++++--- apiserver/nacosserver/v2/config/watch.go | 23 ++++++++++++++++++ cache/api/types.go | 2 +- cache/config/config_file.go | 4 ---- common/metrics/types.go | 8 +++++-- config/config_file.go | 2 +- config/config_file_release.go | 24 +++++++++++++++++++ config/server.go | 12 +++++----- config/server_test.go | 1 - config/watcher.go | 13 +++++----- go.mod | 14 ++++++----- go.sum | 15 ++++++++++++ plugin/statis/logger/statis.go | 10 ++++---- release/standalone/port.properties | 1 - 18 files changed, 157 insertions(+), 51 deletions(-) diff --git a/apiserver/nacosserver/model/constant.go b/apiserver/nacosserver/model/constant.go index 2a239da58..ded1a0870 100644 --- a/apiserver/nacosserver/model/constant.go +++ b/apiserver/nacosserver/model/constant.go @@ -145,5 +145,9 @@ func ToNacosConfigNamespace(ns string) string { } const ( - ActionGetConfigFile = "NACOS_GET_CONFIG" + ActionGetConfigFile = "NACOS_GET_CONFIG" + ActionPublishConfigFile = "NACOS_PUBLISH_CONFIG" + ActionGrpcGetConfigFile = "NACOS_GRPC_GET_CONFIG" + ActionGrpcPublishConfigFile = "NACOS_GRPC_PUBLISH_CONFIG" + ActionGrpcPushConfigFile = "NACOS_GRPC_PUSH_CONFIG" ) diff --git a/apiserver/nacosserver/v1/config/config_file.go b/apiserver/nacosserver/v1/config/config_file.go index ff5f8c072..c263d51b0 100644 --- a/apiserver/nacosserver/v1/config/config_file.go +++ b/apiserver/nacosserver/v1/config/config_file.go @@ -40,7 +40,13 @@ import ( ) func (n *ConfigServer) handlePublishConfig(ctx context.Context, req *model.ConfigFile) (bool, error) { - resp := n.configSvr.UpsertAndReleaseConfigFileFromClient(ctx, req.ToSpecConfigFile()) + var resp *config_manage.ConfigResponse + if req.CasMd5 != "" { + resp = n.configSvr.CasUpsertAndReleaseConfigFileFromClient(ctx, req.ToSpecConfigFile()) + } else { + resp = n.configSvr.UpsertAndReleaseConfigFileFromClient(ctx, req.ToSpecConfigFile()) + } + if resp.GetCode().GetValue() == uint32(apimodel.Code_ExecuteSuccess) { return true, nil } diff --git a/apiserver/nacosserver/v1/discover/instance.go b/apiserver/nacosserver/v1/discover/instance.go index f51cf5179..90c67ae31 100644 --- a/apiserver/nacosserver/v1/discover/instance.go +++ b/apiserver/nacosserver/v1/discover/instance.go @@ -25,9 +25,11 @@ import ( apimodel "github.com/polarismesh/specification/source/go/api/v1/model" apiservice "github.com/polarismesh/specification/source/go/api/v1/service_manage" + "google.golang.org/protobuf/types/known/wrapperspb" "github.com/polarismesh/polaris/apiserver/nacosserver/core" "github.com/polarismesh/polaris/apiserver/nacosserver/model" + commonmodel "github.com/polarismesh/polaris/common/model" "github.com/polarismesh/polaris/common/utils" ) @@ -45,6 +47,24 @@ func (n *DiscoverServer) handleRegister(ctx context.Context, namespace, serviceN func (n *DiscoverServer) handleUpdate(ctx context.Context, namespace, serviceName string, ins *model.Instance) error { specIns := model.PrepareSpecInstance(namespace, serviceName, ins) + if specIns.Id == nil || specIns.GetId().GetValue() == "" { + insId, errRsp := utils.CheckInstanceTetrad(specIns) + if errRsp != nil { + return &model.NacosError{ + ErrCode: int32(model.ExceptionCode_ServerError), + ErrMsg: errRsp.GetInfo().GetValue(), + } + } + specIns.Id = wrapperspb.String(insId) + } + saveIns, err := n.discoverSvr.Cache().GetStore().GetInstance(specIns.GetId().GetValue()) + if err != nil { + return &model.NacosError{ + ErrCode: int32(model.ExceptionCode_ServerError), + ErrMsg: err.Error(), + } + } + specIns = mergeUpdateInstanceInfo(specIns, saveIns) resp := n.discoverSvr.UpdateInstance(ctx, specIns) if apimodel.Code(resp.GetCode().GetValue()) != apimodel.Code_ExecuteSuccess { return &model.NacosError{ @@ -148,3 +168,7 @@ func (n *DiscoverServer) handleQueryInstances(ctx context.Context, params map[st result.Namespace = model.ToNacosNamespace(namespace) return result, nil } + +func mergeUpdateInstanceInfo(req *apiservice.Instance, saveVal *commonmodel.Instance) *apiservice.Instance { + return req +} diff --git a/apiserver/nacosserver/v2/access.go b/apiserver/nacosserver/v2/access.go index 40d82d45b..f4861e88a 100644 --- a/apiserver/nacosserver/v2/access.go +++ b/apiserver/nacosserver/v2/access.go @@ -54,6 +54,7 @@ var ( ) func (h *NacosV2Server) Request(ctx context.Context, payload *nacospb.Payload) (*nacospb.Payload, error) { + ctx = h.ConvertContext(ctx) h.connectionManager.RefreshClient(ctx) ctx = injectPayloadHeader(ctx, payload) handle, val, err := h.UnmarshalPayload(payload) @@ -64,20 +65,8 @@ func (h *NacosV2Server) Request(ctx context.Context, payload *nacospb.Payload) ( if !ok { return nil, ErrorInvalidRequestBodyType } - - if _, ok := debugLevel[msg.GetRequestType()]; !ok { - nacoslog.Info("[NACOS-V2] handler client request", zap.String("conn-id", remote.ValueConnID(ctx)), - utils.ZapRequestID(msg.GetRequestId()), - zap.String("type", msg.GetRequestType()), - ) - } else { - if nacoslog.DebugEnabled() { - nacoslog.Debug("[NACOS-V2] handler client request", zap.String("conn-id", remote.ValueConnID(ctx)), - utils.ZapRequestID(msg.GetRequestId()), - zap.String("type", msg.GetRequestType()), - ) - } - } + nacoslog.Debug("[NACOS-V2] handler client request", zap.String("conn-id", remote.ValueConnID(ctx)), + utils.ZapRequestID(msg.GetRequestId()), zap.String("type", msg.GetRequestType())) connMeta := remote.ValueConnMeta(ctx) startTime := time.Now() diff --git a/apiserver/nacosserver/v2/config/config_file.go b/apiserver/nacosserver/v2/config/config_file.go index 22cf4662a..d1e54305a 100644 --- a/apiserver/nacosserver/v2/config/config_file.go +++ b/apiserver/nacosserver/v2/config/config_file.go @@ -48,7 +48,25 @@ func (h *ConfigServer) handlePublishConfigRequest(ctx context.Context, req nacos return nil, remote.ErrorInvalidRequestBodyType } - resp := h.configSvr.CasUpsertAndReleaseConfigFileFromClient(ctx, configReq.ToSpec()) + var resp *config_manage.ConfigResponse + startTime := commontime.CurrentMillisecond() + defer func() { + plugin.GetStatis().ReportDiscoverCall(metrics.ClientDiscoverMetric{ + Action: nacosmodel.ActionGrpcPublishConfigFile, + ClientIP: meta.ConnectionID, + Namespace: configReq.Tenant, + Resource: metrics.ResourceOfConfigFile(configReq.Group, configReq.DataId), + Timestamp: startTime, + CostTime: commontime.CurrentMillisecond() - startTime, + Success: resp.GetCode().GetValue() == uint32(apimodel.Code_ExecuteSuccess), + }) + }() + + if configReq.CasMd5 != "" { + resp = h.configSvr.CasUpsertAndReleaseConfigFileFromClient(ctx, configReq.ToSpec()) + } else { + resp = h.configSvr.UpsertAndReleaseConfigFileFromClient(ctx, configReq.ToSpec()) + } if resp.GetCode().GetValue() != uint32(apimodel.Code_ExecuteSuccess) { nacoslog.Error("[NACOS-V2][Config] publish config file fail", zap.String("tenant", configReq.Tenant), utils.ZapGroup(configReq.Group), utils.ZapFileName(configReq.DataId), @@ -83,8 +101,8 @@ func (h *ConfigServer) handleGetConfigRequest(ctx context.Context, req nacospb.B startTime := commontime.CurrentMillisecond() defer func() { plugin.GetStatis().ReportDiscoverCall(metrics.ClientDiscoverMetric{ - Action: nacosmodel.ActionGetConfigFile, - ClientIP: utils.ParseClientAddress(ctx), + Action: nacosmodel.ActionGrpcGetConfigFile, + ClientIP: meta.ConnectionID, Namespace: configReq.Tenant, Resource: metrics.ResourceOfConfigFile(configReq.Group, configReq.DataId), Timestamp: startTime, diff --git a/apiserver/nacosserver/v2/config/watch.go b/apiserver/nacosserver/v2/config/watch.go index 21faab30d..646bf03c1 100644 --- a/apiserver/nacosserver/v2/config/watch.go +++ b/apiserver/nacosserver/v2/config/watch.go @@ -28,9 +28,12 @@ import ( nacospb "github.com/polarismesh/polaris/apiserver/nacosserver/v2/pb" "github.com/polarismesh/polaris/apiserver/nacosserver/v2/remote" "github.com/polarismesh/polaris/common/eventhub" + "github.com/polarismesh/polaris/common/metrics" "github.com/polarismesh/polaris/common/model" + commontime "github.com/polarismesh/polaris/common/time" "github.com/polarismesh/polaris/common/utils" "github.com/polarismesh/polaris/config" + "github.com/polarismesh/polaris/plugin" ) type ConnectionClientManager struct { @@ -99,6 +102,9 @@ func (c *StreamWatchContext) ClientID() string { // ShouldNotify . func (c *StreamWatchContext) ShouldNotify(event *model.SimpleConfigFileRelease) bool { + if event.ReleaseType == model.ReleaseTypeGray && !c.betaMatcher(c.ClientLabels(), event) { + return false + } key := event.FileKey() watchFile, ok := c.watchConfigFiles.Load(key) if !ok { @@ -108,6 +114,7 @@ func (c *StreamWatchContext) ShouldNotify(event *model.SimpleConfigFileRelease) if !event.Valid { return true } + nacoslog.Info("should notify", zap.String("client", c.ClientID()), zap.String("save-md5", watchFile.GetMd5().GetValue()), zap.String("recv-md5", event.Md5)) isChange := watchFile.GetMd5().GetValue() != event.Md5 return isChange } @@ -142,6 +149,21 @@ func (c *StreamWatchContext) Reply(event *apiconfig.ConfigClientResponse) { notifyRequest.Group = viewConfig.GetGroup().GetValue() notifyRequest.DataId = viewConfig.GetFileName().GetValue() + success := false + startTime := commontime.CurrentMillisecond() + defer func() { + plugin.GetStatis().ReportDiscoverCall(metrics.ClientDiscoverMetric{ + Action: nacosmodel.ActionGrpcPushConfigFile, + ClientIP: c.ClientID(), + Namespace: notifyRequest.Tenant, + Resource: metrics.ResourceOfConfigFile(notifyRequest.Group, notifyRequest.DataId), + Timestamp: startTime, + CostTime: commontime.CurrentMillisecond() - startTime, + Revision: viewConfig.GetMd5().GetValue(), + Success: success, + }) + }() + remoteClient, ok := c.connMgr.GetClient(c.clientId) if !ok { nacoslog.Error("[NACOS-V2][Config][Push] send ConfigChangeNotifyRequest not found remoteClient", @@ -164,4 +186,5 @@ func (c *StreamWatchContext) Reply(event *apiconfig.ConfigClientResponse) { nacoslog.Error("[NACOS-V2][Config][Push] send ConfigChangeNotifyRequest fail", zap.String("clientId", c.ClientID()), zap.Error(err)) } + success = true } diff --git a/cache/api/types.go b/cache/api/types.go index 7e2360707..188ecacd8 100644 --- a/cache/api/types.go +++ b/cache/api/types.go @@ -382,7 +382,7 @@ type ( // RateLimitCache rateLimit的cache接口 RateLimitCache interface { Cache - // GetRateLimit 根据serviceID进行迭代回调 + // IteratorRateLimit 遍历所有的限流规则 IteratorRateLimit(rateLimitIterProc RateLimitIterProc) // GetRateLimitRules 根据serviceID获取限流数据 GetRateLimitRules(serviceKey model.ServiceKey) ([]*model.RateLimit, string) diff --git a/cache/config/config_file.go b/cache/config/config_file.go index 5fd1034e4..2aa20f128 100644 --- a/cache/config/config_file.go +++ b/cache/config/config_file.go @@ -181,10 +181,6 @@ func (fc *fileCache) setReleases(releases []*model.ConfigFileRelease) (map[strin } if item.Active { - configLog.Info("[Config][Release][Cache] notify config release change", - zap.String("namespace", item.Namespace), zap.String("group", item.Group), zap.String("release", item.Name), - zap.String("file", item.FileName), zap.Uint64("version", item.Version), zap.Bool("valid", item.Valid), - zap.String("type", string(item.ReleaseType))) fc.sendEvent(item) } } diff --git a/common/metrics/types.go b/common/metrics/types.go index 17a6d929e..4bcec5787 100644 --- a/common/metrics/types.go +++ b/common/metrics/types.go @@ -141,8 +141,12 @@ type ClientDiscoverMetric struct { } func (c ClientDiscoverMetric) String() string { - return fmt.Sprintf("%s|%s|%s|%s|%s|%s|%d|%+v", c.ClientIP, c.Action, c.Namespace, c.Resource, - c.Revision, time.Unix(c.Timestamp, 0).Format("2006-01-02 15:04:05"), c.CostTime, c.Success) + revision := c.Revision + if revision == "" { + revision = "-" + } + return fmt.Sprintf("%s|%s|%s|%s|%s|%s|%dms|%+v", c.ClientIP, c.Action, c.Namespace, c.Resource, + revision, time.Unix(c.Timestamp/1000, 0).Format(time.DateTime), c.CostTime, c.Success) } type ConfigMetricType string diff --git a/config/config_file.go b/config/config_file.go index f2f69768e..873f8c142 100644 --- a/config/config_file.go +++ b/config/config_file.go @@ -58,6 +58,7 @@ func (s *Server) CreateConfigFile(ctx context.Context, req *apiconfig.ConfigFile log.Error("[Config][File] create config file commit tx.", utils.RequestID(ctx), zap.Error(err)) return api.NewConfigResponse(commonstore.StoreCode2APICode(err)) } + s.RecordHistory(ctx, configFileRecordEntry(ctx, req, model.OCreate)) resp.ConfigFile = req return resp } @@ -88,7 +89,6 @@ func (s *Server) handleCreateConfigFile(ctx context.Context, tx store.Tx, utils.ZapFileName(req.GetName().GetValue()), zap.Error(err)) return api.NewConfigResponse(commonstore.StoreCode2APICode(err)) } - s.RecordHistory(ctx, configFileRecordEntry(ctx, req, model.OCreate)) return api.NewConfigResponse(apimodel.Code_ExecuteSuccess) } diff --git a/config/config_file_release.go b/config/config_file_release.go index 3a9361110..d2d07a5ff 100644 --- a/config/config_file_release.go +++ b/config/config_file_release.go @@ -136,6 +136,7 @@ func (s *Server) handlePublishConfigFile(ctx context.Context, tx store.Tx, req.Name = utils.NewStringValue(fmt.Sprintf("%s-%d-%d", fileName, time.Now().Unix(), s.nextSequence())) } + fileRelease.Name = req.GetName().GetValue() fileRelease.Format = toPublishFile.Format fileRelease.Metadata = toPublishFile.Metadata fileRelease.Comment = req.GetComment().GetValue() @@ -591,17 +592,25 @@ func (s *Server) CasUpsertAndReleaseConfigFile(ctx context.Context, return api.NewConfigResponse(commonstore.StoreCode2APICode(err)) } + historyRecords := []func(){} + var upsertResp *apiconfig.ConfigResponse if saveFile == nil { if req.GetMd5().GetValue() != "" { return api.NewConfigResponse(apimodel.Code_DataConflict) } upsertResp = s.handleCreateConfigFile(ctx, tx, upsertFileReq) + historyRecords = append(historyRecords, func() { + s.RecordHistory(ctx, configFileRecordEntry(ctx, upsertFileReq, model.OCreate)) + }) } else { if req.GetMd5().GetValue() != CalMd5(saveFile.Content) { return api.NewConfigResponse(apimodel.Code_DataConflict) } upsertResp = s.handleUpdateConfigFile(ctx, tx, upsertFileReq) + historyRecords = append(historyRecords, func() { + s.RecordHistory(ctx, configFileRecordEntry(ctx, upsertFileReq, model.OUpdate)) + }) } if upsertResp.GetCode().GetValue() != uint32(apimodel.Code_ExecuteSuccess) { return upsertResp @@ -625,6 +634,9 @@ func (s *Server) CasUpsertAndReleaseConfigFile(ctx context.Context, log.Error("[Config][File] upsert config file when commit tx.", utils.RequestID(ctx), zap.Error(err)) return api.NewConfigResponse(commonstore.StoreCode2APICode(err)) } + for i := range historyRecords { + historyRecords[i]() + } s.recordReleaseHistory(ctx, data, utils.ReleaseTypeNormal, utils.ReleaseStatusSuccess, "") return releaseResp } @@ -667,9 +679,18 @@ func (s *Server) UpsertAndReleaseConfigFile(ctx context.Context, defer func() { _ = tx.Rollback() }() + + historyRecords := []func(){} upsertResp := s.handleCreateConfigFile(ctx, tx, upsertFileReq) if upsertResp.GetCode().GetValue() == uint32(apimodel.Code_ExistedResource) { upsertResp = s.handleUpdateConfigFile(ctx, tx, upsertFileReq) + historyRecords = append(historyRecords, func() { + s.RecordHistory(ctx, configFileRecordEntry(ctx, upsertFileReq, model.OUpdate)) + }) + } else { + historyRecords = append(historyRecords, func() { + s.RecordHistory(ctx, configFileRecordEntry(ctx, upsertFileReq, model.OCreate)) + }) } if upsertResp.GetCode().GetValue() != uint32(apimodel.Code_ExecuteSuccess) { return upsertResp @@ -693,6 +714,9 @@ func (s *Server) UpsertAndReleaseConfigFile(ctx context.Context, log.Error("[Config][File] upsert config file when commit tx.", utils.RequestID(ctx), zap.Error(err)) return api.NewConfigResponse(commonstore.StoreCode2APICode(err)) } + for i := range historyRecords { + historyRecords[i]() + } s.recordReleaseHistory(ctx, data, utils.ReleaseTypeNormal, utils.ReleaseStatusSuccess, "") return releaseResp } diff --git a/config/server.go b/config/server.go index 9e9413e94..c97b59fc0 100644 --- a/config/server.go +++ b/config/server.go @@ -103,18 +103,18 @@ func Initialize(ctx context.Context, config Config, s store.Store, cacheMgr cach func doInitialize(ctx context.Context, config Config, s store.Store, cacheMgr cachetypes.CacheManager, namespaceOperator namespace.NamespaceOperateServer) (ConfigCenterServer, *Server, error) { + var proxySvr ConfigCenterServer + originSvr := &Server{} + if !config.Open { - originServer.initialized = true + originSvr.initialized = true return nil, nil, nil } - var proxySvr ConfigCenterServer - originSvr := &Server{} - if err := cacheMgr.OpenResourceCache(configCacheEntries...); err != nil { return nil, nil, err } - err := originServer.initialize(ctx, config, s, namespaceOperator, cacheMgr) + err := originSvr.initialize(ctx, config, s, namespaceOperator, cacheMgr) if err != nil { return nil, nil, err } @@ -127,7 +127,7 @@ func doInitialize(ctx context.Context, config Config, s store.Store, cacheMgr ca return nil, nil, fmt.Errorf("name(%s) not exist in serverProxyFactories", order[i]) } - tmpSvr, err := factory(originServer, server) + tmpSvr, err := factory(originSvr, server) if err != nil { return nil, nil, err } diff --git a/config/server_test.go b/config/server_test.go index 66d3a06e2..20409aff6 100644 --- a/config/server_test.go +++ b/config/server_test.go @@ -30,7 +30,6 @@ import ( ) func Test_Initialize(t *testing.T) { - t.SkipNow() eventhub.InitEventHub() ctrl := gomock.NewController(t) mockStore := mockstore.NewMockStore(ctrl) diff --git a/config/watcher.go b/config/watcher.go index c7f096a2d..1af7ff556 100644 --- a/config/watcher.go +++ b/config/watcher.go @@ -330,24 +330,21 @@ func (wc *watchCenter) notifyToWatchers(publishConfigFile *model.SimpleConfigFil if !ok { return } - - log.Info("[Config][Watcher] received config file publish message.", zap.String("file", watchFileId), - zap.Int("clients", clientIds.Len())) - changeNotifyRequest := publishConfigFile.ToSpecNotifyClientRequest() response := api.NewConfigClientResponse(apimodel.Code_ExecuteSuccess, changeNotifyRequest) + notifyCnt := 0 clientIds.Range(func(clientId string) { watchCtx, ok := wc.clients.Load(clientId) if !ok { - log.Info("[Config][Watcher] not found client when do notify.", zap.String("clientId", clientId), + log.Warn("[Config][Watcher] not found client when do notify.", zap.String("clientId", clientId), zap.String("file", watchFileId)) - clientIds.Remove(clientId) return } if watchCtx.ShouldNotify(publishConfigFile) { watchCtx.Reply(response) + notifyCnt++ } // 只能用一次,通知完就要立马清理掉这个 WatchContext if watchCtx.IsOnce() { @@ -355,6 +352,10 @@ func (wc *watchCenter) notifyToWatchers(publishConfigFile *model.SimpleConfigFil wc.RemoveAllWatcher(watchCtx.ClientID()) } }) + + log.Info("[Config][Watcher] received config file release event.", zap.String("file", watchFileId), + zap.Uint64("version", publishConfigFile.Version), zap.Int("clients", clientIds.Len()), + zap.Int("notify", notifyCnt)) } func (wc *watchCenter) MatchBetaReleaseFile(clientLabels map[string]string, event *model.SimpleConfigFileRelease) bool { diff --git a/go.mod b/go.mod index 83fecddb5..67e4431c2 100644 --- a/go.mod +++ b/go.mod @@ -21,7 +21,7 @@ require ( github.com/nicksnyder/go-i18n/v2 v2.2.0 github.com/pkg/errors v0.9.1 github.com/polarismesh/go-restful-openapi/v2 v2.0.0-20220928152401-083908d10219 - github.com/prometheus/client_golang v1.12.2 + github.com/prometheus/client_golang v1.18.0 github.com/smartystreets/goconvey v1.6.4 github.com/spf13/cobra v1.2.1 github.com/stretchr/testify v1.8.3 @@ -30,11 +30,11 @@ require ( go.uber.org/zap v1.23.0 golang.org/x/crypto v0.17.0 golang.org/x/net v0.17.0 - golang.org/x/sync v0.1.0 + golang.org/x/sync v0.6.0 golang.org/x/text v0.14.0 golang.org/x/time v0.1.1-0.20221020023724-80b9fac54d29 google.golang.org/grpc v1.55.0 - google.golang.org/protobuf v1.30.0 + google.golang.org/protobuf v1.31.0 gopkg.in/yaml.v2 v2.4.0 ) @@ -67,9 +67,9 @@ require ( github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect github.com/modern-go/reflect2 v1.0.2 // indirect github.com/pmezard/go-difflib v1.0.0 // indirect - github.com/prometheus/client_model v0.4.0 // indirect - github.com/prometheus/common v0.32.1 // indirect - github.com/prometheus/procfs v0.7.3 // indirect + github.com/prometheus/client_model v0.5.0 // indirect + github.com/prometheus/common v0.45.0 // indirect + github.com/prometheus/procfs v0.12.0 // indirect github.com/smartystreets/assertions v1.0.1 // indirect github.com/spf13/pflag v1.0.5 // indirect go.uber.org/goleak v1.1.12 // indirect @@ -85,6 +85,8 @@ require ( github.com/polarismesh/specification v1.4.2-alpha.7 ) +require github.com/matttproud/golang_protobuf_extensions/v2 v2.0.0 // indirect + require ( github.com/dlclark/regexp2 v1.10.0 go.etcd.io/bbolt v1.3.7 diff --git a/go.sum b/go.sum index fa74a49ed..c544ad485 100644 --- a/go.sum +++ b/go.sum @@ -281,6 +281,8 @@ github.com/mattn/go-isatty v0.0.3/go.mod h1:M+lRXTBqGeGNdLjl/ufCoiOlB5xdOkqRJdNx github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0= github.com/matttproud/golang_protobuf_extensions v1.0.2-0.20181231171920-c182affec369 h1:I0XW9+e1XWDxdcEniV4rQAIOPUGDq67JSCiRCgGCZLI= github.com/matttproud/golang_protobuf_extensions v1.0.2-0.20181231171920-c182affec369/go.mod h1:BSXmuO+STAnVfrANrmjBb36TMTDstsz7MSK+HVaYKv4= +github.com/matttproud/golang_protobuf_extensions/v2 v2.0.0 h1:jWpvCLoY8Z/e3VKvlsiIGKtc+UG6U5vzxaoagmhXfyg= +github.com/matttproud/golang_protobuf_extensions/v2 v2.0.0/go.mod h1:QUyp042oQthUoa9bqDv0ER0wrtXnBruoNd7aNjkbP+k= github.com/miekg/dns v1.0.14/go.mod h1:W1PPwlIAgtquWBMBEV9nkV9Cazfe8ScdGz/Lj7v3Nrg= github.com/mitchellh/cli v1.0.0/go.mod h1:hNIlj7HEI86fIcpObd7a0FcrxTWetlwJDGcceTlRvqc= github.com/mitchellh/go-homedir v1.0.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0= @@ -332,23 +334,31 @@ github.com/prometheus/client_golang v1.7.1/go.mod h1:PY5Wy2awLA44sXw4AOSfFBetzPP github.com/prometheus/client_golang v1.11.0/go.mod h1:Z6t4BnS23TR94PD6BsDNk8yVqroYurpAkEiz0P2BEV0= github.com/prometheus/client_golang v1.12.2 h1:51L9cDoUHVrXx4zWYlcLQIZ+d+VXHgqnYKkIuq4g/34= github.com/prometheus/client_golang v1.12.2/go.mod h1:3Z9XVyYiZYEO+YQWt3RD2R3jrbd179Rt297l4aS6nDY= +github.com/prometheus/client_golang v1.18.0 h1:HzFfmkOzH5Q8L8G+kSJKUx5dtG87sewO+FoDDqP5Tbk= +github.com/prometheus/client_golang v1.18.0/go.mod h1:T+GXkCk5wSJyOqMIzVgvvjFDlkOQntgjkJWKrN5txjA= github.com/prometheus/client_model v0.0.0-20180712105110-5c3871d89910/go.mod h1:MbSGuTsp3dbXC40dX6PRTWyKYBIrTGTE9sqQNg2J8bo= github.com/prometheus/client_model v0.0.0-20190129233127-fd36f4220a90/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA= github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA= github.com/prometheus/client_model v0.2.0/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA= github.com/prometheus/client_model v0.4.0 h1:5lQXD3cAg1OXBf4Wq03gTrXHeaV0TQvGfUooCfx1yqY= github.com/prometheus/client_model v0.4.0/go.mod h1:oMQmHW1/JoDwqLtg57MGgP/Fb1CJEYF2imWWhWtMkYU= +github.com/prometheus/client_model v0.5.0 h1:VQw1hfvPvk3Uv6Qf29VrPF32JB6rtbgI6cYPYQjL0Qw= +github.com/prometheus/client_model v0.5.0/go.mod h1:dTiFglRmd66nLR9Pv9f0mZi7B7fk5Pm3gvsjB5tr+kI= github.com/prometheus/common v0.4.1/go.mod h1:TNfzLD0ON7rHzMJeJkieUDPYmFC7Snx/y86RQel1bk4= github.com/prometheus/common v0.10.0/go.mod h1:Tlit/dnDKsSWFlCLTWaA1cyBgKHSMdTB80sz/V91rCo= github.com/prometheus/common v0.26.0/go.mod h1:M7rCNAaPfAosfx8veZJCuw84e35h3Cfd9VFqTh1DIvc= github.com/prometheus/common v0.32.1 h1:hWIdL3N2HoUx3B8j3YN9mWor0qhY/NlEKZEaXxuIRh4= github.com/prometheus/common v0.32.1/go.mod h1:vu+V0TpY+O6vW9J44gczi3Ap/oXXR10b+M/gUGO4Hls= +github.com/prometheus/common v0.45.0 h1:2BGz0eBc2hdMDLnO/8n0jeB3oPrt2D08CekT0lneoxM= +github.com/prometheus/common v0.45.0/go.mod h1:YJmSTw9BoKxJplESWWxlbyttQR4uaEcGyv9MZjVOJsY= github.com/prometheus/procfs v0.0.0-20181005140218-185b4288413d/go.mod h1:c3At6R/oaqEKCNdg8wHV1ftS6bRYblBhIjjI8uT2IGk= github.com/prometheus/procfs v0.0.2/go.mod h1:TjEm7ze935MbeOT/UhFTIMYKhuLP4wbCsTZCD3I8kEA= github.com/prometheus/procfs v0.1.3/go.mod h1:lV6e/gmhEcM9IjHGsFOCxxuZ+z1YqCvr4OA4YeYWdaU= github.com/prometheus/procfs v0.6.0/go.mod h1:cz+aTbrPOrUb4q7XlbU9ygM+/jj0fzG6c1xBZuNvfVA= github.com/prometheus/procfs v0.7.3 h1:4jVXhlkAyzOScmCkXBTOLRLTz8EeU+eyjrwB/EPq0VU= github.com/prometheus/procfs v0.7.3/go.mod h1:cz+aTbrPOrUb4q7XlbU9ygM+/jj0fzG6c1xBZuNvfVA= +github.com/prometheus/procfs v0.12.0 h1:jluTpSng7V9hY0O2R9DzzJHYb2xULk9VTR1V1R/k6Bo= +github.com/prometheus/procfs v0.12.0/go.mod h1:pcuDEFsWDnvcgNzo4EEweacyhjeA9Zk3cnaOZAZEfOo= github.com/rogpeppe/fastuuid v1.2.0/go.mod h1:jVj6XXZzXRy/MSR5jhDC/2q6DgLz+nrA6LYCDYWNEvQ= github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4= github.com/russross/blackfriday/v2 v2.0.1/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= @@ -526,6 +536,9 @@ golang.org/x/sync v0.0.0-20201207232520-09787c993a3a/go.mod h1:RxMgew5VJxzue5/jJ golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.1.0 h1:wsuoTGHzEhffawBOhz5CYhcrV4IdKZbEyZjBMuTp12o= golang.org/x/sync v0.1.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.3.0/go.mod h1:FU7BRWz2tNW+3quACPkgCx/L+uEAv1htQ0V83Z9Rj+Y= +golang.org/x/sync v0.6.0 h1:5BMeUDZ7vkXGfEr1x9B4bRcTH4lpkTkpdh0T/J+qjbQ= +golang.org/x/sync v0.6.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= golang.org/x/sys v0.0.0-20180823144017-11551d06cbcc/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= @@ -766,6 +779,8 @@ google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp0 google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc= google.golang.org/protobuf v1.30.0 h1:kPPoIgf3TsEvrm0PFe15JQ+570QVxYzEvvHqChK+cng= google.golang.org/protobuf v1.30.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I= +google.golang.org/protobuf v1.31.0 h1:g0LDEJHgrBl9N9r17Ru3sqWhkIx2NB67okBHPwC7hs8= +google.golang.org/protobuf v1.31.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I= gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLkstjWtayDeSgw= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= diff --git a/plugin/statis/logger/statis.go b/plugin/statis/logger/statis.go index 8c1a32037..6a8121c09 100644 --- a/plugin/statis/logger/statis.go +++ b/plugin/statis/logger/statis.go @@ -117,7 +117,9 @@ func (a *StatisWorker) metricsHandle(mt metrics.CallMetricType, start time.Time, var prefixMax int for i := range statics { prefixMax = int(math.Max(float64(prefixMax), float64(len(statics[i].API)))) - msg += formatAPICallStatisItem(mt, statics[i]) + } + for i := range statics { + msg += formatAPICallStatisItem(prefixMax, mt, statics[i]) } if len(msg) == 0 { log.Info(fmt.Sprintf("Statis %s: No API Call\n", startStr)) @@ -133,12 +135,12 @@ func (a *StatisWorker) metricsHandle(mt metrics.CallMetricType, start time.Time, log.Info(header + msg) } -func formatAPICallStatisItem(mt metrics.CallMetricType, item *base.APICallStatisItem) string { +func formatAPICallStatisItem(prefixMax int, mt metrics.CallMetricType, item *base.APICallStatisItem) string { if item.Count == 0 { return "" } - return fmt.Sprintf("%-48v|%12v|%17v|%12v|%12v|%12.3f|%12.3f|%12.3f|\n", - item.API, mt, item.TrafficDirection, item.Code, item.Count, + return fmt.Sprintf("%-"+strconv.Itoa(prefixMax)+"v|%12v|%17v|%12v|%12v|%12.3f|%12.3f|%12.3f|\n", + item.API, item.Protocol, item.TrafficDirection, item.Code, item.Count, float64(item.MinTime)/1e6, float64(item.MaxTime)/1e6, float64(item.AccTime)/float64(item.Count)/1e6, diff --git a/release/standalone/port.properties b/release/standalone/port.properties index 4b57b4712..1ce36e5f7 100644 --- a/release/standalone/port.properties +++ b/release/standalone/port.properties @@ -10,4 +10,3 @@ polaris_limiter_grpc_port=8101 prometheus_port=9090 pushgateway_port=9091 nacos_http_port=8848 -nacos_grpc_port=9848