Performance metrics: Differentiate requests that are from page load (#24327)

* POC page_load_context header

* refactor to make this.pageLoadContext a private field, and relocate setTimeout code

* add pageLoadContext to `ObserveAPIEndpointDuration` method

* move to telemetry_actions

* move PageContext constant in webapp

* give server control of possible page_load_context values

* variable name change

---------

Co-authored-by: mickmister <mickmister>
Co-authored-by: Mattermost Build <build@mattermost.com>
Этот коммит содержится в:
Michael Kochell
2023-10-13 14:59:12 -04:00
коммит произвёл GitHub
родитель 72c75f01ce
Коммит e9da1ee8ca
8 изменённых файлов: 49 добавлений и 8 удалений

Просмотреть файл

@@ -407,8 +407,15 @@ func (h Handler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
if r.URL.Path != model.APIURLSuffix+"/websocket" {
elapsed := float64(time.Since(now)) / float64(time.Second)
pageLoadContext := r.Header.Get("X-Page-Load-Context")
if pageLoadContext != "page_load" && pageLoadContext != "reconnect" {
pageLoadContext = ""
}
originClient := string(originClient(r))
c.App.Metrics().ObserveAPIEndpointDuration(h.HandlerName, r.Method, statusCode, originClient, elapsed)
c.App.Metrics().ObserveAPIEndpointDuration(h.HandlerName, r.Method, statusCode, originClient, pageLoadContext, elapsed)
}
}
}

Просмотреть файл

@@ -58,7 +58,7 @@ type MetricsInterface interface {
IncrementFilesSearchCounter()
ObserveFilesSearchDuration(elapsed float64)
ObserveStoreMethodDuration(method, success string, elapsed float64)
ObserveAPIEndpointDuration(endpoint, method, statusCode, originClient string, elapsed float64)
ObserveAPIEndpointDuration(endpoint, method, statusCode, originClient, pageLoadContext string, elapsed float64)
IncrementPostIndexCounter()
IncrementFileIndexCounter()
IncrementUserIndexCounter()

Просмотреть файл

@@ -239,9 +239,9 @@ func (_m *MetricsInterface) IncrementWebsocketReconnectEvent(eventType string) {
_m.Called(eventType)
}
// ObserveAPIEndpointDuration provides a mock function with given fields: endpoint, method, statusCode, originClient, elapsed
func (_m *MetricsInterface) ObserveAPIEndpointDuration(endpoint string, method string, statusCode string, originClient string, elapsed float64) {
_m.Called(endpoint, method, statusCode, originClient, elapsed)
// ObserveAPIEndpointDuration provides a mock function with given fields: endpoint, method, statusCode, originClient, pageLoadContext, elapsed
func (_m *MetricsInterface) ObserveAPIEndpointDuration(endpoint string, method string, statusCode string, originClient string, pageLoadContext string, elapsed float64) {
_m.Called(endpoint, method, statusCode, originClient, pageLoadContext, elapsed)
}
// ObserveClusterRequestDuration provides a mock function with given fields: elapsed