MM-59360 add telemetry for paid features related to guests (#28295)
* add telemetry for paid features related to guests --------- Co-authored-by: Mattermost Build <build@mattermost.com>
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
18388a8c64
Коммит
662e59865c
@@ -93,6 +93,17 @@ const (
|
||||
TrackPlugins = "plugins"
|
||||
)
|
||||
|
||||
type TrackSKU string
|
||||
|
||||
const (
|
||||
TrackProfessionalSKU TrackSKU = "professional"
|
||||
TrackEnterpriseSKU TrackSKU = "enterprise"
|
||||
)
|
||||
|
||||
type TrackFeature string
|
||||
|
||||
const TrackGuestFeature TrackFeature = "guest_accounts"
|
||||
|
||||
type ServerIface interface {
|
||||
Config() *model.Config
|
||||
IsLeader() bool
|
||||
@@ -119,6 +130,15 @@ type RudderConfig struct {
|
||||
DataplaneURL string
|
||||
}
|
||||
|
||||
type EventFeature struct {
|
||||
Name TrackFeature `json:"name"`
|
||||
SKUS []TrackSKU `json:"skus"`
|
||||
}
|
||||
|
||||
var featureSKUS = map[TrackFeature][]TrackSKU{
|
||||
TrackGuestFeature: {TrackProfessionalSKU, TrackEnterpriseSKU},
|
||||
}
|
||||
|
||||
func New(srv ServerIface, dbStore store.Store, searchEngine *searchengine.Broker, log *mlog.Logger, verbose bool) (*TelemetryService, error) {
|
||||
service := &TelemetryService{
|
||||
srv: srv,
|
||||
@@ -202,7 +222,7 @@ func (ts *TelemetryService) sendDailyTelemetry(override bool) {
|
||||
func (ts *TelemetryService) SendTelemetry(event string, properties map[string]any) {
|
||||
if ts.rudderClient != nil {
|
||||
var context *rudder.Context
|
||||
// if we are part of a cloud installation, add it's ID to the tracked event's context
|
||||
// if we are part of a cloud installation, add its ID to the tracked event's context
|
||||
if installationId := os.Getenv("MM_CLOUD_INSTALLATION_ID"); installationId != "" {
|
||||
context = &rudder.Context{Traits: map[string]any{"installationId": installationId}}
|
||||
}
|
||||
@@ -218,6 +238,38 @@ func (ts *TelemetryService) SendTelemetry(event string, properties map[string]an
|
||||
}
|
||||
}
|
||||
|
||||
func (ts *TelemetryService) SendTelemetryForFeature(featureName TrackFeature, event string, properties map[string]any) {
|
||||
if ts.rudderClient != nil {
|
||||
skus, ok := featureSKUS[featureName]
|
||||
if !ok {
|
||||
skus = []TrackSKU{}
|
||||
mlog.Warn("Telemetry SKUS are not defined for the feature", mlog.String("feature", featureName))
|
||||
}
|
||||
feature := EventFeature{
|
||||
Name: featureName,
|
||||
SKUS: skus,
|
||||
}
|
||||
|
||||
var context *rudder.Context = &rudder.Context{
|
||||
Extra: map[string]any{"feature": feature},
|
||||
}
|
||||
// if we are part of a cloud installation, add its ID to the tracked event's context
|
||||
if installationId := os.Getenv("MM_CLOUD_INSTALLATION_ID"); installationId != "" {
|
||||
context.Traits = map[string]any{"installationId": installationId}
|
||||
}
|
||||
|
||||
err := ts.rudderClient.Enqueue(rudder.Track{
|
||||
Event: event,
|
||||
UserId: ts.TelemetryID,
|
||||
Properties: properties,
|
||||
Context: context,
|
||||
})
|
||||
if err != nil {
|
||||
ts.log.Warn("Error sending telemetry for feature", mlog.Err(err))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func isDefaultArray(setting, defaultValue []string) bool {
|
||||
if len(setting) != len(defaultValue) {
|
||||
return false
|
||||
|
||||
Ссылка в новой задаче
Block a user