Skip to content

Commit

Permalink
Merge branch 'main' into emate/enable-user-indexes-collector
Browse files Browse the repository at this point in the history
  • Loading branch information
Tofel authored Oct 22, 2024
2 parents a6f3f9b + 8f5d72b commit ec87b00
Show file tree
Hide file tree
Showing 10 changed files with 90 additions and 45 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/release-go-module.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ jobs:
VERSION=$(echo "$TAG_REF" | cut -d'/' -f2)
# Find the latest tag for the same package that is not the current tag
LAST_TAG=$(git describe --abbrev=0 --match "$PACKAGE_NAME/v*" --tags $(git rev-list --tags --skip=1 --max-count=1))
LAST_TAG=$(git describe --abbrev=0 --always --match "$PACKAGE_NAME/v*" --tags $(git rev-list --tags --skip=1 --max-count=1))
echo "Last tag: ${LAST_TAG}"
# If no previous tag is found, use the initial commit as the reference
Expand Down
6 changes: 1 addition & 5 deletions havoc/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,14 @@ module github.com/smartcontractkit/chainlink-testing-framework/havoc

go 1.22.5

exclude github.com/chaos-mesh/chaos-mesh/api/v1alpha1 v0.0.0-20220226050744-799408773657

require (
github.com/chaos-mesh/chaos-mesh/api v0.0.0-20240821051457-da69c6d9617a
github.com/pkg/errors v0.9.1
github.com/rs/zerolog v1.33.0
github.com/smartcontractkit/chainlink-testing-framework/lib/grafana v1.50.0
k8s.io/api v0.31.0
k8s.io/client-go v0.31.0
sigs.k8s.io/controller-runtime v0.16.2
sigs.k8s.io/controller-runtime v0.19.0
)

