mirror of
https://github.com/mattermost/mattermost.git
synced 2025-02-25 18:55:24 -06:00
[MM-54290] Add CPU profile to support package (#24477)
This commit is contained in:
parent
153ebc31d7
commit
845ea2a984
@ -10,6 +10,7 @@ import (
|
||||
"runtime"
|
||||
"runtime/pprof"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/hashicorp/go-multierror"
|
||||
"github.com/pkg/errors"
|
||||
@ -21,6 +22,10 @@ import (
|
||||
"github.com/mattermost/mattermost/server/v8/config"
|
||||
)
|
||||
|
||||
const (
|
||||
cpuProfileDuration = 5 * time.Second
|
||||
)
|
||||
|
||||
func (a *App) GenerateSupportPacket(c *request.Context) []model.FileData {
|
||||
// If any errors we come across within this function, we will log it in a warning.txt file so that we know why certain files did not get produced if any
|
||||
var warnings []string
|
||||
@ -35,6 +40,7 @@ func (a *App) GenerateSupportPacket(c *request.Context) []model.FileData {
|
||||
"config": a.createSanitizedConfigFile,
|
||||
"mattermost log": a.getMattermostLog,
|
||||
"notification log": a.getNotificationsLog,
|
||||
"cpu profile": a.createCPUProfile,
|
||||
"heap profile": a.createHeapProfile,
|
||||
}
|
||||
|
||||
@ -294,6 +300,25 @@ func (a *App) createSanitizedConfigFile(_ *request.Context) (*model.FileData, er
|
||||
return fileData, nil
|
||||
}
|
||||
|
||||
func (a *App) createCPUProfile(_ *request.Context) (*model.FileData, error) {
|
||||
var b bytes.Buffer
|
||||
|
||||
err := pprof.StartCPUProfile(&b)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "failed to start CPU profile")
|
||||
}
|
||||
|
||||
time.Sleep(cpuProfileDuration)
|
||||
|
||||
pprof.StopCPUProfile()
|
||||
|
||||
fileData := &model.FileData{
|
||||
Filename: "cpu.prof",
|
||||
Body: b.Bytes(),
|
||||
}
|
||||
return fileData, nil
|
||||
}
|
||||
|
||||
func (a *App) createHeapProfile(*request.Context) (*model.FileData, error) {
|
||||
var b bytes.Buffer
|
||||
|
||||
|
@ -102,7 +102,15 @@ func TestGenerateSupportPacket(t *testing.T) {
|
||||
|
||||
fileDatas := th.App.GenerateSupportPacket(ctx)
|
||||
var rFileNames []string
|
||||
testFiles := []string{"support_packet.yaml", "plugins.json", "sanitized_config.json", "mattermost.log", "notifications.log", "heap.prof"}
|
||||
testFiles := []string{
|
||||
"support_packet.yaml",
|
||||
"plugins.json",
|
||||
"sanitized_config.json",
|
||||
"mattermost.log",
|
||||
"notifications.log",
|
||||
"cpu.prof",
|
||||
"heap.prof",
|
||||
}
|
||||
for _, fileData := range fileDatas {
|
||||
require.NotNil(t, fileData)
|
||||
assert.Positive(t, len(fileData.Body))
|
||||
@ -117,7 +125,14 @@ func TestGenerateSupportPacket(t *testing.T) {
|
||||
err = os.Remove("mattermost.log")
|
||||
require.NoError(t, err)
|
||||
fileDatas = th.App.GenerateSupportPacket(ctx)
|
||||
testFiles = []string{"support_packet.yaml", "plugins.json", "sanitized_config.json", "heap.prof", "warning.txt"}
|
||||
testFiles = []string{
|
||||
"support_packet.yaml",
|
||||
"plugins.json",
|
||||
"sanitized_config.json",
|
||||
"cpu.prof",
|
||||
"heap.prof",
|
||||
"warning.txt",
|
||||
}
|
||||
rFileNames = nil
|
||||
for _, fileData := range fileDatas {
|
||||
require.NotNil(t, fileData)
|
||||
|
Loading…
Reference in New Issue
Block a user