[MM-54289] Add heap profile to support package (#24476)
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
b7b08dbc0f
Коммит
153ebc31d7
@@ -4,9 +4,11 @@
|
|||||||
package app
|
package app
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"bytes"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"os"
|
"os"
|
||||||
"runtime"
|
"runtime"
|
||||||
|
"runtime/pprof"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/hashicorp/go-multierror"
|
"github.com/hashicorp/go-multierror"
|
||||||
@@ -33,6 +35,7 @@ func (a *App) GenerateSupportPacket(c *request.Context) []model.FileData {
|
|||||||
"config": a.createSanitizedConfigFile,
|
"config": a.createSanitizedConfigFile,
|
||||||
"mattermost log": a.getMattermostLog,
|
"mattermost log": a.getMattermostLog,
|
||||||
"notification log": a.getNotificationsLog,
|
"notification log": a.getNotificationsLog,
|
||||||
|
"heap profile": a.createHeapProfile,
|
||||||
}
|
}
|
||||||
|
|
||||||
for name, fn := range functions {
|
for name, fn := range functions {
|
||||||
@@ -290,3 +293,18 @@ func (a *App) createSanitizedConfigFile(_ *request.Context) (*model.FileData, er
|
|||||||
}
|
}
|
||||||
return fileData, nil
|
return fileData, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (a *App) createHeapProfile(*request.Context) (*model.FileData, error) {
|
||||||
|
var b bytes.Buffer
|
||||||
|
|
||||||
|
err := pprof.Lookup("heap").WriteTo(&b, 0)
|
||||||
|
if err != nil {
|
||||||
|
return nil, errors.Wrap(err, "failed to lookup heap profile")
|
||||||
|
}
|
||||||
|
|
||||||
|
fileData := &model.FileData{
|
||||||
|
Filename: "heap.prof",
|
||||||
|
Body: b.Bytes(),
|
||||||
|
}
|
||||||
|
return fileData, nil
|
||||||
|
}
|
||||||
|
|||||||
@@ -102,7 +102,7 @@ func TestGenerateSupportPacket(t *testing.T) {
|
|||||||
|
|
||||||
fileDatas := th.App.GenerateSupportPacket(ctx)
|
fileDatas := th.App.GenerateSupportPacket(ctx)
|
||||||
var rFileNames []string
|
var rFileNames []string
|
||||||
testFiles := []string{"support_packet.yaml", "plugins.json", "sanitized_config.json", "mattermost.log", "notifications.log"}
|
testFiles := []string{"support_packet.yaml", "plugins.json", "sanitized_config.json", "mattermost.log", "notifications.log", "heap.prof"}
|
||||||
for _, fileData := range fileDatas {
|
for _, fileData := range fileDatas {
|
||||||
require.NotNil(t, fileData)
|
require.NotNil(t, fileData)
|
||||||
assert.Positive(t, len(fileData.Body))
|
assert.Positive(t, len(fileData.Body))
|
||||||
@@ -117,7 +117,7 @@ func TestGenerateSupportPacket(t *testing.T) {
|
|||||||
err = os.Remove("mattermost.log")
|
err = os.Remove("mattermost.log")
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
fileDatas = th.App.GenerateSupportPacket(ctx)
|
fileDatas = th.App.GenerateSupportPacket(ctx)
|
||||||
testFiles = []string{"support_packet.yaml", "plugins.json", "sanitized_config.json", "warning.txt"}
|
testFiles = []string{"support_packet.yaml", "plugins.json", "sanitized_config.json", "heap.prof", "warning.txt"}
|
||||||
rFileNames = nil
|
rFileNames = nil
|
||||||
for _, fileData := range fileDatas {
|
for _, fileData := range fileDatas {
|
||||||
require.NotNil(t, fileData)
|
require.NotNil(t, fileData)
|
||||||
|
|||||||
Ссылка в новой задаче
Block a user