From 436d98e1a050cf1cd2a6185f6bc9da09ce9c81e0 Mon Sep 17 00:00:00 2001 From: ErickSkrauch Date: Sun, 26 Apr 2020 16:34:46 +0300 Subject: [PATCH] Fix stats reporting for batch UUIDs provider --- CHANGELOG.md | 4 ++++ eventsubscribers/stats_reporter.go | 10 +++++----- eventsubscribers/stats_reporter_test.go | 11 ++++++++--- 3 files changed, 17 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9fde16a..141ee2b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - [#24](https://github.com/elyby/chrly/issues/24): Added a new batch Mojang UUIDs provider strategy `full-bus` and corresponding configuration param `QUEUE_STRATEGY` with the default value `periodic`. +### Changed +- `ely.skinsystem.{hostname}.app.mojang_textures.usernames.round_time` timer will not be recorded if the iteration was + empty. + ## [4.4.1] - 2020-04-24 ### Added - [#20](https://github.com/elyby/chrly/issues/20): Print hostname in the `version` command output. diff --git a/eventsubscribers/stats_reporter.go b/eventsubscribers/stats_reporter.go index 849c644..3c535d2 100644 --- a/eventsubscribers/stats_reporter.go +++ b/eventsubscribers/stats_reporter.go @@ -96,12 +96,12 @@ func (s *StatsReporter) ConfigureWithDispatcher(d Subscriber) { d.Subscribe("mojang_textures:batch_uuids_provider:round", func(usernames []string, queueSize int) { s.UpdateGauge("mojang_textures.usernames.iteration_size", int64(len(usernames))) s.UpdateGauge("mojang_textures.usernames.queue_size", int64(queueSize)) + if len(usernames) != 0 { + s.startTimeRecording("batch_uuids_provider_round_time_" + strings.Join(usernames, "|")) + } }) - d.Subscribe("mojang_textures:batch_uuids_provider:before_round", func() { - s.startTimeRecording("batch_uuids_provider_round_time") - }) - d.Subscribe("mojang_textures:batch_uuids_provider:after_round", func() { - s.finalizeTimeRecording("batch_uuids_provider_round_time", "mojang_textures.usernames.round_time") + d.Subscribe("mojang_textures:batch_uuids_provider:result", func(usernames []string, profiles []*mojang.ProfileInfo, err error) { + s.finalizeTimeRecording("batch_uuids_provider_round_time_"+strings.Join(usernames, "|"), "mojang_textures.usernames.round_time") }) } diff --git a/eventsubscribers/stats_reporter_test.go b/eventsubscribers/stats_reporter_test.go index 448bafc..33eb4ed 100644 --- a/eventsubscribers/stats_reporter_test.go +++ b/eventsubscribers/stats_reporter_test.go @@ -337,19 +337,24 @@ var statsReporterTestCases = []*StatsReporterTestCase{ { Events: [][]interface{}{ {"mojang_textures:batch_uuids_provider:round", []string{"username1", "username2"}, 5}, + {"mojang_textures:batch_uuids_provider:result", []string{"username1", "username2"}, []*mojang.ProfileInfo{}, nil}, }, ExpectedCalls: [][]interface{}{ {"UpdateGauge", "mojang_textures.usernames.iteration_size", int64(2)}, {"UpdateGauge", "mojang_textures.usernames.queue_size", int64(5)}, + {"RecordTimer", "mojang_textures.usernames.round_time", mock.AnythingOfType("time.Duration")}, }, }, { Events: [][]interface{}{ - {"mojang_textures:batch_uuids_provider:before_round"}, - {"mojang_textures:batch_uuids_provider:after_round"}, + {"mojang_textures:batch_uuids_provider:round", []string{}, 0}, + // This event will be not emitted, but we emit it to ensure, that RecordTimer will not be called + {"mojang_textures:batch_uuids_provider:result", []string{}, []*mojang.ProfileInfo{}, nil}, }, ExpectedCalls: [][]interface{}{ - {"RecordTimer", "mojang_textures.usernames.round_time", mock.AnythingOfType("time.Duration")}, + {"UpdateGauge", "mojang_textures.usernames.iteration_size", int64(0)}, + {"UpdateGauge", "mojang_textures.usernames.queue_size", int64(0)}, + // Should not call RecordTimer }, }, }