From 4784d166392decf869991122cbbc3cdaa3d4dbbe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BE=90=E8=81=AA?= Date: Thu, 21 Jul 2022 18:01:27 +0800 Subject: [PATCH] fix: report metrics to prometheus --- docs/CHANGELOG.md | 27 +++------------------------ hrp/internal/boomer/output.go | 9 +++++---- hrp/internal/boomer/runner.go | 5 +++-- hrp/plugin.go | 3 +-- 4 files changed, 12 insertions(+), 32 deletions(-) diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md index 61780740..f918cbcc 100644 --- a/docs/CHANGELOG.md +++ b/docs/CHANGELOG.md @@ -5,11 +5,6 @@ **go version** - feat: support multi-machine collaborative distributed load testing - -## v4.1.7 (2022-07-18) - -**go version** - - feat: support indicating type and filename when uploading file - feat: support to infer MIME type of the file automatically - feat: support omitting websocket url if not necessary @@ -284,8 +279,7 @@ - feat: implement `transaction` mechanism for load test - feat: continue running next step when failure occurs with `--continue-on-failure` flag, default to failfast - feat: report GA events with version -- feat: run load test with the given limit and burst as rate limiter, use `--spawn-count`, `--spawn-rate` - and `--request-increase-rate` flag +- feat: run load test with the given limit and burst as rate limiter, use `--spawn-count`, `--spawn-rate` and `--request-increase-rate` flag - feat: report runner state to prometheus - refactor: fork [boomer] as submodule initially and made a lot of changes - change: update API models @@ -339,8 +333,7 @@ ## 3.1.8 (2022-03-22) -- feat: add `--profile` flag for har2case to support overwrite headers/cookies with specified yaml/json configuration - file +- feat: add `--profile` flag for har2case to support overwrite headers/cookies with specified yaml/json configuration file - feat: support variable and function in response extract expression - fix: keep negative index in jmespath unchanged when converting pytest files, e.g. body.users[-1] - fix: variable should not start with digit @@ -658,31 +651,17 @@ reference: [v2-changelog] [hrp]: https://github.com/httprunner/hrp - [hashicorp/go-plugin]: https://github.com/hashicorp/go-plugin - [go plugin]: https://pkg.go.dev/plugin - [docs repo]: https://github.com/httprunner/httprunner.github.io - [zerolog]: https://github.com/rs/zerolog - [jmespath]: https://jmespath.org/ - [mkdocs]: https://www.mkdocs.org/ - [github-actions]: https://github.com/httprunner/hrp/actions - [boomer]: github.com/myzhan/boomer - [sentry sdk]: https://github.com/getsentry/sentry-go - [pushgateway]: https://github.com/prometheus/pushgateway - [locust]: https://locust.io/ - [black]: https://github.com/psf/black - [loguru]: https://github.com/Delgan/loguru - -[v2-changelog]: https://github.com/httprunner/httprunner/blob/v2/docs/CHANGELOG.md +[v2-changelog]: https://github.com/httprunner/httprunner/blob/v2/docs/CHANGELOG.md \ No newline at end of file diff --git a/hrp/internal/boomer/output.go b/hrp/internal/boomer/output.go index ec4ab82e..55dec290 100644 --- a/hrp/internal/boomer/output.go +++ b/hrp/internal/boomer/output.go @@ -475,7 +475,8 @@ type PrometheusPusherOutput struct { // OnStart will register all prometheus metric collectors func (o *PrometheusPusherOutput) OnStart() { - o.reset() + // reset all prometheus metrics + resetPrometheusMetrics() log.Info().Msg("register prometheus metric collectors") registry := prometheus.NewRegistry() registry.MustRegister( @@ -608,9 +609,9 @@ func (o *PrometheusPusherOutput) OnEvent(data map[string]interface{}) { } } -// reset will reset all metrics -func (o *PrometheusPusherOutput) reset() { - log.Info().Msg("reset metrics") +// resetPrometheusMetrics will reset all metrics +func resetPrometheusMetrics() { + log.Info().Msg("reset all prometheus metrics") gaugeNumRequests.Reset() gaugeNumFailures.Reset() gaugeMedianResponseTime.Reset() diff --git a/hrp/internal/boomer/runner.go b/hrp/internal/boomer/runner.go index cf6ceb11..503ffbaa 100644 --- a/hrp/internal/boomer/runner.go +++ b/hrp/internal/boomer/runner.go @@ -927,14 +927,15 @@ func (r *workerRunner) start() { close(r.doneChan) - // notify master that worker is stopped - r.onStopped() // wait until all stats are reported successfully <-r.reportedChan // report test result r.reportTestResult() // output teardown r.outputOnStop() + + // notify master that worker is stopped + r.onStopped() }() // start stats report diff --git a/hrp/plugin.go b/hrp/plugin.go index ff8252b5..d98437ac 100644 --- a/hrp/plugin.go +++ b/hrp/plugin.go @@ -8,10 +8,9 @@ import ( "github.com/httprunner/funplugin" "github.com/httprunner/funplugin/fungo" - "github.com/rs/zerolog/log" - "github.com/httprunner/httprunner/v4/hrp/internal/builtin" "github.com/httprunner/httprunner/v4/hrp/internal/sdk" + "github.com/rs/zerolog/log" ) const (