Skip to content

Commit

Permalink
[MM-61121] Add diagnostics data to the Support Packet (#1131)
Browse files Browse the repository at this point in the history
Co-authored-by: kshitij katiyar <kshitij.katiyar@brightscout.com>
  • Loading branch information
hanzei and Kshitij-Katiyar authored Dec 10, 2024
1 parent 6a7a70f commit a8d2403
Show file tree
Hide file tree
Showing 4 changed files with 123 additions and 35 deletions.
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 @@ -630,8 +630,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/filepath"

"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"))
}

serverICount, cloudICount, err := p.instanceCount()
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: serverICount + cloudICount,
ServerInstanceCount: serverICount,
CloudInstanceCount: cloudICount,
SubscriptionCount: subscriptionCount,
ConnectedUserCount: connectedUserCount,
}
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()
}
87 changes: 58 additions & 29 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,52 +24,79 @@ func (p *Plugin) OnSendDailyTelemetry() {
args := map[string]interface{}{}

// Jira instances
server, cloud := 0, 0
instances, err := p.instanceStore.LoadInstances()
serverICount, cloudICount, err := p.instanceCount()
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
args["instance_count"] = serverICount + cloudICount
if serverICount > 0 {
args["server_instance_count"] = serverICount
}

// 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)
if cloudICount > 0 {
args["cloud_instance_count"] = cloudICount
}
}

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()
connectedUsers, err := p.userCount()
if err != nil {
p.client.Log.Warn("Failed to get the number of connected users for telemetry", "error", err)
} else {
args["connected_user_count"] = connected
args["connected_user_count"] = connectedUsers
}

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)
}
numSubscriptions += len(subs.Channel.ByID)
}

return numSubscriptions, nil
}

func (p *Plugin) userCount() (int, error) {
return p.userStore.CountUsers()
}

// 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

0 comments on commit a8d2403

Please sign in to comment.