[MM-59292] Add metadata to Support Packet (#27573)
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
a4bdb65037
Коммит
ff3ed78124
@@ -41,6 +41,7 @@ func (a *App) GenerateSupportPacket(c request.CTX, options *model.SupportPacketO
|
|||||||
"cpu profile": a.createCPUProfile,
|
"cpu profile": a.createCPUProfile,
|
||||||
"heap profile": a.createHeapProfile,
|
"heap profile": a.createHeapProfile,
|
||||||
"goroutines": a.createGoroutineProfile,
|
"goroutines": a.createGoroutineProfile,
|
||||||
|
"metadata": a.createSupportPacketMetadata,
|
||||||
}
|
}
|
||||||
|
|
||||||
if options.IncludeLogs {
|
if options.IncludeLogs {
|
||||||
@@ -412,3 +413,21 @@ func (a *App) createGoroutineProfile(_ request.CTX) (*model.FileData, error) {
|
|||||||
}
|
}
|
||||||
return fileData, nil
|
return fileData, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (a *App) createSupportPacketMetadata(_ request.CTX) (*model.FileData, error) {
|
||||||
|
metadata, err := model.GeneratePacketMetadata(model.SupportPacketType, a.TelemetryId(), a.License(), nil)
|
||||||
|
if err != nil {
|
||||||
|
return nil, errors.Wrap(err, "failed to generate packet metadata")
|
||||||
|
}
|
||||||
|
|
||||||
|
b, err := yaml.Marshal(metadata)
|
||||||
|
if err != nil {
|
||||||
|
return nil, errors.Wrap(err, "failed to marshal packet metadata into yaml")
|
||||||
|
}
|
||||||
|
|
||||||
|
fileData := &model.FileData{
|
||||||
|
Filename: model.PacketMetadataFileName,
|
||||||
|
Body: b,
|
||||||
|
}
|
||||||
|
return fileData, nil
|
||||||
|
}
|
||||||
|
|||||||
@@ -214,6 +214,7 @@ func TestGenerateSupportPacket(t *testing.T) {
|
|||||||
var rFileNames []string
|
var rFileNames []string
|
||||||
testFiles := []string{
|
testFiles := []string{
|
||||||
"support_packet.yaml",
|
"support_packet.yaml",
|
||||||
|
"metadata.yaml",
|
||||||
"plugins.json",
|
"plugins.json",
|
||||||
"sanitized_config.json",
|
"sanitized_config.json",
|
||||||
"mattermost.log",
|
"mattermost.log",
|
||||||
@@ -238,6 +239,7 @@ func TestGenerateSupportPacket(t *testing.T) {
|
|||||||
|
|
||||||
testFiles := []string{
|
testFiles := []string{
|
||||||
"support_packet.yaml",
|
"support_packet.yaml",
|
||||||
|
"metadata.yaml",
|
||||||
"plugins.json",
|
"plugins.json",
|
||||||
"sanitized_config.json",
|
"sanitized_config.json",
|
||||||
"cpu.prof",
|
"cpu.prof",
|
||||||
@@ -267,6 +269,7 @@ func TestGenerateSupportPacket(t *testing.T) {
|
|||||||
})
|
})
|
||||||
testFiles := []string{
|
testFiles := []string{
|
||||||
"support_packet.yaml",
|
"support_packet.yaml",
|
||||||
|
"metadata.yaml",
|
||||||
"plugins.json",
|
"plugins.json",
|
||||||
"sanitized_config.json",
|
"sanitized_config.json",
|
||||||
"cpu.prof",
|
"cpu.prof",
|
||||||
@@ -424,3 +427,24 @@ func TestCreateSanitizedConfigFile(t *testing.T) {
|
|||||||
assert.Positive(t, len(fileData.Body))
|
assert.Positive(t, len(fileData.Body))
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestCreateSupportPacketMetadata(t *testing.T) {
|
||||||
|
th := Setup(t)
|
||||||
|
defer th.TearDown()
|
||||||
|
|
||||||
|
t.Run("Happy path", func(t *testing.T) {
|
||||||
|
fileData, err := th.App.createSupportPacketMetadata(th.Context)
|
||||||
|
require.NoError(t, err)
|
||||||
|
require.NotNil(t, fileData)
|
||||||
|
assert.Equal(t, "metadata.yaml", fileData.Filename)
|
||||||
|
assert.Positive(t, len(fileData.Body))
|
||||||
|
|
||||||
|
metadate, err := model.ParsePacketMetadata(fileData.Body)
|
||||||
|
assert.NoError(t, err)
|
||||||
|
require.NotNil(t, metadate)
|
||||||
|
assert.Equal(t, model.SupportPacketType, metadate.Type)
|
||||||
|
assert.Equal(t, model.CurrentVersion, metadate.ServerVersion)
|
||||||
|
assert.NotEmpty(t, metadate.ServerID)
|
||||||
|
assert.NotEmpty(t, metadate.GeneratedAt)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|||||||
@@ -103,18 +103,18 @@ func ParsePacketMetadata(b []byte) (*PacketMetadata, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// GeneratePacketMetadata is a utility function to generate metadata for customer provided Packets.
|
// GeneratePacketMetadata is a utility function to generate metadata for customer provided Packets.
|
||||||
// It will construct it from serverID and optionally a license.
|
// It will construct it from a Packet Type, the telemetryID and optionally a license.
|
||||||
func GeneratePacketMetadata(serverID string, license *License, extra map[string]any) (*PacketMetadata, error) {
|
func GeneratePacketMetadata(t PacketType, telemetryID string, license *License, extra map[string]any) (*PacketMetadata, error) {
|
||||||
if extra == nil {
|
if extra == nil {
|
||||||
extra = make(map[string]any)
|
extra = make(map[string]any)
|
||||||
}
|
}
|
||||||
|
|
||||||
md := PacketMetadata{
|
md := &PacketMetadata{
|
||||||
Version: CurrentMetadataVersion,
|
Version: CurrentMetadataVersion,
|
||||||
Type: PluginPacketType,
|
Type: t,
|
||||||
GeneratedAt: GetMillis(),
|
GeneratedAt: GetMillis(),
|
||||||
ServerVersion: CurrentVersion,
|
ServerVersion: CurrentVersion,
|
||||||
ServerID: serverID,
|
ServerID: telemetryID,
|
||||||
Extras: extra,
|
Extras: extra,
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -127,5 +127,5 @@ func GeneratePacketMetadata(serverID string, license *License, extra map[string]
|
|||||||
return nil, fmt.Errorf("invalid metadata: %w", err)
|
return nil, fmt.Errorf("invalid metadata: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
return &md, nil
|
return md, nil
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -162,7 +162,7 @@ func (s *SystemService) GeneratePacketMetadata(path string, pluginMeta map[strin
|
|||||||
pluginMeta["plugin_id"] = manifest.Id
|
pluginMeta["plugin_id"] = manifest.Id
|
||||||
pluginMeta["plugin_version"] = manifest.Version
|
pluginMeta["plugin_version"] = manifest.Version
|
||||||
|
|
||||||
md, err := model.GeneratePacketMetadata(serverID, license, pluginMeta)
|
md, err := model.GeneratePacketMetadata(model.PluginPacketType, serverID, license, pluginMeta)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", errors.Wrap(err, "failed to get packet metadata")
|
return "", errors.Wrap(err, "failed to get packet metadata")
|
||||||
}
|
}
|
||||||
|
|||||||
Ссылка в новой задаче
Block a user