change: remove namespace

This commit is contained in:
debugtalk
2021-12-22 21:01:43 +08:00
parent 8e58e25e2b
commit c7d6426f51
4 changed files with 39 additions and 91 deletions

View File

@@ -1,7 +1,6 @@
package cmd
import (
"fmt"
"os"
"strings"
@@ -42,7 +41,7 @@ func Execute() {
RootCmd.PersistentFlags().BoolVar(&logJSON, "log-json", false, "set log to json format")
if err := RootCmd.Execute(); err != nil {
fmt.Println(err)
log.Error().Err(err).Msg("Failed to execute root command")
os.Exit(1)
}
}

View File

@@ -246,81 +246,68 @@ func deserializeStatsEntry(stat interface{}) (entryOutput *statsEntryOutput, err
return
}
const (
namespace = "boomer"
)
// gauge vectors for requests
var (
gaugeNumRequests = prometheus.NewGaugeVec(
prometheus.GaugeOpts{
Namespace: namespace,
Name: "num_requests",
Help: "The number of requests",
Name: "num_requests",
Help: "The number of requests",
},
[]string{"method", "name"},
)
gaugeNumFailures = prometheus.NewGaugeVec(
prometheus.GaugeOpts{
Namespace: namespace,
Name: "num_failures",
Help: "The number of failures",
Name: "num_failures",
Help: "The number of failures",
},
[]string{"method", "name"},
)
gaugeMedianResponseTime = prometheus.NewGaugeVec(
prometheus.GaugeOpts{
Namespace: namespace,
Name: "median_response_time",
Help: "The median response time",
Name: "median_response_time",
Help: "The median response time",
},
[]string{"method", "name"},
)
gaugeAverageResponseTime = prometheus.NewGaugeVec(
prometheus.GaugeOpts{
Namespace: namespace,
Name: "average_response_time",
Help: "The average response time",
Name: "average_response_time",
Help: "The average response time",
},
[]string{"method", "name"},
)
gaugeMinResponseTime = prometheus.NewGaugeVec(
prometheus.GaugeOpts{
Namespace: namespace,
Name: "min_response_time",
Help: "The min response time",
Name: "min_response_time",
Help: "The min response time",
},
[]string{"method", "name"},
)
gaugeMaxResponseTime = prometheus.NewGaugeVec(
prometheus.GaugeOpts{
Namespace: namespace,
Name: "max_response_time",
Help: "The max response time",
Name: "max_response_time",
Help: "The max response time",
},
[]string{"method", "name"},
)
gaugeAverageContentLength = prometheus.NewGaugeVec(
prometheus.GaugeOpts{
Namespace: namespace,
Name: "average_content_length",
Help: "The average content length",
Name: "average_content_length",
Help: "The average content length",
},
[]string{"method", "name"},
)
gaugeCurrentRPS = prometheus.NewGaugeVec(
prometheus.GaugeOpts{
Namespace: namespace,
Name: "current_rps",
Help: "The current requests per second",
Name: "current_rps",
Help: "The current requests per second",
},
[]string{"method", "name"},
)
gaugeCurrentFailPerSec = prometheus.NewGaugeVec(
prometheus.GaugeOpts{
Namespace: namespace,
Name: "current_fail_per_sec",
Help: "The current failure number per second",
Name: "current_fail_per_sec",
Help: "The current failure number per second",
},
[]string{"method", "name"},
)
@@ -330,37 +317,32 @@ var (
var (
gaugeUsers = prometheus.NewGauge(
prometheus.GaugeOpts{
Namespace: namespace,
Name: "users",
Help: "The current number of users",
Name: "users",
Help: "The current number of users",
},
)
gaugeTotalRPS = prometheus.NewGauge(
prometheus.GaugeOpts{
Namespace: namespace,
Name: "total_rps",
Help: "The requests per second in total",
Name: "total_rps",
Help: "The requests per second in total",
},
)
gaugeTotalFailRatio = prometheus.NewGauge(
prometheus.GaugeOpts{
Namespace: namespace,
Name: "fail_ratio",
Help: "The ratio of request failures in total",
Name: "fail_ratio",
Help: "The ratio of request failures in total",
},
)
gaugeTransactionsPassed = prometheus.NewGauge(
prometheus.GaugeOpts{
Namespace: namespace,
Name: "transactions_passed",
Help: "The accumulated number of passed transactions",
Name: "transactions_passed",
Help: "The accumulated number of passed transactions",
},
)
gaugeTransactionsFailed = prometheus.NewGauge(
prometheus.GaugeOpts{
Namespace: namespace,
Name: "transactions_failed",
Help: "The accumulated number of failed transactions",
Name: "transactions_failed",
Help: "The accumulated number of failed transactions",
},
)
)

View File

@@ -1,9 +1,7 @@
package boomer
import (
"fmt"
"math"
"sort"
"testing"
)
@@ -108,27 +106,3 @@ func TestConsoleOutput(t *testing.T) {
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)
}

View File

@@ -1,6 +1,7 @@
package boomer
import (
"encoding/json"
"time"
)
@@ -311,23 +312,15 @@ func (s *statsEntry) logError(err string) {
}
func (s *statsEntry) serialize() map[string]interface{} {
result := make(map[string]interface{})
result["name"] = s.Name
result["method"] = s.Method
result["last_request_timestamp"] = s.LastRequestTimestamp
result["start_time"] = s.StartTime
result["num_requests"] = s.NumRequests
// Boomer doesn't allow None response time for requests like locust.
// num_none_requests is added to keep compatible with locust.
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
var result map[string]interface{}
val, err := json.Marshal(s)
if err != nil {
return nil
}
err = json.Unmarshal(val, &result)
if err != nil {
return nil
}
return result
}