Skip to content

Commit

Permalink
MM-59369: rework chat subscription logic (#709)
Browse files Browse the repository at this point in the history
* mv monitor to root

* less testutils

* rm unused channel subscription renewal

* rm testutils dependency in msteams client

* rm testutils dependency in sqlstore

* rm testutils

* rework chats subscription logic

* downgrade client errors to warning, let upper layer handle

* Update server/subscriptions.go
  • Loading branch information
lieut-data authored Jul 18, 2024
1 parent 75d63d2 commit 4585e70
Show file tree
Hide file tree
Showing 14 changed files with 525 additions and 1,422 deletions.
3 changes: 1 addition & 2 deletions server/converters_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"time"

"github.com/mattermost/mattermost-plugin-msteams/server/msteams/clientmodels"
"github.com/mattermost/mattermost-plugin-msteams/server/testutils"
"github.com/mattermost/mattermost/server/public/model"
"github.com/stretchr/testify/assert"
)
Expand Down Expand Up @@ -92,7 +91,7 @@ func TestHandleMentions(t *testing.T) {
Mentions: []clientmodels.Mention{
{
ID: 0,
UserID: testutils.GetTeamsUserID(),
UserID: model.NewId(),
MentionedText: "mockMentionedText",
},
},
Expand Down
1 change: 1 addition & 0 deletions server/helper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ func (th *testHelper) Reset(t *testing.T) *testHelper {
th.p.clientBuilderWithToken = func(redirectURL, tenantID, clientId, clientSecret string, token *oauth2.Token, apiClient *pluginapi.LogService) msteams.Client {
return clientMock
}
th.p.monitor.client = th.p.msteamsAppClient

var err error
th.metricsSnapshot, err = th.p.metricsService.GetRegistry().Gather()
Expand Down
20 changes: 10 additions & 10 deletions server/metrics/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,16 @@ const (
MetricsCloudInstallationLabel = "installationId"
MetricsVersionLabel = "version"

ActionSourceMSTeams = "msteams"
ActionSourceMattermost = "mattermost"
ActionCreated = "created"
ActionUpdated = "updated"
ActionDeleted = "deleted"
ReactionSetAction = "set"
ReactionUnsetAction = "unset"
SubscriptionRefreshed = "refreshed"
SubscriptionConnected = "connected"
SubscriptionReconnected = "reconnected"
ActionSourceMSTeams = "msteams"
ActionSourceMattermost = "mattermost"
ActionCreated = "created"
ActionUpdated = "updated"
ActionDeleted = "deleted"
ReactionSetAction = "set"
ReactionUnsetAction = "unset"
SubscriptionRefreshed = "refreshed"
SubscriptionConnected = "connected"
SubscriptionDeleted = "deleted"

DiscardedReasonNone = ""
DiscardedReasonInvalidChangeType = "invalid_change_type"
Expand Down
19 changes: 4 additions & 15 deletions server/monitor/monitor.go → server/monitor.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
package monitor
package main

import (
"fmt"
"runtime/debug"
"sync"
"time"

"github.com/mattermost/mattermost-plugin-msteams/server/metrics"
Expand Down Expand Up @@ -32,7 +31,7 @@ type Monitor struct {
}

// New creates a new instance of the Monitor job.
func New(client msteams.Client, store store.Store, api plugin.API, metrics metrics.Metrics, baseURL string, webhookSecret string, useEvaluationAPI bool) *Monitor {
func NewMonitor(client msteams.Client, store store.Store, api plugin.API, metrics metrics.Metrics, baseURL string, webhookSecret string, useEvaluationAPI bool) *Monitor {
return &Monitor{
client: client,
store: store,
Expand Down Expand Up @@ -97,21 +96,11 @@ func (m *Monitor) runMonitoringSystemJob() {
done := m.metrics.ObserveWorker(metrics.WorkerMonitor)
defer done()

msteamsSubscriptionsMap, allChatsSubscription, err := m.getMSTeamsSubscriptionsMap()
_, allChatsSubscription, err := m.getMSTeamsSubscriptionsMap()
if err != nil {
m.api.LogError("Unable to fetch subscriptions from MS Teams", "error", err.Error())
return
}

var wg sync.WaitGroup

wg.Add(1)
go func() {
defer wg.Done()
m.checkChannelsSubscriptions(msteamsSubscriptionsMap)
}()

m.checkGlobalChatsSubscription(msteamsSubscriptionsMap, allChatsSubscription)

wg.Wait()
m.checkGlobalChatsSubscription(allChatsSubscription)
}
Loading

0 comments on commit 4585e70

Please sign in to comment.