generated from mattermost/mattermost-plugin-starter-template
-
Notifications
You must be signed in to change notification settings - Fork 156
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[MM-61124] Add diagnostics data to the Support Packet (#1957)
- Loading branch information
Showing
10 changed files
with
191 additions
and
60 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
package main | ||
|
||
import ( | ||
"path/filepath" | ||
|
||
"github.com/hashicorp/go-multierror" | ||
"github.com/pkg/errors" | ||
"gopkg.in/yaml.v3" | ||
|
||
"github.com/mattermost/mattermost-plugin-playbooks/server/app" | ||
"github.com/mattermost/mattermost/server/public/model" | ||
"github.com/mattermost/mattermost/server/public/plugin" | ||
) | ||
|
||
type SupportPacket struct { | ||
Version string `yaml:"version"` | ||
// The total number of playbooks. | ||
TotalPlaybooks int64 `yaml:"total_playbooks"` | ||
// The number of active playbooks. | ||
ActivePlaybooks int64 `yaml:"active_playbooks"` | ||
// The total number of playbook runs. | ||
TotalPlaybookRuns int64 `yaml:"total_playbook_runs"` | ||
} | ||
|
||
func (p *Plugin) GenerateSupportData(_ *plugin.Context) ([]*model.FileData, error) { | ||
var result *multierror.Error | ||
|
||
playbooks, err := p.playbookService.GetPlaybooks() | ||
if err != nil { | ||
result = multierror.Append(result, errors.Wrap(err, "Failed to get total number of playbooks for Support Packet")) | ||
} | ||
|
||
activePlaybooks, err := p.playbookService.GetActivePlaybooks() | ||
if err != nil { | ||
result = multierror.Append(result, errors.Wrap(err, "Failed to get number of active playbooks for Support Packet")) | ||
} | ||
|
||
playbookRuns, err := p.playbookRunService.GetPlaybookRuns(app.RequesterInfo{IsAdmin: true}, app.PlaybookRunFilterOptions{SkipExtras: true}) | ||
if err != nil { | ||
result = multierror.Append(result, errors.Wrap(err, "Failed to get total number of playbook runs for Support Packet")) | ||
} | ||
|
||
diagnostics := SupportPacket{ | ||
Version: manifest.Version, | ||
TotalPlaybooks: int64(len(playbooks)), | ||
ActivePlaybooks: int64(len(activePlaybooks)), | ||
TotalPlaybookRuns: int64(playbookRuns.TotalCount), | ||
} | ||
body, err := yaml.Marshal(diagnostics) | ||
if err != nil { | ||
return nil, errors.Wrap(err, "Failed to marshal diagnostics") | ||
} | ||
|
||
return []*model.FileData{{ | ||
Filename: filepath.Join(manifest.Id, "diagnostics.yaml"), | ||
Body: body, | ||
}}, result.ErrorOrNil() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package main | ||
|
||
import ( | ||
"archive/zip" | ||
"bytes" | ||
"context" | ||
"path" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
"github.com/stretchr/testify/require" | ||
"gopkg.in/yaml.v3" | ||
) | ||
|
||
func TestGenerateSupportData(t *testing.T) { | ||
e := Setup(t) | ||
e.CreateBasic() | ||
|
||
data, _, err := e.ServerAdminClient.GenerateSupportPacket(context.Background()) | ||
require.NoError(t, err) | ||
require.NotEmpty(t, data) | ||
|
||
zr, err := zip.NewReader(bytes.NewReader(data), int64(len(data))) | ||
require.NoError(t, err) | ||
require.NotNil(t, zr) | ||
|
||
f, err := zr.Open(path.Join(manifest.Id, "diagnostics.yaml")) | ||
require.NoError(t, err) | ||
require.NotNil(t, f) | ||
|
||
var sp SupportPacket | ||
err = yaml.NewDecoder(f).Decode(&sp) | ||
require.NoError(t, err) | ||
|
||
assert.Equal(t, manifest.Version, sp.Version) | ||
assert.Equal(t, int64(4), sp.TotalPlaybooks) | ||
assert.Equal(t, int64(3), sp.ActivePlaybooks) | ||
assert.Equal(t, int64(1), sp.TotalPlaybookRuns) | ||
} |