change: remove namespace

This commit is contained in:
debugtalk
2021-12-22 21:04:20 +08:00
parent 8e58e25e2b
commit c7d6426f51
4 changed files with 39 additions and 91 deletions
+1 -2
View File
@@ -1,7 +1,6 @@
package cmd package cmd
import ( import (
"fmt"
"os" "os"
"strings" "strings"
@@ -42,7 +41,7 @@ func Execute() {
RootCmd.PersistentFlags().BoolVar(&logJSON, "log-json", false, "set log to json format") RootCmd.PersistentFlags().BoolVar(&logJSON, "log-json", false, "set log to json format")
if err := RootCmd.Execute(); err != nil { if err := RootCmd.Execute(); err != nil {
fmt.Println(err) log.Error().Err(err).Msg("Failed to execute root command")
os.Exit(1) os.Exit(1)
} }
} }
-18
View File
@@ -246,15 +246,10 @@ func deserializeStatsEntry(stat interface{}) (entryOutput *statsEntryOutput, err
return return
} }
const (
namespace = "boomer"
)
// gauge vectors for requests // gauge vectors for requests
var ( var (
gaugeNumRequests = prometheus.NewGaugeVec( gaugeNumRequests = prometheus.NewGaugeVec(
prometheus.GaugeOpts{ prometheus.GaugeOpts{
Namespace: namespace,
Name: "num_requests", Name: "num_requests",
Help: "The number of requests", Help: "The number of requests",
}, },
@@ -262,7 +257,6 @@ var (
) )
gaugeNumFailures = prometheus.NewGaugeVec( gaugeNumFailures = prometheus.NewGaugeVec(
prometheus.GaugeOpts{ prometheus.GaugeOpts{
Namespace: namespace,
Name: "num_failures", Name: "num_failures",
Help: "The number of failures", Help: "The number of failures",
}, },
@@ -270,7 +264,6 @@ var (
) )
gaugeMedianResponseTime = prometheus.NewGaugeVec( gaugeMedianResponseTime = prometheus.NewGaugeVec(
prometheus.GaugeOpts{ prometheus.GaugeOpts{
Namespace: namespace,
Name: "median_response_time", Name: "median_response_time",
Help: "The median response time", Help: "The median response time",
}, },
@@ -278,7 +271,6 @@ var (
) )
gaugeAverageResponseTime = prometheus.NewGaugeVec( gaugeAverageResponseTime = prometheus.NewGaugeVec(
prometheus.GaugeOpts{ prometheus.GaugeOpts{
Namespace: namespace,
Name: "average_response_time", Name: "average_response_time",
Help: "The average response time", Help: "The average response time",
}, },
@@ -286,7 +278,6 @@ var (
) )
gaugeMinResponseTime = prometheus.NewGaugeVec( gaugeMinResponseTime = prometheus.NewGaugeVec(
prometheus.GaugeOpts{ prometheus.GaugeOpts{
Namespace: namespace,
Name: "min_response_time", Name: "min_response_time",
Help: "The min response time", Help: "The min response time",
}, },
@@ -294,7 +285,6 @@ var (
) )
gaugeMaxResponseTime = prometheus.NewGaugeVec( gaugeMaxResponseTime = prometheus.NewGaugeVec(
prometheus.GaugeOpts{ prometheus.GaugeOpts{
Namespace: namespace,
Name: "max_response_time", Name: "max_response_time",
Help: "The max response time", Help: "The max response time",
}, },
@@ -302,7 +292,6 @@ var (
) )
gaugeAverageContentLength = prometheus.NewGaugeVec( gaugeAverageContentLength = prometheus.NewGaugeVec(
prometheus.GaugeOpts{ prometheus.GaugeOpts{
Namespace: namespace,
Name: "average_content_length", Name: "average_content_length",
Help: "The average content length", Help: "The average content length",
}, },
@@ -310,7 +299,6 @@ var (
) )
gaugeCurrentRPS = prometheus.NewGaugeVec( gaugeCurrentRPS = prometheus.NewGaugeVec(
prometheus.GaugeOpts{ prometheus.GaugeOpts{
Namespace: namespace,
Name: "current_rps", Name: "current_rps",
Help: "The current requests per second", Help: "The current requests per second",
}, },
@@ -318,7 +306,6 @@ var (
) )
gaugeCurrentFailPerSec = prometheus.NewGaugeVec( gaugeCurrentFailPerSec = prometheus.NewGaugeVec(
prometheus.GaugeOpts{ prometheus.GaugeOpts{
Namespace: namespace,
Name: "current_fail_per_sec", Name: "current_fail_per_sec",
Help: "The current failure number per second", Help: "The current failure number per second",
}, },
@@ -330,35 +317,30 @@ var (
var ( var (
gaugeUsers = prometheus.NewGauge( gaugeUsers = prometheus.NewGauge(
prometheus.GaugeOpts{ prometheus.GaugeOpts{
Namespace: namespace,
Name: "users", Name: "users",
Help: "The current number of users", Help: "The current number of users",
}, },
) )
gaugeTotalRPS = prometheus.NewGauge( gaugeTotalRPS = prometheus.NewGauge(
prometheus.GaugeOpts{ prometheus.GaugeOpts{
Namespace: namespace,
Name: "total_rps", Name: "total_rps",
Help: "The requests per second in total", Help: "The requests per second in total",
}, },
) )
gaugeTotalFailRatio = prometheus.NewGauge( gaugeTotalFailRatio = prometheus.NewGauge(
prometheus.GaugeOpts{ prometheus.GaugeOpts{
Namespace: namespace,
Name: "fail_ratio", Name: "fail_ratio",
Help: "The ratio of request failures in total", Help: "The ratio of request failures in total",
}, },
) )
gaugeTransactionsPassed = prometheus.NewGauge( gaugeTransactionsPassed = prometheus.NewGauge(
prometheus.GaugeOpts{ prometheus.GaugeOpts{
Namespace: namespace,
Name: "transactions_passed", Name: "transactions_passed",
Help: "The accumulated number of passed transactions", Help: "The accumulated number of passed transactions",
}, },
) )
gaugeTransactionsFailed = prometheus.NewGauge( gaugeTransactionsFailed = prometheus.NewGauge(
prometheus.GaugeOpts{ prometheus.GaugeOpts{
Namespace: namespace,
Name: "transactions_failed", Name: "transactions_failed",
Help: "The accumulated number of failed transactions", Help: "The accumulated number of failed transactions",
}, },
-26
View File
@@ -1,9 +1,7 @@
package boomer package boomer
import ( import (
"fmt"
"math" "math"
"sort"
"testing" "testing"
) )
@@ -108,27 +106,3 @@ func TestConsoleOutput(t *testing.T) {
o.OnStop() o.OnStop()
} }
func TestSortString(t *testing.T) {
stats := []struct {
method string
name string
}{
{"transaction", "Action"},
{"request-GET", "get with params"},
{"request-POST", "post form data"},
{"request-POST", "post json data"},
{"transaction", "tran1"},
}
sort.Slice(stats, func(i, j int) bool {
if stats[i].method < stats[j].method {
return true
}
return stats[i].name < stats[j].name
})
fmt.Println(stats)
}
+10 -17
View File
@@ -1,6 +1,7 @@
package boomer package boomer
import ( import (
"encoding/json"
"time" "time"
) )
@@ -311,23 +312,15 @@ func (s *statsEntry) logError(err string) {
} }
func (s *statsEntry) serialize() map[string]interface{} { func (s *statsEntry) serialize() map[string]interface{} {
result := make(map[string]interface{}) var result map[string]interface{}
result["name"] = s.Name val, err := json.Marshal(s)
result["method"] = s.Method if err != nil {
result["last_request_timestamp"] = s.LastRequestTimestamp return nil
result["start_time"] = s.StartTime }
result["num_requests"] = s.NumRequests err = json.Unmarshal(val, &result)
// Boomer doesn't allow None response time for requests like locust. if err != nil {
// num_none_requests is added to keep compatible with locust. return nil
result["num_none_requests"] = 0 }
result["num_failures"] = s.NumFailures
result["total_response_time"] = s.TotalResponseTime
result["max_response_time"] = s.MaxResponseTime
result["min_response_time"] = s.MinResponseTime
result["total_content_length"] = s.TotalContentLength
result["response_times"] = s.ResponseTimes
result["num_reqs_per_sec"] = s.NumReqsPerSec
result["num_fail_per_sec"] = s.NumFailPerSec
return result return result
} }