MM-23131 Include HTTP status code in the metrics (#14240)

* ResponseWriter wrapper to get status code

For our metrics, we need the status code returned by a request
so this wrapper includes a new method StatusCode() that includes
the desired code

* Shadow the responsewriter variable in the handlers

In order to avoid confusion to people deciding what variable to use.
I've also changed the tests to reflect this change and added a new
one that checks the Flush method works
Этот коммит содержится в:
Mario de Frutos Dieguez
2020-04-14 14:15:00 +02:00
коммит произвёл GitHub
родитель 53c1c0d4b4
Коммит aafea55976
5 изменённых файлов: 157 добавлений и 5 удалений

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

@@ -48,7 +48,7 @@ type MetricsInterface interface {
IncrementPostsSearchCounter()
ObservePostsSearchDuration(elapsed float64)
ObserveStoreMethodDuration(method, success string, elapsed float64)
ObserveApiEndpointDuration(endpoint, method string, elapsed float64)
ObserveApiEndpointDuration(endpoint, method, statusCode string, elapsed float64)
IncrementPostIndexCounter()
IncrementUserIndexCounter()
IncrementChannelIndexCounter()

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

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