[incubator-servicecomb-service-center] branch master updated: SCB-994 SC can not read the context when client using grpc api (#476)
This is an automated email from the ASF dual-hosted git repository. asifdxtreme pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/incubator-servicecomb-service-center.git The following commit(s) were added to refs/heads/master by this push: new ea31a1a SCB-994 SC can not read the context when client using grpc api (#476) ea31a1a is described below commit ea31a1a3c9fdbd242817157f61e4aad15bfa5f0f Author: little-cui AuthorDate: Sat Nov 3 00:19:28 2018 +0800 SCB-994 SC can not read the context when client using grpc api (#476) * Support gRPC context * Bug fixes --- pkg/util/context.go | 30 - pkg/util/context_grpc.go | 32 + pkg/util/context_grpc_test.go| 57 server/handler/context/v3.go | 4 +- server/handler/context/v4.go | 4 +- server/rest/controller/v4/instance_controller.go | 8 ++-- server/service/instance.go | 2 +- 7 files changed, 118 insertions(+), 19 deletions(-) diff --git a/pkg/util/context.go b/pkg/util/context.go index 79fb515..838d4a6 100644 --- a/pkg/util/context.go +++ b/pkg/util/context.go @@ -22,6 +22,13 @@ import ( "time" ) +const ( + CtxDomain= "domain" + CtxProject = "project" + CtxTargetDomain = "target-domain" + CtxTargetProject = "target-project" +) + type StringContext struct { parentCtx context.Context kv*ConcurrentMap @@ -46,7 +53,7 @@ func (c *StringContext) Value(key interface{}) interface{} { } v, ok := c.kv.Get(k) if !ok { - return c.parentCtx.Value(key) + return FromContext(c.parentCtx, k) } return v } @@ -94,7 +101,10 @@ func CloneContext(ctx context.Context) context.Context { } func FromContext(ctx context.Context, key string) interface{} { - return ctx.Value(key) + if v := ctx.Value(key); v != nil { + return v + } + return FromMetadata(ctx, key) } func SetRequestContext(r *http.Request, key string, val interface{}) *http.Request { @@ -116,7 +126,7 @@ func ParseTargetDomainProject(ctx context.Context) string { } func ParseDomain(ctx context.Context) string { - v, ok := FromContext(ctx, "domain").(string) + v, ok := FromContext(ctx, CtxDomain).(string) if !ok { return "" } @@ -124,7 +134,7 @@ func ParseDomain(ctx context.Context) string { } func ParseTargetDomain(ctx context.Context) string { - v, _ := FromContext(ctx, "target-domain").(string) + v, _ := FromContext(ctx, CtxTargetDomain).(string) if len(v) == 0 { return ParseDomain(ctx) } @@ -132,7 +142,7 @@ func ParseTargetDomain(ctx context.Context) string { } func ParseProject(ctx context.Context) string { - v, ok := FromContext(ctx, "project").(string) + v, ok := FromContext(ctx, CtxProject).(string) if !ok { return "" } @@ -140,7 +150,7 @@ func ParseProject(ctx context.Context) string { } func ParseTargetProject(ctx context.Context) string { - v, _ := FromContext(ctx, "target-project").(string) + v, _ := FromContext(ctx, CtxTargetProject).(string) if len(v) == 0 { return ParseProject(ctx) } @@ -148,19 +158,19 @@ func ParseTargetProject(ctx context.Context) string { } func SetDomain(ctx context.Context, domain string) context.Context { - return SetContext(ctx, "domain", domain) + return SetContext(ctx, CtxDomain, domain) } func SetProject(ctx context.Context, project string) context.Context { - return SetContext(ctx, "project", project) + return SetContext(ctx, CtxProject, project) } func SetTargetDomain(ctx context.Context, domain string) context.Context { - return SetContext(ctx, "target-domain", domain) + return SetContext(ctx, CtxTargetDomain, domain) } func SetTargetProject(ctx context.Context, project string) context.Context { - return SetContext(ctx, "target-project", project) + return SetContext(ctx, CtxTargetProject, project) } func SetDomainProject(ctx context.Context, domain string, project string) context.Context { diff --git a/pkg/util/context_grpc.go b/pkg/util/context_grpc.go new file mode 100644 index 000..d2badb6 --- /dev/null +++ b/pkg/util/context_grpc.go @@ -0,0 +1,32 @@ +// 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 +// +//
[GitHub] asifdxtreme closed pull request #476: SCB-994 SC can not read the context when client using grpc api
asifdxtreme closed pull request #476: SCB-994 SC can not read the context when client using grpc api URL: https://github.com/apache/incubator-servicecomb-service-center/pull/476 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/pkg/util/context.go b/pkg/util/context.go index 79fb515e..838d4a6d 100644 --- a/pkg/util/context.go +++ b/pkg/util/context.go @@ -22,6 +22,13 @@ import ( "time" ) +const ( + CtxDomain= "domain" + CtxProject = "project" + CtxTargetDomain = "target-domain" + CtxTargetProject = "target-project" +) + type StringContext struct { parentCtx context.Context kv*ConcurrentMap @@ -46,7 +53,7 @@ func (c *StringContext) Value(key interface{}) interface{} { } v, ok := c.kv.Get(k) if !ok { - return c.parentCtx.Value(key) + return FromContext(c.parentCtx, k) } return v } @@ -94,7 +101,10 @@ func CloneContext(ctx context.Context) context.Context { } func FromContext(ctx context.Context, key string) interface{} { - return ctx.Value(key) + if v := ctx.Value(key); v != nil { + return v + } + return FromMetadata(ctx, key) } func SetRequestContext(r *http.Request, key string, val interface{}) *http.Request { @@ -116,7 +126,7 @@ func ParseTargetDomainProject(ctx context.Context) string { } func ParseDomain(ctx context.Context) string { - v, ok := FromContext(ctx, "domain").(string) + v, ok := FromContext(ctx, CtxDomain).(string) if !ok { return "" } @@ -124,7 +134,7 @@ func ParseDomain(ctx context.Context) string { } func ParseTargetDomain(ctx context.Context) string { - v, _ := FromContext(ctx, "target-domain").(string) + v, _ := FromContext(ctx, CtxTargetDomain).(string) if len(v) == 0 { return ParseDomain(ctx) } @@ -132,7 +142,7 @@ func ParseTargetDomain(ctx context.Context) string { } func ParseProject(ctx context.Context) string { - v, ok := FromContext(ctx, "project").(string) + v, ok := FromContext(ctx, CtxProject).(string) if !ok { return "" } @@ -140,7 +150,7 @@ func ParseProject(ctx context.Context) string { } func ParseTargetProject(ctx context.Context) string { - v, _ := FromContext(ctx, "target-project").(string) + v, _ := FromContext(ctx, CtxTargetProject).(string) if len(v) == 0 { return ParseProject(ctx) } @@ -148,19 +158,19 @@ func ParseTargetProject(ctx context.Context) string { } func SetDomain(ctx context.Context, domain string) context.Context { - return SetContext(ctx, "domain", domain) + return SetContext(ctx, CtxDomain, domain) } func SetProject(ctx context.Context, project string) context.Context { - return SetContext(ctx, "project", project) + return SetContext(ctx, CtxProject, project) } func SetTargetDomain(ctx context.Context, domain string) context.Context { - return SetContext(ctx, "target-domain", domain) + return SetContext(ctx, CtxTargetDomain, domain) } func SetTargetProject(ctx context.Context, project string) context.Context { - return SetContext(ctx, "target-project", project) + return SetContext(ctx, CtxTargetProject, project) } func SetDomainProject(ctx context.Context, domain string, project string) context.Context { diff --git a/pkg/util/context_grpc.go b/pkg/util/context_grpc.go new file mode 100644 index ..d2badb66 --- /dev/null +++ b/pkg/util/context_grpc.go @@ -0,0 +1,32 @@ +// 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 util + +import ( + "golang.org/x/net/context" + "google.golang.org/grpc/metadata" +) + +func FromMetadata(ctx context.Context, key string) string { + md, ok := metadata.FromIncomingContext(ctx) + if !ok { + return "" + } + if values, ok := md[key];
[incubator-servicecomb-service-center] branch master updated: SCB-977 Dependencies will not be updated in 5min when re-create provider service (#478)
This is an automated email from the ASF dual-hosted git repository. asifdxtreme pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/incubator-servicecomb-service-center.git The following commit(s) were added to refs/heads/master by this push: new 7f9cdb7 SCB-977 Dependencies will not be updated in 5min when re-create provider service (#478) 7f9cdb7 is described below commit 7f9cdb72cc949a26cf1b62a1fd620e910924749f Author: little-cui AuthorDate: Sat Nov 3 00:18:24 2018 +0800 SCB-977 Dependencies will not be updated in 5min when re-create provider service (#478) --- .../service/event/dependency_rule_event_handler.go | 51 + .../event/dependency_rule_event_handler_test.go| 64 ++ server/service/event/event.go | 1 + server/service/event/instance_event_handler.go | 13 +++-- server/service/event/rule_event_handler.go | 7 ++- server/service/event/service_event_handler.go | 5 +- server/service/event/tag_event_handler.go | 10 ++-- 7 files changed, 136 insertions(+), 15 deletions(-) diff --git a/server/service/event/dependency_rule_event_handler.go b/server/service/event/dependency_rule_event_handler.go new file mode 100644 index 000..3befe09 --- /dev/null +++ b/server/service/event/dependency_rule_event_handler.go @@ -0,0 +1,51 @@ +/* + * 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 event + +import ( + "github.com/apache/incubator-servicecomb-service-center/pkg/log" + "github.com/apache/incubator-servicecomb-service-center/server/core" + "github.com/apache/incubator-servicecomb-service-center/server/core/backend" + pb "github.com/apache/incubator-servicecomb-service-center/server/core/proto" + "github.com/apache/incubator-servicecomb-service-center/server/plugin/pkg/discovery" + "github.com/apache/incubator-servicecomb-service-center/server/service/cache" +) + +type DependencyRuleEventHandler struct { +} + +func (h *DependencyRuleEventHandler) Type() discovery.Type { + return backend.DEPENDENCY_RULE +} + +func (h *DependencyRuleEventHandler) OnEvent(evt discovery.KvEvent) { + action := evt.Type + if action != pb.EVT_UPDATE && action != pb.EVT_DELETE { + return + } + t, providerKey := core.GetInfoFromDependencyRuleKV(evt.KV.Key) + if t != core.DEPS_PROVIDER { + return + } + log.Debugf("caught [%s] provider rule[%s/%s/%s/%s] event", + action, providerKey.Environment, providerKey.AppId, providerKey.ServiceName, providerKey.Version) + cache.DependencyRule.Remove(providerKey) +} + +func NewDependencyRuleEventHandler() *DependencyRuleEventHandler { + return {} +} diff --git a/server/service/event/dependency_rule_event_handler_test.go b/server/service/event/dependency_rule_event_handler_test.go new file mode 100644 index 000..9a4ec3b --- /dev/null +++ b/server/service/event/dependency_rule_event_handler_test.go @@ -0,0 +1,64 @@ +/* + * 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 event + +import ( + "github.com/apache/incubator-servicecomb-service-center/server/core" + pb "github.com/apache/incubator-servicecomb-service-center/server/core/proto" + "github.com/apache/incubator-servicecomb-service-center/server/plugin/pkg/discovery" +
[GitHub] asifdxtreme closed pull request #478: SCB-977 Dependencies will not be updated in 5min when re-create provider service
asifdxtreme closed pull request #478: SCB-977 Dependencies will not be updated in 5min when re-create provider service URL: https://github.com/apache/incubator-servicecomb-service-center/pull/478 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/service/event/dependency_rule_event_handler.go b/server/service/event/dependency_rule_event_handler.go new file mode 100644 index ..3befe092 --- /dev/null +++ b/server/service/event/dependency_rule_event_handler.go @@ -0,0 +1,51 @@ +/* + * 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 event + +import ( + "github.com/apache/incubator-servicecomb-service-center/pkg/log" + "github.com/apache/incubator-servicecomb-service-center/server/core" + "github.com/apache/incubator-servicecomb-service-center/server/core/backend" + pb "github.com/apache/incubator-servicecomb-service-center/server/core/proto" + "github.com/apache/incubator-servicecomb-service-center/server/plugin/pkg/discovery" + "github.com/apache/incubator-servicecomb-service-center/server/service/cache" +) + +type DependencyRuleEventHandler struct { +} + +func (h *DependencyRuleEventHandler) Type() discovery.Type { + return backend.DEPENDENCY_RULE +} + +func (h *DependencyRuleEventHandler) OnEvent(evt discovery.KvEvent) { + action := evt.Type + if action != pb.EVT_UPDATE && action != pb.EVT_DELETE { + return + } + t, providerKey := core.GetInfoFromDependencyRuleKV(evt.KV.Key) + if t != core.DEPS_PROVIDER { + return + } + log.Debugf("caught [%s] provider rule[%s/%s/%s/%s] event", + action, providerKey.Environment, providerKey.AppId, providerKey.ServiceName, providerKey.Version) + cache.DependencyRule.Remove(providerKey) +} + +func NewDependencyRuleEventHandler() *DependencyRuleEventHandler { + return {} +} diff --git a/server/service/event/dependency_rule_event_handler_test.go b/server/service/event/dependency_rule_event_handler_test.go new file mode 100644 index ..9a4ec3b5 --- /dev/null +++ b/server/service/event/dependency_rule_event_handler_test.go @@ -0,0 +1,64 @@ +/* + * 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 event + +import ( + "github.com/apache/incubator-servicecomb-service-center/server/core" + pb "github.com/apache/incubator-servicecomb-service-center/server/core/proto" + "github.com/apache/incubator-servicecomb-service-center/server/plugin/pkg/discovery" + "github.com/apache/incubator-servicecomb-service-center/server/service/cache" + "golang.org/x/net/context" + "testing" +) + +func TestNewDependencyRuleEventHandler(t *testing.T) { + consumerId := "1" + provider := {Tenant: "x/y", Version: "0+"} + b := cache.DependencyRule.ExistVersionRule(context.Background(), consumerId, provider) + if b { + t.Fatalf("TestNewDependencyRuleEventHandler failed") + } + h := NewDependencyRuleEventHandler() + h.OnEvent(discovery.KvEvent{Type: pb.EVT_CREATE}) + b = cache.DependencyRule.ExistVersionRule(context.Background(), consumerId, provider) + if !b { +
[GitHub] asifdxtreme closed pull request #479: SCB-988 Add loadbalancer in sc client
asifdxtreme closed pull request #479: SCB-988 Add loadbalancer in sc client URL: https://github.com/apache/incubator-servicecomb-service-center/pull/479 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/pkg/client/sc/apis.go b/pkg/client/sc/apis.go index 63e96e7e..2947297f 100644 --- a/pkg/client/sc/apis.go +++ b/pkg/client/sc/apis.go @@ -47,16 +47,8 @@ func (c *SCClient) toError(body []byte) *scerr.Error { return message } -func (c *SCClient) commonHeaders() http.Header { - var headers = make(http.Header) - if len(c.Config.Token) > 0 { - headers.Set("X-Auth-Token", c.Config.Token) - } - return headers -} - func (c *SCClient) GetScVersion() (*version.VersionSet, *scerr.Error) { - resp, err := c.URLClient.HttpDo(http.MethodGet, c.Config.Addr+apiVersionURL, c.commonHeaders(), nil) + resp, err := c.RestDo(http.MethodGet, apiVersionURL, c.CommonHeaders(), nil) if err != nil { return nil, scerr.NewError(scerr.ErrInternal, err.Error()) } @@ -82,10 +74,10 @@ func (c *SCClient) GetScVersion() (*version.VersionSet, *scerr.Error) { } func (c *SCClient) GetScCache() (*model.Cache, *scerr.Error) { - headers := c.commonHeaders() + headers := c.CommonHeaders() // only default domain has admin permission headers.Set("X-Domain-Name", "default") - resp, err := c.URLClient.HttpDo(http.MethodGet, c.Config.Addr+apiDumpURL, headers, nil) + resp, err := c.RestDo(http.MethodGet, apiDumpURL, headers, nil) if err != nil { return nil, scerr.NewError(scerr.ErrInternal, err.Error()) } @@ -112,10 +104,10 @@ func (c *SCClient) GetScCache() (*model.Cache, *scerr.Error) { func (c *SCClient) GetSchemasByServiceId(domainProject, serviceId string) ([]*pb.Schema, *scerr.Error) { domain, project := core.FromDomainProject(domainProject) - headers := c.commonHeaders() + headers := c.CommonHeaders() headers.Set("X-Domain-Name", domain) - resp, err := c.URLClient.HttpDo(http.MethodGet, - c.Config.Addr+fmt.Sprintf(apiSchemasURL, project, serviceId)+"?withSchema=1", + resp, err := c.RestDo(http.MethodGet, + fmt.Sprintf(apiSchemasURL, project, serviceId)+"?withSchema=1", headers, nil) if err != nil { return nil, scerr.NewError(scerr.ErrInternal, err.Error()) @@ -143,10 +135,10 @@ func (c *SCClient) GetSchemasByServiceId(domainProject, serviceId string) ([]*pb func (c *SCClient) GetSchemaBySchemaId(domainProject, serviceId, schemaId string) (*pb.Schema, *scerr.Error) { domain, project := core.FromDomainProject(domainProject) - headers := c.commonHeaders() + headers := c.CommonHeaders() headers.Set("X-Domain-Name", domain) - resp, err := c.URLClient.HttpDo(http.MethodGet, - c.Config.Addr+fmt.Sprintf(apiSchemaURL, project, serviceId, schemaId), + resp, err := c.RestDo(http.MethodGet, + fmt.Sprintf(apiSchemaURL, project, serviceId, schemaId), headers, nil) if err != nil { return nil, scerr.NewError(scerr.ErrInternal, err.Error()) @@ -177,10 +169,10 @@ func (c *SCClient) GetSchemaBySchemaId(domainProject, serviceId, schemaId string } func (c *SCClient) GetClusters() (registry.Clusters, *scerr.Error) { - headers := c.commonHeaders() + headers := c.CommonHeaders() // only default domain has admin permission headers.Set("X-Domain-Name", "default") - resp, err := c.URLClient.HttpDo(http.MethodGet, c.Config.Addr+apiClustersURL, headers, nil) + resp, err := c.RestDo(http.MethodGet, apiClustersURL, headers, nil) if err != nil { return nil, scerr.NewError(scerr.ErrInternal, err.Error()) } @@ -206,10 +198,10 @@ func (c *SCClient) GetClusters() (registry.Clusters, *scerr.Error) { } func (c *SCClient) HealthCheck() *scerr.Error { - headers := c.commonHeaders() + headers := c.CommonHeaders() // only default domain has admin permission headers.Set("X-Domain-Name", "default") - resp, err := c.URLClient.HttpDo(http.MethodGet, c.Config.Addr+apiHealthURL, headers, nil) + resp, err := c.RestDo(http.MethodGet, apiHealthURL, headers, nil) if err != nil { return scerr.NewError(scerr.ErrUnavailableBackend, err.Error()) } diff --git a/pkg/client/sc/client.go b/pkg/client/sc/client.go index 0d95dcd5..38ab11bd 100644 --- a/pkg/client/sc/client.go +++ b/pkg/client/sc/client.go @@ -16,18 +16,26 @@ package sc import ( - "github.com/apache/incubator-servicecomb-service-center/pkg/rest" +
[incubator-servicecomb-service-center] branch master updated: SCB-988 Add loadbalancer in sc client (#479)
This is an automated email from the ASF dual-hosted git repository. asifdxtreme pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/incubator-servicecomb-service-center.git The following commit(s) were added to refs/heads/master by this push: new dc76a75 SCB-988 Add loadbalancer in sc client (#479) dc76a75 is described below commit dc76a7515fa4518b3bf2a75327661e1bb97fa3c4 Author: little-cui AuthorDate: Sat Nov 3 00:16:48 2018 +0800 SCB-988 Add loadbalancer in sc client (#479) --- pkg/client/sc/apis.go | 34 ++ pkg/client/sc/client.go| 18 ++-- pkg/client/sc/{client.go => client_lb.go} | 34 -- pkg/client/sc/config.go| 4 +- pkg/{client/sc/client.go => lb/loadbalancer.go}| 19 ++-- .../sc/config.go => lb/loadbalancer_test.go} | 53 +- pkg/{client/sc/client.go => lb/roundrobin.go} | 38 +++- pkg/rest/client.go | 10 ++-- scctl/pkg/cmd/cmd.go | 4 +- .../pkg/discovery/servicecenter/aggregate.go | 16 +++ 10 files changed, 130 insertions(+), 100 deletions(-) diff --git a/pkg/client/sc/apis.go b/pkg/client/sc/apis.go index 63e96e7..2947297 100644 --- a/pkg/client/sc/apis.go +++ b/pkg/client/sc/apis.go @@ -47,16 +47,8 @@ func (c *SCClient) toError(body []byte) *scerr.Error { return message } -func (c *SCClient) commonHeaders() http.Header { - var headers = make(http.Header) - if len(c.Config.Token) > 0 { - headers.Set("X-Auth-Token", c.Config.Token) - } - return headers -} - func (c *SCClient) GetScVersion() (*version.VersionSet, *scerr.Error) { - resp, err := c.URLClient.HttpDo(http.MethodGet, c.Config.Addr+apiVersionURL, c.commonHeaders(), nil) + resp, err := c.RestDo(http.MethodGet, apiVersionURL, c.CommonHeaders(), nil) if err != nil { return nil, scerr.NewError(scerr.ErrInternal, err.Error()) } @@ -82,10 +74,10 @@ func (c *SCClient) GetScVersion() (*version.VersionSet, *scerr.Error) { } func (c *SCClient) GetScCache() (*model.Cache, *scerr.Error) { - headers := c.commonHeaders() + headers := c.CommonHeaders() // only default domain has admin permission headers.Set("X-Domain-Name", "default") - resp, err := c.URLClient.HttpDo(http.MethodGet, c.Config.Addr+apiDumpURL, headers, nil) + resp, err := c.RestDo(http.MethodGet, apiDumpURL, headers, nil) if err != nil { return nil, scerr.NewError(scerr.ErrInternal, err.Error()) } @@ -112,10 +104,10 @@ func (c *SCClient) GetScCache() (*model.Cache, *scerr.Error) { func (c *SCClient) GetSchemasByServiceId(domainProject, serviceId string) ([]*pb.Schema, *scerr.Error) { domain, project := core.FromDomainProject(domainProject) - headers := c.commonHeaders() + headers := c.CommonHeaders() headers.Set("X-Domain-Name", domain) - resp, err := c.URLClient.HttpDo(http.MethodGet, - c.Config.Addr+fmt.Sprintf(apiSchemasURL, project, serviceId)+"?withSchema=1", + resp, err := c.RestDo(http.MethodGet, + fmt.Sprintf(apiSchemasURL, project, serviceId)+"?withSchema=1", headers, nil) if err != nil { return nil, scerr.NewError(scerr.ErrInternal, err.Error()) @@ -143,10 +135,10 @@ func (c *SCClient) GetSchemasByServiceId(domainProject, serviceId string) ([]*pb func (c *SCClient) GetSchemaBySchemaId(domainProject, serviceId, schemaId string) (*pb.Schema, *scerr.Error) { domain, project := core.FromDomainProject(domainProject) - headers := c.commonHeaders() + headers := c.CommonHeaders() headers.Set("X-Domain-Name", domain) - resp, err := c.URLClient.HttpDo(http.MethodGet, - c.Config.Addr+fmt.Sprintf(apiSchemaURL, project, serviceId, schemaId), + resp, err := c.RestDo(http.MethodGet, + fmt.Sprintf(apiSchemaURL, project, serviceId, schemaId), headers, nil) if err != nil { return nil, scerr.NewError(scerr.ErrInternal, err.Error()) @@ -177,10 +169,10 @@ func (c *SCClient) GetSchemaBySchemaId(domainProject, serviceId, schemaId string } func (c *SCClient) GetClusters() (registry.Clusters, *scerr.Error) { - headers := c.commonHeaders() + headers := c.CommonHeaders() // only default domain has admin permission headers.Set("X-Domain-Name", "default") - resp, err := c.URLClient.HttpDo(http.MethodGet, c.Config.Addr+apiClustersURL, headers, nil) + resp, err := c.RestDo(http.MethodGet, apiClustersURL, headers, nil) if err != nil { return nil, scerr.NewError(scerr.ErrInternal, err.Error()) } @@ -206,10 +198,10 @@ func (c *SCClient)
[incubator-servicecomb-website] branch asf-site updated (f654f02 -> 1beae1f)
This is an automated email from the ASF dual-hosted git repository. ningjiang pushed a change to branch asf-site in repository https://gitbox.apache.org/repos/asf/incubator-servicecomb-website.git. from f654f02 Publish the website add 1c5ea73 Update OSI Report Blog add 3f4dccd Add images for hybrid demo article. add 3d1b820 Add the blog 'load test saga with kubernetes' new 6165237 Merge branch 'master' into asf-site new 1beae1f Publish the website The 2 revisions listed above as "new" are entirely new to this repository and will be described in separate emails. The revisions listed as "add" were already present in the repository and have only been added to this reference. Summary of changes: .../cn/2018-09-11-loadtest-saga-with-kubernetes.md | 160 _posts/cn/2018-10-15-OSI-Workshop-Report.md| 2 +- assets/images/OSI/OSI-Tracks.png | Bin 165029 -> 0 bytes assets/images/OSI/Patners.png | Bin 116394 -> 0 bytes assets/images/OSI/Speakers.jpg | Bin 2886295 -> 0 bytes assets/images/hybrid-arch.jpg | Bin 0 -> 22772 bytes assets/images/hybrid-consumer-result.png | Bin 0 -> 13916 bytes assets/images/hybrid-mesher-process.jpg| Bin 0 -> 17217 bytes assets/images/hybrid-servicecenter-result.png | Bin 0 -> 49970 bytes assets/images/hybrid-sidecar-injector.jpg | Bin 0 -> 19811 bytes assets/images/jmeter-collector.png | Bin 0 -> 55774 bytes assets/images/spring-demo.jpg | Bin 0 -> 25204 bytes content/assets/images/OSI/OSI-Tracks.png | Bin 165029 -> 0 bytes content/assets/images/OSI/Patners.png | Bin 116394 -> 0 bytes content/assets/images/OSI/Speakers.jpg | Bin 2886295 -> 0 bytes content/assets/images/hybrid-arch.jpg | Bin 0 -> 22772 bytes content/assets/images/hybrid-consumer-result.png | Bin 0 -> 13916 bytes content/assets/images/hybrid-mesher-process.jpg| Bin 0 -> 17217 bytes .../assets/images/hybrid-servicecenter-result.png | Bin 0 -> 49970 bytes content/assets/images/hybrid-sidecar-injector.jpg | Bin 0 -> 19811 bytes content/assets/images/jmeter-collector.png | Bin 0 -> 55774 bytes content/assets/images/spring-demo.jpg | Bin 0 -> 25204 bytes .../index.html | 6 +- content/cn/docs/crm-part-I/index.html | 2 +- ...dex.html => loadtest-saga-with-kubernetes.html} | 269 +++-- content/cn/docs/osi-microservices/index.html | 131 +- content/cn/year-archive/index.html | 237 ++ .../index.html | 8 +- content/docs/osi-microservices/index.html | 6 +- content/feed.xml | 190 ++- content/sitemap.xml| 4 + content/sitemap/index.html | 4 +- content/year-archive/index.html| 101 33 files changed, 755 insertions(+), 365 deletions(-) create mode 100644 _posts/cn/2018-09-11-loadtest-saga-with-kubernetes.md delete mode 100644 assets/images/OSI/OSI-Tracks.png delete mode 100644 assets/images/OSI/Patners.png delete mode 100644 assets/images/OSI/Speakers.jpg create mode 100644 assets/images/hybrid-arch.jpg create mode 100644 assets/images/hybrid-consumer-result.png create mode 100644 assets/images/hybrid-mesher-process.jpg create mode 100644 assets/images/hybrid-servicecenter-result.png create mode 100644 assets/images/hybrid-sidecar-injector.jpg create mode 100644 assets/images/jmeter-collector.png create mode 100644 assets/images/spring-demo.jpg delete mode 100644 content/assets/images/OSI/OSI-Tracks.png delete mode 100644 content/assets/images/OSI/Patners.png delete mode 100644 content/assets/images/OSI/Speakers.jpg create mode 100644 content/assets/images/hybrid-arch.jpg create mode 100644 content/assets/images/hybrid-consumer-result.png create mode 100644 content/assets/images/hybrid-mesher-process.jpg create mode 100644 content/assets/images/hybrid-servicecenter-result.png create mode 100644 content/assets/images/hybrid-sidecar-injector.jpg create mode 100644 content/assets/images/jmeter-collector.png create mode 100644 content/assets/images/spring-demo.jpg copy content/cn/docs/{performance-test-on-seckill-with-jmeter/index.html => loadtest-saga-with-kubernetes.html} (57%)
[incubator-servicecomb-website] 02/02: Publish the website
This is an automated email from the ASF dual-hosted git repository. ningjiang pushed a commit to branch asf-site in repository https://gitbox.apache.org/repos/asf/incubator-servicecomb-website.git commit 1beae1f594b12e969a08113e0773ce1b7d745083 Author: Willem Jiang AuthorDate: Fri Nov 2 18:17:19 2018 +0800 Publish the website --- content/assets/images/OSI/OSI-Tracks.png | Bin 165029 -> 0 bytes content/assets/images/OSI/Patners.png | Bin 116394 -> 0 bytes content/assets/images/OSI/Speakers.jpg | Bin 2886295 -> 0 bytes content/assets/images/hybrid-arch.jpg | Bin 0 -> 22772 bytes content/assets/images/hybrid-consumer-result.png | Bin 0 -> 13916 bytes content/assets/images/hybrid-mesher-process.jpg| Bin 0 -> 17217 bytes .../assets/images/hybrid-servicecenter-result.png | Bin 0 -> 49970 bytes content/assets/images/hybrid-sidecar-injector.jpg | Bin 0 -> 19811 bytes content/assets/images/jmeter-collector.png | Bin 0 -> 55774 bytes content/assets/images/spring-demo.jpg | Bin 0 -> 25204 bytes .../index.html | 6 +- content/cn/docs/crm-part-I/index.html | 2 +- ...dex.html => loadtest-saga-with-kubernetes.html} | 249 - content/cn/docs/osi-microservices/index.html | 131 +-- content/cn/year-archive/index.html | 237 .../index.html | 8 +- content/docs/osi-microservices/index.html | 6 +- content/feed.xml | 190 +++- content/sitemap.xml| 4 + content/sitemap/index.html | 4 +- content/year-archive/index.html| 101 - 21 files changed, 601 insertions(+), 337 deletions(-) diff --git a/content/assets/images/OSI/OSI-Tracks.png b/content/assets/images/OSI/OSI-Tracks.png deleted file mode 100644 index db6eefc..000 Binary files a/content/assets/images/OSI/OSI-Tracks.png and /dev/null differ diff --git a/content/assets/images/OSI/Patners.png b/content/assets/images/OSI/Patners.png deleted file mode 100644 index d931c65..000 Binary files a/content/assets/images/OSI/Patners.png and /dev/null differ diff --git a/content/assets/images/OSI/Speakers.jpg b/content/assets/images/OSI/Speakers.jpg deleted file mode 100644 index 9e328a7..000 Binary files a/content/assets/images/OSI/Speakers.jpg and /dev/null differ diff --git a/content/assets/images/hybrid-arch.jpg b/content/assets/images/hybrid-arch.jpg new file mode 100644 index 000..95df0ae Binary files /dev/null and b/content/assets/images/hybrid-arch.jpg differ diff --git a/content/assets/images/hybrid-consumer-result.png b/content/assets/images/hybrid-consumer-result.png new file mode 100644 index 000..085f7ca Binary files /dev/null and b/content/assets/images/hybrid-consumer-result.png differ diff --git a/content/assets/images/hybrid-mesher-process.jpg b/content/assets/images/hybrid-mesher-process.jpg new file mode 100644 index 000..977b45c Binary files /dev/null and b/content/assets/images/hybrid-mesher-process.jpg differ diff --git a/content/assets/images/hybrid-servicecenter-result.png b/content/assets/images/hybrid-servicecenter-result.png new file mode 100644 index 000..d020b9e Binary files /dev/null and b/content/assets/images/hybrid-servicecenter-result.png differ diff --git a/content/assets/images/hybrid-sidecar-injector.jpg b/content/assets/images/hybrid-sidecar-injector.jpg new file mode 100644 index 000..fb41c63 Binary files /dev/null and b/content/assets/images/hybrid-sidecar-injector.jpg differ diff --git a/content/assets/images/jmeter-collector.png b/content/assets/images/jmeter-collector.png new file mode 100644 index 000..1b1f7e0 Binary files /dev/null and b/content/assets/images/jmeter-collector.png differ diff --git a/content/assets/images/spring-demo.jpg b/content/assets/images/spring-demo.jpg new file mode 100644 index 000..e590530 Binary files /dev/null and b/content/assets/images/spring-demo.jpg differ diff --git a/content/cn/docs/Apache-ServiceComb-Meetup-2018-Shanghai/index.html b/content/cn/docs/Apache-ServiceComb-Meetup-2018-Shanghai/index.html index deb6690..7eda5a6 100644 --- a/content/cn/docs/Apache-ServiceComb-Meetup-2018-Shanghai/index.html +++ b/content/cn/docs/Apache-ServiceComb-Meetup-2018-Shanghai/index.html @@ -701,11 +701,11 @@ -客户管理系统微服务化实战-PartI +使用Kubernetes对Saga进行压力测试 -客户管理系统微服务化实战-PartI +如何使用Kubernetes方便的对Saga进行性能测试 @@ -713,7 +713,7 @@ - 5 分钟 阅读 + 1 分钟 阅读 diff --git a/content/cn/docs/crm-part-I/index.html b/content/cn/docs/crm-part-I/index.html index 5bf8a6a..1af5fd6 100644 --- a/content/cn/docs/crm-part-I/index.html +++ b/content/cn/docs/crm-part-I/index.html @@ -1253,7 +1253,7 @@ ">向前
[incubator-servicecomb-website] 01/02: Merge branch 'master' into asf-site
This is an automated email from the ASF dual-hosted git repository. ningjiang pushed a commit to branch asf-site in repository https://gitbox.apache.org/repos/asf/incubator-servicecomb-website.git commit 6165237f7629c6e2490af912df8d152658fa1de6 Merge: f654f02 3d1b820 Author: Willem Jiang AuthorDate: Fri Nov 2 18:16:23 2018 +0800 Merge branch 'master' into asf-site .../cn/2018-09-11-loadtest-saga-with-kubernetes.md | 160 + _posts/cn/2018-10-15-OSI-Workshop-Report.md| 2 +- assets/images/OSI/OSI-Tracks.png | Bin 165029 -> 0 bytes assets/images/OSI/Patners.png | Bin 116394 -> 0 bytes assets/images/OSI/Speakers.jpg | Bin 2886295 -> 0 bytes assets/images/hybrid-arch.jpg | Bin 0 -> 22772 bytes assets/images/hybrid-consumer-result.png | Bin 0 -> 13916 bytes assets/images/hybrid-mesher-process.jpg| Bin 0 -> 17217 bytes assets/images/hybrid-servicecenter-result.png | Bin 0 -> 49970 bytes assets/images/hybrid-sidecar-injector.jpg | Bin 0 -> 19811 bytes assets/images/jmeter-collector.png | Bin 0 -> 55774 bytes assets/images/spring-demo.jpg | Bin 0 -> 25204 bytes 12 files changed, 161 insertions(+), 1 deletion(-)
[incubator-servicecomb-website] 01/02: Add images for hybrid demo article.
This is an automated email from the ASF dual-hosted git repository. ningjiang pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/incubator-servicecomb-website.git commit 3f4dccd9031651c5847ed90060e1275ee0abf7d4 Author: Zhen Ju AuthorDate: Tue Sep 25 11:01:12 2018 +0800 Add images for hybrid demo article. --- assets/images/hybrid-arch.jpg | Bin 0 -> 22772 bytes assets/images/hybrid-consumer-result.png | Bin 0 -> 13916 bytes assets/images/hybrid-mesher-process.jpg | Bin 0 -> 17217 bytes assets/images/hybrid-servicecenter-result.png | Bin 0 -> 49970 bytes assets/images/hybrid-sidecar-injector.jpg | Bin 0 -> 19811 bytes 5 files changed, 0 insertions(+), 0 deletions(-) diff --git a/assets/images/hybrid-arch.jpg b/assets/images/hybrid-arch.jpg new file mode 100644 index 000..95df0ae Binary files /dev/null and b/assets/images/hybrid-arch.jpg differ diff --git a/assets/images/hybrid-consumer-result.png b/assets/images/hybrid-consumer-result.png new file mode 100644 index 000..085f7ca Binary files /dev/null and b/assets/images/hybrid-consumer-result.png differ diff --git a/assets/images/hybrid-mesher-process.jpg b/assets/images/hybrid-mesher-process.jpg new file mode 100644 index 000..977b45c Binary files /dev/null and b/assets/images/hybrid-mesher-process.jpg differ diff --git a/assets/images/hybrid-servicecenter-result.png b/assets/images/hybrid-servicecenter-result.png new file mode 100644 index 000..d020b9e Binary files /dev/null and b/assets/images/hybrid-servicecenter-result.png differ diff --git a/assets/images/hybrid-sidecar-injector.jpg b/assets/images/hybrid-sidecar-injector.jpg new file mode 100644 index 000..fb41c63 Binary files /dev/null and b/assets/images/hybrid-sidecar-injector.jpg differ
[incubator-servicecomb-website] 02/02: Add the blog 'load test saga with kubernetes'
This is an automated email from the ASF dual-hosted git repository. ningjiang pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/incubator-servicecomb-website.git commit 3d1b8207d5c01d5480ea0c4636d6380f6fd256df Author: Zhen Ju AuthorDate: Tue Sep 25 19:50:48 2018 +0800 Add the blog 'load test saga with kubernetes' --- .../cn/2018-09-11-loadtest-saga-with-kubernetes.md | 160 + assets/images/jmeter-collector.png | Bin 0 -> 55774 bytes assets/images/spring-demo.jpg | Bin 0 -> 25204 bytes 3 files changed, 160 insertions(+) diff --git a/_posts/cn/2018-09-11-loadtest-saga-with-kubernetes.md b/_posts/cn/2018-09-11-loadtest-saga-with-kubernetes.md new file mode 100644 index 000..2e8395b --- /dev/null +++ b/_posts/cn/2018-09-11-loadtest-saga-with-kubernetes.md @@ -0,0 +1,160 @@ +--- +title: "使用Kubernetes对Saga进行压力测试" +lang: cn +ref: loadtest-saga-with-kubernetes +permalink: /cn/docs/loadtest-saga-with-kubernetes +excerpt: "如何使用Kubernetes方便的对Saga进行性能测试" +last_modified_at: 2018-09-11T10:26:28+08:00 +author: Zhen Ju +tags: [microservice, servicemesh, saga] +redirect_from: + - /theme-setup/ +--- + +## 使用Kubernetes对Saga进行压力测试 + +Apache ServiceComb (incubating) Saga 是一个微服务应用的数据最终一致性解决方案。Saga在try阶段直接提交事务,后续rollback阶段则通过反向的补偿操作来完成。 + +基于ServiceComb Saga的项目,基本的构架如下: + +![overview](https://raw.githubusercontent.com/apache/incubator-servicecomb-saga/master/docs/static_files/pack.png) + +在我们的Saga实现中,业务服务引入Omega库,通过Omega将事务相关信息作为事件发送给Alpha server,由Alpha server统一进行协调。Alpha server将事务保存在PostgreSQL中,后台定期进行扫描。当扫描到异常事件时,尝试向事件对应的Omega发送gRPC请求,调用补偿方法。由于在原生业务中加入了Omega,进行了一系列后台操作,因此需要对整个框架进行压力测试,以获取框架的基础性能报告。 + +在Cloud Native时代,容器几乎是标准的部署形态,应用程序容器化之后,通过Kubernetes进行容器编排,可以轻松的实现弹性扩容、任务调度等,非常适合对该项目进行压力测试。有鉴于此,我们将demo项目构建成docker镜像,并部署到Kubernetes集群中,通过Kubernetes的一系列组件,对demo方便的进行压力测试,以对Saga项目的性能有一个初步的评估。 + + + + + +### "Kubernetize"服务 + +我们的demo项目由Java编写、maven作为依赖管理工具,在项目中引入了fabric8插件,编译程序时可以顺便将jar包构建成docker镜像。首先,我们构建alpha-server镜像: + +```bash +$ cd alpha/alpha-server +$ mvn clean install -Pdocker +``` + +然后进入demo项目路径`saga-demo/saga-spring-demo`,执行相同的maven构建命令,构建完成后,我们可以看到产生了4个相关镜像: + +```bash +$ docker images | grep SNAPHOST # {version}-SNAPSHOT是构建过程中使用的镜像标签 +alpha-server:0.3.0-SNAPSHOT +booking:0.3.0-SNAPSHOT +car:0.3.0-SNAPSHOT +hotel:0.3.0-SNAPSHOT +``` + +至此,我们已经构建好所需镜像,下一步便是编写Kubernetes所需的资源文件,这一步我们不再赘述,项目中已经有写好的yaml文件,路径在`saga-demo/saga-k8s-resources`,目录结构如下: + +```base +. +├── base +│ ├── alpha.yaml +│ ├── jmeter-collector.yaml +│ └── postgresql.yaml +├── README.md +└── spring-demo +├── booking.yaml +├── car.yaml +├── hotel.yaml +└── test +├── jmeter.configmap.yaml +└── jmeter.yaml +``` + +其中`base`目录包含了alpha-server,postgresql以及用于收集测试报告的jmeter-collector3个服务。`spring-demo`目录包含了demo项目的所有服务,`spring-demo/test`路径下包含了对demo测试所需的服务。 + + + +我们通过最基础的deployment和service对项目进行部署,程序之间通过域名互相访问,通过`kubectl`命令对Kubernetes资源进行部署: + +```bash +$ kubectl create ns servicecomb # 默认所有服务都在servicecomb namespace下 +$ kubectl apply -f ./base +$ kubectl apply -f ./spring-demo +``` + +我们通过`kubectl exec`命令进入一个pod,通过curl命令测试booking程序: + +```bash +$ kubectl exec -it -n servicecomb alpha-server-x +$ curl http://booking.servicecomb:8083/booking/test/2/2 +resp: OK +``` + +至此,我们的demo项目就已经运行起来了。 + + + +### 部署JMeter + +我们选用[JMeter](https://jmeter.apache.org/)作为压测工具,[Docker Hub](https://hub.docker.com/)上已有公共镜像[justb4/jmeter](https://hub.docker.com/r/justb4/jmeter/),该镜像比较成熟,启动前会先侦测系统中可用内存,按照一定比例为jmeter申请jvm内存,可以最大化、合理的利用系统资源。 + +当我们部署JMeter时,为了保持测试的灵活性,一般需要将JMeter脚本单独存储,而JMeter程序可以通过某种方式获取测试脚本,进而保证测试配置可以单独修改,不需要重新构建JMeter镜像。在Kubernetes中,我们可以将JMeter的配置文件存放于[ConfigMap](https://kubernetes.io/docs/tasks/configure-pod-container/configure-pod-configmap/),并通过[VolumeMount](https://kubernetes.io/docs/concepts/storage/volumes/)挂载到JMeter容器的指定目录,这样,当我们需要修改测试配置时,只需修改ConfigMap,并重新部署JMeter deployment,即可完成配置的更新。 + +部署ConfigMap命令如下: + +```bash +$ kubectl apply -f spring-demo/test/jmeter.configmap.yaml +``` + + + +### JMeter 镜像改造 + +由于原有的JMeter容器执行完测试之后就退出了,如果在单机环境、仅运行docker容器的环境下,我们可以在执行`docker run`命令时通过-v参数将宿主机目录挂载到容器中,以保存测试的结果。但是Kubernetes环境,每个pod部署时都是根据一定的算法分配到不同节点上的,节点即是容器的宿主机。但是,登录到节点并找到相应目录来查看结果似乎是非常“不体面”的姿势,因此需要构建一个服务,收集JMeter生成的报告,并能够方便的展示。为此,我们用go语言实现了一个简单的文件上传服务,并附带静态文件服务。该服务收到JMeter测试报告达成的tgz压缩包,将其解压到相应静态文件服务目录中,这样,我们就可以方便的在集群中查看测试结果。该服务就是上文提到的jmeter-collector服务。 + +这样一来,我们还需要对JMeter服务进行一些小改造,当执行完JMeter测试后,我们通过一个脚本将测试结果目录打包上传到jmeter-collector服务。这些改造都已经完成并做好了相应的镜像,直接使用项目中的资源即可: + +```bash +$ kubectl apply -f spring-demo/test/jmeter.yaml +``` + +现在,我们已经配置好JMeter相关资源,执行`kubectl logs`检查JMeter运行状况: + +```bash +$ kubectl get pod -n servicecomb | grep spring-demo-jmeter +spring-demo-jmeter-x +$ kubectl logs -f -n servicecomb pring-demo-jmeter-x +... +summary +420 in 00:00:22 = 18.8/s Avg: 214 Min: 111 Max: 471 Err: 207 (49.29%) Active: 12 Started: 12 Finished: 0 +``` + +可以看到JMeter已经开始逐步增加测试线程进行压测了。 +
[GitHub] WillemJiang closed pull request #147: Add the blog 'Load test saga with Kubernetes'
WillemJiang closed pull request #147: Add the blog 'Load test saga with Kubernetes' URL: https://github.com/apache/incubator-servicecomb-website/pull/147 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/_posts/cn/2018-09-11-loadtest-saga-with-kubernetes.md b/_posts/cn/2018-09-11-loadtest-saga-with-kubernetes.md new file mode 100644 index ..2e8395bf --- /dev/null +++ b/_posts/cn/2018-09-11-loadtest-saga-with-kubernetes.md @@ -0,0 +1,160 @@ +--- +title: "使用Kubernetes对Saga进行压力测试" +lang: cn +ref: loadtest-saga-with-kubernetes +permalink: /cn/docs/loadtest-saga-with-kubernetes +excerpt: "如何使用Kubernetes方便的对Saga进行性能测试" +last_modified_at: 2018-09-11T10:26:28+08:00 +author: Zhen Ju +tags: [microservice, servicemesh, saga] +redirect_from: + - /theme-setup/ +--- + +## 使用Kubernetes对Saga进行压力测试 + +Apache ServiceComb (incubating) Saga 是一个微服务应用的数据最终一致性解决方案。Saga在try阶段直接提交事务,后续rollback阶段则通过反向的补偿操作来完成。 + +基于ServiceComb Saga的项目,基本的构架如下: + +![overview](https://raw.githubusercontent.com/apache/incubator-servicecomb-saga/master/docs/static_files/pack.png) + +在我们的Saga实现中,业务服务引入Omega库,通过Omega将事务相关信息作为事件发送给Alpha server,由Alpha server统一进行协调。Alpha server将事务保存在PostgreSQL中,后台定期进行扫描。当扫描到异常事件时,尝试向事件对应的Omega发送gRPC请求,调用补偿方法。由于在原生业务中加入了Omega,进行了一系列后台操作,因此需要对整个框架进行压力测试,以获取框架的基础性能报告。 + +在Cloud Native时代,容器几乎是标准的部署形态,应用程序容器化之后,通过Kubernetes进行容器编排,可以轻松的实现弹性扩容、任务调度等,非常适合对该项目进行压力测试。有鉴于此,我们将demo项目构建成docker镜像,并部署到Kubernetes集群中,通过Kubernetes的一系列组件,对demo方便的进行压力测试,以对Saga项目的性能有一个初步的评估。 + + + + + +### "Kubernetize"服务 + +我们的demo项目由Java编写、maven作为依赖管理工具,在项目中引入了fabric8插件,编译程序时可以顺便将jar包构建成docker镜像。首先,我们构建alpha-server镜像: + +```bash +$ cd alpha/alpha-server +$ mvn clean install -Pdocker +``` + +然后进入demo项目路径`saga-demo/saga-spring-demo`,执行相同的maven构建命令,构建完成后,我们可以看到产生了4个相关镜像: + +```bash +$ docker images | grep SNAPHOST # {version}-SNAPSHOT是构建过程中使用的镜像标签 +alpha-server:0.3.0-SNAPSHOT +booking:0.3.0-SNAPSHOT +car:0.3.0-SNAPSHOT +hotel:0.3.0-SNAPSHOT +``` + +至此,我们已经构建好所需镜像,下一步便是编写Kubernetes所需的资源文件,这一步我们不再赘述,项目中已经有写好的yaml文件,路径在`saga-demo/saga-k8s-resources`,目录结构如下: + +```base +. +├── base +│ ├── alpha.yaml +│ ├── jmeter-collector.yaml +│ └── postgresql.yaml +├── README.md +└── spring-demo +├── booking.yaml +├── car.yaml +├── hotel.yaml +└── test +├── jmeter.configmap.yaml +└── jmeter.yaml +``` + +其中`base`目录包含了alpha-server,postgresql以及用于收集测试报告的jmeter-collector3个服务。`spring-demo`目录包含了demo项目的所有服务,`spring-demo/test`路径下包含了对demo测试所需的服务。 + + + +我们通过最基础的deployment和service对项目进行部署,程序之间通过域名互相访问,通过`kubectl`命令对Kubernetes资源进行部署: + +```bash +$ kubectl create ns servicecomb # 默认所有服务都在servicecomb namespace下 +$ kubectl apply -f ./base +$ kubectl apply -f ./spring-demo +``` + +我们通过`kubectl exec`命令进入一个pod,通过curl命令测试booking程序: + +```bash +$ kubectl exec -it -n servicecomb alpha-server-x +$ curl http://booking.servicecomb:8083/booking/test/2/2 +resp: OK +``` + +至此,我们的demo项目就已经运行起来了。 + + + +### 部署JMeter + +我们选用[JMeter](https://jmeter.apache.org/)作为压测工具,[Docker Hub](https://hub.docker.com/)上已有公共镜像[justb4/jmeter](https://hub.docker.com/r/justb4/jmeter/),该镜像比较成熟,启动前会先侦测系统中可用内存,按照一定比例为jmeter申请jvm内存,可以最大化、合理的利用系统资源。 + +当我们部署JMeter时,为了保持测试的灵活性,一般需要将JMeter脚本单独存储,而JMeter程序可以通过某种方式获取测试脚本,进而保证测试配置可以单独修改,不需要重新构建JMeter镜像。在Kubernetes中,我们可以将JMeter的配置文件存放于[ConfigMap](https://kubernetes.io/docs/tasks/configure-pod-container/configure-pod-configmap/),并通过[VolumeMount](https://kubernetes.io/docs/concepts/storage/volumes/)挂载到JMeter容器的指定目录,这样,当我们需要修改测试配置时,只需修改ConfigMap,并重新部署JMeter deployment,即可完成配置的更新。 + +部署ConfigMap命令如下: + +```bash +$ kubectl apply -f spring-demo/test/jmeter.configmap.yaml +``` + + + +### JMeter 镜像改造 + +由于原有的JMeter容器执行完测试之后就退出了,如果在单机环境、仅运行docker容器的环境下,我们可以在执行`docker run`命令时通过-v参数将宿主机目录挂载到容器中,以保存测试的结果。但是Kubernetes环境,每个pod部署时都是根据一定的算法分配到不同节点上的,节点即是容器的宿主机。但是,登录到节点并找到相应目录来查看结果似乎是非常“不体面”的姿势,因此需要构建一个服务,收集JMeter生成的报告,并能够方便的展示。为此,我们用go语言实现了一个简单的文件上传服务,并附带静态文件服务。该服务收到JMeter测试报告达成的tgz压缩包,将其解压到相应静态文件服务目录中,这样,我们就可以方便的在集群中查看测试结果。该服务就是上文提到的jmeter-collector服务。 + +这样一来,我们还需要对JMeter服务进行一些小改造,当执行完JMeter测试后,我们通过一个脚本将测试结果目录打包上传到jmeter-collector服务。这些改造都已经完成并做好了相应的镜像,直接使用项目中的资源即可: + +```bash +$ kubectl apply -f spring-demo/test/jmeter.yaml +``` + +现在,我们已经配置好JMeter相关资源,执行`kubectl logs`检查JMeter运行状况: + +```bash +$ kubectl get pod -n servicecomb | grep spring-demo-jmeter +spring-demo-jmeter-x +$ kubectl logs -f -n servicecomb pring-demo-jmeter-x +... +summary +420 in 00:00:22 = 18.8/s Avg: 214 Min: 111 Max: 471 Err: 207 (49.29%) Active: 12 Started: 12 Finished: 0 +``` + +可以看到JMeter已经开始逐步增加测试线程进行压测了。 + +由于我们用deployment部署JMeter,当执行结束后,容器正常退出,Kubernetes会重新启动容器,将测试服务再次拉起。因此测试会持续进行,直到我们将deployment删除。 + +至此,我们已经完成了demo和相应的压力测试服务,整个集群中相关资源的结构如下图所示: +
[incubator-servicecomb-website] branch master updated (1c5ea73 -> 3d1b820)
This is an automated email from the ASF dual-hosted git repository. ningjiang pushed a change to branch master in repository https://gitbox.apache.org/repos/asf/incubator-servicecomb-website.git. from 1c5ea73 Update OSI Report Blog new 3f4dccd Add images for hybrid demo article. new 3d1b820 Add the blog 'load test saga with kubernetes' The 2 revisions listed above as "new" are entirely new to this repository and will be described in separate emails. The revisions listed as "add" were already present in the repository and have only been added to this reference. Summary of changes: .../cn/2018-09-11-loadtest-saga-with-kubernetes.md | 160 + assets/images/hybrid-arch.jpg | Bin 0 -> 22772 bytes assets/images/hybrid-consumer-result.png | Bin 0 -> 13916 bytes assets/images/hybrid-mesher-process.jpg| Bin 0 -> 17217 bytes assets/images/hybrid-servicecenter-result.png | Bin 0 -> 49970 bytes assets/images/hybrid-sidecar-injector.jpg | Bin 0 -> 19811 bytes assets/images/jmeter-collector.png | Bin 0 -> 55774 bytes assets/images/spring-demo.jpg | Bin 0 -> 25204 bytes 8 files changed, 160 insertions(+) create mode 100644 _posts/cn/2018-09-11-loadtest-saga-with-kubernetes.md create mode 100644 assets/images/hybrid-arch.jpg create mode 100644 assets/images/hybrid-consumer-result.png create mode 100644 assets/images/hybrid-mesher-process.jpg create mode 100644 assets/images/hybrid-servicecenter-result.png create mode 100644 assets/images/hybrid-sidecar-injector.jpg create mode 100644 assets/images/jmeter-collector.png create mode 100644 assets/images/spring-demo.jpg
[GitHub] coveralls commented on issue #479: SCB-988 Add loadbalancer in sc client
coveralls commented on issue #479: SCB-988 Add loadbalancer in sc client URL: https://github.com/apache/incubator-servicecomb-service-center/pull/479#issuecomment-435327798 [![Coverage Status](https://coveralls.io/builds/19871376/badge)](https://coveralls.io/builds/19871376) Coverage increased (+0.03%) to 62.651% when pulling **57342ebd0230d86a7c89a42b2e4eb58857853888 on little-cui:lb** into **eb3aea04769d5cec222aa98a23c461f37cd84f9e on apache:master**. 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 With regards, Apache Git Services
[GitHub] codecov-io commented on issue #479: SCB-988 Add loadbalancer in sc client
codecov-io commented on issue #479: SCB-988 Add loadbalancer in sc client URL: https://github.com/apache/incubator-servicecomb-service-center/pull/479#issuecomment-435327716 # [Codecov](https://codecov.io/gh/apache/incubator-servicecomb-service-center/pull/479?src=pr=h1) Report > Merging [#479](https://codecov.io/gh/apache/incubator-servicecomb-service-center/pull/479?src=pr=desc) into [master](https://codecov.io/gh/apache/incubator-servicecomb-service-center/commit/eb3aea04769d5cec222aa98a23c461f37cd84f9e?src=pr=desc) will **increase** coverage by `0.04%`. > The diff coverage is `94.11%`. [![Impacted file tree graph](https://codecov.io/gh/apache/incubator-servicecomb-service-center/pull/479/graphs/tree.svg?width=650=GAaF7zrg8R=150=pr)](https://codecov.io/gh/apache/incubator-servicecomb-service-center/pull/479?src=pr=tree) ```diff @@Coverage Diff @@ ## master #479 +/- ## == + Coverage 60.24% 60.29% +0.04% == Files 156 157 +1 Lines 1348413501 +17 == + Hits 8124 8140 +16 - Misses 4779 4780 +1 Partials 581 581 ``` | [Impacted Files](https://codecov.io/gh/apache/incubator-servicecomb-service-center/pull/479?src=pr=tree) | Coverage Δ | | |---|---|---| | [pkg/lb/roundrobin.go](https://codecov.io/gh/apache/incubator-servicecomb-service-center/pull/479/diff?src=pr=tree#diff-cGtnL2xiL3JvdW5kcm9iaW4uZ28=) | `94.11% <94.11%> (ø)` | | | [pkg/tlsutil/tlsutil.go](https://codecov.io/gh/apache/incubator-servicecomb-service-center/pull/479/diff?src=pr=tree#diff-cGtnL3Rsc3V0aWwvdGxzdXRpbC5nbw==) | `73.58% <0%> (-0.95%)` | :arrow_down: | | [server/broker/service.go](https://codecov.io/gh/apache/incubator-servicecomb-service-center/pull/479/diff?src=pr=tree#diff-c2VydmVyL2Jyb2tlci9zZXJ2aWNlLmdv) | `57.94% <0%> (+0.15%)` | :arrow_up: | -- [Continue to review full report at Codecov](https://codecov.io/gh/apache/incubator-servicecomb-service-center/pull/479?src=pr=continue). > **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta) > `Δ = absolute (impact)`, `ø = not affected`, `? = missing data` > Powered by [Codecov](https://codecov.io/gh/apache/incubator-servicecomb-service-center/pull/479?src=pr=footer). Last update [eb3aea0...57342eb](https://codecov.io/gh/apache/incubator-servicecomb-service-center/pull/479?src=pr=lastupdated). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments). 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 With regards, Apache Git Services
[GitHub] msnetc opened a new issue #979: RestSchema和RpcSchema里面加个字段描述schema
msnetc opened a new issue #979: RestSchema和RpcSchema里面加个字段描述schema URL: https://github.com/apache/incubator-servicecomb-java-chassis/issues/979 现在的RestSchema和RpcSchema只有schemaId, 不能描述清楚这个schema的内容。 我们需要维护一个文档来描述schema包含的功能。 能否在RestSchema和RpcSchema中增加字段,如schemaName, schemaNote等,描述它的内容。 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 With regards, Apache Git Services
[GitHub] crystaldust opened a new pull request #147: Add the blog 'Load test saga with Kubernetes'
crystaldust opened a new pull request #147: Add the blog 'Load test saga with Kubernetes' URL: https://github.com/apache/incubator-servicecomb-website/pull/147 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 With regards, Apache Git Services
[GitHub] coveralls commented on issue #480: SCB-993 Can not test Schema if instance port greater than 4 digits
coveralls commented on issue #480: SCB-993 Can not test Schema if instance port greater than 4 digits URL: https://github.com/apache/incubator-servicecomb-service-center/pull/480#issuecomment-435312371 [![Coverage Status](https://coveralls.io/builds/19870573/badge)](https://coveralls.io/builds/19870573) Coverage decreased (-0.09%) to 62.646% when pulling **8dd472ee911057e4ef2269b45f683a098f92fc15 on little-cui:ui** into **2a7fa4d8913919463a9899ac78b53037e48b7f64 on apache:master**. 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 With regards, Apache Git Services
[GitHub] asifdxtreme closed pull request #480: SCB-993 Can not test Schema if instance port greater than 4 digits
asifdxtreme closed pull request #480: SCB-993 Can not test Schema if instance port greater than 4 digits URL: https://github.com/apache/incubator-servicecomb-service-center/pull/480 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/frontend/app/scripts/modules/serviceCenter/controllers/schemaCtrl.js b/frontend/app/scripts/modules/serviceCenter/controllers/schemaCtrl.js index ab24663a..cd21f130 100644 --- a/frontend/app/scripts/modules/serviceCenter/controllers/schemaCtrl.js +++ b/frontend/app/scripts/modules/serviceCenter/controllers/schemaCtrl.js @@ -261,14 +261,8 @@ angular.module('serviceCenter.sc') httpService.apiRequest(url, method, null, headers, "nopopup").then(function(response) { $(".loader").hide(); if (response && response.data && response.data.schema) { -if ($scope.selectedAddress.indexOf("rest") != -1) { -var rest = $scope.selectedAddress.split(':'); -var ip = rest[1].substring(2, rest[1].length) + ":" + rest[2].substring(0, 4); -} -if ($scope.selectedAddress.indexOf("highway") != -1) { -var highway = $scope.selectedAddress.split(':'); -var ip = highway[1].substring(2, highway[1].length) + ":" + highway[2].substring(0, 4); -} +var arr = /^(?:\w+:\/\/)?([^\/?#]+)(.*)$/.exec($scope.selectedAddress); +var ip = arr[1]; var schema = response.data.schema; schema = schema.replace(/\\\s/g, ""); var json = YAML.parse(schema); 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 With regards, Apache Git Services
[incubator-servicecomb-service-center] branch master updated: SCB-993 Can not test Schema if instance port greater than 4 digits (#480)
This is an automated email from the ASF dual-hosted git repository. asifdxtreme pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/incubator-servicecomb-service-center.git The following commit(s) were added to refs/heads/master by this push: new eb3aea0 SCB-993 Can not test Schema if instance port greater than 4 digits (#480) eb3aea0 is described below commit eb3aea04769d5cec222aa98a23c461f37cd84f9e Author: little-cui AuthorDate: Fri Nov 2 16:43:22 2018 +0800 SCB-993 Can not test Schema if instance port greater than 4 digits (#480) --- .../scripts/modules/serviceCenter/controllers/schemaCtrl.js| 10 ++ 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/frontend/app/scripts/modules/serviceCenter/controllers/schemaCtrl.js b/frontend/app/scripts/modules/serviceCenter/controllers/schemaCtrl.js index ab24663..cd21f13 100644 --- a/frontend/app/scripts/modules/serviceCenter/controllers/schemaCtrl.js +++ b/frontend/app/scripts/modules/serviceCenter/controllers/schemaCtrl.js @@ -261,14 +261,8 @@ angular.module('serviceCenter.sc') httpService.apiRequest(url, method, null, headers, "nopopup").then(function(response) { $(".loader").hide(); if (response && response.data && response.data.schema) { -if ($scope.selectedAddress.indexOf("rest") != -1) { -var rest = $scope.selectedAddress.split(':'); -var ip = rest[1].substring(2, rest[1].length) + ":" + rest[2].substring(0, 4); -} -if ($scope.selectedAddress.indexOf("highway") != -1) { -var highway = $scope.selectedAddress.split(':'); -var ip = highway[1].substring(2, highway[1].length) + ":" + highway[2].substring(0, 4); -} +var arr = /^(?:\w+:\/\/)?([^\/?#]+)(.*)$/.exec($scope.selectedAddress); +var ip = arr[1]; var schema = response.data.schema; schema = schema.replace(/\\\s/g, ""); var json = YAML.parse(schema);
[GitHub] little-cui opened a new pull request #480: SCB-993 Can not test Schema if instance port greater than 4 digits
little-cui opened a new pull request #480: SCB-993 Can not test Schema if instance port greater than 4 digits URL: https://github.com/apache/incubator-servicecomb-service-center/pull/480 Follow this checklist to help us incorporate your contribution quickly and easily: - [ ] Make sure there is a [JIRA issue](https://issues.apache.org/jira/browse/SCB) filed for the change (usually before you start working on it). Trivial changes like typos do not require a JIRA issue. Your pull request should address just this issue, without pulling in other changes. - [ ] Each commit in the pull request should have a meaningful subject line and body. - [ ] Format the pull request title like `[SCB-XXX] Fixes bug in ApproximateQuantiles`, where you replace `SCB-XXX` with the appropriate JIRA issue. - [ ] Write a pull request description that is detailed enough to understand what the pull request does, how, and why. - [ ] Run `go build` `go test` `go fmt` `go vet` to make sure basic checks pass. A more thorough check will be performed on your pull request automatically. - [ ] If this contribution is large, please file an Apache [Individual Contributor License Agreement](https://www.apache.org/licenses/icla.pdf). --- 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 With regards, Apache Git Services