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
This commit is contained in:
Bill Thorp 2022-02-04 16:19:01 -05:00 committed by Bill Thorp
parent 9061dd309f
commit cf03209c16

View File

@ -48,6 +48,7 @@ func (vc *versionCollector) collect(useragentRaw []byte, method string) error {
return errs.New("invalid user agent %q: %v", string(useragentRaw), err) return errs.New("invalid user agent %q: %v", string(useragentRaw), err)
} }
foundProduct := false
for _, entry := range entries { for _, entry := range entries {
if strings.EqualFold(entry.Product, uplinkProduct) { if strings.EqualFold(entry.Product, uplinkProduct) {
vo := versionOccurrence{ vo := versionOccurrence{
@ -60,11 +61,12 @@ func (vc *versionCollector) collect(useragentRaw []byte, method string) error {
} else if knownUserAgent(entry.Product) { } else if knownUserAgent(entry.Product) {
// for known user agents monitor only product // for known user agents monitor only product
mon.Meter("user_agents", monkit.NewSeriesTag("user_agent", strings.ToLower(entry.Product))).Mark(1) mon.Meter("user_agents", monkit.NewSeriesTag("user_agent", strings.ToLower(entry.Product))).Mark(1)
} else { foundProduct = true
// lets keep also general value for other user agents
mon.Meter("user_agents", monkit.NewSeriesTag("user_agent", "other")).Mark(1)
} }
} }
if !foundProduct { // lets keep also general value for other user agents
mon.Meter("user_agents", monkit.NewSeriesTag("user_agent", "other")).Mark(1)
}
return nil return nil
} }