Skip to content

Commit

Permalink
Release 3.2.5 (#937)
Browse files Browse the repository at this point in the history
- #929
- #930
- #935
- Revert migration to go1.18 done in one of the cherry-picked prs, go version kept as go1.13 to avoid all migration of ioutil (migrated as part of model.AppError change)
- Bump 3.2.5

Fixes
- Telemetry race condition
- Telemetry rudder keys
  • Loading branch information
trilopin authored May 8, 2023
1 parent 05bf60b commit acca43d
Show file tree
Hide file tree
Showing 14 changed files with 657 additions and 339 deletions.
28 changes: 22 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ GOPATH ?= $(shell go env GOPATH)
GO_TEST_FLAGS ?= -race
GO_BUILD_FLAGS ?=
MM_UTILITIES_DIR ?= ../mattermost-utilities
DEFAULT_GOOS := $(shell go env GOOS)
DEFAULT_GOARCH := $(shell go env GOARCH)

export GO111MODULE=on

Expand All @@ -22,6 +24,12 @@ ifneq ($(wildcard build/custom.mk),)
include build/custom.mk
endif

ifneq ($(MM_DEBUG),)
GO_BUILD_GCFLAGS = -gcflags "all=-N -l"
else
GO_BUILD_GCFLAGS =
endif

## Checks the code style, tests, builds and bundles the plugin.
all: check-style test dist

Expand Down Expand Up @@ -50,16 +58,24 @@ golangci-lint:
@echo Running golangci-lint
golangci-lint run ./...

## Builds the server, if it exists, including support for multiple architectures.
## Builds the server, if it exists, for all supported architectures, unless MM_SERVICESETTINGS_ENABLEDEVELOPER is set
.PHONY: server
server:
ifneq ($(HAS_SERVER),)
ifneq ($(MM_DEBUG),)
$(info DEBUG mode is on; to disable, unset MM_DEBUG)
endif
mkdir -p server/dist;
cd server && env GOOS=linux GOARCH=amd64 $(GO) build $(GO_BUILD_FLAGS) -trimpath -o dist/plugin-linux-amd64;
cd server && env GOOS=linux GOARCH=arm64 $(GO) build $(GO_BUILD_FLAGS) -trimpath -o dist/plugin-linux-arm64;
cd server && env GOOS=darwin GOARCH=amd64 $(GO) build $(GO_BUILD_FLAGS) -trimpath -o dist/plugin-darwin-amd64;
cd server && env GOOS=darwin GOARCH=arm64 $(GO) build $(GO_BUILD_FLAGS) -trimpath -o dist/plugin-darwin-arm64;
cd server && env GOOS=windows GOARCH=amd64 $(GO) build $(GO_BUILD_FLAGS) -trimpath -o dist/plugin-windows-amd64.exe;
ifneq ($(MM_SERVICESETTINGS_ENABLEDEVELOPER),)
@echo Building plugin only for $(DEFAULT_GOOS)-$(DEFAULT_GOARCH) because MM_SERVICESETTINGS_ENABLEDEVELOPER is enabled
cd server && env CGO_ENABLED=0 $(GO) build $(GO_BUILD_FLAGS) $(GO_BUILD_GCFLAGS) -trimpath -o dist/plugin-$(DEFAULT_GOOS)-$(DEFAULT_GOARCH);
else
cd server && env CGO_ENABLED=0 GOOS=linux GOARCH=amd64 $(GO) build $(GO_BUILD_FLAGS) $(GO_BUILD_GCFLAGS) -trimpath -o dist/plugin-linux-amd64;
cd server && env CGO_ENABLED=0 GOOS=linux GOARCH=arm64 $(GO) build $(GO_BUILD_FLAGS) $(GO_BUILD_GCFLAGS) -trimpath -o dist/plugin-linux-arm64;
cd server && env CGO_ENABLED=0 GOOS=darwin GOARCH=amd64 $(GO) build $(GO_BUILD_FLAGS) $(GO_BUILD_GCFLAGS) -trimpath -o dist/plugin-darwin-amd64;
cd server && env CGO_ENABLED=0 GOOS=darwin GOARCH=arm64 $(GO) build $(GO_BUILD_FLAGS) $(GO_BUILD_GCFLAGS) -trimpath -o dist/plugin-darwin-arm64;
cd server && env CGO_ENABLED=0 GOOS=windows GOARCH=amd64 $(GO) build $(GO_BUILD_FLAGS) $(GO_BUILD_GCFLAGS) -trimpath -o dist/plugin-windows-amd64.exe;
endif
endif

## Ensures NPM dependencies are installed without having to run this all the time.
Expand Down
13 changes: 10 additions & 3 deletions build/custom.mk
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
# Include custom targets and environment variables here
ifndef MM_RUDDER_WRITE_KEY
MM_RUDDER_WRITE_KEY = 1d5bMvdrfWClLxgK1FvV3s4U1tg

.DEFAULT_GOAL := all

# If there's no MM_RUDDER_PLUGINS_PROD, add DEV data
RUDDER_WRITE_KEY = 1d5bMvdrfWClLxgK1FvV3s4U1tg
ifdef MM_RUDDER_PLUGINS_PROD
RUDDER_WRITE_KEY = $(MM_RUDDER_PLUGINS_PROD)
endif
LDFLAGS += -X "github.com/mattermost/mattermost-plugin-jira/server/utils/telemetry.rudderWriteKey=$(MM_RUDDER_WRITE_KEY)"

LDFLAGS += -X "github.com/mattermost/mattermost-plugin-jira/server/telemetry.rudderWriteKey=$(RUDDER_WRITE_KEY)"


# Build info
BUILD_DATE = $(shell date -u)
Expand Down
3 changes: 2 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ require (
github.com/mholt/archiver/v3 v3.5.1
github.com/pkg/errors v0.9.1
github.com/rbriski/atlassian-jwt v0.0.0-20180307182949-7bb4ae273058
github.com/stretchr/testify v1.7.0
github.com/rudderlabs/analytics-go v3.3.2+incompatible
github.com/stretchr/testify v1.8.0
golang.org/x/oauth2 v0.0.0-20211104180415-d3ed0bb246c8
golang.org/x/text v0.3.7
)
10 changes: 7 additions & 3 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -1549,17 +1549,20 @@ github.com/stretchr/objx v0.0.0-20180129172003-8a3f7159479f/go.mod h1:HFkY916IF+
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.2.0/go.mod h1:qt09Ya8vawLte6SNmTgCsAVtYtaKzEcn8ATUoHMkEqE=
github.com/stretchr/objx v0.3.0 h1:NGXK3lHquSN08v5vWalVI/L8XU9hdzE/G6xsrze47As=
github.com/stretchr/objx v0.3.0/go.mod h1:qt09Ya8vawLte6SNmTgCsAVtYtaKzEcn8ATUoHMkEqE=
github.com/stretchr/objx v0.4.0 h1:M2gUjqZET1qApGOWNSnZ49BAIMX4F/1plDv3+l31EJ4=
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
github.com/stretchr/testify v0.0.0-20180303142811-b89eecf5ca5d/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
github.com/stretchr/testify v1.2.0/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA=
github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY=
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.8.0 h1:pSgiaMZlXftHpm5L7V1+rVB+AZJydKsMxsQBIJw4PKk=
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
github.com/subosito/gotenv v1.2.0/go.mod h1:N0PQaV/YGNqwC0u51sEeR/aUtSLEXKX9iv69rRypqCw=
github.com/syndtr/gocapability v0.0.0-20170704070218-db04d3cc01c8/go.mod h1:hkRG7XYTFWNJGYcbNJQlaLq0fg1yr4J4t/NcTQtrfww=
github.com/syndtr/gocapability v0.0.0-20180916011248-d98352740cb2/go.mod h1:hkRG7XYTFWNJGYcbNJQlaLq0fg1yr4J4t/NcTQtrfww=
Expand Down Expand Up @@ -2450,8 +2453,9 @@ gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY=
gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=
gopkg.in/yaml.v3 v3.0.0-20191120175047-4206685974f2/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b h1:h8qDotaEPuJATrMmW04NCwg7v22aHH28wwpauUhK9Oo=
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gorm.io/driver/postgres v1.0.8/go.mod h1:4eOzrI1MUfm6ObJU/UcmbXyiHSs8jSwH95G5P5dxcAg=
gorm.io/gorm v1.20.12/go.mod h1:0HFTzE/SqkGTzK6TlDPPQbAYCluiVvhzoA1+aVyzenw=
gorm.io/gorm v1.21.4/go.mod h1:0HFTzE/SqkGTzK6TlDPPQbAYCluiVvhzoA1+aVyzenw=
Expand Down
4 changes: 2 additions & 2 deletions plugin.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
"description": "Atlassian Jira plugin for Mattermost.",
"homepage_url": "https://github.com/mattermost/mattermost-plugin-jira",
"support_url": "https://github.com/mattermost/mattermost-plugin-jira/issues",
"release_notes_url": "https://github.com/mattermost/mattermost-plugin-jira/releases/tag/v3.2.4",
"release_notes_url": "https://github.com/mattermost/mattermost-plugin-jira/releases/tag/v3.2.5",
"icon_path": "assets/icon.svg",
"version": "3.2.4",
"version": "3.2.5",
"min_server_version": "6.5.0",
"server": {
"executables": {
Expand Down
1 change: 0 additions & 1 deletion server/issue.go
Original file line number Diff line number Diff line change
Expand Up @@ -539,7 +539,6 @@ func (p *Plugin) httpGetJiraProjectMetadata(w http.ResponseWriter, r *http.Reque
}
}

type option = utils.ReactSelectOption
projects := []utils.ReactSelectOption{}
issues := map[string][]utils.ReactSelectOption{}
for _, prj := range plist {
Expand Down
2 changes: 1 addition & 1 deletion server/manifest.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ var manifest = struct {
Version string
}{
ID: "jira",
Version: "3.2.4",
Version: "3.2.5",
}
82 changes: 12 additions & 70 deletions server/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,14 @@ import (

pluginapi "github.com/mattermost/mattermost-plugin-api"
"github.com/mattermost/mattermost-plugin-api/experimental/flow"
"github.com/mattermost/mattermost-plugin-api/experimental/telemetry"
"github.com/mattermost/mattermost-server/v6/model"
"github.com/mattermost/mattermost-server/v6/plugin"

"github.com/mattermost/mattermost-plugin-autolink/server/autolink"
"github.com/mattermost/mattermost-plugin-autolink/server/autolinkclient"

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

Expand Down Expand Up @@ -128,15 +128,18 @@ type Plugin struct {
// channel to distribute work to the webhook processors
webhookQueue chan *webhookMessage

// service that determines if this Mattermost instance has access to
// enterprise features
enterpriseChecker enterprise.Checker

// Telemetry package copied inside repository, should be changed
// to pluginapi's one (0.1.3+) when min_server_version is safe to point at 7.x

// telemetry client
telemetryClient telemetry.Client

// telemetry Tracker
tracker telemetry.Tracker

// service that determines if this Mattermost instance has access to
// enterprise features
enterpriseChecker enterprise.Checker
}

func (p *Plugin) getConfig() config {
Expand Down Expand Up @@ -191,21 +194,10 @@ func (p *Plugin) OnConfigurationChange() error {
}
}

diagnostics := false
if p.API.GetConfig().LogSettings.EnableDiagnostics != nil {
diagnostics = *p.API.GetConfig().LogSettings.EnableDiagnostics
}

// create new tracker on each configuration change
p.tracker = telemetry.NewTracker(
p.telemetryClient,
p.API.GetDiagnosticId(),
p.API.GetServerVersion(),
manifest.ID,
manifest.Version,
"jira",
diagnostics,
)
if p.tracker != nil {
p.tracker.ReloadConfig(telemetry.NewTrackerConfig(p.API.GetConfig()))
}

return nil
}
Expand Down Expand Up @@ -336,11 +328,7 @@ func (p *Plugin) OnActivate() error {
}
}()

// initialize the rudder client once on activation
p.telemetryClient, err = telemetry.NewRudderClient()
if err != nil {
p.API.LogError("Cannot create telemetry client. err=%v", err)
}
p.initializeTelemetry()

return nil
}
Expand Down Expand Up @@ -510,52 +498,6 @@ func (p *Plugin) trackWithArgs(name, userID string, args map[string]interface{})
_ = p.tracker.TrackUserEvent(name, userID, args)
}

