From 3863a88421b3d969aa74e4ce864a98e34e788f06 Mon Sep 17 00:00:00 2001 From: kuzxnia Date: Sat, 17 Feb 2024 14:34:54 +0100 Subject: [PATCH] added exporting metrics to prometheus and removed custom log setup --- cli/agent.go | 10 +-- cli/cli.go | 27 ++------ cli/config.go | 31 ++++----- cli/install.go | 9 +-- cli/progress.go | 2 +- cli/start.go | 7 +- cli/stop.go | 9 +-- cli/uninstall.go | 9 +-- cli/watch.go | 6 +- cmd/main.go | 21 +++--- lbot/agent.go | 110 +++++++++++++++++--------------- lbot/config.go | 36 +++++++---- lbot/config/config.go | 40 ++++++------ lbot/log/log.go | 138 ---------------------------------------- lbot/progress.go | 2 +- lbot/proto/config.pb.go | 80 +++++++++++++++++------ lbot/proto/config.proto | 10 ++- 17 files changed, 232 insertions(+), 315 deletions(-) delete mode 100644 lbot/log/log.go diff --git a/cli/agent.go b/cli/agent.go index e449f3d..7b01f87 100644 --- a/cli/agent.go +++ b/cli/agent.go @@ -7,7 +7,7 @@ import ( ) // tutaj nie powinno wchodziΔ‡ proto -func StartAgent(context context.Context, stdin bool, port string, configFile string) (err error) { +func StartAgent(context context.Context, stdin bool, cmdPort string, configFile string) (err error) { var requestConfig *lbot.ConfigRequest if stdin { @@ -24,11 +24,13 @@ func StartAgent(context context.Context, stdin bool, port string, configFile str } } - agent := lbot.NewAgent(context, Logger) + if cmdPort != "" { + requestConfig.AgentPort = cmdPort + } + agent := lbot.NewAgent(context) if requestConfig != nil { agent.ApplyConfig(requestConfig) } - - agent.Listen(port) + agent.Listen() return nil } diff --git a/cli/cli.go b/cli/cli.go index 933072c..a01192a 100644 --- a/cli/cli.go +++ b/cli/cli.go @@ -3,12 +3,9 @@ package cli import ( "errors" "fmt" - "strings" "time" "github.com/kuzxnia/loadbot/lbot" - "github.com/kuzxnia/loadbot/lbot/config" - applog "github.com/kuzxnia/loadbot/lbot/log" "github.com/kuzxnia/loadbot/lbot/proto" log "github.com/sirupsen/logrus" "github.com/spf13/cobra" @@ -19,33 +16,21 @@ const ( AgentUri = "agent-uri" ) -var ( - Logger *log.Entry - Conn *grpc.ClientConn -) - -func New(rootLogger *log.Entry, version string, commit string, date string) *cobra.Command { - Logger = rootLogger +var Conn *grpc.ClientConn +func New(version string, commit string, date string) *cobra.Command { cmd := cobra.Command{ Use: "loadbot", Short: "A command-line database workload driver ", Version: fmt.Sprintf("%s (commit: %s) (build date: %s)", version, commit, date), PersistentPreRunE: func(cmd *cobra.Command, args []string) (err error) { f := cmd.Flags() - loglvl, _ := f.GetString(config.FlagLogLevel) - logfmt, _ := f.GetString(config.FlagLogFormat) - err = applog.Configure(Logger, loglvl, logfmt) - if err != nil { - return fmt.Errorf("failed to configure logger: %w", err) - } - - // move to driver group + // move to driver group agentUri, _ := f.GetString(AgentUri) Conn, err = grpc.Dial(agentUri, grpc.WithInsecure()) // valiedate connection if err != nil { - Logger.Fatal("Found errors trying to connect to loadbot-agent:", err) + log.Fatal("Found errors trying to connect to loadbot-agent:", err) return } @@ -58,10 +43,8 @@ func New(rootLogger *log.Entry, version string, commit string, date string) *cob }, } pf := cmd.PersistentFlags() - // move to driver group + // move to driver group pf.StringP(AgentUri, "u", "127.0.0.1:1234", "loadbot agent uri (default: 127.0.0.1:1234)") - pf.String(config.FlagLogLevel, applog.LevelInfo, fmt.Sprintf("log level, must be one of: %s", strings.Join(applog.Levels, ", "))) - pf.String(config.FlagLogFormat, applog.FormatFancy, fmt.Sprintf("log format, must be one of: %s", strings.Join(applog.Formats, ", "))) // setup supcommands // cmd.AddGroup(&OrchiestrationGroup) diff --git a/cli/config.go b/cli/config.go index 51bb7b9..bc1635a 100644 --- a/cli/config.go +++ b/cli/config.go @@ -12,6 +12,7 @@ import ( "github.com/kuzxnia/loadbot/lbot" "github.com/kuzxnia/loadbot/lbot/proto" + log "github.com/sirupsen/logrus" "google.golang.org/grpc" ) @@ -20,7 +21,7 @@ import ( func SetConfigDriver(conn *grpc.ClientConn, parsedConfig *lbot.ConfigRequest) (err error) { requestConfig := BuildConfigRequest(parsedConfig) - Logger.Info("πŸš€ Setting new config") + log.Info("πŸš€ Setting new config") client := proto.NewSetConfigProcessClient(conn) reply, err := client.Run(context.TODO(), requestConfig) @@ -28,8 +29,8 @@ func SetConfigDriver(conn *grpc.ClientConn, parsedConfig *lbot.ConfigRequest) (e return fmt.Errorf("Setting config failed: %w", err) } - Logger.Infof("Received: %v", reply) - Logger.Info("βœ… Setting config succeeded") + log.Infof("Received: %v", reply) + log.Info("βœ… Setting config succeeded") return } @@ -43,18 +44,18 @@ func BuildConfigRequest(request *lbot.ConfigRequest) *proto.ConfigRequest { } for i, job := range request.Jobs { cfg.Jobs[i] = &proto.JobRequest{ - Name: job.Name, - Database: job.Database, - Collection: job.Collection, - Type: job.Type, - Schema: job.Schema, - Connections: job.Connections, - Pace: job.Pace, - DataSize: job.DataSize, - BatchSize: job.BatchSize, - Duration: job.Duration.String(), - Operations: job.Operations, - Timeout: job.Timeout.String(), + Name: job.Name, + Database: job.Database, + Collection: job.Collection, + Type: job.Type, + Schema: job.Schema, + Connections: job.Connections, + Pace: job.Pace, + DataSize: job.DataSize, + BatchSize: job.BatchSize, + Duration: job.Duration.String(), + Operations: job.Operations, + Timeout: job.Timeout.String(), // todo: setup filters and schema inside // Filter: job.Filter, } diff --git a/cli/install.go b/cli/install.go index dc67756..ff9548c 100644 --- a/cli/install.go +++ b/cli/install.go @@ -4,6 +4,7 @@ import ( "net/rpc" "github.com/kuzxnia/loadbot/orchiestrator" + log "github.com/sirupsen/logrus" "github.com/spf13/cobra" ) @@ -38,19 +39,19 @@ func installationHandler(cmd *cobra.Command, args []string) error { } var reply int - Logger.Info("πŸš€ Starting installation process") + log.Info("πŸš€ Starting installation process") client, err := rpc.DialHTTP("tcp", "127.0.0.1:1234") if err != nil { - Logger.Fatal("Found errors trying to connect to lbot-agent:", err) + log.Fatal("Found errors trying to connect to lbot-agent:", err) } err = client.Call("InstallationProcess.Run", request, &reply) if err != nil { - Logger.Fatal("InstallationProcess error:", err) + log.Fatal("InstallationProcess error:", err) } - Logger.Info("βœ… Installation process succeeded") + log.Info("βœ… Installation process succeeded") return nil } diff --git a/cli/progress.go b/cli/progress.go index 96520d0..03c13f7 100644 --- a/cli/progress.go +++ b/cli/progress.go @@ -4,12 +4,12 @@ import ( "context" "fmt" "io" - "log" "os" "github.com/cheggaaa/pb/v3" "github.com/kuzxnia/loadbot/lbot/proto" "github.com/samber/lo" + log "github.com/sirupsen/logrus" "google.golang.org/grpc" ) diff --git a/cli/start.go b/cli/start.go index 735a54c..ab01344 100644 --- a/cli/start.go +++ b/cli/start.go @@ -5,6 +5,7 @@ import ( "fmt" "github.com/kuzxnia/loadbot/lbot/proto" + log "github.com/sirupsen/logrus" "google.golang.org/grpc" ) @@ -13,7 +14,7 @@ import ( // tutaj nie powinno wchodziΔ‡ proto func StartDriver(conn grpc.ClientConnInterface, request *proto.StartRequest) (err error) { // todo: mapowanie to proto - Logger.Info("πŸš€ Starting stress test") + log.Info("πŸš€ Starting stress test") client := proto.NewStartProcessClient(conn) @@ -22,8 +23,8 @@ func StartDriver(conn grpc.ClientConnInterface, request *proto.StartRequest) (er return fmt.Errorf("starting stress test failed: %w", err) } - Logger.Infof("Received: %v", reply) - Logger.Info("βœ… Starting stress test succeeded") + log.Infof("Received: %v", reply) + log.Info("βœ… Starting stress test succeeded") return } diff --git a/cli/stop.go b/cli/stop.go index 91f9b4e..02af4ca 100644 --- a/cli/stop.go +++ b/cli/stop.go @@ -4,22 +4,23 @@ import ( "context" "github.com/kuzxnia/loadbot/lbot/proto" + log "github.com/sirupsen/logrus" "google.golang.org/grpc" ) func StopDriver(conn grpc.ClientConnInterface, request *proto.StopRequest) (err error) { - Logger.Info("πŸš€ Stopping stress test") + log.Info("πŸš€ Stopping stress test") client := proto.NewStopProcessClient(conn) reply, err := client.Run(context.TODO(), request) if err != nil { - Logger.Fatal("arith error:", err) + log.Fatal("arith error:", err) return } - Logger.Infof("Received: %v", reply) - Logger.Info("βœ… Stopping stress test succeeded") + log.Infof("Received: %v", reply) + log.Info("βœ… Stopping stress test succeeded") return nil } diff --git a/cli/uninstall.go b/cli/uninstall.go index 952b7e1..94b35ac 100644 --- a/cli/uninstall.go +++ b/cli/uninstall.go @@ -4,27 +4,28 @@ import ( "net/rpc" "github.com/kuzxnia/loadbot/orchiestrator" + log "github.com/sirupsen/logrus" "github.com/spf13/cobra" ) func unInstallationHandler(cmd *cobra.Command, args []string) error { request := orchiestrator.UnInstallationRequest{} - Logger.Info("πŸš€ Starting installation process") + log.Info("πŸš€ Starting installation process") var reply int client, err := rpc.DialHTTP("tcp", "127.0.0.1:1234") if err != nil { - Logger.Fatal("Found errors trying to connect to lbot-agent:", err) + log.Fatal("Found errors trying to connect to lbot-agent:", err) } err = client.Call("UnInstallationProcess.Run", request, &reply) if err != nil { - Logger.Fatal("UnInstallationProcess error:", err) + log.Fatal("UnInstallationProcess error:", err) // return fmt.Errorf("installation failed: %w", err) } - Logger.Info("βœ… Installation process succeeded") + log.Info("βœ… Installation process succeeded") return nil } diff --git a/cli/watch.go b/cli/watch.go index 19f4dd4..ddc59b6 100644 --- a/cli/watch.go +++ b/cli/watch.go @@ -4,14 +4,14 @@ import ( "context" "fmt" "io" - "log" "github.com/kuzxnia/loadbot/lbot/proto" + log "github.com/sirupsen/logrus" "google.golang.org/grpc" ) func WatchDriver(conn grpc.ClientConnInterface, request *proto.WatchRequest) (err error) { - Logger.Info("πŸš€ Starting stress test") + log.Info("πŸš€ Starting stress test") client := proto.NewWatchProcessClient(conn) @@ -38,7 +38,7 @@ func WatchDriver(conn grpc.ClientConnInterface, request *proto.WatchRequest) (er <-done // we will wait until all response is received - Logger.Info("βœ… Starting stress test succeeded") + log.Info("βœ… Starting stress test succeeded") return } diff --git a/cmd/main.go b/cmd/main.go index e37dc47..2b537cb 100644 --- a/cmd/main.go +++ b/cmd/main.go @@ -2,11 +2,10 @@ package main import ( "context" - "fmt" "os" "github.com/kuzxnia/loadbot/cli" - "github.com/kuzxnia/loadbot/lbot/log" + log "github.com/sirupsen/logrus" ) var ( @@ -26,19 +25,15 @@ func run() int { ctx, cancel := context.WithCancel(context.Background()) defer cancel() - logger, err := log.NewLogger(ctx) - if err != nil { - fmt.Printf("❌ Error: %s\n", err.Error()) //nolint:forbidigo - - return 1 - } - - rootCmd := cli.New(logger, version, commit, date) - - err = rootCmd.ExecuteContext(ctx) + log.SetOutput(os.Stdout) + log.SetFormatter(&log.TextFormatter{ + FullTimestamp: true, + }) + rootCmd := cli.New(version, commit, date) + err := rootCmd.ExecuteContext(ctx) if err != nil { - logger.Errorf("❌ Error: %s", err.Error()) + log.Errorf("❌ Error: %s", err.Error()) return 1 } diff --git a/lbot/agent.go b/lbot/agent.go index c4fce31..c31db4f 100644 --- a/lbot/agent.go +++ b/lbot/agent.go @@ -2,15 +2,15 @@ package lbot import ( "context" + "fmt" "net" "net/http" - _ "net/http/pprof" "os" "os/signal" "syscall" + "time" "github.com/VictoriaMetrics/metrics" - "github.com/kuzxnia/loadbot/lbot/config" "github.com/kuzxnia/loadbot/lbot/proto" log "github.com/sirupsen/logrus" "google.golang.org/grpc" @@ -18,82 +18,90 @@ import ( ) type Agent struct { - ctx context.Context - log *log.Entry - config *config.Config - lbot *Lbot + ctx context.Context + lbot *Lbot + grpcServer *grpc.Server } -func NewAgent(ctx context.Context, logger *log.Entry) *Agent { +func NewAgent(ctx context.Context) *Agent { + lbot := NewLbot(ctx) + + grpcServer := grpc.NewServer() + // register commands + proto.RegisterStartProcessServer(grpcServer, NewStartProcess(ctx, lbot)) + proto.RegisterStopProcessServer(grpcServer, NewStoppingProcess(ctx, lbot)) + proto.RegisterSetConfigProcessServer(grpcServer, NewSetConfigProcess(ctx, lbot)) + proto.RegisterWatchProcessServer(grpcServer, NewWatchingProcess(ctx, lbot)) + proto.RegisterProgressProcessServer(grpcServer, NewProgressProcess(ctx, lbot)) + reflection.Register(grpcServer) + return &Agent{ - ctx: ctx, - log: logger, - lbot: NewLbot(ctx), + ctx: ctx, + lbot: lbot, + grpcServer: grpcServer, } } -func (a *Agent) Listen(port string) error { - address := "0.0.0.0:" + port +func (a *Agent) Listen() error { + stopSignal := make(chan os.Signal, 1) + signal.Notify( + stopSignal, os.Interrupt, syscall.SIGHUP, syscall.SIGINT, syscall.SIGQUIT, syscall.SIGTERM, + ) + + log.Info("waiting for new config version") - l, err := net.Listen("tcp", address) + address := "0.0.0.0:" + a.lbot.config.AgentPort + tcpListener, err := net.Listen("tcp", address) if err != nil { - a.log.Fatal("listen error:", err) + log.Fatal("listen error:", err) + return err } + defer tcpListener.Close() - grpcServer := grpc.NewServer() - // register commands - proto.RegisterStartProcessServer(grpcServer, NewStartProcess(a.ctx, a.lbot)) - proto.RegisterStopProcessServer(grpcServer, NewStoppingProcess(a.ctx, a.lbot)) - proto.RegisterSetConfigProcessServer(grpcServer, NewSetConfigProcess(a.ctx, a.lbot)) - proto.RegisterWatchProcessServer(grpcServer, NewWatchingProcess(a.ctx, a.lbot)) - proto.RegisterProgressProcessServer(grpcServer, NewProgressProcess(a.ctx, a.lbot)) - - reflection.Register(grpcServer) - - a.log.Info("Started lbot-agent on " + address) - stop := make(chan os.Signal, 1) - signal.Notify( - stop, os.Interrupt, syscall.SIGHUP, syscall.SIGINT, syscall.SIGQUIT, syscall.SIGTERM, - ) + log.Info("Started lbot-agent on " + address) + defer func() { + log.Info("Stopped lbot-agent started on " + address) + a.grpcServer.GracefulStop() + }() go func() { - if err := grpcServer.Serve(l); err != nil { + if err := a.grpcServer.Serve(tcpListener); err != nil { log.Fatalf("failed to serve: %s", err) } }() - // register metrics - http.HandleFunc("/metrics", func(w http.ResponseWriter, req *http.Request) { - metrics.WritePrometheus(w, true) - }) - go func() { - a.log.Info("Started lbot-agent metrics on :8090") - http.ListenAndServe(":8090", nil) - }() + if a.lbot.config.MetricsExportPort != "" { + http.HandleFunc("/metrics", func(w http.ResponseWriter, req *http.Request) { + metrics.WritePrometheus(w, true) + }) + go func() { + log.Infof("Started metrics exporter on :%s/metrics", a.lbot.config.MetricsExportPort) + http.ListenAndServe(":"+a.lbot.config.MetricsExportPort, nil) + }() + } else if a.lbot.config.MetricsExportUrl != "" { + log.Info("Started exporting metrics :", a.lbot.config.MetricsExportPort) + metricsLabels := fmt.Sprintf(`instance="%s"`, a.lbot.config.AgentName) + metrics.InitPush( + a.lbot.config.MetricsExportUrl, + 10*time.Second, // todo: add interval param + metricsLabels, + true, + ) + } - <-stop - grpcServer.GracefulStop() + <-stopSignal + fmt.Println("Received stop signal. Exiting.") + // a.grpcServer.GracefulStop() // is this needed? _, cancel := context.WithCancel(a.ctx) cancel() - a.log.Info("Shuted down lbot-agent") - return nil } -// runned when initializing agent, and after reconfig func (a *Agent) ApplyConfig(request *ConfigRequest) error { - // todo: - // check if operation is running - // lock ? or apply config and restart - // if some operation is running { - // return errors.New("") - // } - cfg := NewConfig(request) a.lbot.SetConfig(cfg) - return nil } diff --git a/lbot/config.go b/lbot/config.go index 2788047..5f64d79 100644 --- a/lbot/config.go +++ b/lbot/config.go @@ -16,10 +16,14 @@ import ( func NewConfig(request *ConfigRequest) *config.Config { cfg := &config.Config{ - ConnectionString: request.ConnectionString, - Jobs: make([]*config.Job, len(request.Jobs)), - Schemas: make([]*config.Schema, len(request.Schemas)), - Debug: request.Debug, + ConnectionString: request.ConnectionString, + AgentName: request.AgentName, + AgentPort: request.AgentPort, + MetricsExportUrl: request.MetricsExportUrl, + MetricsExportPort: request.MetricsExportPort, + Jobs: make([]*config.Job, len(request.Jobs)), + Schemas: make([]*config.Schema, len(request.Schemas)), + Debug: request.Debug, } for i, job := range request.Jobs { cfg.Jobs[i] = &config.Job{ @@ -54,10 +58,14 @@ func NewConfig(request *ConfigRequest) *config.Config { func NewConfigFromProtoConfigRequest(request *proto.ConfigRequest) *config.Config { cfg := &config.Config{ - ConnectionString: request.ConnectionString, - Jobs: make([]*config.Job, len(request.Jobs)), - Schemas: make([]*config.Schema, len(request.Schemas)), - Debug: request.Debug, + ConnectionString: request.ConnectionString, + AgentName: request.AgentName, + AgentPort: request.AgentPort, + MetricsExportUrl: request.MetricsExportUrl, + MetricsExportPort: request.MetricsExportPort, + Jobs: make([]*config.Job, len(request.Jobs)), + Schemas: make([]*config.Schema, len(request.Schemas)), + Debug: request.Debug, } for i, job := range request.Jobs { duration, _ := time.ParseDuration(job.Duration) @@ -93,10 +101,14 @@ func NewConfigFromProtoConfigRequest(request *proto.ConfigRequest) *config.Confi // todo: should be pointers type ConfigRequest struct { - ConnectionString string `json:"connection_string"` - Jobs []*JobRequest `json:"jobs"` - Schemas []*SchemaRequest `json:"schemas"` - Debug bool `json:"debug"` + ConnectionString string `json:"connection_string"` + AgentName string `json:"agent_name"` + AgentPort string `json:"agent_port"` + MetricsExportUrl string `json:"metrics_export_url"` + MetricsExportPort string `json:"metrics_export_port"` + Jobs []*JobRequest `json:"jobs"` + Schemas []*SchemaRequest `json:"schemas"` + Debug bool `json:"debug"` } type JobRequest struct { diff --git a/lbot/config/config.go b/lbot/config/config.go index 00597c9..4281e79 100644 --- a/lbot/config/config.go +++ b/lbot/config/config.go @@ -5,27 +5,31 @@ import ( ) type Config struct { - ConnectionString string `json:"connection_string"` - Jobs []*Job `json:"jobs"` - Schemas []*Schema `json:"schemas"` - Debug bool `json:"debug"` + ConnectionString string `json:"connection_string"` + AgentName string `json:"agent_name"` + AgentPort string `json:"agent_port"` + MetricsExportUrl string `json:"metrics_export_url"` + MetricsExportPort string `json:"metrics_export_port"` + Jobs []*Job `json:"jobs"` + Schemas []*Schema `json:"schemas"` + Debug bool `json:"debug"` } type Job struct { - Parent *Config - Name string - Database string - Collection string - Type string - Schema string - Connections uint64 // Maximum number of concurrent connections - Pace uint64 // rps limit / peace - if not set max - DataSize uint64 // data size in bytes - BatchSize uint64 - Duration time.Duration - Operations uint64 - Timeout time.Duration // if not set, default - Filter map[string]interface{} + Parent *Config + Name string + Database string + Collection string + Type string + Schema string + Connections uint64 // Maximum number of concurrent connections + Pace uint64 // rps limit / peace - if not set max + DataSize uint64 // data size in bytes + BatchSize uint64 + Duration time.Duration + Operations uint64 + Timeout time.Duration // if not set, default + Filter map[string]interface{} } type Schema struct { diff --git a/lbot/log/log.go b/lbot/log/log.go deleted file mode 100644 index e5d4fd1..0000000 --- a/lbot/log/log.go +++ /dev/null @@ -1,138 +0,0 @@ -package log - -import ( - "context" - "fmt" - "os" - "strings" - - "github.com/forPelevin/gomoji" - log "github.com/sirupsen/logrus" -) - -type LoggerContextKey string - -const ( - FormatJSON = "json" - FormatFancy = "fancy" - - LevelTrace = "trace" - LevelDebug = "debug" - LevelInfo = "info" - LevelWarn = "warn" - LevelError = "error" - LevelFatal = "fatal" - LevelPanic = "panic" - - FormatContextKey LoggerContextKey = "log-format" -) - -var ( - Formats = []string{FormatJSON, FormatFancy} - Levels = []string{ - LevelTrace, LevelDebug, LevelInfo, LevelWarn, - LevelError, LevelFatal, LevelPanic, - } -) - -func NewLogger(ctx context.Context) (*log.Entry, error) { - configureGlobalLogger() - - l := log.New() - l.SetOutput(os.Stdout) - - entry := l.WithContext(ctx) - - err := Configure(entry, LevelInfo, FormatFancy) - if err != nil { - return nil, err - } - - return entry, nil -} - -func Configure(entry *log.Entry, level string, format string) error { - logger := entry.Logger - logger.SetOutput(os.Stdout) - - formatter, err := getLogFormatter(format) - if err != nil { - return err - } - - logLevel, err := getLogLevel(level) - if err != nil { - return err - } - - logger.SetFormatter(formatter) - logger.SetLevel(logLevel) - - entry.Context = context.WithValue(entry.Context, FormatContextKey, format) - - return nil -} - -//nolint:ireturn,nolintlint -func getLogFormatter(format string) (log.Formatter, error) { - switch format { - case FormatJSON: - return &jsonFormatter{}, nil - case FormatFancy: - return &fancyFormatter{}, nil - default: - return &fancyFormatter{}, nil - - } -} - -func getLogLevel(level string) (log.Level, error) { - switch level { - case LevelTrace: - return log.TraceLevel, nil - case LevelDebug: - return log.DebugLevel, nil - case LevelInfo: - return log.InfoLevel, nil - case LevelWarn: - return log.WarnLevel, nil - case LevelError: - return log.ErrorLevel, nil - case LevelFatal: - return log.FatalLevel, nil - case LevelPanic: - return log.PanicLevel, nil - default: - return log.InfoLevel, nil - } -} - -type jsonFormatter struct { - inner log.JSONFormatter -} - -func (f *jsonFormatter) Format(e *log.Entry) ([]byte, error) { - e.Message = strings.TrimSpace(gomoji.RemoveEmojis(e.Message)) - - formatted, err := f.inner.Format(e) - if err != nil { - return nil, fmt.Errorf("failed to format log entry: %w", err) - } - - return formatted, nil -} - -type fancyFormatter struct{} - -func (f *fancyFormatter) Format(e *log.Entry) ([]byte, error) { - return []byte(e.Message + "\n"), nil -} - -func configureGlobalLogger() { - log.SetFormatter(&log.TextFormatter{ - FullTimestamp: true, - PadLevelText: true, - }) - log.SetOutput(os.Stdout) - log.SetLevel(log.DebugLevel) -} diff --git a/lbot/progress.go b/lbot/progress.go index 010703f..5655a94 100644 --- a/lbot/progress.go +++ b/lbot/progress.go @@ -3,12 +3,12 @@ package lbot import ( "context" "fmt" - "log" "time" "github.com/kuzxnia/loadbot/lbot/driver" "github.com/kuzxnia/loadbot/lbot/proto" "github.com/samber/lo" + log "github.com/sirupsen/logrus" ) type ProgressProcess struct { diff --git a/lbot/proto/config.pb.go b/lbot/proto/config.pb.go index 9a808f1..765abd1 100644 --- a/lbot/proto/config.pb.go +++ b/lbot/proto/config.pb.go @@ -248,10 +248,14 @@ type ConfigRequest struct { sizeCache protoimpl.SizeCache unknownFields protoimpl.UnknownFields - ConnectionString string `protobuf:"bytes,1,opt,name=connection_string,json=connectionString,proto3" json:"connection_string,omitempty"` - Jobs []*JobRequest `protobuf:"bytes,2,rep,name=jobs,proto3" json:"jobs,omitempty"` - Schemas []*SchemaRequest `protobuf:"bytes,3,rep,name=schemas,proto3" json:"schemas,omitempty"` - Debug bool `protobuf:"varint,4,opt,name=debug,proto3" json:"debug,omitempty"` + ConnectionString string `protobuf:"bytes,1,opt,name=connection_string,json=connectionString,proto3" json:"connection_string,omitempty"` + AgentName string `protobuf:"bytes,2,opt,name=agent_name,json=agentName,proto3" json:"agent_name,omitempty"` + AgentPort string `protobuf:"bytes,3,opt,name=agent_port,json=agentPort,proto3" json:"agent_port,omitempty"` + MetricsExportUrl string `protobuf:"bytes,4,opt,name=metrics_export_url,json=metricsExportUrl,proto3" json:"metrics_export_url,omitempty"` + MetricsExportPort string `protobuf:"bytes,5,opt,name=metrics_export_port,json=metricsExportPort,proto3" json:"metrics_export_port,omitempty"` + Jobs []*JobRequest `protobuf:"bytes,6,rep,name=jobs,proto3" json:"jobs,omitempty"` + Schemas []*SchemaRequest `protobuf:"bytes,7,rep,name=schemas,proto3" json:"schemas,omitempty"` + Debug bool `protobuf:"varint,8,opt,name=debug,proto3" json:"debug,omitempty"` } func (x *ConfigRequest) Reset() { @@ -293,6 +297,34 @@ func (x *ConfigRequest) GetConnectionString() string { return "" } +func (x *ConfigRequest) GetAgentName() string { + if x != nil { + return x.AgentName + } + return "" +} + +func (x *ConfigRequest) GetAgentPort() string { + if x != nil { + return x.AgentPort + } + return "" +} + +func (x *ConfigRequest) GetMetricsExportUrl() string { + if x != nil { + return x.MetricsExportUrl + } + return "" +} + +func (x *ConfigRequest) GetMetricsExportPort() string { + if x != nil { + return x.MetricsExportPort + } + return "" +} + func (x *ConfigRequest) GetJobs() []*JobRequest { if x != nil { return x.Jobs @@ -393,24 +425,34 @@ var file_lbot_proto_config_proto_rawDesc = []byte{ 0x75, 0x74, 0x12, 0x2c, 0x0a, 0x06, 0x66, 0x69, 0x6c, 0x74, 0x65, 0x72, 0x18, 0x0d, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x14, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x41, 0x6e, 0x79, 0x52, 0x06, 0x66, 0x69, 0x6c, 0x74, 0x65, 0x72, - 0x22, 0xa9, 0x01, 0x0a, 0x0d, 0x43, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x52, 0x65, 0x71, 0x75, 0x65, + 0x22, 0xc5, 0x02, 0x0a, 0x0d, 0x43, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x2b, 0x0a, 0x11, 0x63, 0x6f, 0x6e, 0x6e, 0x65, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x5f, 0x73, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x10, 0x63, 0x6f, 0x6e, 0x6e, 0x65, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x53, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x12, - 0x25, 0x0a, 0x04, 0x6a, 0x6f, 0x62, 0x73, 0x18, 0x02, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x11, 0x2e, - 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x4a, 0x6f, 0x62, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, - 0x52, 0x04, 0x6a, 0x6f, 0x62, 0x73, 0x12, 0x2e, 0x0a, 0x07, 0x73, 0x63, 0x68, 0x65, 0x6d, 0x61, - 0x73, 0x18, 0x03, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x14, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, - 0x53, 0x63, 0x68, 0x65, 0x6d, 0x61, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x52, 0x07, 0x73, - 0x63, 0x68, 0x65, 0x6d, 0x61, 0x73, 0x12, 0x14, 0x0a, 0x05, 0x64, 0x65, 0x62, 0x75, 0x67, 0x18, - 0x04, 0x20, 0x01, 0x28, 0x08, 0x52, 0x05, 0x64, 0x65, 0x62, 0x75, 0x67, 0x22, 0x10, 0x0a, 0x0e, - 0x43, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x32, 0x48, - 0x0a, 0x10, 0x53, 0x65, 0x74, 0x43, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x50, 0x72, 0x6f, 0x63, 0x65, - 0x73, 0x73, 0x12, 0x34, 0x0a, 0x03, 0x52, 0x75, 0x6e, 0x12, 0x14, 0x2e, 0x70, 0x72, 0x6f, 0x74, - 0x6f, 0x2e, 0x43, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, - 0x15, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x43, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x52, 0x65, - 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x00, 0x42, 0x08, 0x5a, 0x06, 0x70, 0x72, 0x6f, 0x74, - 0x6f, 0x2f, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, + 0x1d, 0x0a, 0x0a, 0x61, 0x67, 0x65, 0x6e, 0x74, 0x5f, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x02, 0x20, + 0x01, 0x28, 0x09, 0x52, 0x09, 0x61, 0x67, 0x65, 0x6e, 0x74, 0x4e, 0x61, 0x6d, 0x65, 0x12, 0x1d, + 0x0a, 0x0a, 0x61, 0x67, 0x65, 0x6e, 0x74, 0x5f, 0x70, 0x6f, 0x72, 0x74, 0x18, 0x03, 0x20, 0x01, + 0x28, 0x09, 0x52, 0x09, 0x61, 0x67, 0x65, 0x6e, 0x74, 0x50, 0x6f, 0x72, 0x74, 0x12, 0x2c, 0x0a, + 0x12, 0x6d, 0x65, 0x74, 0x72, 0x69, 0x63, 0x73, 0x5f, 0x65, 0x78, 0x70, 0x6f, 0x72, 0x74, 0x5f, + 0x75, 0x72, 0x6c, 0x18, 0x04, 0x20, 0x01, 0x28, 0x09, 0x52, 0x10, 0x6d, 0x65, 0x74, 0x72, 0x69, + 0x63, 0x73, 0x45, 0x78, 0x70, 0x6f, 0x72, 0x74, 0x55, 0x72, 0x6c, 0x12, 0x2e, 0x0a, 0x13, 0x6d, + 0x65, 0x74, 0x72, 0x69, 0x63, 0x73, 0x5f, 0x65, 0x78, 0x70, 0x6f, 0x72, 0x74, 0x5f, 0x70, 0x6f, + 0x72, 0x74, 0x18, 0x05, 0x20, 0x01, 0x28, 0x09, 0x52, 0x11, 0x6d, 0x65, 0x74, 0x72, 0x69, 0x63, + 0x73, 0x45, 0x78, 0x70, 0x6f, 0x72, 0x74, 0x50, 0x6f, 0x72, 0x74, 0x12, 0x25, 0x0a, 0x04, 0x6a, + 0x6f, 0x62, 0x73, 0x18, 0x06, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x11, 0x2e, 0x70, 0x72, 0x6f, 0x74, + 0x6f, 0x2e, 0x4a, 0x6f, 0x62, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x52, 0x04, 0x6a, 0x6f, + 0x62, 0x73, 0x12, 0x2e, 0x0a, 0x07, 0x73, 0x63, 0x68, 0x65, 0x6d, 0x61, 0x73, 0x18, 0x07, 0x20, + 0x03, 0x28, 0x0b, 0x32, 0x14, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x53, 0x63, 0x68, 0x65, + 0x6d, 0x61, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x52, 0x07, 0x73, 0x63, 0x68, 0x65, 0x6d, + 0x61, 0x73, 0x12, 0x14, 0x0a, 0x05, 0x64, 0x65, 0x62, 0x75, 0x67, 0x18, 0x08, 0x20, 0x01, 0x28, + 0x08, 0x52, 0x05, 0x64, 0x65, 0x62, 0x75, 0x67, 0x22, 0x10, 0x0a, 0x0e, 0x43, 0x6f, 0x6e, 0x66, + 0x69, 0x67, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x32, 0x48, 0x0a, 0x10, 0x53, 0x65, + 0x74, 0x43, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x50, 0x72, 0x6f, 0x63, 0x65, 0x73, 0x73, 0x12, 0x34, + 0x0a, 0x03, 0x52, 0x75, 0x6e, 0x12, 0x14, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x43, 0x6f, + 0x6e, 0x66, 0x69, 0x67, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x15, 0x2e, 0x70, 0x72, + 0x6f, 0x74, 0x6f, 0x2e, 0x43, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, + 0x73, 0x65, 0x22, 0x00, 0x42, 0x08, 0x5a, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2f, 0x62, 0x06, + 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, } var ( diff --git a/lbot/proto/config.proto b/lbot/proto/config.proto index e9789a2..ea6a3a1 100644 --- a/lbot/proto/config.proto +++ b/lbot/proto/config.proto @@ -36,9 +36,13 @@ message JobRequest { message ConfigRequest { string connection_string = 1; - repeated JobRequest jobs = 2; - repeated SchemaRequest schemas = 3; - bool debug = 4; + string agent_name = 2; + string agent_port = 3; + string metrics_export_url = 4; + string metrics_export_port = 5; + repeated JobRequest jobs = 6; + repeated SchemaRequest schemas = 7; + bool debug = 8; } message ConfigResponse {}