change: update logs

This commit is contained in:
debugtalk
2021-12-22 20:45:53 +08:00
parent f0a16de225
commit a36232b734
6 changed files with 28 additions and 24 deletions

View File

@@ -6,6 +6,8 @@
- feat: support `--continue-on-failure` flag to continue running next step when failure occurs, default to failfast - feat: support `--continue-on-failure` flag to continue running next step when failure occurs, default to failfast
- refactor: fork [boomer] as sub module - refactor: fork [boomer] as sub module
- feat: report GA events with version - feat: report GA events with version
- feat: run load test with the given limit and burst as rate limiter
- change: update API models
## v0.2.2 (2021-12-07) ## v0.2.2 (2021-12-07)

View File

@@ -49,7 +49,7 @@ func Execute() {
func setLogLevel(level string) { func setLogLevel(level string) {
level = strings.ToUpper(level) level = strings.ToUpper(level)
log.Info().Msgf("Set log level to %s", level) log.Info().Str("level", level).Msg("Set log level")
switch level { switch level {
case "DEBUG": case "DEBUG":
zerolog.SetGlobalLevel(zerolog.DebugLevel) zerolog.SetGlobalLevel(zerolog.DebugLevel)

View File

@@ -1,9 +1,10 @@
package boomer package boomer
import ( import (
"log"
"math" "math"
"time" "time"
"github.com/rs/zerolog/log"
) )
// A Boomer is used to run tasks. // A Boomer is used to run tasks.
@@ -36,20 +37,19 @@ func (b *Boomer) SetRateLimiter(maxRPS int64, requestIncreaseRate string) {
var rateLimiter RateLimiter var rateLimiter RateLimiter
var err error var err error
if requestIncreaseRate != "-1" { if requestIncreaseRate != "-1" {
if maxRPS > 0 { if maxRPS <= 0 {
log.Println("The max RPS that boomer may generate is limited to", maxRPS, "with a increase rate", requestIncreaseRate) maxRPS = math.MaxInt64
rateLimiter, err = NewRampUpRateLimiter(maxRPS, requestIncreaseRate, time.Second)
} else {
log.Println("The max RPS that boomer may generate is limited by a increase rate", requestIncreaseRate)
rateLimiter, err = NewRampUpRateLimiter(math.MaxInt64, requestIncreaseRate, time.Second)
} }
log.Warn().Int64("maxRPS", maxRPS).Str("increaseRate", requestIncreaseRate).Msg("set ramp up rate limiter")
rateLimiter, err = NewRampUpRateLimiter(math.MaxInt64, requestIncreaseRate, time.Second)
} else { } else {
if maxRPS > 0 { if maxRPS > 0 {
log.Println("The max RPS that boomer may generate is limited to", maxRPS) log.Warn().Int64("maxRPS", maxRPS).Msg("set stable rate limiter")
rateLimiter = NewStableRateLimiter(maxRPS, time.Second) rateLimiter = NewStableRateLimiter(maxRPS, time.Second)
} }
} }
if err != nil { if err != nil {
log.Error().Err(err).Msg("failed to create rate limiter")
return return
} }
b.rateLimiter = rateLimiter b.rateLimiter = rateLimiter
@@ -77,13 +77,13 @@ func (b *Boomer) Run(tasks ...*Task) {
if b.cpuProfile != "" { if b.cpuProfile != "" {
err := startCPUProfile(b.cpuProfile, b.cpuProfileDuration) err := startCPUProfile(b.cpuProfile, b.cpuProfileDuration)
if err != nil { if err != nil {
log.Printf("Error starting cpu profiling, %v", err) log.Error().Err(err).Msg("failed to start cpu profiling")
} }
} }
if b.memoryProfile != "" { if b.memoryProfile != "" {
err := startMemoryProfile(b.memoryProfile, b.memoryProfileDuration) err := startMemoryProfile(b.memoryProfile, b.memoryProfileDuration)
if err != nil { if err != nil {
log.Printf("Error starting memory profiling, %v", err) log.Error().Err(err).Msg("failed to start memory profiling")
} }
} }

View File

@@ -3,7 +3,6 @@ package boomer
import ( import (
"encoding/json" "encoding/json"
"fmt" "fmt"
"log"
"os" "os"
"sort" "sort"
"strconv" "strconv"
@@ -13,6 +12,7 @@ import (
"github.com/olekukonko/tablewriter" "github.com/olekukonko/tablewriter"
"github.com/prometheus/client_golang/prometheus" "github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/push" "github.com/prometheus/client_golang/prometheus/push"
"github.com/rs/zerolog/log"
) )
// Output is primarily responsible for printing test results to different destinations // Output is primarily responsible for printing test results to different destinations
@@ -120,7 +120,7 @@ func (o *ConsoleOutput) OnStop() {
func (o *ConsoleOutput) OnEvent(data map[string]interface{}) { func (o *ConsoleOutput) OnEvent(data map[string]interface{}) {
output, err := convertData(data) output, err := convertData(data)
if err != nil { if err != nil {
log.Println(fmt.Sprintf("convert data error: %v", err)) log.Error().Err(err).Msg("failed to convert data")
return return
} }
@@ -380,7 +380,7 @@ type PrometheusPusherOutput struct {
// OnStart will register all prometheus metric collectors // OnStart will register all prometheus metric collectors
func (o *PrometheusPusherOutput) OnStart() { func (o *PrometheusPusherOutput) OnStart() {
log.Println("register prometheus metric collectors") log.Info().Msg("register prometheus metric collectors")
registry := prometheus.NewRegistry() registry := prometheus.NewRegistry()
registry.MustRegister( registry.MustRegister(
// gauge vectors for requests // gauge vectors for requests
@@ -412,7 +412,7 @@ func (o *PrometheusPusherOutput) OnStop() {
func (o *PrometheusPusherOutput) OnEvent(data map[string]interface{}) { func (o *PrometheusPusherOutput) OnEvent(data map[string]interface{}) {
output, err := convertData(data) output, err := convertData(data)
if err != nil { if err != nil {
log.Println(fmt.Sprintf("convert data error: %v", err)) log.Error().Err(err).Msg("failed to convert data")
return return
} }
@@ -444,6 +444,6 @@ func (o *PrometheusPusherOutput) OnEvent(data map[string]interface{}) {
} }
if err := o.pusher.Push(); err != nil { if err := o.pusher.Push(); err != nil {
log.Println(fmt.Sprintf("Could not push to Pushgateway: error: %v", err)) log.Error().Err(err).Msg("push to Pushgateway failed")
} }
} }

View File

@@ -2,13 +2,14 @@ package boomer
import ( import (
"fmt" "fmt"
"log"
"math/rand" "math/rand"
"os" "os"
"runtime/debug" "runtime/debug"
"sync" "sync"
"sync/atomic" "sync/atomic"
"time" "time"
"github.com/rs/zerolog/log"
) )
const ( const (
@@ -116,7 +117,7 @@ func (r *runner) outputOnStop() {
} }
func (r *runner) spawnWorkers(spawnCount int, quit chan bool, spawnCompleteFunc func()) { func (r *runner) spawnWorkers(spawnCount int, quit chan bool, spawnCompleteFunc func()) {
log.Println("Spawning", spawnCount, "clients immediately") log.Info().Int("spawnCount", spawnCount).Msg("Spawning clients immediately")
for i := 1; i <= spawnCount; i++ { for i := 1; i <= spawnCount; i++ {
select { select {

View File

@@ -4,11 +4,12 @@ import (
"crypto/md5" "crypto/md5"
"fmt" "fmt"
"io" "io"
"log"
"math" "math"
"os" "os"
"runtime/pprof" "runtime/pprof"
"time" "time"
"github.com/rs/zerolog/log"
) )
func round(val float64, roundOn float64, places int) (newVal float64) { func round(val float64, roundOn float64, places int) (newVal float64) {
@@ -41,14 +42,14 @@ func startMemoryProfile(file string, duration time.Duration) (err error) {
return err return err
} }
log.Println("Start memory profiling for", duration) log.Info().Dur("duration", duration).Msg("Start memory profiling")
time.AfterFunc(duration, func() { time.AfterFunc(duration, func() {
err = pprof.WriteHeapProfile(f) err = pprof.WriteHeapProfile(f)
if err != nil { if err != nil {
log.Println(err) log.Error().Err(err).Msg("failed to write memory profile")
} }
f.Close() f.Close()
log.Println("Stop memory profiling after", duration) log.Info().Dur("duration", duration).Msg("Stop memory profiling")
}) })
return nil return nil
} }
@@ -60,7 +61,7 @@ func startCPUProfile(file string, duration time.Duration) (err error) {
return err return err
} }
log.Println("Start cpu profiling for", duration) log.Info().Dur("duration", duration).Msg("Start CPU profiling")
err = pprof.StartCPUProfile(f) err = pprof.StartCPUProfile(f)
if err != nil { if err != nil {
f.Close() f.Close()
@@ -70,7 +71,7 @@ func startCPUProfile(file string, duration time.Duration) (err error) {
time.AfterFunc(duration, func() { time.AfterFunc(duration, func() {
pprof.StopCPUProfile() pprof.StopCPUProfile()
f.Close() f.Close()
log.Println("Stop CPU profiling after", duration) log.Info().Dur("duration", duration).Msg("Stop CPU profiling")
}) })
return nil return nil
} }