From 6c6f1bb97b565ebd9f503ea7ebb8faec2b45d3a0 Mon Sep 17 00:00:00 2001 From: kuzxnia Date: Sun, 18 Feb 2024 10:44:21 +0100 Subject: [PATCH] added job type metrics label --- cli/agent.go | 3 --- cli/config.go | 8 +++----- cli/start.go | 8 +++----- cli/stop.go | 8 ++++---- docs/setup/metrics.md | 12 ++++++------ lbot/agent.go | 6 +++--- lbot/driver/driver.go | 2 +- lbot/driver/metrics.go | 7 ++++--- 8 files changed, 24 insertions(+), 30 deletions(-) diff --git a/cli/agent.go b/cli/agent.go index ae9fe30..cd159e8 100644 --- a/cli/agent.go +++ b/cli/agent.go @@ -37,9 +37,6 @@ func StartAgent(context context.Context, config *lbot.AgentRequest, stdin bool, if lo.IsEmpty(requestConfig.Agent.Port) { requestConfig.Agent.Port = "1234" } - if lo.IsEmpty(requestConfig.Agent.MetricsExportPort) { - requestConfig.Agent.MetricsExportPort = "9090" - } if lo.IsNotEmpty(config.Name) { requestConfig.Agent.Name = config.Name diff --git a/cli/config.go b/cli/config.go index bc1635a..3ad7161 100644 --- a/cli/config.go +++ b/cli/config.go @@ -12,7 +12,6 @@ import ( "github.com/kuzxnia/loadbot/lbot" "github.com/kuzxnia/loadbot/lbot/proto" - log "github.com/sirupsen/logrus" "google.golang.org/grpc" ) @@ -21,16 +20,15 @@ import ( func SetConfigDriver(conn *grpc.ClientConn, parsedConfig *lbot.ConfigRequest) (err error) { requestConfig := BuildConfigRequest(parsedConfig) - log.Info("πŸš€ Setting new config") + fmt.Println("πŸš€ Setting new config") client := proto.NewSetConfigProcessClient(conn) - reply, err := client.Run(context.TODO(), requestConfig) + _, err = client.Run(context.TODO(), requestConfig) if err != nil { return fmt.Errorf("Setting config failed: %w", err) } - log.Infof("Received: %v", reply) - log.Info("βœ… Setting config succeeded") + fmt.Println("βœ… Setting config succeeded") return } diff --git a/cli/start.go b/cli/start.go index ab01344..9fdbbf7 100644 --- a/cli/start.go +++ b/cli/start.go @@ -5,7 +5,6 @@ import ( "fmt" "github.com/kuzxnia/loadbot/lbot/proto" - log "github.com/sirupsen/logrus" "google.golang.org/grpc" ) @@ -14,17 +13,16 @@ import ( // tutaj nie powinno wchodziΔ‡ proto func StartDriver(conn grpc.ClientConnInterface, request *proto.StartRequest) (err error) { // todo: mapowanie to proto - log.Info("πŸš€ Starting stress test") + fmt.Println("πŸš€ Starting stress test") client := proto.NewStartProcessClient(conn) - reply, err := client.Run(context.TODO(), request) + _, err = client.Run(context.TODO(), request) if err != nil { return fmt.Errorf("starting stress test failed: %w", err) } - log.Infof("Received: %v", reply) - log.Info("βœ… Starting stress test succeeded") + fmt.Println("βœ… Starting stress test succeeded") return } diff --git a/cli/stop.go b/cli/stop.go index 02af4ca..dc7d9fc 100644 --- a/cli/stop.go +++ b/cli/stop.go @@ -2,6 +2,7 @@ package cli import ( "context" + "fmt" "github.com/kuzxnia/loadbot/lbot/proto" log "github.com/sirupsen/logrus" @@ -9,18 +10,17 @@ import ( ) func StopDriver(conn grpc.ClientConnInterface, request *proto.StopRequest) (err error) { - log.Info("πŸš€ Stopping stress test") + fmt.Println("πŸš€ Stopping stress test") client := proto.NewStopProcessClient(conn) - reply, err := client.Run(context.TODO(), request) + _, err = client.Run(context.TODO(), request) if err != nil { log.Fatal("arith error:", err) return } - log.Infof("Received: %v", reply) - log.Info("βœ… Stopping stress test succeeded") + fmt.Println("βœ… Stopping stress test succeeded") return nil } diff --git a/docs/setup/metrics.md b/docs/setup/metrics.md index 8a7382f..23fcdb2 100644 --- a/docs/setup/metrics.md +++ b/docs/setup/metrics.md @@ -26,7 +26,7 @@ Configure the [agent](/loadbot/setup/agent/) using the following flags: The metrics available for monitoring encompass both system-level metrics and custom metrics related to your workloads. Here are some popular metrics from a Go application's perspective: -System Metrics: +##### System Metrics: - `go_goroutines` - `go_threads` @@ -35,20 +35,20 @@ System Metrics: - `go_memstats_alloc_bytes_total` - `process_resident_memory_bytes` -Custom Workload Metrics: +##### Custom Workload Metrics: - `requests_total` - `requests_error` -- `requests_duration_seconds (histogram)` +- `requests_duration_seconds` #### Labels for Querying -When querying metrics, you can utilize labels to specify job-related information: +When querying custom workload metrics, you can utilize labels to specify job-related information: ``` -{job="job_name_here", job_uuid="auto_generate_uuid", agent="agent_name_here"} +{job="job_name_here", job_uuid="auto_generate_uuid", job_type="write|bulk_write|read|update..." agent="agent_name_here"} ``` -Example query: +##### Example query: ``` requests_total{job="workload 1", agent="186.12.9.19"} ``` diff --git a/lbot/agent.go b/lbot/agent.go index cfbed6d..301c13a 100644 --- a/lbot/agent.go +++ b/lbot/agent.go @@ -67,7 +67,7 @@ func (a *Agent) Listen() error { } }() - if a.lbot.config.Agent.MetricsExportPort != "" { + if lo.IsNotEmpty(a.lbot.config.Agent.MetricsExportPort) { http.HandleFunc("/metrics", func(w http.ResponseWriter, req *http.Request) { metrics.WritePrometheus(w, true) }) @@ -75,8 +75,8 @@ func (a *Agent) Listen() error { log.Infof("Started metrics exporter on :%s/metrics", a.lbot.config.Agent.MetricsExportPort) http.ListenAndServe(":"+a.lbot.config.Agent.MetricsExportPort, nil) }() - } else if a.lbot.config.Agent.MetricsExportUrl != "" { - log.Info("Started exporting metrics :", a.lbot.config.Agent.MetricsExportPort) + } else if lo.IsNotEmpty(a.lbot.config.Agent.MetricsExportUrl) { + log.Info("Started exporting metrics to ", a.lbot.config.Agent.MetricsExportUrl) metricsLabels := lo.If( a.lbot.config.Agent.Name != "", diff --git a/lbot/driver/driver.go b/lbot/driver/driver.go index 92a1209..51f7f42 100644 --- a/lbot/driver/driver.go +++ b/lbot/driver/driver.go @@ -37,7 +37,7 @@ func NewWorker(ctx context.Context, cfg *config.Config, job *config.Job, dataPoo worker.wg.Add(int(job.Connections)) worker.pool = NewJobPool(job) worker.rateLimiter = NewLimiter(job) - worker.Metrics = NewMetrics(job.Name) + worker.Metrics = NewMetrics(job) worker.done = false // introduce no db worker diff --git a/lbot/driver/metrics.go b/lbot/driver/metrics.go index 9b52125..27c5748 100644 --- a/lbot/driver/metrics.go +++ b/lbot/driver/metrics.go @@ -1,10 +1,12 @@ package driver import ( + "fmt" "time" "github.com/VictoriaMetrics/metrics" "github.com/google/uuid" + "github.com/kuzxnia/loadbot/lbot/config" ) type Metrics struct { @@ -15,9 +17,8 @@ type Metrics struct { // ResponseSize *metrics.Histogram } -func NewMetrics(job_name string) *Metrics { - // toto: move uuid to worker, and change label to worker uuid - jobLabel := "{job=\"" + job_name + "\", job_uuid=\"" + uuid.New().String() + "\"}" +func NewMetrics(job *config.Job) *Metrics { + jobLabel := fmt.Sprintf(`{job="%s",job_uuid="%s",job_type="%s"}`, job.Name, uuid.New().String(), job.Type) return &Metrics{ requests: metrics.NewCounter("requests_total" + jobLabel),