require (
Expand Down Expand Up @@ -76,6 +74,4 @@ require (
sigs.k8s.io/yaml v1.4.0 // indirect
)

replace sigs.k8s.io/controller-runtime => sigs.k8s.io/controller-runtime v0.19.0

retract [v1.999.0-test-release, v1.999.999-test-release]
2 changes: 1 addition & 1 deletion lib/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ require (
github.com/prometheus/client_golang v1.19.1
github.com/prometheus/common v0.55.0
github.com/rs/zerolog v1.30.0
github.com/slack-go/slack v0.12.2
github.com/slack-go/slack v0.15.0
github.com/smartcontractkit/chainlink-testing-framework/seth v1.2.1-0.20240827112945-bd8c580392d6
github.com/smartcontractkit/chainlink-testing-framework/wasp v0.4.9
github.com/spf13/cobra v1.8.1
Expand Down
4 changes: 2 additions & 2 deletions lib/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -1045,8 +1045,8 @@ github.com/sirupsen/logrus v1.4.2/go.mod h1:tLMulIdttU9McNUspp0xgXVQah82FyeX6Mwd
github.com/sirupsen/logrus v1.6.0/go.mod h1:7uNnSEd1DgxDLC74fIahvMZmmYsHGZGEOFrfsX/uA88=
github.com/sirupsen/logrus v1.9.3 h1:dueUQJ1C2q9oE3F7wvmSGAaVtTmUizReu6fjN8uqzbQ=
github.com/sirupsen/logrus v1.9.3/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ=
github.com/slack-go/slack v0.12.2 h1:x3OppyMyGIbbiyFhsBmpf9pwkUzMhthJMRNmNlA4LaQ=
github.com/slack-go/slack v0.12.2/go.mod h1:hlGi5oXA+Gt+yWTPP0plCdRKmjsDxecdHxYQdlMQKOw=
github.com/slack-go/slack v0.15.0 h1:LE2lj2y9vqqiOf+qIIy0GvEoxgF1N5yLGZffmEZykt0=
github.com/slack-go/slack v0.15.0/go.mod h1:hlGi5oXA+Gt+yWTPP0plCdRKmjsDxecdHxYQdlMQKOw=
github.com/smartcontractkit/chainlink-testing-framework/grafana v0.0.0-20240328204215-ac91f55f1449 h1:fX/xmGm1GBsD1ZZnooNT+eWA0hiTAqFlHzOC5CY4dy8=
github.com/smartcontractkit/chainlink-testing-framework/grafana v0.0.0-20240328204215-ac91f55f1449/go.mod h1:DC8sQMyTlI/44UCTL8QWFwb0bYNoXCfjwCv2hMivYZU=
github.com/smartcontractkit/chainlink-testing-framework/seth v1.2.1-0.20240827112945-bd8c580392d6 h1:ItZ75xmt+VHR/lw+GJwSWj9XICpgZ94dJ+I/5jdet7c=
Expand Down
15 changes: 10 additions & 5 deletions lib/testreporters/slack_notification.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ var (
)

// Uploads a slack file to the designated channel using the API key
func UploadSlackFile(slackClient *slack.Client, uploadParams slack.FileUploadParameters) error {
func UploadSlackFile(slackClient *slack.Client, uploadParams slack.UploadFileV2Parameters) error {
log.Info().
Str("Slack API Key", SlackAPIKey).
Str("Slack Channel", SlackChannel).
Expand All @@ -35,17 +35,22 @@ func UploadSlackFile(slackClient *slack.Client, uploadParams slack.FileUploadPar
if SlackChannel == "" {
return fmt.Errorf("unable to upload file without a Slack Channel")
}
if uploadParams.Channels == nil || uploadParams.Channels[0] == "" {
uploadParams.Channels = []string{SlackChannel}
if uploadParams.Channel == "" {
uploadParams.Channel = SlackChannel
}
if uploadParams.File != "" {
if _, err := os.Stat(uploadParams.File); errors.Is(err, os.ErrNotExist) {
file, err := os.Stat(uploadParams.File)
if errors.Is(err, os.ErrNotExist) {
return fmt.Errorf("unable to upload file as it does not exist: %w", err)
} else if err != nil {
return err
}
// file size is now mandatory, so we need to set if it's empty
if uploadParams.FileSize == 0 {
uploadParams.FileSize = int(file.Size())
}
}
_, err := slackClient.UploadFile(uploadParams)
_, err := slackClient.UploadFileV2(uploadParams)
return err
}

Expand Down
2 changes: 2 additions & 0 deletions seth/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,8 @@ export SETH_ROOT_PRIVATE_KEY=ac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae7
alias seth="SETH_CONFIG_PATH=seth.toml go run cmd/seth/seth.go" # useful alias for CLI
```

> Find the log level options [here](https://github.com/rs/zerolog?tab=readme-ov-file#leveled-logging)
Alternatively if you don't have a network defined in the TOML you can still use the CLI by providing these 2 key env vars:

```sh
Expand Down
4 changes: 2 additions & 2 deletions wasp/examples/scenario/vu.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ func NewExampleScenario(target string) *VirtualUser {
return &VirtualUser{
VUControl: wasp.NewVUControl(),
target: target,
rl: ratelimit.New(10),
rl: ratelimit.New(10, ratelimit.WithoutSlack),
client: resty.New().SetBaseURL(target),
Data: make([]string, 0),
}
Expand All @@ -34,7 +34,7 @@ func (m *VirtualUser) Clone(_ *wasp.Generator) wasp.VirtualUser {
return &VirtualUser{
VUControl: wasp.NewVUControl(),
target: m.target,
rl: ratelimit.New(10),
rl: ratelimit.New(10, ratelimit.WithoutSlack),
client: resty.New().SetBaseURL(m.target),
Data: make([]string, 0),
}
Expand Down
34 changes: 23 additions & 11 deletions wasp/wasp.go
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,7 @@ type Stats struct {
CurrentSegment atomic.Int64 `json:"current_schedule_segment"`
SamplesRecorded atomic.Int64 `json:"samples_recorded"`
SamplesSkipped atomic.Int64 `json:"samples_skipped"`
RunStarted atomic.Bool `json:"runStarted"`
RunPaused atomic.Bool `json:"runPaused"`
RunStopped atomic.Bool `json:"runStopped"`
RunFailed atomic.Bool `json:"runFailed"`
Expand Down Expand Up @@ -224,6 +225,7 @@ type Generator struct {
labels model.LabelSet
rl atomic.Pointer[ratelimit.Limiter]
scheduleSegments []*Segment
currentSegmentMu *sync.Mutex
currentSegment *Segment
ResponsesWaitGroup *sync.WaitGroup
dataWaitGroup *sync.WaitGroup
Expand Down Expand Up @@ -298,6 +300,7 @@ func NewGenerator(cfg *Config) (*Generator, error) {
Responses: NewResponses(rch),
ResponsesChan: rch,
labels: ls,
currentSegmentMu: &sync.Mutex{},
responsesData: &ResponseData{
okDataMu: &sync.Mutex{},
OKData: NewSliceBuffer[any](cfg.CallResultBufLen),
Expand All @@ -323,16 +326,13 @@ func NewGenerator(cfg *Config) (*Generator, error) {
return g, nil
}

// setupSchedule set up initial data for both RPS and VirtualUser load types
func (g *Generator) setupSchedule() {
// runExecuteLoop set up initial data for both RPS and VirtualUser load types
func (g *Generator) runExecuteLoop() {
g.currentSegment = g.scheduleSegments[0]
g.stats.LastSegment.Store(int64(len(g.scheduleSegments)))
switch g.Cfg.LoadType {
case RPS:
g.ResponsesWaitGroup.Add(1)
g.stats.CurrentRPS.Store(g.currentSegment.From)
newRateLimit := ratelimit.New(int(g.currentSegment.From), ratelimit.Per(g.Cfg.RateLimitUnitDuration))
g.rl.Store(&newRateLimit)
// we run pacedCall controlled by stats.CurrentRPS
go func() {
for {
Expand All @@ -347,7 +347,9 @@ func (g *Generator) setupSchedule() {
}
}()
case VU:
g.currentSegmentMu.Lock()
g.stats.CurrentVUs.Store(g.currentSegment.From)
g.currentSegmentMu.Unlock()
// we start all vus once
vus := g.stats.CurrentVUs.Load()
for i := 0; i < int(vus); i++ {
Expand Down Expand Up @@ -449,6 +451,7 @@ func (g *Generator) runVU(vu VirtualUser) {
// changing both internal and Stats values to report
func (g *Generator) processSegment() bool {
defer func() {
g.stats.RunStarted.Store(true)
g.Log.Info().
Int64("Segment", g.stats.CurrentSegment.Load()).
Int64("VUs", g.stats.CurrentVUs.Load()).
Expand All @@ -458,11 +461,13 @@ func (g *Generator) processSegment() bool {
if g.stats.CurrentSegment.Load() == g.stats.LastSegment.Load() {
return true
}
g.currentSegmentMu.Lock()
g.currentSegment = g.scheduleSegments[g.stats.CurrentSegment.Load()]
g.currentSegmentMu.Unlock()
g.stats.CurrentSegment.Add(1)
switch g.Cfg.LoadType {
case RPS:
newRateLimit := ratelimit.New(int(g.currentSegment.From), ratelimit.Per(g.Cfg.RateLimitUnitDuration))
newRateLimit := ratelimit.New(int(g.currentSegment.From), ratelimit.Per(g.Cfg.RateLimitUnitDuration), ratelimit.WithoutSlack)
g.rl.Store(&newRateLimit)
g.stats.CurrentRPS.Store(g.currentSegment.From)
case VU:
Expand Down Expand Up @@ -491,9 +496,9 @@ func (g *Generator) processSegment() bool {
return false
}

// runSchedule runs scheduling loop
// runScheduleLoop runs scheduling loop
// processing segments inside the whole schedule
func (g *Generator) runSchedule() {
func (g *Generator) runScheduleLoop() {
go func() {
for {
select {
Expand Down Expand Up @@ -583,11 +588,17 @@ func (g *Generator) collectVUResults() {

// pacedCall calls a gun according to a scheduleSegments or plain RPS
func (g *Generator) pacedCall() {
if g.stats.RunPaused.Load() || g.stats.RunStopped.Load() {
if !g.Stats().RunStarted.Load() {
return
}
l := *g.rl.Load()
l.Take()
if g.stats.RunPaused.Load() {
return
}
if g.stats.RunStopped.Load() {
return
}
result := make(chan *Response)
requestCtx, cancel := context.WithTimeout(context.Background(), g.Cfg.CallTimeout)
callStartTS := time.Now()
Expand Down Expand Up @@ -621,9 +632,9 @@ func (g *Generator) Run(wait bool) (interface{}, bool) {
g.sendResponsesToLoki()
g.sendStatsToLoki()
}
g.setupSchedule()
g.runScheduleLoop()
g.runExecuteLoop()
g.collectVUResults()
g.runSchedule()
if wait {
return g.Wait()
}
Expand All @@ -648,6 +659,7 @@ func (g *Generator) Stop() (interface{}, bool) {
if g.stats.RunStopped.Load() {
return nil, true
}
g.stats.RunStarted.Store(false)
g.stats.RunStopped.Store(true)
g.stats.RunFailed.Store(true)
g.Log.Warn().Msg("Graceful stop")
Expand Down
2 changes: 1 addition & 1 deletion wasp/wasp_bench_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ func BenchmarkPacedCall(b *testing.B) {
Gun: NewMockGun(&MockGunConfig{}),
})
require.NoError(b, err)
gen.setupSchedule()
gen.runExecuteLoop()
b.ResetTimer()
for i := 0; i < b.N; i++ {
gen.pacedCall()
Expand Down
Loading

0 comments on commit ec87b00

Please sign in to comment.