Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[MM-61121] Add diagnostics data to the Support Packet #1131

Merged
merged 9 commits into from
Dec 10, 2024
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,26 @@ module github.com/mattermost/mattermost-plugin-jira

go 1.22

toolchain go1.22.2
toolchain go1.22.8

require (
github.com/andygrunwald/go-jira v1.16.0
github.com/blang/semver/v4 v4.0.0
github.com/dghubble/oauth1 v0.5.0
github.com/golang-jwt/jwt/v5 v5.2.1
github.com/gorilla/mux v1.8.1
github.com/hashicorp/go-multierror v1.1.1
github.com/jarcoal/httpmock v1.0.8
github.com/mattermost/mattermost-plugin-autolink v1.2.2-0.20210709183311-c8fa30db649f
github.com/mattermost/mattermost/server/public v0.1.7
github.com/mattermost/mattermost/server/public v0.1.9
github.com/pkg/errors v0.9.1
github.com/rbriski/atlassian-jwt v0.0.0-20240408161306-6b6d681cf2d9
github.com/rudderlabs/analytics-go v3.3.3+incompatible
github.com/stretchr/testify v1.9.0
github.com/trivago/tgo v1.0.7
golang.org/x/oauth2 v0.21.0
golang.org/x/text v0.16.0
gopkg.in/yaml.v3 v3.0.1
)

