From cf03209c166e16b9e105c64df03c1f18f6febd15 Mon Sep 17 00:00:00 2001 From: Bill Thorp Date: Fri, 4 Feb 2022 16:19:01 -0500 Subject: [PATCH] satellite/metainfo: only collect metric "other" once per user agent A user-agent string can contain multiple "products", in the case of Gateway-MT at least this includes the HTTP client's full user agent. This means that "other" is often logged even when we know the Storj product, and sometimes logged more than once per call to "collect". This makes sure that "other" is only logged if a product isn't identified, and only logged once. Change-Id: I8536f7eb32877e36fec97dab7b8d477ccb10f92e --- satellite/metainfo/version_collector.go | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/satellite/metainfo/version_collector.go b/satellite/metainfo/version_collector.go index 4f056cef2..0bc372296 100644 --- a/satellite/metainfo/version_collector.go +++ b/satellite/metainfo/version_collector.go @@ -48,6 +48,7 @@ func (vc *versionCollector) collect(useragentRaw []byte, method string) error { return errs.New("invalid user agent %q: %v", string(useragentRaw), err) } + foundProduct := false for _, entry := range entries { if strings.EqualFold(entry.Product, uplinkProduct) { vo := versionOccurrence{ @@ -60,11 +61,12 @@ func (vc *versionCollector) collect(useragentRaw []byte, method string) error { } else if knownUserAgent(entry.Product) { // for known user agents monitor only product mon.Meter("user_agents", monkit.NewSeriesTag("user_agent", strings.ToLower(entry.Product))).Mark(1) - } else { - // lets keep also general value for other user agents - mon.Meter("user_agents", monkit.NewSeriesTag("user_agent", "other")).Mark(1) + foundProduct = true } } + if !foundProduct { // lets keep also general value for other user agents + mon.Meter("user_agents", monkit.NewSeriesTag("user_agent", "other")).Mark(1) + } return nil }