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>
Этот коммит содержится в:
Guillermo Vayá
2024-10-07 13:30:19 +02:00
коммит произвёл GitHub
родитель 18388a8c64
Коммит 662e59865c
4 изменённых файлов: 126 добавлений и 22 удалений

Просмотреть файл

@@ -35,17 +35,20 @@ type FakeConfigService struct {
cfg *model.Config
}
type testBatch struct {
MessageId string
UserId string
Event string
Timestamp time.Time
Properties map[string]any
Context map[string]any
}
type testTelemetryPayload struct {
MessageId string
SentAt time.Time
Batch []struct {
MessageId string
UserId string
Event string
Timestamp time.Time
Properties map[string]any
}
Context struct {
Batch []testBatch
Context struct {
Library struct {
Name string
Version string
@@ -53,15 +56,7 @@ type testTelemetryPayload struct {
}
}
type testBatch struct {
MessageId string
UserId string
Event string
Timestamp time.Time
Properties map[string]any
}
func assertPayload(t *testing.T, actual testTelemetryPayload, event string, properties map[string]any) {
func assertPayload(t *testing.T, actual testTelemetryPayload, event string, properties map[string]any, featureContext map[string]any) {
t.Helper()
assert.NotEmpty(t, actual.MessageId)
assert.False(t, actual.SentAt.IsZero())
@@ -75,6 +70,11 @@ func assertPayload(t *testing.T, actual testTelemetryPayload, event string, prop
if properties != nil {
assert.Equal(t, properties, actual.Batch[0].Properties)
}
if featureContext != nil {
actualFeature := actual.Batch[0].Context["feature"].(map[string]any)
assert.Equal(t, featureContext["name"], actualFeature["name"], "feature name must match")
assert.Equal(t, featureContext["skus"], actualFeature["skus"], "SKUs must match")
}
}
assert.Equal(t, "analytics-go", actual.Context.Library.Name)
assert.Equal(t, "3.3.0", actual.Context.Library.Version)
@@ -85,7 +85,7 @@ func collectBatches(t *testing.T, info *[]testBatch, pchan chan testTelemetryPay
for {
select {
case result := <-pchan:
assertPayload(t, result, "", nil)
assertPayload(t, result, "", nil, nil)
*info = append(*info, result.Batch[0])
case <-time.After(2 * time.Second):
return
@@ -126,7 +126,7 @@ func makeTelemetryServiceAndReceiver(t *testing.T, cloudLicense bool) (*Telemetr
// initializing rudder send a client identify message
select {
case identifyMessage := <-pchan:
assertPayload(t, identifyMessage, "", nil)
assertPayload(t, identifyMessage, "", nil, nil)
case <-time.After(2 * time.Second):
require.Fail(t, "Did not receive ID message")
}
@@ -435,7 +435,7 @@ func TestRudderTelemetry(t *testing.T) {
for {
select {
case result := <-pchan:
assertPayload(t, result, "", nil)
assertPayload(t, result, "", nil, nil)
*info = append(*info, result.Batch[0].Event)
case <-time.After(2 * time.Second):
return
@@ -452,7 +452,29 @@ func TestRudderTelemetry(t *testing.T) {
case result := <-pchan:
assertPayload(t, result, "Testing Telemetry", map[string]any{
"hey": testValue,
})
}, nil)
case <-time.After(2 * time.Second):
require.Fail(t, "Did not receive telemetry")
}
})
t.Run("Send Feature", func(t *testing.T) {
const testEvent = "test-send-value-4567"
const testProperty = "test-property-9876"
service.SendTelemetryForFeature(TrackGuestFeature, testEvent, map[string]any{
"prop": testProperty,
})
select {
case result := <-pchan:
assertPayload(
t,
result,
testEvent,
map[string]any{"prop": testProperty},
map[string]any{"skus": []any{"professional", "enterprise"}, "name": "guest_accounts"},
)
case <-time.After(2 * time.Second):
require.Fail(t, "Did not receive telemetry")
}