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