http

package
v1.15.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 12, 2025 License: MIT Imports: 37 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func PerfTestAgentCMD added in v1.15.3

func PerfTestAgentCMD() *cobra.Command

PerfTestAgentCMD is the command for performance testing agent

func PerfTestCollectorCMD added in v1.15.3

func PerfTestCollectorCMD() *cobra.Command

PerfTestCollectorCMD is the command for running collector performance test for HTTP API

func PerfTestHTTP2CMD

func PerfTestHTTP2CMD() *cobra.Command

PerfTestHTTP2CMD creates a new cobra.Command for HTTP/2 performance test.

func PerfTestHTTP3CMD

func PerfTestHTTP3CMD() *cobra.Command

PerfTestHTTP3CMD creates a new cobra.Command for HTTP/3 performance test.

func PerfTestHTTPCMD

func PerfTestHTTPCMD() *cobra.Command

PerfTestHTTPCMD creates a new cobra.Command for HTTP/1.1 performance test.

Types

type Agent added in v1.15.3

type Agent struct {
	// config info
	ID            string
	CollectorHost string
	AgentHost     string
	TestURL       string
	TestMethod    string
	// contains filtered or unexported fields
}

Agent is the core structure of performance testing services

func NewAgent added in v1.15.3

func NewAgent(id, collectorHost, agentHost, testURL, testMethod string) (*Agent, error)

NewAgent creates a new Agent instance

func (*Agent) Run added in v1.15.3

func (a *Agent) Run(ctx context.Context, loop bool) error

Run agent main loop

type AgentInfo added in v1.15.3

type AgentInfo struct {
	ID       string      `json:"id"`
	Callback string      `json:"callback"`
	URL      string      `json:"url"`
	Method   string      `json:"method"`
	Status   AgentStatus `json:"status"`
}

AgentInfo store registered agent information

type AgentStatus added in v1.15.3

type AgentStatus string

AgentStatus defined agent status

const (
	AgentStatusIdle       AgentStatus = "idle"
	AgentStatusRegistered AgentStatus = "registered"
	AgentStatusRunning    AgentStatus = "running"
	AgentStatusFinished   AgentStatus = "finished"
	AgentStatusStopped    AgentStatus = "stopped"
	AgentStatusCanceled   AgentStatus = "canceled"
)

type Builder added in v1.15.3

type Builder struct {
	strings.Builder
}

func (*Builder) WriteString added in v1.15.3

func (b *Builder) WriteString(s string)

func (*Builder) WriteStringf added in v1.15.3

func (b *Builder) WriteStringf(format string, args ...interface{})

type CollectorServer added in v1.15.3

type CollectorServer struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

CollectorServer manage all test sessions

func NewCollectorServer added in v1.15.3

func NewCollectorServer(port int, collectorHost string) (*CollectorServer, error)

func (*CollectorServer) Run added in v1.15.3

func (s *CollectorServer) Run(printHelp func()) error

Run collector server.

type HTTPReqParams

type HTTPReqParams struct {
	URL     string
	Method  string
	Headers map[string]string
	Body    []byte
	// contains filtered or unexported fields
}

type PerfTestData added in v1.15.3

type PerfTestData struct {
	ID     string `json:"id"`     // test id
	URL    string `json:"url"`    // test url
	Method string `json:"method"` // test method

	TotalDuration float64 `json:"total_duration"` // unit: s
	TotalRequests int64   `json:"total_requests"`
	SuccessCount  int64   `json:"success_count"`
	ErrorCount    int64   `json:"error_count"`
	QPS           float64 `json:"qps"` // unit: req/sec

	AvgLatency float64 `json:"avg_latency"` // unit: ms
	P25Latency float64 `json:"p25_latency"` // unit: ms
	P50Latency float64 `json:"p50_latency"` // unit: ms
	P95Latency float64 `json:"p95_latency"` // unit: ms
	P99Latency float64 `json:"p99_latency"` // unit: ms
	MaxLatency float64 `json:"max_latency"` // unit: ms
	MinLatency float64 `json:"min_latency"` // unit: ms

	TotalSent     int64 `json:"total_sent"`     // unit: bytes
	TotalReceived int64 `json:"total_received"` // unit: bytes

	StatusCodes map[int]int64 `json:"status_codes"`
	CreatedAt   string        `json:"created_at"`
	Status      string        `json:"status"`   // running, finished, stopped
	AgentID     string        `json:"agent_id"` // agent identify

	Errors []string `json:"errors"` // error details
}