require (
Expand All @@ -38,7 +40,6 @@ require (
github.com/gorilla/websocket v1.5.3 // indirect
github.com/hashicorp/errwrap v1.1.0 // indirect
github.com/hashicorp/go-hclog v1.6.3 // indirect
github.com/hashicorp/go-multierror v1.1.1 // indirect
github.com/hashicorp/go-plugin v1.6.1 // indirect
github.com/hashicorp/yamux v0.1.1 // indirect
github.com/klauspost/compress v1.15.14 // indirect
Expand Down Expand Up @@ -79,5 +80,4 @@ require (
gopkg.in/ini.v1 v1.67.0 // indirect
gopkg.in/natefinch/lumberjack.v2 v2.2.1 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -629,8 +629,8 @@ github.com/mattermost/mattermost-plugin-autolink v1.2.2-0.20210709183311-c8fa30d
github.com/mattermost/mattermost-plugin-autolink v1.2.2-0.20210709183311-c8fa30db649f/go.mod h1:JO5RQqTYL2D1zDz7+5ucAmNeRMiudDvZQoRtqbm+1sU=
github.com/mattermost/mattermost-server/v5 v5.3.2-0.20210621071817-df224571d8a1 h1:5/lZibP83SrOpuKs4fE782pfWNFX/QTWwO2PuJJwGJ4=
github.com/mattermost/mattermost-server/v5 v5.3.2-0.20210621071817-df224571d8a1/go.mod h1:S3zT7H4bAxsev1d2ThoSRBhyEXZa6JZOfpxvy2B25y4=
github.com/mattermost/mattermost/server/public v0.1.7 h1:WA+fnLrQQeE6xTyHERqcGiKljBFK6m8WYL4Pez07ko4=
github.com/mattermost/mattermost/server/public v0.1.7/go.mod h1:SkTKbMul91Rq0v2dIxe8mqzUOY+3KwlwwLmAlxDfGCk=
github.com/mattermost/mattermost/server/public v0.1.9 h1:l/OKPRVuFeqL0yqRVC/JpveG5sLNKcT9llxqMkO9e+s=
github.com/mattermost/mattermost/server/public v0.1.9/go.mod h1:SkTKbMul91Rq0v2dIxe8mqzUOY+3KwlwwLmAlxDfGCk=
github.com/mattermost/rsc v0.0.0-20160330161541-bbaefb05eaa0/go.mod h1:nV5bfVpT//+B1RPD2JvRnxbkLmJEYXmRaaVl15fsXjs=
github.com/mattn/go-colorable v0.0.9/go.mod h1:9vuHe8Xs5qXnSaW/c/ABM9alt+Vo+STaOChaDxuIBZU=
github.com/mattn/go-colorable v0.1.1/go.mod h1:FuOcm+DKB9mbwrcAfNl7/TZVBZ6rcnceauSikq3lYCQ=
Expand Down
59 changes: 59 additions & 0 deletions server/support_packet.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
package main

import (
"path"

"github.com/hashicorp/go-multierror"
"github.com/pkg/errors"
"gopkg.in/yaml.v3"

"github.com/mattermost/mattermost/server/public/model"
"github.com/mattermost/mattermost/server/public/plugin"
)

type SupportPacket struct {
Version string `yaml:"version"`

InstanceCount int `yaml:"instance_count"`
ServerInstanceCount int `yaml:"server_instance_count"`
CloudInstanceCount int `yaml:"cloud_instance_count"`
SubscriptionCount int `yaml:"subscription_count"`
ConnectedUserCount int `yaml:"connected_user_count"`
}

func (p *Plugin) GenerateSupportData(_ *plugin.Context) ([]*model.FileData, error) {
var result *multierror.Error

connectedUserCount, err := p.userCount()
if err != nil {
result = multierror.Append(result, errors.Wrap(err, "Failed to get the number of connected users for Support Packet"))
}

server, cloud, err := p.instanceCount()
hanzei marked this conversation as resolved.
Show resolved Hide resolved
if err != nil {
result = multierror.Append(result, errors.Wrap(err, "Failed to get the number of instances for Support Packet"))
}

subscriptionCount, err := p.subscriptionCount()
if err != nil {
result = multierror.Append(result, errors.Wrap(err, "Failed to get the number of subscriptions for Support Packet"))
}

diagnostics := SupportPacket{
Version: manifest.Version,
InstanceCount: server + cloud,
ServerInstanceCount: server,
CloudInstanceCount: cloud,
SubscriptionCount: subscriptionCount,
ConnectedUserCount: connectedUserCount,
}
b, err := yaml.Marshal(diagnostics)
hanzei marked this conversation as resolved.
Show resolved Hide resolved
if err != nil {
return nil, errors.Wrap(err, "Failed to marshal diagnostics")
}

return []*model.FileData{{
Filename: path.Join(manifest.Id, "diagnostics.yaml"),
hanzei marked this conversation as resolved.
Show resolved Hide resolved
Body: b,
}}, result.ErrorOrNil()
}
75 changes: 52 additions & 23 deletions server/telemetry.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package main

import (
"github.com/pkg/errors"

"github.com/mattermost/mattermost-plugin-jira/server/telemetry"
)

Expand All @@ -22,43 +24,28 @@ func (p *Plugin) OnSendDailyTelemetry() {
args := map[string]interface{}{}

// Jira instances
server, cloud := 0, 0
instances, err := p.instanceStore.LoadInstances()
server, cloud, err := p.instanceCount()
hanzei marked this conversation as resolved.
Show resolved Hide resolved
if err != nil {
p.client.Log.Warn("Failed to get instances for telemetry", "error", err)
} else {
for _, id := range instances.IDs() {
switch instances.Get(id).Type {
case ServerInstanceType:
server++
case CloudInstanceType:
cloud++
}
}
args["instance_count"] = server + cloud
if server > 0 {
args["server_instance_count"] = server
}
if cloud > 0 {
args["cloud_instance_count"] = cloud
}
}

// Subscriptions
numSubscriptions := 0
var subs *Subscriptions
for _, id := range instances.IDs() {
subs, err = p.getSubscriptions(id)
if err != nil {
p.client.Log.Warn("Failed to get subscriptions for telemetry", "error", err)
}
numSubscriptions += len(subs.Channel.ByID)
}

args["subscriptions"] = numSubscriptions
subscriptionCount, err := p.subscriptionCount()
if err != nil {
p.client.Log.Warn("Failed to get the number of subscriptions for telemetry", "error", err)
} else {
args["subscriptions"] = subscriptionCount
}

// Connected users
connected, err := p.userStore.CountUsers()
connected, err := p.userCount()
hanzei marked this conversation as resolved.
Show resolved Hide resolved
if err != nil {
p.client.Log.Warn("Failed to get the number of connected users for telemetry", "error", err)
} else {
Expand All @@ -68,6 +55,48 @@ func (p *Plugin) OnSendDailyTelemetry() {
p.TrackEvent("stats", args)
}

func (p *Plugin) instanceCount() (server int, cloud int, err error) {
instances, err := p.instanceStore.LoadInstances()
if err != nil {
return
}

for _, id := range instances.IDs() {
switch instances.Get(id).Type {
case ServerInstanceType:
server++
case CloudInstanceType:
cloud++
}
}

return
}

func (p *Plugin) subscriptionCount() (int, error) {
instances, err := p.instanceStore.LoadInstances()
if err != nil {
return 0, err
}

// Subscriptions
numSubscriptions := 0
var subs *Subscriptions
for _, id := range instances.IDs() {
subs, err = p.getSubscriptions(id)
if err != nil {
return 0, errors.Wrapf(err, "failed to get subscription %q for telemetry", id)
hanzei marked this conversation as resolved.
Show resolved Hide resolved
}
numSubscriptions += len(subs.Channel.ByID)
}

return numSubscriptions, nil
}

func (p *Plugin) userCount() (int, error) {
return p.userStore.CountUsers()
hanzei marked this conversation as resolved.
Show resolved Hide resolved
}

// Initialize telemetry setups the tracker/clients needed to send telemetry data.
// The telemetry.NewTrackerConfig(...) param will take care of extract/parse the config to set the right settings.
// If you don't want the default behavior you still can pass a different telemetry.TrackerConfig data.
Expand Down
Loading