MM-60269: Removed an incorrect return that caused missing API timing metrics for 4xx and 5xx errors (#28049)
* removed an incorretc return that caused missing API timing metrics for 4xx and 5xx errors * Added tests and recorded metric for URL length limit as well * Status code fix
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
9591e6182f
Коммит
c2c37cea20
@@ -155,4 +155,67 @@ func TestSubmitMetrics(t *testing.T) {
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, http.StatusOK, resp.StatusCode)
|
||||
})
|
||||
|
||||
t.Run("metrics recorded for API errors", func(t *testing.T) {
|
||||
metricsMock := setupMetricsMock()
|
||||
metricsMock.On("IncrementClientLongTasks", mock.AnythingOfType("string"), mock.AnythingOfType("string"), mock.AnythingOfType("float64")).Return()
|
||||
|
||||
platform.RegisterMetricsInterface(func(_ *platform.PlatformService, _, _ string) einterfaces.MetricsInterface {
|
||||
return metricsMock
|
||||
})
|
||||
t.Cleanup(func() {
|
||||
platform.RegisterMetricsInterface(func(_ *platform.PlatformService, _, _ string) einterfaces.MetricsInterface {
|
||||
return nil
|
||||
})
|
||||
})
|
||||
|
||||
th := SetupEnterpriseWithServerOptions(t, []app.Option{app.StartMetrics})
|
||||
defer th.TearDown()
|
||||
|
||||
// enable metrics and add the license
|
||||
th.App.Srv().SetLicense(model.NewTestLicense())
|
||||
th.App.UpdateConfig(func(cfg *model.Config) { *cfg.MetricsSettings.Enable = true })
|
||||
th.App.UpdateConfig(func(cfg *model.Config) { *cfg.MetricsSettings.ListenAddress = ":0" })
|
||||
|
||||
_, resp, err := th.Client.CreatePost(th.Context.Context(), &model.Post{
|
||||
ChannelId: model.NewId(),
|
||||
})
|
||||
|
||||
require.Error(t, err)
|
||||
require.Equal(t, http.StatusForbidden, resp.StatusCode)
|
||||
metricsMock.AssertCalled(t, "IncrementHTTPRequest")
|
||||
metricsMock.AssertCalled(t, "IncrementHTTPError")
|
||||
})
|
||||
|
||||
t.Run("metrics recorded for URL length limit errors", func(t *testing.T) {
|
||||
metricsMock := setupMetricsMock()
|
||||
metricsMock.On("IncrementClientLongTasks", mock.AnythingOfType("string"), mock.AnythingOfType("string"), mock.AnythingOfType("float64")).Return()
|
||||
|
||||
platform.RegisterMetricsInterface(func(_ *platform.PlatformService, _, _ string) einterfaces.MetricsInterface {
|
||||
return metricsMock
|
||||
})
|
||||
t.Cleanup(func() {
|
||||
platform.RegisterMetricsInterface(func(_ *platform.PlatformService, _, _ string) einterfaces.MetricsInterface {
|
||||
return nil
|
||||
})
|
||||
})
|
||||
|
||||
th := SetupEnterpriseWithServerOptions(t, []app.Option{app.StartMetrics})
|
||||
defer th.TearDown()
|
||||
|
||||
// enable metrics and add the license
|
||||
th.App.Srv().SetLicense(model.NewTestLicense())
|
||||
th.App.UpdateConfig(func(cfg *model.Config) { *cfg.MetricsSettings.Enable = true })
|
||||
th.App.UpdateConfig(func(cfg *model.Config) { *cfg.MetricsSettings.ListenAddress = ":0" })
|
||||
th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.MaximumURLLength = 1 })
|
||||
|
||||
_, resp, err := th.Client.CreatePost(th.Context.Context(), &model.Post{
|
||||
ChannelId: model.NewId(),
|
||||
})
|
||||
|
||||
require.Error(t, err)
|
||||
require.Equal(t, http.StatusRequestURITooLong, resp.StatusCode)
|
||||
metricsMock.AssertCalled(t, "IncrementHTTPRequest")
|
||||
metricsMock.AssertCalled(t, "IncrementHTTPError")
|
||||
})
|
||||
}
|
||||
|
||||
Ссылка в новой задаче
Block a user