little-cui closed pull request #280: SCB-339 The wrong statistics in
micro-service
URL: https://github.com/apache/incubator-servicecomb-service-center/pull/280
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/key_generator.go b/server/core/key_generator.go
index cdd0e80c..cb012362 100644
--- a/server/core/key_generator.go
+++ b/server/core/key_generator.go
@@ -78,6 +78,14 @@ func GetServiceAliasRootKey(domainProject string) string {
}, "/")
}
+func GetServiceAppKey(domainProject, env, appId string) string {
+ return util.StringJoin([]string{
+ GetServiceIndexRootKey(domainProject),
+ env,
+ appId,
+ }, "/")
+}
+
func GetServiceRuleRootKey(domainProject string) string {
return util.StringJoin([]string{
GetRootKey(),
diff --git a/server/govern/service.go b/server/govern/service.go
index 73780e54..fa640a2a 100644
--- a/server/govern/service.go
+++ b/server/govern/service.go
@@ -180,13 +180,7 @@ func (governService *GovernService) GetApplications(ctx
context.Context, in *pb.
}
domainProject := util.ParseDomainProject(ctx)
- key := util.StringJoin([]string{
- apt.GetServiceIndexRootKey(domainProject),
- in.Environment,
- }, "/")
- if key[len(key)-1:] != "/" {
- key += "/"
- }
+ key := apt.GetServiceAppKey(domainProject, in.Environment, "")
opts := append(serviceUtil.FromContext(ctx),
registry.WithStrKey(key),
diff --git a/server/plugin/infra/registry/etcd/etcd.go
b/server/plugin/infra/registry/etcd/etcd.go
index 941aa7cd..6cd984a6 100644
--- a/server/plugin/infra/registry/etcd/etcd.go
+++ b/server/plugin/infra/registry/etcd/etcd.go
@@ -250,12 +250,12 @@ func (c *EtcdClient) paging(ctx context.Context, op
registry.PluginOp) (*clientv
start := time.Now()
tempOp := op
tempOp.CountOnly = true
- coutResp, err := c.Client.Get(ctx, key, c.toGetRequest(tempOp)...)
+ countResp, err := c.Client.Get(ctx, key, c.toGetRequest(tempOp)...)
if err != nil {
return nil, err
}
- recordCount := coutResp.Count
+ recordCount := countResp.Count
if op.Offset == -1 && recordCount < op.Limit {
return nil, nil // no paging
}
@@ -268,9 +268,9 @@ func (c *EtcdClient) paging(ctx context.Context, op
registry.PluginOp) (*clientv
if len(op.EndKey) > 0 {
tempOp.EndKey = op.EndKey
}
- tempOp.Revision = coutResp.Header.Revision
+ tempOp.Revision = countResp.Header.Revision
- etcdResp = coutResp
+ etcdResp = countResp
etcdResp.Kvs = make([]*mvccpb.KeyValue, 0, etcdResp.Count)
pageCount := recordCount / op.Limit
@@ -344,6 +344,9 @@ func (c *EtcdClient) Do(ctx context.Context, opts
...registry.PluginOpOption) (*
switch op.Action {
case registry.Get:
var etcdResp *clientv3.GetResponse
+ if op.Prefix && op.Key[len(op.Key)-1] != '/' {
+ op.Key = append(op.Key, '/')
+ }
key := util.BytesToStringWithNoCopy(op.Key)
if (op.Prefix || len(op.EndKey) > 0) && !op.CountOnly {
@@ -517,10 +520,10 @@ func (c *EtcdClient) Watch(ctx context.Context, opts
...registry.PluginOpOption)
client := clientv3.NewWatcher(c.Client)
defer client.Close()
- key := util.BytesToStringWithNoCopy(op.Key)
- if op.Prefix && key[len(key)-1] != '/' {
- key += "/"
+ if op.Prefix && op.Key[len(op.Key)-1] != '/' {
+ op.Key = append(op.Key, '/')
}
+ key := util.BytesToStringWithNoCopy(op.Key)
// ??????context???????????watch??
ws := client.Watch(context.Background(), key,
c.toGetRequest(op)...)
diff --git a/server/service/microservices.go b/server/service/microservices.go
index 85143337..15c904a9 100644
--- a/server/service/microservices.go
+++ b/server/service/microservices.go
@@ -127,16 +127,18 @@ func (s *MicroServiceService) CreateServicePri(ctx
context.Context, in *pb.Creat
}, err
}
key := apt.GenerateServiceKey(domainProject, serviceId)
+ keyBytes := util.StringToBytesWithNoCopy(key)
index := apt.GenerateServiceIndexKey(serviceKey)
indexBytes := util.StringToBytesWithNoCopy(index)
aliasBytes :=
util.StringToBytesWithNoCopy(apt.GenerateServiceAliasKey(serviceKey))
opts := []registry.PluginOp{
- registry.OpPut(registry.WithStrKey(key),
registry.WithValue(data)),
+ registry.OpPut(registry.WithKey(keyBytes),
registry.WithValue(data)),
registry.OpPut(registry.WithKey(indexBytes),
registry.WithStrValue(serviceId)),
}
uniqueCmpOpts := []registry.CompareOp{
registry.OpCmp(registry.CmpVer(indexBytes), registry.CMP_EQUAL,
0),
+ registry.OpCmp(registry.CmpVer(keyBytes), registry.CMP_EQUAL,
0),
}
if len(serviceKey.Alias) > 0 {
@@ -204,11 +206,7 @@ func (s *MicroServiceService) DeleteServicePri(ctx
context.Context, serviceId st
title = "force delete"
}
- isServiceCenter := func(serviceId string) bool {
- return serviceId == apt.Service.ServiceId
- }
-
- if isServiceCenter(serviceId) {
+ if serviceId == apt.Service.ServiceId {
err := errors.New("not allow to delete service center")
util.Logger().Errorf(err, "%s micro-service failed, serviceId
is %s", title, serviceId)
return pb.CreateResponse(scerr.ErrInvalidParams, err.Error()),
nil
----------------------------------------------------------------
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:
[email protected]
With regards,
Apache Git Services