forked from cadence-workflow/cadence
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Open source bench tests (Part 1) (cadence-workflow#3990)
- Loading branch information
Showing
20 changed files
with
1,438 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,128 @@ | ||
// Copyright (c) 2017-2021 Uber Technologies Inc. | ||
|
||
// Permission is hereby granted, free of charge, to any person obtaining a copy | ||
// of this software and associated documentation files (the "Software"), to deal | ||
// in the Software without restriction, including without limitation the rights | ||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
// copies of the Software, and to permit persons to whom the Software is | ||
// furnished to do so, subject to the following conditions: | ||
// | ||
// The above copyright notice and this permission notice shall be included in all | ||
// copies or substantial portions of the Software. | ||
// | ||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
// SOFTWARE. | ||
|
||
package lib | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
|
||
"go.uber.org/cadence/.gen/go/cadence/workflowserviceclient" | ||
"go.uber.org/cadence/.gen/go/shared" | ||
"go.uber.org/cadence/client" | ||
"go.uber.org/yarpc" | ||
"go.uber.org/yarpc/transport/tchannel" | ||
) | ||
|
||
const workflowRetentionDays = 1 | ||
|
||
// CadenceClient is an abstraction on top of | ||
// the cadence library client that serves as | ||
// a union of all the client interfaces that | ||
// the library exposes | ||
type CadenceClient struct { | ||
client.Client | ||
// domainClient only exposes domain API | ||
client.DomainClient | ||
// this is the service needed to start the workers | ||
Service workflowserviceclient.Interface | ||
} | ||
|
||
// CreateDomain creates a cadence domain with the given name and description | ||
// if the domain already exist, this method silently returns success | ||
func (client CadenceClient) CreateDomain(name string, desc string, owner string) error { | ||
emitMetric := true | ||
isGlobalDomain := false | ||
retention := int32(workflowRetentionDays) | ||
req := &shared.RegisterDomainRequest{ | ||
Name: &name, | ||
Description: &desc, | ||
OwnerEmail: &owner, | ||
WorkflowExecutionRetentionPeriodInDays: &retention, | ||
EmitMetric: &emitMetric, | ||
IsGlobalDomain: &isGlobalDomain, | ||
} | ||
err := client.Register(context.Background(), req) | ||
if err != nil { | ||
if _, ok := err.(*shared.DomainAlreadyExistsError); !ok { | ||
return err | ||
} | ||
} | ||
return nil | ||
} | ||
|
||
// NewCadenceClients builds a CadenceClient for each domain from the runtimeContext | ||
func NewCadenceClients(runtime *RuntimeContext) (map[string]CadenceClient, error) { | ||
cadenceClients := make(map[string]CadenceClient) | ||
for _, domain := range runtime.Bench.Domains { | ||
client, err := NewCadenceClientForDomain(runtime, domain) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
cadenceClients[domain] = client | ||
} | ||
|
||
return cadenceClients, nil | ||
} | ||
|
||
// NewCadenceClientForDomain builds a CadenceClient for a specified domain based on runtimeContext | ||
func NewCadenceClientForDomain( | ||
runtime *RuntimeContext, | ||
domain string, | ||
) (CadenceClient, error) { | ||
|
||
ch, err := tchannel.NewChannelTransport( | ||
tchannel.ServiceName(runtime.Bench.Name), | ||
) | ||
if err != nil { | ||
return CadenceClient{}, fmt.Errorf("failed to create transport channel: %v", err) | ||
} | ||
|
||
dispatcher := yarpc.NewDispatcher(yarpc.Config{ | ||
Name: runtime.Bench.Name, | ||
Outbounds: yarpc.Outbounds{ | ||
runtime.Cadence.ServiceName: {Unary: ch.NewSingleOutbound(runtime.Cadence.HostNameAndPort)}, | ||
}, | ||
}) | ||
|
||
if err := dispatcher.Start(); err != nil { | ||
dispatcher.Stop() | ||
return CadenceClient{}, fmt.Errorf("failed to create outbound transport channel: %v", err) | ||
} | ||
|
||
var cadenceClient CadenceClient | ||
cadenceClient.Service = workflowserviceclient.New(dispatcher.ClientConfig(runtime.Cadence.ServiceName)) | ||
cadenceClient.Client = client.NewClient( | ||
cadenceClient.Service, | ||
domain, | ||
&client.Options{ | ||
MetricsScope: runtime.Metrics, | ||
}, | ||
) | ||
cadenceClient.DomainClient = client.NewDomainClient( | ||
cadenceClient.Service, | ||
&client.Options{ | ||
MetricsScope: runtime.Metrics, | ||
}, | ||
) | ||
|
||
return cadenceClient, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
// Copyright (c) 2017-2021 Uber Technologies Inc. | ||
|
||
// Permission is hereby granted, free of charge, to any person obtaining a copy | ||
// of this software and associated documentation files (the "Software"), to deal | ||
// in the Software without restriction, including without limitation the rights | ||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
// copies of the Software, and to permit persons to whom the Software is | ||
// furnished to do so, subject to the following conditions: | ||
// | ||
// The above copyright notice and this permission notice shall be included in all | ||
// copies or substantial portions of the Software. | ||
// | ||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
// SOFTWARE. | ||
|
||
package lib | ||
|
||
import ( | ||
"errors" | ||
|
||
"github.com/uber/cadence/common/service/config" | ||
) | ||
|
||
type ( | ||
// Config contains the configuration for cadence bench | ||
Config struct { | ||
Bench Bench `yaml:"bench"` | ||
Cadence Cadence `yaml:"cadence"` | ||
Log config.Logger `yaml:"log"` | ||
Metrics config.Metrics `yaml:"metrics"` | ||
} | ||
|
||
// Cadence contains the configuration for cadence service | ||
Cadence struct { | ||
ServiceName string `yaml:"service"` | ||
HostNameAndPort string `yaml:"host"` | ||
} | ||
|
||
// Bench contains the configuration for bench tests | ||
Bench struct { | ||
Name string `yaml:"name"` | ||
Domains []string `yaml:"domains"` | ||
NumTaskLists int `yaml:"numTaskLists"` | ||
} | ||
|
||
// BasicTestConfig contains the configuration for running the Basic test scenario | ||
// TODO: update comment | ||
BasicTestConfig struct { | ||
TotalLaunchCount int `yaml:"totalLaunchCount"` | ||
RoutineCount int `yaml:"routineCount"` | ||
ChainSequence int `yaml:"chainSequence"` | ||
ConcurrentCount int `yaml:"concurrentCount"` | ||
PayloadSizeBytes int `yaml:"payloadSizeBytes"` | ||
MinCadenceSleepInSeconds int `yaml:"minCadenceSleepInSeconds"` | ||
MaxCadenceSleepInSeconds int `yaml:"maxCadenceSleepInSeconds"` | ||
ExecutionStartToCloseTimeoutInSeconds int `yaml:"executionStartToCloseTimeoutInSeconds"` // default 5m | ||
ContextTimeoutInSeconds int `yaml:"contextTimeoutInSeconds"` // default 3s | ||
PanicStressWorkflow bool `yaml:"panicStressWorkflow"` // default false | ||
FailureThreshold float64 `yaml:"failureThreshold"` | ||
} | ||
) | ||
|
||
func (c *Config) Validate() error { | ||
if len(c.Bench.Name) == 0 { | ||
return errors.New("missing value for bench service name") | ||
} | ||
if len(c.Bench.Domains) == 0 { | ||
return errors.New("missing value for domains property") | ||
} | ||
if c.Bench.NumTaskLists == 0 { | ||
return errors.New("number of taskLists can not be 0") | ||
} | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
// Copyright (c) 2017-2021 Uber Technologies Inc. | ||
|
||
// Permission is hereby granted, free of charge, to any person obtaining a copy | ||
// of this software and associated documentation files (the "Software"), to deal | ||
// in the Software without restriction, including without limitation the rights | ||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
// copies of the Software, and to permit persons to whom the Software is | ||
// furnished to do so, subject to the following conditions: | ||
// | ||
// The above copyright notice and this permission notice shall be included in all | ||
// copies or substantial portions of the Software. | ||
// | ||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
// SOFTWARE. | ||
|
||
package lib | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/suite" | ||
) | ||
|
||
type ConfigTestSuite struct { | ||
suite.Suite | ||
} | ||
|
||
func TestConfigTestSuite(t *testing.T) { | ||
suite.Run(t, new(ConfigTestSuite)) | ||
} | ||
|
||
func (s *ConfigTestSuite) TestValidate() { | ||
testCases := []func(*Config){ | ||
func(c *Config) { c.Bench.Name = "" }, | ||
func(c *Config) { c.Bench.Domains = []string{} }, | ||
func(c *Config) { c.Bench.NumTaskLists = 0 }, | ||
} | ||
|
||
for _, tc := range testCases { | ||
config := s.buildConfig() | ||
tc(&config) | ||
s.Error(config.Validate()) | ||
} | ||
} | ||
|
||
func (s *ConfigTestSuite) buildConfig() Config { | ||
return Config{ | ||
Bench: Bench{ | ||
Name: "cadence-bench", | ||
Domains: []string{"cadence-bench"}, | ||
NumTaskLists: 1, | ||
}, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
// Copyright (c) 2017-2021 Uber Technologies Inc. | ||
|
||
// Permission is hereby granted, free of charge, to any person obtaining a copy | ||
// of this software and associated documentation files (the "Software"), to deal | ||
// in the Software without restriction, including without limitation the rights | ||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
// copies of the Software, and to permit persons to whom the Software is | ||
// furnished to do so, subject to the following conditions: | ||
// | ||
// The above copyright notice and this permission notice shall be included in all | ||
// copies or substantial portions of the Software. | ||
// | ||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
// SOFTWARE. | ||
|
||
package lib | ||
|
||
import ( | ||
"github.com/uber-go/tally" | ||
"go.uber.org/zap" | ||
|
||
"github.com/uber/cadence/common/log/loggerimpl" | ||
) | ||
|
||
const ( | ||
defaultCadenceLocalHostPort = "127.0.0.1:7933" | ||
defaultCadenceServiceName = "cadence-frontend" | ||
) | ||
|
||
// ContextKey is an alias for string, used as context key | ||
type ContextKey string | ||
|
||
const ( | ||
// CtxKeyRuntimeContext is the name of the context key whose value is the RuntimeContext | ||
CtxKeyRuntimeContext = ContextKey("ctxKeyRuntimeCtx") | ||
|
||
// CtxKeyCadenceClient is the name of the context key for the cadence client this cadence worker listens to | ||
CtxKeyCadenceClient = ContextKey("ctxKeyCadenceClient") | ||
) | ||
|
||
// RuntimeContext contains all of the context information | ||
// needed at cadence bench runtime | ||
type RuntimeContext struct { | ||
Bench Bench | ||
Cadence Cadence | ||
Logger *zap.Logger | ||
Metrics tally.Scope | ||
} | ||
|
||
// NewRuntimeContext builds a runtime context from the config | ||
func NewRuntimeContext(cfg *Config) (*RuntimeContext, error) { | ||
logger := cfg.Log.NewZapLogger() | ||
|
||
metricsScope := cfg.Metrics.NewScope(loggerimpl.NewLogger(logger), cfg.Bench.Name) | ||
|
||
if cfg.Cadence.ServiceName == "" { | ||
cfg.Cadence.ServiceName = defaultCadenceServiceName | ||
} | ||
|
||
if cfg.Cadence.HostNameAndPort == "" { | ||
cfg.Cadence.HostNameAndPort = defaultCadenceLocalHostPort | ||
} | ||
|
||
return &RuntimeContext{ | ||
Bench: cfg.Bench, | ||
Cadence: cfg.Cadence, | ||
Logger: logger, | ||
Metrics: metricsScope, | ||
}, nil | ||
} |
Oops, something went wrong.