This is an automated email from the ASF dual-hosted git repository.

tianxiaoliang pushed a commit to branch v1.x
in repository https://gitbox.apache.org/repos/asf/servicecomb-service-center.git


The following commit(s) were added to refs/heads/v1.x by this push:
     new 4bfdba8  Fix: Service/Instance Quota incorrect (#1084)
4bfdba8 is described below

commit 4bfdba8cc8ae2ae5729d2c3af61e28907e66f486
Author: little-cui <[email protected]>
AuthorDate: Mon Jul 5 21:31:33 2021 +0800

    Fix: Service/Instance Quota incorrect (#1084)
---
 server/plugin/quota/buildin/common.go       | 10 ++++-
 server/plugin/quota/buildin/counter.go      | 57 -----------------------------
 server/plugin/quota/buildin/counter_test.go | 50 -------------------------
 3 files changed, 8 insertions(+), 109 deletions(-)

diff --git a/server/plugin/quota/buildin/common.go 
b/server/plugin/quota/buildin/common.go
index ee351f3..42d6b23 100644
--- a/server/plugin/quota/buildin/common.go
+++ b/server/plugin/quota/buildin/common.go
@@ -21,6 +21,8 @@ import (
        "context"
        "errors"
        "fmt"
+       "strings"
+
        "github.com/apache/servicecomb-service-center/pkg/log"
        "github.com/apache/servicecomb-service-center/server/core"
        "github.com/apache/servicecomb-service-center/server/core/backend"
@@ -85,9 +87,13 @@ func resourceLimitHandler(ctx context.Context, res 
*quota.ApplyQuotaResource) (i
 
        switch res.QuotaType {
        case quota.MicroServiceInstanceQuotaType:
-               return globalCounter.InstanceCount, nil
+               domain := domainProject[:strings.Index(domainProject, 
core.SPLIT)]
+               key = core.GetInstanceRootKey(domain) + core.SPLIT
+               indexer = backend.Store().Instance()
        case quota.MicroServiceQuotaType:
-               return globalCounter.ServiceCount, nil
+               domain := domainProject[:strings.Index(domainProject, 
core.SPLIT)]
+               key = core.GetServiceRootKey(domain) + core.SPLIT
+               indexer = backend.Store().Service()
        case quota.RuleQuotaType:
                key = core.GenerateServiceRuleKey(domainProject, serviceID, "")
                indexer = backend.Store().Rule()
diff --git a/server/plugin/quota/buildin/counter.go 
b/server/plugin/quota/buildin/counter.go
deleted file mode 100644
index 9f406ac..0000000
--- a/server/plugin/quota/buildin/counter.go
+++ /dev/null
@@ -1,57 +0,0 @@
-// Licensed to the Apache Software Foundation (ASF) under one or more
-// contributor license agreements.  See the NOTICE file distributed with
-// this work for additional information regarding copyright ownership.
-// The ASF licenses this file to You under the Apache License, Version 2.0
-// (the "License"); you may not use this file except in compliance with
-// the License.  You may obtain a copy of the License at
-//
-//     http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-
-package buildin
-
-import (
-       "github.com/apache/servicecomb-service-center/server/core/backend"
-       "github.com/apache/servicecomb-service-center/server/plugin/discovery"
-       
"github.com/apache/servicecomb-service-center/server/plugin/quota/counter"
-)
-
-var globalCounter = &GlobalCounter{}
-
-func init() {
-       counter.RegisterCounter(globalCounter)
-}
-
-type GlobalCounter struct {
-       ServiceCount  int64
-       InstanceCount int64
-}
-
-func (c *GlobalCounter) OnCreate(t discovery.Type, domainProject string) {
-       switch t {
-       case backend.ServiceIndex:
-               c.ServiceCount++
-       case backend.INSTANCE:
-               c.InstanceCount++
-       }
-}
-
-func (c *GlobalCounter) OnDelete(t discovery.Type, domainProject string) {
-       switch t {
-       case backend.ServiceIndex:
-               if c.ServiceCount == 0 {
-                       return
-               }
-               c.ServiceCount--
-       case backend.INSTANCE:
-               if c.InstanceCount == 0 {
-                       return
-               }
-               c.InstanceCount--
-       }
-}
diff --git a/server/plugin/quota/buildin/counter_test.go 
b/server/plugin/quota/buildin/counter_test.go
deleted file mode 100644
index 149bc89..0000000
--- a/server/plugin/quota/buildin/counter_test.go
+++ /dev/null
@@ -1,50 +0,0 @@
-// Licensed to the Apache Software Foundation (ASF) under one or more
-// contributor license agreements.  See the NOTICE file distributed with
-// this work for additional information regarding copyright ownership.
-// The ASF licenses this file to You under the Apache License, Version 2.0
-// (the "License"); you may not use this file except in compliance with
-// the License.  You may obtain a copy of the License at
-//
-//     http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-
-package buildin
-
-import (
-       "github.com/apache/servicecomb-service-center/server/core/backend"
-       "testing"
-)
-
-func TestGlobalCounter_OnCreate(t *testing.T) {
-       var counter GlobalCounter
-       counter.OnCreate(backend.SERVICE, "a/b")
-       counter.OnCreate(backend.ServiceIndex, "a/b")
-       counter.OnCreate(backend.INSTANCE, "a/b")
-       counter.OnCreate(backend.ServiceIndex, "a/b")
-       counter.OnCreate(backend.INSTANCE, "a/b")
-       if counter.ServiceCount != 2 || counter.InstanceCount != 2 {
-               t.Fatal("TestGlobalCounter_OnCreate failed", counter)
-       }
-}
-
-func TestGlobalCounter_OnDelete(t *testing.T) {
-       var counter GlobalCounter
-       counter.OnDelete(backend.SERVICE, "a/b")
-       counter.OnDelete(backend.ServiceIndex, "a/b")
-       counter.OnDelete(backend.INSTANCE, "a/b")
-       if counter.ServiceCount != 0 || counter.InstanceCount != 0 {
-               t.Fatal("TestGlobalCounter_OnDelete failed", counter)
-       }
-       counter.OnCreate(backend.ServiceIndex, "a/b")
-       counter.OnCreate(backend.INSTANCE, "a/b")
-       counter.OnDelete(backend.ServiceIndex, "a/b")
-       counter.OnDelete(backend.INSTANCE, "a/b")
-       if counter.ServiceCount != 0 || counter.InstanceCount != 0 {
-               t.Fatal("TestGlobalCounter_OnDelete failed", counter)
-       }
-}

Reply via email to