[MM-41200] Add OnSendDailyTelemetry() plugin hook (#19387)
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
7c9708ef49
Коммит
0d67995eb4
@@ -1259,3 +1259,46 @@ func TestHookRunDataRetention(t *testing.T) {
|
||||
|
||||
require.True(t, hookCalled)
|
||||
}
|
||||
|
||||
func TestHookOnSendDailyTelemetry(t *testing.T) {
|
||||
th := Setup(t).InitBasic()
|
||||
defer th.TearDown()
|
||||
|
||||
tearDown, pluginIDs, _ := SetAppEnvironmentWithPlugins(t,
|
||||
[]string{
|
||||
`
|
||||
package main
|
||||
|
||||
import (
|
||||
"github.com/mattermost/mattermost-server/v6/plugin"
|
||||
)
|
||||
|
||||
type MyPlugin struct {
|
||||
plugin.MattermostPlugin
|
||||
}
|
||||
|
||||
func (p *MyPlugin) OnSendDailyTelemetry() {
|
||||
return
|
||||
}
|
||||
|
||||
func main() {
|
||||
plugin.ClientMain(&MyPlugin{})
|
||||
}
|
||||
`}, th.App, th.NewPluginAPI)
|
||||
defer tearDown()
|
||||
|
||||
require.Len(t, pluginIDs, 1)
|
||||
pluginID := pluginIDs[0]
|
||||
|
||||
require.True(t, th.App.GetPluginsEnvironment().IsActive(pluginID))
|
||||
|
||||
hookCalled := false
|
||||
th.App.GetPluginsEnvironment().RunMultiPluginHook(func(hooks plugin.Hooks) bool {
|
||||
hooks.OnSendDailyTelemetry()
|
||||
|
||||
hookCalled = true
|
||||
return hookCalled
|
||||
}, plugin.OnSendDailyTelemetryID)
|
||||
|
||||
require.True(t, hookCalled)
|
||||
}
|
||||
|
||||
@@ -742,6 +742,38 @@ func (s *hooksRPCServer) OnInstall(args *Z_OnInstallArgs, returns *Z_OnInstallRe
|
||||
return nil
|
||||
}
|
||||
|
||||
func init() {
|
||||
hookNameToId["OnSendDailyTelemetry"] = OnSendDailyTelemetryID
|
||||
}
|
||||
|
||||
type Z_OnSendDailyTelemetryArgs struct {
|
||||
}
|
||||
|
||||
type Z_OnSendDailyTelemetryReturns struct {
|
||||
}
|
||||
|
||||
func (g *hooksRPCClient) OnSendDailyTelemetry() {
|
||||
_args := &Z_OnSendDailyTelemetryArgs{}
|
||||
_returns := &Z_OnSendDailyTelemetryReturns{}
|
||||
if g.implemented[OnSendDailyTelemetryID] {
|
||||
if err := g.client.Call("Plugin.OnSendDailyTelemetry", _args, _returns); err != nil {
|
||||
g.log.Error("RPC call OnSendDailyTelemetry to plugin failed.", mlog.Err(err))
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func (s *hooksRPCServer) OnSendDailyTelemetry(args *Z_OnSendDailyTelemetryArgs, returns *Z_OnSendDailyTelemetryReturns) error {
|
||||
if hook, ok := s.impl.(interface {
|
||||
OnSendDailyTelemetry()
|
||||
}); ok {
|
||||
hook.OnSendDailyTelemetry()
|
||||
} else {
|
||||
return encodableError(fmt.Errorf("Hook OnSendDailyTelemetry called but not implemented."))
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
type Z_RegisterCommandArgs struct {
|
||||
A *model.Command
|
||||
}
|
||||
|
||||
@@ -41,6 +41,7 @@ const (
|
||||
WebSocketMessageHasBeenPostedID = 23
|
||||
RunDataRetentionID = 24
|
||||
OnInstallID = 25
|
||||
OnSendDailyTelemetryID = 26
|
||||
TotalHooksID = iota
|
||||
)
|
||||
|
||||
@@ -246,7 +247,7 @@ type Hooks interface {
|
||||
// Minimum server version: 6.0
|
||||
WebSocketMessageHasBeenPosted(webConnID, userID string, req *model.WebSocketRequest)
|
||||
|
||||
// RunDataRetention is invoked during a DataRetentionJob
|
||||
// RunDataRetention is invoked during a DataRetentionJob.
|
||||
//
|
||||
// Minimum server version: 6.4
|
||||
RunDataRetention(nowTime, batchSize int64) (int64, error)
|
||||
@@ -258,4 +259,9 @@ type Hooks interface {
|
||||
//
|
||||
// Minimum server version: 6.5
|
||||
OnInstall(c *Context, event model.OnInstallEvent) error
|
||||
|
||||
// OnSendDailyTelemetry is invoked when the server send the daily telemtry data.
|
||||
//
|
||||
// Minimum server version: 6.5
|
||||
OnSendDailyTelemetry()
|
||||
}
|
||||
|
||||
@@ -200,3 +200,9 @@ func (hooks *hooksTimerLayer) OnInstall(c *Context, event model.OnInstallEvent)
|
||||
hooks.recordTime(startTime, "OnInstall", _returnsA == nil)
|
||||
return _returnsA
|
||||
}
|
||||
|
||||
func (hooks *hooksTimerLayer) OnSendDailyTelemetry() {
|
||||
startTime := timePkg.Now()
|
||||
hooks.hooksImpl.OnSendDailyTelemetry()
|
||||
hooks.recordTime(startTime, "OnSendDailyTelemetry", true)
|
||||
}
|
||||
|
||||
@@ -213,6 +213,11 @@ func (_m *Hooks) OnPluginClusterEvent(c *plugin.Context, ev model.PluginClusterE
|
||||
_m.Called(c, ev)
|
||||
}
|
||||
|
||||
// OnSendDailyTelemetry provides a mock function with given fields:
|
||||
func (_m *Hooks) OnSendDailyTelemetry() {
|
||||
_m.Called()
|
||||
}
|
||||
|
||||
// OnWebSocketConnect provides a mock function with given fields: webConnID, userID
|
||||
func (_m *Hooks) OnWebSocketConnect(webConnID string, userID string) {
|
||||
_m.Called(webConnID, userID)
|
||||
|
||||
@@ -902,6 +902,11 @@ func (ts *TelemetryService) trackPlugins() {
|
||||
"plugins_with_settings": settingsCount,
|
||||
"plugins_with_broken_manifests": brokenManifestCount,
|
||||
})
|
||||
|
||||
pluginsEnvironment.RunMultiPluginHook(func(hooks plugin.Hooks) bool {
|
||||
hooks.OnSendDailyTelemetry()
|
||||
return true
|
||||
}, plugin.OnSendDailyTelemetryID)
|
||||
}
|
||||
|
||||
func (ts *TelemetryService) trackServer() {
|
||||
|
||||
Ссылка в новой задаче
Block a user