MM-21357: Use typed constants ClusterEvent (#17920)
* MM-21357: Use typed constants ClusterEvent Use typed constants for: - model.ClusterEvent https://mattermost.atlassian.net/browse/MM-21357 ```release-note Use typed constant for model.ClusterEvent ``` * trigger CI ```release-note NONE ```
Этот коммит содержится в:
коммит произвёл
Claudio Costa
родитель
9ae45d55d9
Коммит
623f8dc9af
@@ -1758,7 +1758,7 @@ func TestInstallMarketplacePlugin(t *testing.T) {
|
|||||||
}, "missing prepackaged and remote plugin signatures")
|
}, "missing prepackaged and remote plugin signatures")
|
||||||
}
|
}
|
||||||
|
|
||||||
func findClusterMessages(event string, msgs []*model.ClusterMessage) []*model.ClusterMessage {
|
func findClusterMessages(event model.ClusterEvent, msgs []*model.ClusterMessage) []*model.ClusterMessage {
|
||||||
var result []*model.ClusterMessage
|
var result []*model.ClusterMessage
|
||||||
for _, msg := range msgs {
|
for _, msg := range msgs {
|
||||||
if msg.Event == event {
|
if msg.Event == event {
|
||||||
|
|||||||
@@ -126,7 +126,7 @@ func (c *ClusterMock) SendClusterMessageToNode(nodeID string, msg *model.Cluster
|
|||||||
|
|
||||||
func (c *ClusterMock) StartInterNodeCommunication() {}
|
func (c *ClusterMock) StartInterNodeCommunication() {}
|
||||||
func (c *ClusterMock) StopInterNodeCommunication() {}
|
func (c *ClusterMock) StopInterNodeCommunication() {}
|
||||||
func (c *ClusterMock) RegisterClusterMessageHandler(event string, crm einterfaces.ClusterMessageHandler) {
|
func (c *ClusterMock) RegisterClusterMessageHandler(event model.ClusterEvent, crm einterfaces.ClusterMessageHandler) {
|
||||||
}
|
}
|
||||||
func (c *ClusterMock) GetClusterId() string { return "cluster_mock" }
|
func (c *ClusterMock) GetClusterId() string { return "cluster_mock" }
|
||||||
func (c *ClusterMock) IsLeader() bool { return false }
|
func (c *ClusterMock) IsLeader() bool { return false }
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ import (
|
|||||||
"github.com/mattermost/mattermost-server/v5/model"
|
"github.com/mattermost/mattermost-server/v5/model"
|
||||||
)
|
)
|
||||||
|
|
||||||
func (s *Server) notifyClusterPluginEvent(event string, data model.PluginEventData) {
|
func (s *Server) notifyClusterPluginEvent(event model.ClusterEvent, data model.PluginEventData) {
|
||||||
if s.Cluster != nil {
|
if s.Cluster != nil {
|
||||||
s.Cluster.SendClusterMessage(&model.ClusterMessage{
|
s.Cluster.SendClusterMessage(&model.ClusterMessage{
|
||||||
Event: event,
|
Event: event,
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ type ClusterMessageHandler func(msg *model.ClusterMessage)
|
|||||||
type ClusterInterface interface {
|
type ClusterInterface interface {
|
||||||
StartInterNodeCommunication()
|
StartInterNodeCommunication()
|
||||||
StopInterNodeCommunication()
|
StopInterNodeCommunication()
|
||||||
RegisterClusterMessageHandler(event string, crm ClusterMessageHandler)
|
RegisterClusterMessageHandler(event model.ClusterEvent, crm ClusterMessageHandler)
|
||||||
GetClusterId() string
|
GetClusterId() string
|
||||||
IsLeader() bool
|
IsLeader() bool
|
||||||
// HealthScore returns a number which is indicative of how well an instance is meeting
|
// HealthScore returns a number which is indicative of how well an instance is meeting
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ package einterfaces
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/mattermost/logr"
|
"github.com/mattermost/logr"
|
||||||
|
"github.com/mattermost/mattermost-server/v5/model"
|
||||||
)
|
)
|
||||||
|
|
||||||
type MetricsInterface interface {
|
type MetricsInterface interface {
|
||||||
@@ -22,7 +23,7 @@ type MetricsInterface interface {
|
|||||||
|
|
||||||
IncrementClusterRequest()
|
IncrementClusterRequest()
|
||||||
ObserveClusterRequestDuration(elapsed float64)
|
ObserveClusterRequestDuration(elapsed float64)
|
||||||
IncrementClusterEventType(eventType string)
|
IncrementClusterEventType(eventType model.ClusterEvent)
|
||||||
|
|
||||||
IncrementLogin()
|
IncrementLogin()
|
||||||
IncrementLoginFail()
|
IncrementLoginFail()
|
||||||
|
|||||||
@@ -187,7 +187,7 @@ func (_m *ClusterInterface) NotifyMsg(buf []byte) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// RegisterClusterMessageHandler provides a mock function with given fields: event, crm
|
// RegisterClusterMessageHandler provides a mock function with given fields: event, crm
|
||||||
func (_m *ClusterInterface) RegisterClusterMessageHandler(event string, crm einterfaces.ClusterMessageHandler) {
|
func (_m *ClusterInterface) RegisterClusterMessageHandler(event model.ClusterEvent, crm einterfaces.ClusterMessageHandler) {
|
||||||
_m.Called(event, crm)
|
_m.Called(event, crm)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -7,6 +7,8 @@ package mocks
|
|||||||
import (
|
import (
|
||||||
logr "github.com/mattermost/logr"
|
logr "github.com/mattermost/logr"
|
||||||
mock "github.com/stretchr/testify/mock"
|
mock "github.com/stretchr/testify/mock"
|
||||||
|
|
||||||
|
model "github.com/mattermost/mattermost-server/v5/model"
|
||||||
)
|
)
|
||||||
|
|
||||||
// MetricsInterface is an autogenerated mock type for the MetricsInterface type
|
// MetricsInterface is an autogenerated mock type for the MetricsInterface type
|
||||||
@@ -61,7 +63,7 @@ func (_m *MetricsInterface) IncrementChannelIndexCounter() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// IncrementClusterEventType provides a mock function with given fields: eventType
|
// IncrementClusterEventType provides a mock function with given fields: eventType
|
||||||
func (_m *MetricsInterface) IncrementClusterEventType(eventType string) {
|
func (_m *MetricsInterface) IncrementClusterEventType(eventType model.ClusterEvent) {
|
||||||
_m.Called(eventType)
|
_m.Called(eventType)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -8,38 +8,40 @@ import (
|
|||||||
"io"
|
"io"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
type ClusterEvent string
|
||||||
|
|
||||||
const (
|
const (
|
||||||
ClusterEventPublish = "publish"
|
ClusterEventPublish ClusterEvent = "publish"
|
||||||
ClusterEventUpdateStatus = "update_status"
|
ClusterEventUpdateStatus ClusterEvent = "update_status"
|
||||||
ClusterEventInvalidateAllCaches = "inv_all_caches"
|
ClusterEventInvalidateAllCaches ClusterEvent = "inv_all_caches"
|
||||||
ClusterEventInvalidateCacheForReactions = "inv_reactions"
|
ClusterEventInvalidateCacheForReactions ClusterEvent = "inv_reactions"
|
||||||
ClusterEventInvalidateCacheForChannelMembersNotifyProps = "inv_channel_members_notify_props"
|
ClusterEventInvalidateCacheForChannelMembersNotifyProps ClusterEvent = "inv_channel_members_notify_props"
|
||||||
ClusterEventInvalidateCacheForChannelByName = "inv_channel_name"
|
ClusterEventInvalidateCacheForChannelByName ClusterEvent = "inv_channel_name"
|
||||||
ClusterEventInvalidateCacheForChannel = "inv_channel"
|
ClusterEventInvalidateCacheForChannel ClusterEvent = "inv_channel"
|
||||||
ClusterEventInvalidateCacheForChannelGuestCount = "inv_channel_guest_count"
|
ClusterEventInvalidateCacheForChannelGuestCount ClusterEvent = "inv_channel_guest_count"
|
||||||
ClusterEventInvalidateCacheForUser = "inv_user"
|
ClusterEventInvalidateCacheForUser ClusterEvent = "inv_user"
|
||||||
ClusterEventInvalidateCacheForUserTeams = "inv_user_teams"
|
ClusterEventInvalidateCacheForUserTeams ClusterEvent = "inv_user_teams"
|
||||||
ClusterEventClearSessionCacheForUser = "clear_session_user"
|
ClusterEventClearSessionCacheForUser ClusterEvent = "clear_session_user"
|
||||||
ClusterEventInvalidateCacheForRoles = "inv_roles"
|
ClusterEventInvalidateCacheForRoles ClusterEvent = "inv_roles"
|
||||||
ClusterEventInvalidateCacheForRolePermissions = "inv_role_permissions"
|
ClusterEventInvalidateCacheForRolePermissions ClusterEvent = "inv_role_permissions"
|
||||||
ClusterEventInvalidateCacheForProfileByIds = "inv_profile_ids"
|
ClusterEventInvalidateCacheForProfileByIds ClusterEvent = "inv_profile_ids"
|
||||||
ClusterEventInvalidateCacheForProfileInChannel = "inv_profile_in_channel"
|
ClusterEventInvalidateCacheForProfileInChannel ClusterEvent = "inv_profile_in_channel"
|
||||||
ClusterEventInvalidateCacheForSchemes = "inv_schemes"
|
ClusterEventInvalidateCacheForSchemes ClusterEvent = "inv_schemes"
|
||||||
ClusterEventInvalidateCacheForFileInfos = "inv_file_infos"
|
ClusterEventInvalidateCacheForFileInfos ClusterEvent = "inv_file_infos"
|
||||||
ClusterEventInvalidateCacheForWebhooks = "inv_webhooks"
|
ClusterEventInvalidateCacheForWebhooks ClusterEvent = "inv_webhooks"
|
||||||
ClusterEventInvalidateCacheForEmojisById = "inv_emojis_by_id"
|
ClusterEventInvalidateCacheForEmojisById ClusterEvent = "inv_emojis_by_id"
|
||||||
ClusterEventInvalidateCacheForEmojisIdByName = "inv_emojis_id_by_name"
|
ClusterEventInvalidateCacheForEmojisIdByName ClusterEvent = "inv_emojis_id_by_name"
|
||||||
ClusterEventInvalidateCacheForChannelPinnedpostsCounts = "inv_channel_pinnedposts_counts"
|
ClusterEventInvalidateCacheForChannelPinnedpostsCounts ClusterEvent = "inv_channel_pinnedposts_counts"
|
||||||
ClusterEventInvalidateCacheForChannelMemberCounts = "inv_channel_member_counts"
|
ClusterEventInvalidateCacheForChannelMemberCounts ClusterEvent = "inv_channel_member_counts"
|
||||||
ClusterEventInvalidateCacheForLastPosts = "inv_last_posts"
|
ClusterEventInvalidateCacheForLastPosts ClusterEvent = "inv_last_posts"
|
||||||
ClusterEventInvalidateCacheForLastPostTime = "inv_last_post_time"
|
ClusterEventInvalidateCacheForLastPostTime ClusterEvent = "inv_last_post_time"
|
||||||
ClusterEventInvalidateCacheForTeams = "inv_teams"
|
ClusterEventInvalidateCacheForTeams ClusterEvent = "inv_teams"
|
||||||
ClusterEventClearSessionCacheForAllUsers = "inv_all_user_sessions"
|
ClusterEventClearSessionCacheForAllUsers ClusterEvent = "inv_all_user_sessions"
|
||||||
ClusterEventInstallPlugin = "install_plugin"
|
ClusterEventInstallPlugin ClusterEvent = "install_plugin"
|
||||||
ClusterEventRemovePlugin = "remove_plugin"
|
ClusterEventRemovePlugin ClusterEvent = "remove_plugin"
|
||||||
ClusterEventPluginEvent = "plugin_event"
|
ClusterEventPluginEvent ClusterEvent = "plugin_event"
|
||||||
ClusterEventInvalidateCacheForTermsOfService = "inv_terms_of_service"
|
ClusterEventInvalidateCacheForTermsOfService ClusterEvent = "inv_terms_of_service"
|
||||||
ClusterEventBusyStateChanged = "busy_state_change"
|
ClusterEventBusyStateChanged ClusterEvent = "busy_state_change"
|
||||||
|
|
||||||
// Gossip communication
|
// Gossip communication
|
||||||
ClusterGossipEventRequestGetLogs = "gossip_request_get_logs"
|
ClusterGossipEventRequestGetLogs = "gossip_request_get_logs"
|
||||||
@@ -57,7 +59,7 @@ const (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type ClusterMessage struct {
|
type ClusterMessage struct {
|
||||||
Event string `json:"event"`
|
Event ClusterEvent `json:"event"`
|
||||||
SendType string `json:"-"`
|
SendType string `json:"-"`
|
||||||
WaitForAllToSend bool `json:"-"`
|
WaitForAllToSend bool `json:"-"`
|
||||||
Data string `json:"data,omitempty"`
|
Data string `json:"data,omitempty"`
|
||||||
|
|||||||
4
services/cache/cache.go
поставляемый
4
services/cache/cache.go
поставляемый
@@ -6,6 +6,8 @@ package cache
|
|||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/mattermost/mattermost-server/v5/model"
|
||||||
)
|
)
|
||||||
|
|
||||||
// ErrKeyNotFound is the error when the given key is not found
|
// ErrKeyNotFound is the error when the given key is not found
|
||||||
@@ -42,7 +44,7 @@ type Cache interface {
|
|||||||
Len() (int, error)
|
Len() (int, error)
|
||||||
|
|
||||||
// GetInvalidateClusterEvent returns the cluster event configured when this cache was created.
|
// GetInvalidateClusterEvent returns the cluster event configured when this cache was created.
|
||||||
GetInvalidateClusterEvent() string
|
GetInvalidateClusterEvent() model.ClusterEvent
|
||||||
|
|
||||||
// Name returns the name of the cache
|
// Name returns the name of the cache
|
||||||
Name() string
|
Name() string
|
||||||
|
|||||||
6
services/cache/lru.go
поставляемый
6
services/cache/lru.go
поставляемый
@@ -24,7 +24,7 @@ type LRU struct {
|
|||||||
items map[string]*list.Element
|
items map[string]*list.Element
|
||||||
defaultExpiry time.Duration
|
defaultExpiry time.Duration
|
||||||
name string
|
name string
|
||||||
invalidateClusterEvent string
|
invalidateClusterEvent model.ClusterEvent
|
||||||
}
|
}
|
||||||
|
|
||||||
// LRUOptions contains options for initializing LRU cache
|
// LRUOptions contains options for initializing LRU cache
|
||||||
@@ -32,7 +32,7 @@ type LRUOptions struct {
|
|||||||
Name string
|
Name string
|
||||||
Size int
|
Size int
|
||||||
DefaultExpiry time.Duration
|
DefaultExpiry time.Duration
|
||||||
InvalidateClusterEvent string
|
InvalidateClusterEvent model.ClusterEvent
|
||||||
// StripedBuckets is used only by LRUStriped and shouldn't be greater than the number
|
// StripedBuckets is used only by LRUStriped and shouldn't be greater than the number
|
||||||
// of CPUs available on the machine running this cache.
|
// of CPUs available on the machine running this cache.
|
||||||
StripedBuckets int
|
StripedBuckets int
|
||||||
@@ -128,7 +128,7 @@ func (l *LRU) Len() (int, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// GetInvalidateClusterEvent returns the cluster event configured when this cache was created.
|
// GetInvalidateClusterEvent returns the cluster event configured when this cache was created.
|
||||||
func (l *LRU) GetInvalidateClusterEvent() string {
|
func (l *LRU) GetInvalidateClusterEvent() model.ClusterEvent {
|
||||||
return l.invalidateClusterEvent
|
return l.invalidateClusterEvent
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
6
services/cache/lru_striped.go
поставляемый
6
services/cache/lru_striped.go
поставляемый
@@ -9,6 +9,8 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/cespare/xxhash/v2"
|
"github.com/cespare/xxhash/v2"
|
||||||
|
|
||||||
|
"github.com/mattermost/mattermost-server/v5/model"
|
||||||
)
|
)
|
||||||
|
|
||||||
// LRUStriped keeps LRU caches in buckets in order to lower mutex contention.
|
// LRUStriped keeps LRU caches in buckets in order to lower mutex contention.
|
||||||
@@ -39,7 +41,7 @@ import (
|
|||||||
type LRUStriped struct {
|
type LRUStriped struct {
|
||||||
buckets []*LRU
|
buckets []*LRU
|
||||||
name string
|
name string
|
||||||
invalidateClusterEvent string
|
invalidateClusterEvent model.ClusterEvent
|
||||||
}
|
}
|
||||||
|
|
||||||
func (L LRUStriped) hashkeyMapHash(key string) uint64 {
|
func (L LRUStriped) hashkeyMapHash(key string) uint64 {
|
||||||
@@ -108,7 +110,7 @@ func (L LRUStriped) Len() (int, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// GetInvalidateClusterEvent does the same as LRU.GetInvalidateClusterEvent
|
// GetInvalidateClusterEvent does the same as LRU.GetInvalidateClusterEvent
|
||||||
func (L LRUStriped) GetInvalidateClusterEvent() string {
|
func (L LRUStriped) GetInvalidateClusterEvent() model.ClusterEvent {
|
||||||
return L.invalidateClusterEvent
|
return L.invalidateClusterEvent
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
4
services/cache/provider.go
поставляемый
4
services/cache/provider.go
поставляемый
@@ -5,6 +5,8 @@ package cache
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/mattermost/mattermost-server/v5/model"
|
||||||
)
|
)
|
||||||
|
|
||||||
// CacheOptions contains options for initializaing a cache
|
// CacheOptions contains options for initializaing a cache
|
||||||
@@ -12,7 +14,7 @@ type CacheOptions struct {
|
|||||||
Size int
|
Size int
|
||||||
DefaultExpiry time.Duration
|
DefaultExpiry time.Duration
|
||||||
Name string
|
Name string
|
||||||
InvalidateClusterEvent string
|
InvalidateClusterEvent model.ClusterEvent
|
||||||
Striped bool
|
Striped bool
|
||||||
StripedBuckets int
|
StripedBuckets int
|
||||||
}
|
}
|
||||||
|
|||||||
5
services/cache/provider_test.go
поставляемый
5
services/cache/provider_test.go
поставляемый
@@ -7,6 +7,7 @@ import (
|
|||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/mattermost/mattermost-server/v5/model"
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -56,7 +57,7 @@ func TestNewCache(t *testing.T) {
|
|||||||
|
|
||||||
size := 1
|
size := 1
|
||||||
expiry := 1 * time.Second
|
expiry := 1 * time.Second
|
||||||
event := "clusterEvent"
|
event := model.ClusterEvent("clusterEvent")
|
||||||
c, err := p.NewCache(&CacheOptions{
|
c, err := p.NewCache(&CacheOptions{
|
||||||
Size: size,
|
Size: size,
|
||||||
Name: "name",
|
Name: "name",
|
||||||
@@ -139,7 +140,7 @@ func TestNewCache_Striped(t *testing.T) {
|
|||||||
|
|
||||||
size := 1
|
size := 1
|
||||||
expiry := 1 * time.Second
|
expiry := 1 * time.Second
|
||||||
event := "clusterEvent"
|
event := model.ClusterEvent("clusterEvent")
|
||||||
c, err := p.NewCache(&CacheOptions{
|
c, err := p.NewCache(&CacheOptions{
|
||||||
Size: size,
|
Size: size,
|
||||||
Name: "name",
|
Name: "name",
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ func (c *FakeClusterInterface) StartInterNodeCommunication() {}
|
|||||||
|
|
||||||
func (c *FakeClusterInterface) StopInterNodeCommunication() {}
|
func (c *FakeClusterInterface) StopInterNodeCommunication() {}
|
||||||
|
|
||||||
func (c *FakeClusterInterface) RegisterClusterMessageHandler(event string, crm einterfaces.ClusterMessageHandler) {
|
func (c *FakeClusterInterface) RegisterClusterMessageHandler(event model.ClusterEvent, crm einterfaces.ClusterMessageHandler) {
|
||||||
c.clusterMessageHandler = crm
|
c.clusterMessageHandler = crm
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Ссылка в новой задаче
Block a user