From 3cd12acc1ba5c4bd996369006ff8245b932f604b Mon Sep 17 00:00:00 2001 From: ErickSkrauch Date: Wed, 13 Dec 2023 01:56:40 +0100 Subject: [PATCH] Export profile requests metrics to statsd --- CHANGELOG.md | 5 +++++ eventsubscribers/stats_reporter.go | 2 ++ eventsubscribers/stats_reporter_test.go | 8 ++++++++ 3 files changed, 15 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7c4100b..53b5f9b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,11 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). ## [Unreleased] - xxxx-xx-xx +### Added +- New StatsD metrics: + - Counters: + - `ely.skinsystem.{hostname}.app.profiles.request` + ### Changed - Bumped Go version to 1.21. diff --git a/eventsubscribers/stats_reporter.go b/eventsubscribers/stats_reporter.go index 286014e..9158838 100644 --- a/eventsubscribers/stats_reporter.go +++ b/eventsubscribers/stats_reporter.go @@ -133,6 +133,8 @@ func (s *StatsReporter) handleBeforeRequest(req *http.Request) { key = "signed_textures.request" } else if strings.HasPrefix(p, "/textures/") { key = "textures.request" + } else if strings.HasPrefix(p, "/profile/") { + key = "profiles.request" } else if m == http.MethodPost && p == "/api/skins" { key = "api.skins.post.request" } else if m == http.MethodDelete && strings.HasPrefix(p, "/api/skins/") { diff --git a/eventsubscribers/stats_reporter_test.go b/eventsubscribers/stats_reporter_test.go index 4fedb77..0923039 100644 --- a/eventsubscribers/stats_reporter_test.go +++ b/eventsubscribers/stats_reporter_test.go @@ -99,6 +99,14 @@ var statsReporterTestCases = []*StatsReporterTestCase{ {"IncCounter", "signed_textures.request", int64(1)}, }, }, + { + Events: [][]interface{}{ + {"skinsystem:before_request", httptest.NewRequest("GET", "http://localhost/profile/username", nil)}, + }, + ExpectedCalls: [][]interface{}{ + {"IncCounter", "profiles.request", int64(1)}, + }, + }, { Events: [][]interface{}{ {"skinsystem:before_request", httptest.NewRequest("POST", "http://localhost/api/skins", nil)},