From 2d94e9f75d0959032522232daf38720094fcdff4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BE=90=E8=81=AA?= Date: Thu, 20 Jan 2022 15:02:35 +0800 Subject: [PATCH 1/3] fix: inaccurate to report data. --- boomer.go | 2 +- internal/boomer/output.go | 25 +++++++++++++++---------- 2 files changed, 16 insertions(+), 11 deletions(-) diff --git a/boomer.go b/boomer.go index 49410898..8ec0ff67 100644 --- a/boomer.go +++ b/boomer.go @@ -140,7 +140,7 @@ func (b *HRPBoomer) convertBoomerTask(testcase *TestCase) *boomer.Task { if stepData.stepType == stepTypeTransaction { // transaction // 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) transactionSuccess = true // reset flag for next transaction } diff --git a/internal/boomer/output.go b/internal/boomer/output.go index 70ab8b06..2f05149d 100644 --- a/internal/boomer/output.go +++ b/internal/boomer/output.go @@ -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 var ( summaryResponseTime = prometheus.NewSummaryVec( @@ -399,13 +410,6 @@ var ( 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. @@ -436,7 +440,8 @@ func (o *PrometheusPusherOutput) OnStart() { gaugeAverageContentLength, gaugeCurrentRPS, gaugeCurrentFailPerSec, - gaugeErrors, + // counter for total + counterErrors, // summary for total summaryResponseTime, // gauges for total @@ -505,11 +510,11 @@ func (o *PrometheusPusherOutput) OnEvent(data map[string]interface{}) { // errors for _, requestError := range output.Errors { - gaugeErrors.WithLabelValues( + counterErrors.WithLabelValues( requestError["method"].(string), requestError["name"].(string), requestError["error"].(string), - ).Set(float64(requestError["occurrences"].(int64))) + ).Add(float64(requestError["occurrences"].(int64))) } if err := o.pusher.Push(); err != nil { From 520e1e722262c134de2bca43c38eca9eba60e2b4 Mon Sep 17 00:00:00 2001 From: debugtalk Date: Mon, 24 Jan 2022 17:34:23 +0800 Subject: [PATCH 2/3] fix: download from github if aliyun oss url is invalid --- .gitignore | 1 + Makefile | 5 +++++ cli/scripts/bump_version.sh | 23 +++++++++++++++++++++++ cli/scripts/install.sh | 27 +++++++++++++++------------ 4 files changed, 44 insertions(+), 12 deletions(-) create mode 100644 cli/scripts/bump_version.sh diff --git a/.gitignore b/.gitignore index e5528b08..5d528d38 100644 --- a/.gitignore +++ b/.gitignore @@ -19,6 +19,7 @@ __debug_bin .idea/ __pycache__ .DS_Store +*.bak site/ output/ diff --git a/Makefile b/Makefile index b75eb2cc..98c17985 100644 --- a/Makefile +++ b/Makefile @@ -8,6 +8,11 @@ test: ## run unit tests @echo "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 build: ## build hrp cli tool @echo "[info] build hrp cli tool" diff --git a/cli/scripts/bump_version.sh b/cli/scripts/bump_version.sh new file mode 100644 index 00000000..7be0a2b6 --- /dev/null +++ b/cli/scripts/bump_version.sh @@ -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 diff --git a/cli/scripts/install.sh b/cli/scripts/install.sh index 14573cd8..b236a689 100644 --- a/cli/scripts/install.sh +++ b/cli/scripts/install.sh @@ -2,6 +2,8 @@ # install hrp with one shell command # bash -c "$(curl -ksSL https://httprunner.oss-cn-beijing.aliyuncs.com/install.sh)" +LATEST_VERSION="v0.5.2" + set -e function echoError() { @@ -46,14 +48,6 @@ function get_pkg_suffix() { 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() { pkg=$1 if [[ $pkg == *.zip ]]; then # windows @@ -67,16 +61,25 @@ function extract_pkg() { function main() { echoInfo "Detect target hrp package..." - version=$(get_latest_version) - echo "Latest version: $version" + version=$LATEST_VERSION os=$(get_os) echo "Current OS: $os" arch=$(get_arch) echo "Current ARCH: $arch" pkg_suffix=$(get_pkg_suffix $os) 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 echoInfo "Created temp dir..." From 387d4a46fbd075f52db55a5464ec10cabc989d86 Mon Sep 17 00:00:00 2001 From: debugtalk Date: Mon, 24 Jan 2022 21:06:36 +0800 Subject: [PATCH 3/3] fix: avoid removing hrp in current dir --- cli/scripts/install.sh | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/cli/scripts/install.sh b/cli/scripts/install.sh index b236a689..af495e31 100644 --- a/cli/scripts/install.sh +++ b/cli/scripts/install.sh @@ -101,10 +101,10 @@ function main() { echo echoInfo "Installing..." - if hrp -v > /dev/null; then + if hrp -v > /dev/null && [ $(command -v hrp) != "./hrp" ]; then echoWarn "$(hrp -v) exists, remove first !!!" - echo "$ rm -rf $(which hrp)" - rm -rf "$(which hrp)" + echo "$ rm -rf $(command -v hrp)" + rm -rf "$(command -v hrp)" fi echo "$ chmod +x hrp && mv hrp /usr/local/bin/" @@ -113,8 +113,8 @@ function main() { echo echoInfo "Check installation..." - echo "$ which hrp" - which hrp + echo "$ command -v hrp" + command -v hrp echo "$ hrp -v" hrp -v echo "$ hrp -h"