PerfTestData test statistics data

type PerfTestHTTP

type PerfTestHTTP struct {
	ID string // performance test ID

	Client *http.Client
	Params *HTTPReqParams

	Worker        int
	TotalRequests uint64
	Duration      time.Duration

	PushURL           string
	PrometheusJobName string
	// contains filtered or unexported fields
}

PerfTestHTTP performance test parameters for HTTP

func (*PerfTestHTTP) Run added in v1.15.3

func (p *PerfTestHTTP) Run(ctx context.Context, duration time.Duration, out string) error

Run the performance test with fixed number of requests or fixed duration.

func (*PerfTestHTTP) RunWithFixedDuration

func (p *PerfTestHTTP) RunWithFixedDuration(globalCtx context.Context) (*Statistics, error)

RunWithFixedDuration implements performance with a fixed duration.

func (*PerfTestHTTP) RunWithFixedRequestsNum

func (p *PerfTestHTTP) RunWithFixedRequestsNum(globalCtx context.Context) (*Statistics, error)

RunWithFixedRequestsNum implements performance with a fixed number of requests.

type Result

type Result struct {
	Duration   time.Duration
	ReqSize    int64
	RespSize   int64
	StatusCode int
	Err        error
}

Result record the results of the request

type Statistics

type Statistics struct {
	ID string `json:"id"` // Performance Test ID

	URL    string `json:"url"`    // performed request URL
	Method string `json:"method"` // request method
	Body   string `json:"body"`   // request body (JSON)

	TotalRequests uint64   `json:"total_requests"` // total requests
	TotalDuration float64  `json:"total_duration"` //  total duration (seconds)
	SuccessCount  uint64   `json:"success_count"`  // successful requests (status code 2xx)
	ErrorCount    uint64   `json:"error_count"`    // failed requests (status code not 2xx)
	Errors        []string `json:"errors"`         // error details

	QPS        float64 `json:"qps"`         // requests per second (Throughput)
	AvgLatency float64 `json:"avg_latency"` // average latency (ms)
	P25Latency float64 `json:"p25_latency"` // 25th percentile latency (ms)
	P50Latency float64 `json:"p50_latency"` // 50th percentile latency (ms)
	P95Latency float64 `json:"p95_latency"` // 95th percentile latency (ms)
	P99Latency float64 `json:"p99_latency"` // 95th percentile latency (ms)
	MinLatency float64 `json:"min_latency"` // minimum latency (ms)
	MaxLatency float64 `json:"max_latency"` // maximum latency (ms)

	TotalSent     int64 `json:"total_sent"`     // total sent (bytes)
	TotalReceived int64 `json:"total_received"` // total received (bytes)

	StatusCodes map[int]int64 `json:"status_codes"` // status code distribution (count)

	CreatedAt time.Time `json:"created_at"` // created time

	Status  string `json:"status"`   // running, finished
	AgentID string `json:"agent_id"` // identify agent
}

Statistics performance test statistical data

func (*Statistics) Save

func (s *Statistics) Save(filePath string) error

Save saves the statistics data to a JSON file.

type TestSession added in v1.15.3

type TestSession struct {
	sync.Mutex
	TestID           string
	Status           TestStatus
	ExpectedAgents   int
	Agents           map[string]*AgentInfo
	TestingReports   map[string]PerfTestData // agentID -> PerfTestData
	FinalReports     map[string]PerfTestData // agentID -> PerfTestData
	AggregatedReport *PerfTestData
	CreatedAt        time.Time
}

TestSession manage all states of a single test

func NewTestSession added in v1.15.3

func NewTestSession(expectedAgents int) *TestSession

type TestStatus added in v1.15.3

type TestStatus string
const (
	StatusPending   TestStatus = "pending"
	StatusRunning   TestStatus = "running"
	StatusStopped   TestStatus = "stopped"
	StatusCompleted TestStatus = "completed"
	StatusAborted   TestStatus = "aborted"
)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL