[MM-57010] Include client type in websocket connections metric (#26763)
* Include client type in websocket connections metric * Unexport field
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
effb99301e
Коммит
4b508eed46
@@ -430,9 +430,7 @@ func (h Handler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||
pageLoadContext = ""
|
||||
}
|
||||
|
||||
originClient := string(originClient(r))
|
||||
|
||||
c.App.Metrics().ObserveAPIEndpointDuration(h.HandlerName, r.Method, statusCode, originClient, pageLoadContext, elapsed)
|
||||
c.App.Metrics().ObserveAPIEndpointDuration(h.HandlerName, r.Method, statusCode, string(GetOriginClient(r)), pageLoadContext, elapsed)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -446,12 +444,12 @@ const (
|
||||
OriginClientDesktop OriginClient = "desktop"
|
||||
)
|
||||
|
||||
// originClient returns the device from which the provided request was issued. The algorithm roughly looks like:
|
||||
// GetOriginClient returns the device from which the provided request was issued. The algorithm roughly looks like:
|
||||
// - If the URL contains the query mobilev2=true, then it's mobile
|
||||
// - If the first field of the user agent starts with either "rnbeta" or "Mattermost", then it's mobile
|
||||
// - If the last field of the user agent starts with "Mattermost", then it's desktop
|
||||
// - Otherwise, it's web
|
||||
func originClient(r *http.Request) OriginClient {
|
||||
func GetOriginClient(r *http.Request) OriginClient {
|
||||
userAgent := r.Header.Get("User-Agent")
|
||||
fields := strings.Fields(userAgent)
|
||||
if len(fields) < 1 {
|
||||
|
||||
@@ -883,7 +883,7 @@ func TestCheckCSRFToken(t *testing.T) {
|
||||
})
|
||||
}
|
||||
|
||||
func TestOriginClient(t *testing.T) {
|
||||
func TestGetOriginClient(t *testing.T) {
|
||||
testCases := []struct {
|
||||
name string
|
||||
userAgent string
|
||||
@@ -945,7 +945,7 @@ func TestOriginClient(t *testing.T) {
|
||||
}
|
||||
|
||||
// Compute origin client
|
||||
actualClient := originClient(req)
|
||||
actualClient := GetOriginClient(req)
|
||||
|
||||
require.Equal(t, tc.expectedClient, actualClient)
|
||||
}
|
||||
|
||||
Ссылка в новой задаче
Block a user