[MM-55268] Implement ServeMetrics plugins hook (#24249)
* Implement ServeMetrics plugins hook * Update error id * Simplify * Revert "Simplify" This reverts commit c9dc5d5eac6c933ff69e158cf3e34d0973bd3bcd. * Add comment and error handler * Wrap error * Update translation file --------- Co-authored-by: Mattermost Build <build@mattermost.com>
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
926142ca22
Коммит
aa3a12f183
@@ -2305,3 +2305,63 @@ func TestSendPushNotification(t *testing.T) {
|
||||
}
|
||||
assert.Equal(t, 6, numMessages)
|
||||
}
|
||||
|
||||
func TestPluginServeMetrics(t *testing.T) {
|
||||
th := Setup(t, StartMetrics)
|
||||
defer th.TearDown()
|
||||
|
||||
var prevEnable *bool
|
||||
var prevAddress *string
|
||||
th.App.UpdateConfig(func(cfg *model.Config) {
|
||||
prevEnable = cfg.MetricsSettings.Enable
|
||||
prevAddress = cfg.MetricsSettings.ListenAddress
|
||||
cfg.MetricsSettings.Enable = model.NewBool(true)
|
||||
cfg.MetricsSettings.ListenAddress = model.NewString(":30067")
|
||||
})
|
||||
defer th.App.UpdateConfig(func(cfg *model.Config) {
|
||||
cfg.MetricsSettings.Enable = prevEnable
|
||||
cfg.MetricsSettings.ListenAddress = prevAddress
|
||||
})
|
||||
|
||||
testFolder, found := fileutils.FindDir("channels/app/plugin_api_tests")
|
||||
require.True(t, found, "Cannot find tests folder")
|
||||
fullPath := path.Join(testFolder, "manual.test_serve_metrics_plugin", "main.go")
|
||||
|
||||
pluginCode, err := os.ReadFile(fullPath)
|
||||
require.NoError(t, err)
|
||||
require.NotEmpty(t, pluginCode)
|
||||
|
||||
tearDown, ids, errors := SetAppEnvironmentWithPlugins(t, []string{string(pluginCode)}, th.App, th.NewPluginAPI)
|
||||
defer tearDown()
|
||||
require.NoError(t, errors[0])
|
||||
require.Len(t, ids, 1)
|
||||
|
||||
pluginID := ids[0]
|
||||
require.NotEmpty(t, pluginID)
|
||||
|
||||
reqURL := fmt.Sprintf("http://localhost%s/plugins/%s/metrics", *th.App.Config().MetricsSettings.ListenAddress, pluginID)
|
||||
req, err := http.NewRequest("GET", reqURL, nil)
|
||||
require.NoError(t, err)
|
||||
|
||||
client := &http.Client{}
|
||||
resp, err := client.Do(req)
|
||||
require.NoError(t, err)
|
||||
|
||||
defer resp.Body.Close()
|
||||
|
||||
body, err := io.ReadAll(resp.Body)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, "METRICS", string(body))
|
||||
|
||||
reqURL = fmt.Sprintf("http://localhost%s/plugins/%s/metrics/subpath", *th.App.Config().MetricsSettings.ListenAddress, pluginID)
|
||||
req, err = http.NewRequest("GET", reqURL, nil)
|
||||
require.NoError(t, err)
|
||||
|
||||
resp, err = client.Do(req)
|
||||
require.NoError(t, err)
|
||||
defer resp.Body.Close()
|
||||
|
||||
body, err = io.ReadAll(resp.Body)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, "METRICS SUBPATH", string(body))
|
||||
}
|
||||
|
||||
Ссылка в новой задаче
Block a user