func (p *Plugin) OnSendDailyTelemetry() {
args := map[string]interface{}{}

// Jira instances
server, cloud := 0, 0
instances, err := p.instanceStore.LoadInstances()
if err != nil {
p.API.LogWarn("Failed to get instances for telemetry", "error", err)
}
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
}

// Connected users
connected, err := p.userStore.CountUsers()
if err != nil {
p.API.LogWarn("Failed to get the number of connected users for telemetry", "error", err)
}
args["connected_user_count"] = connected

// Subscriptions
subscriptions := 0
for _, id := range instances.IDs() {
subs, err := p.getSubscriptions(id)
if err != nil {
p.API.LogWarn("Failed to get subscriptions for telemetry", "error", err)
}
subscriptions += len(subs.Channel.ByID)
}
args["subscriptions"] = subscriptions

_ = p.tracker.TrackEvent("stats", args)
}

func (p *Plugin) OnInstall(c *plugin.Context, event model.OnInstallEvent) error {
instances, err := p.instanceStore.LoadInstances()
if err != nil {
Expand Down
95 changes: 95 additions & 0 deletions server/telemetry.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
package main

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

func (p *Plugin) TrackEvent(event string, properties map[string]interface{}) {
err := p.tracker.TrackEvent(event, properties)
if err != nil {
p.API.LogDebug("Error sending telemetry event", "event", event, "error", err.Error())
}
}

func (p *Plugin) TrackUserEvent(event, userID string, properties map[string]interface{}) {
err := p.tracker.TrackUserEvent(event, userID, properties)
if err != nil {
p.API.LogDebug("Error sending user telemetry event", "event", event, "error", err.Error())
}
}

func (p *Plugin) OnSendDailyTelemetry() {
args := map[string]interface{}{}

// Jira instances
server, cloud := 0, 0
instances, err := p.instanceStore.LoadInstances()
if err != nil {
p.API.LogWarn("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.API.LogWarn("Failed to get subscriptions for telemetry", "error", err)
}
numSubscriptions += len(subs.Channel.ByID)
}

args["subscriptions"] = numSubscriptions
}

// Connected users
connected, err := p.userStore.CountUsers()
if err != nil {
p.API.LogWarn("Failed to get the number of connected users for telemetry", "error", err)
} else {
args["connected_user_count"] = connected
}

p.TrackEvent("stats", args)
}

// 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.
func (p *Plugin) initializeTelemetry() {
var err error

// Telemetry client
p.telemetryClient, err = telemetry.NewRudderClient()
if err != nil {
p.API.LogWarn("Telemetry client not started", "error", err.Error())
return
}

// Get config values
p.tracker = telemetry.NewTracker(
p.telemetryClient,
p.API.GetDiagnosticId(),
p.API.GetServerVersion(),
manifest.ID,
manifest.Version,
"jira",
telemetry.NewTrackerConfig(p.API.GetConfig()),
telemetry.NewLogger(p.API),
)
}
Loading

0 comments on commit acca43d

Please sign in to comment.