[ https://issues.apache.org/jira/browse/SCB-339?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16378390#comment-16378390 ]
ASF GitHub Bot commented on SCB-339: ------------------------------------ asifdxtreme closed pull request #291: SCB-339 Exclude the version in online services calculation URL: https://github.com/apache/incubator-servicecomb-service-center/pull/291 This is a PR merged from a forked repository. As GitHub hides the original diff on merge, it is displayed below for the sake of provenance: As this is a foreign pull request (from a fork), the diff is supplied below (as it won't show otherwise due to GitHub magic): diff --git a/server/core/backend/store/defer.go b/server/core/backend/store/defer.go index 173a44a9..d35f9734 100644 --- a/server/core/backend/store/defer.go +++ b/server/core/backend/store/defer.go @@ -117,7 +117,7 @@ func (iedh *InstanceEventDeferHandler) check(stopCh <-chan struct{}) { } total := iedh.cache.Size() - if del > 0 && total > 0 && float64(del) >= float64(total)*iedh.Percent { + if !iedh.enabled && del > 0 && total > 0 && float64(del) >= float64(total)*iedh.Percent { iedh.enabled = true util.Logger().Warnf(nil, "self preservation is enabled, caught %d/%d(>=%.0f%%) DELETE events", del, total, iedh.Percent*100) diff --git a/server/govern/service.go b/server/govern/service.go index 73780e54..4a0abe87 100644 --- a/server/govern/service.go +++ b/server/govern/service.go @@ -365,25 +365,27 @@ func statistics(ctx context.Context) (*pb.Statistics, error) { key := apt.GetServiceIndexRootKey(domainProject) + "/" svcOpts := append(opts, registry.WithStrKey(key), - registry.WithPrefix(), - registry.WithKeyOnly()) + registry.WithPrefix()) respSvc, err := store.Store().ServiceIndex().Search(ctx, svcOpts...) if err != nil { return nil, err } - app := make(map[string]interface{}, respSvc.Count) - svcWithNonVersion := make(map[string]interface{}, respSvc.Count) + app := make(map[string]struct{}, respSvc.Count) + svcWithNonVersion := make(map[string]struct{}, respSvc.Count) + svcIdToNonVerKey := make(map[string]string, respSvc.Count) for _, kv := range respSvc.Kvs { - key, _ := pb.GetInfoFromSvcIndexKV(kv) - + key, val := pb.GetInfoFromSvcIndexKV(kv) if _, ok := app[key.AppId]; !ok { - app[key.AppId] = nil + app[key.AppId] = struct{}{} } key.Version = "" svcWithNonVersionKey := apt.GenerateServiceIndexKey(key) - svcWithNonVersion[svcWithNonVersionKey] = nil + if _, ok := svcWithNonVersion[svcWithNonVersionKey]; !ok { + svcWithNonVersion[svcWithNonVersionKey] = struct{}{} + } + svcIdToNonVerKey[util.BytesToStringWithNoCopy(val)] = svcWithNonVersionKey } result.Services.Count = int64(len(svcWithNonVersion)) @@ -400,11 +402,15 @@ func statistics(ctx context.Context) (*pb.Statistics, error) { return nil, err } - onlineServices := make(map[string]interface{}, respSvc.Count) + onlineServices := make(map[string]struct{}, respSvc.Count) for _, kv := range respIns.Kvs { serviceId, _, _, _ := pb.GetInfoFromInstKV(kv) - if _, ok := onlineServices[serviceId]; !ok { - onlineServices[serviceId] = nil + key, ok := svcIdToNonVerKey[serviceId] + if !ok { + continue + } + if _, ok := onlineServices[key]; !ok { + onlineServices[key] = struct{}{} } } result.Instances.Count = respIns.Count ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: us...@infra.apache.org > The wrong statistics in micro-service > ------------------------------------- > > Key: SCB-339 > URL: https://issues.apache.org/jira/browse/SCB-339 > Project: Apache ServiceComb > Issue Type: Bug > Components: Service-Center > Reporter: little-cui > Assignee: little-cui > Priority: Major > Fix For: service-center-1.0.0-m2 > > -- This message was sent by Atlassian JIRA (v7.6.3#76005)