Merge branch 'main' of github.com:httprunner/hrp

Change-Id: Ia0ad0c10312d94904de0caf38bf4deb395ab6b73
This commit is contained in:
buyuxiang
2022-01-24 21:19:56 +08:00
6 changed files with 65 additions and 28 deletions
+1
View File
@@ -19,6 +19,7 @@ __debug_bin
.idea/ .idea/
__pycache__ __pycache__
.DS_Store .DS_Store
*.bak
site/ site/
output/ output/
+5
View File
@@ -8,6 +8,11 @@ test: ## run unit tests
@echo "go test -race -v ./..." @echo "go test -race -v ./..."
@go test -race -v ./... @go test -race -v ./...
.PHONY: bump
bump: ## bump hrp version
@echo "[info] bump hrp version"
@. cli/scripts/bump_version.sh $(version)
.PHONY: build .PHONY: build
build: ## build hrp cli tool build: ## build hrp cli tool
@echo "[info] build hrp cli tool" @echo "[info] build hrp cli tool"
+1 -1
View File
@@ -140,7 +140,7 @@ func (b *HRPBoomer) convertBoomerTask(testcase *TestCase) *boomer.Task {
if stepData.stepType == stepTypeTransaction { if stepData.stepType == stepTypeTransaction {
// transaction // transaction
// FIXME: support nested transactions // FIXME: support nested transactions
if stepData.elapsed != 0 { // only record when transaction ends if step.ToStruct().Transaction.Type == transactionEnd { // only record when transaction ends
b.RecordTransaction(stepData.name, transactionSuccess, stepData.elapsed, 0) b.RecordTransaction(stepData.name, transactionSuccess, stepData.elapsed, 0)
transactionSuccess = true // reset flag for next transaction transactionSuccess = true // reset flag for next transaction
} }
+23
View File
@@ -0,0 +1,23 @@
#!/bin/bash
# build hrp cli binary for testing
# release will be triggered on github actions, see .github/workflows/release.yml
# Usage:
# $ make bump version=v0.5.2
# or
# $ bash cli/scripts/bump_version.sh v0.5.2
set -e
version=$1
if [ -z "$version" ]; then
echo "version is required"
exit 1
fi
echo "bump hrp version to $version"
sed -i'.bak' "s/\"v.*\"/\"$version\"/g" internal/version/init.go
echo "bump install.sh version to $version"
sed -i'.bak' "s/LATEST_VERSION=\"v.*\"/LATEST_VERSION=\"$version\"/g" cli/scripts/install.sh
+20 -17
View File
@@ -2,6 +2,8 @@
# install hrp with one shell command # install hrp with one shell command
# bash -c "$(curl -ksSL https://httprunner.oss-cn-beijing.aliyuncs.com/install.sh)" # bash -c "$(curl -ksSL https://httprunner.oss-cn-beijing.aliyuncs.com/install.sh)"
LATEST_VERSION="v0.5.2"
set -e set -e
function echoError() { function echoError() {
@@ -46,14 +48,6 @@ function get_pkg_suffix() {
fi fi
} }
function get_download_url() {
# github
# url="https://github.com/httprunner/hrp/releases/download/$version/$1"
# aliyun oss
url="https://httprunner.oss-cn-beijing.aliyuncs.com/$1"
echo $url
}
function extract_pkg() { function extract_pkg() {
pkg=$1 pkg=$1
if [[ $pkg == *.zip ]]; then # windows if [[ $pkg == *.zip ]]; then # windows
@@ -67,16 +61,25 @@ function extract_pkg() {
function main() { function main() {
echoInfo "Detect target hrp package..." echoInfo "Detect target hrp package..."
version=$(get_latest_version) version=$LATEST_VERSION
echo "Latest version: $version"
os=$(get_os) os=$(get_os)
echo "Current OS: $os" echo "Current OS: $os"
arch=$(get_arch) arch=$(get_arch)
echo "Current ARCH: $arch" echo "Current ARCH: $arch"
pkg_suffix=$(get_pkg_suffix $os) pkg_suffix=$(get_pkg_suffix $os)
pkg="hrp-$version-$os-$arch$pkg_suffix" pkg="hrp-$version-$os-$arch$pkg_suffix"
url=$(get_download_url $pkg)
echo "Selected package: $url" # download from aliyun OSS
url="https://httprunner.oss-cn-beijing.aliyuncs.com/$pkg"
if ! curl --output /dev/null --silent --head --fail "$url"; then
# aliyun OSS url is invalid, try to download from github
version=$(get_latest_version)
pkg="hrp-$version-$os-$arch$pkg_suffix"
url="https://github.com/httprunner/hrp/releases/download/$version/$pkg"
fi
echo "Latest version: $version"
echo "Download url: $url"
echo echo
echoInfo "Created temp dir..." echoInfo "Created temp dir..."
@@ -98,10 +101,10 @@ function main() {
echo echo
echoInfo "Installing..." echoInfo "Installing..."
if hrp -v > /dev/null; then if hrp -v > /dev/null && [ $(command -v hrp) != "./hrp" ]; then
echoWarn "$(hrp -v) exists, remove first !!!" echoWarn "$(hrp -v) exists, remove first !!!"
echo "$ rm -rf $(which hrp)" echo "$ rm -rf $(command -v hrp)"
rm -rf "$(which hrp)" rm -rf "$(command -v hrp)"
fi fi
echo "$ chmod +x hrp && mv hrp /usr/local/bin/" echo "$ chmod +x hrp && mv hrp /usr/local/bin/"
@@ -110,8 +113,8 @@ function main() {
echo echo
echoInfo "Check installation..." echoInfo "Check installation..."
echo "$ which hrp" echo "$ command -v hrp"
which hrp command -v hrp
echo "$ hrp -v" echo "$ hrp -v"
hrp -v hrp -v
echo "$ hrp -h" echo "$ hrp -h"
+15 -10
View File
@@ -337,6 +337,17 @@ var (
) )
) )
// counter for total
var (
counterErrors = prometheus.NewCounterVec(
prometheus.CounterOpts{
Name: "errors",
Help: "The errors of load testing",
},
[]string{"method", "name", "error"},
)
)
// summary for total // summary for total
var ( var (
summaryResponseTime = prometheus.NewSummaryVec( summaryResponseTime = prometheus.NewSummaryVec(
@@ -399,13 +410,6 @@ var (
Help: "The accumulated number of failed transactions", Help: "The accumulated number of failed transactions",
}, },
) )
gaugeErrors = prometheus.NewGaugeVec(
prometheus.GaugeOpts{
Name: "errors",
Help: "The errors of load testing",
},
[]string{"method", "name", "error"},
)
) )
// NewPrometheusPusherOutput returns a PrometheusPusherOutput. // NewPrometheusPusherOutput returns a PrometheusPusherOutput.
@@ -436,7 +440,8 @@ func (o *PrometheusPusherOutput) OnStart() {
gaugeAverageContentLength, gaugeAverageContentLength,
gaugeCurrentRPS, gaugeCurrentRPS,
gaugeCurrentFailPerSec, gaugeCurrentFailPerSec,
gaugeErrors, // counter for total
counterErrors,
// summary for total // summary for total
summaryResponseTime, summaryResponseTime,
// gauges for total // gauges for total
@@ -505,11 +510,11 @@ func (o *PrometheusPusherOutput) OnEvent(data map[string]interface{}) {
// errors // errors
for _, requestError := range output.Errors { for _, requestError := range output.Errors {
gaugeErrors.WithLabelValues( counterErrors.WithLabelValues(
requestError["method"].(string), requestError["method"].(string),
requestError["name"].(string), requestError["name"].(string),
requestError["error"].(string), requestError["error"].(string),
).Set(float64(requestError["occurrences"].(int64))) ).Add(float64(requestError["occurrences"].(int64)))
} }
if err := o.pusher.Push(); err != nil { if err := o.pusher.Push(); err != nil {