Add mobile metrics (#27045)
* Add mobile metrics * Fix mocks * Add tests * Fix lint * Address feedback * Fix lint * Fix test * Fix CI --------- Co-authored-by: Mattermost Build <build@mattermost.com>
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
691386a814
Коммит
1ec2de4a95
@@ -42,6 +42,7 @@ const (
|
||||
MetricsSubsystemSystem = "system"
|
||||
MetricsSubsystemJobs = "jobs"
|
||||
MetricsSubsystemNotifications = "notifications"
|
||||
MetricsSubsystemClientsMobileApp = "mobileapp"
|
||||
MetricsSubsystemClientsWeb = "webapp"
|
||||
MetricsCloudInstallationLabel = "installationId"
|
||||
MetricsCloudDatabaseClusterLabel = "databaseClusterName"
|
||||
@@ -222,6 +223,10 @@ type MetricsInterfaceImpl struct {
|
||||
ClientTeamSwitchDuration *prometheus.HistogramVec
|
||||
ClientRHSLoadDuration *prometheus.HistogramVec
|
||||
ClientGlobalThreadsLoadDuration *prometheus.HistogramVec
|
||||
|
||||
MobileClientLoadDuration *prometheus.HistogramVec
|
||||
MobileClientChannelSwitchDuration *prometheus.HistogramVec
|
||||
MobileClientTeamSwitchDuration *prometheus.HistogramVec
|
||||
}
|
||||
|
||||
func init() {
|
||||
@@ -1262,6 +1267,42 @@ func New(ps *platform.PlatformService, driver, dataSource string) *MetricsInterf
|
||||
)
|
||||
m.Registry.MustRegister(m.ClientGlobalThreadsLoadDuration)
|
||||
|
||||
m.MobileClientLoadDuration = prometheus.NewHistogramVec(
|
||||
prometheus.HistogramOpts{
|
||||
Namespace: MetricsNamespace,
|
||||
Subsystem: MetricsSubsystemClientsMobileApp,
|
||||
Name: "mobile_load",
|
||||
Help: "Duration of the time taken from when a user opens the app and the app finally loads all relevant information (seconds)",
|
||||
Buckets: []float64{1, 1.5, 2, 3, 4, 4.5, 5, 5.5, 6, 7.5, 10, 20, 25, 30},
|
||||
},
|
||||
[]string{"platform"},
|
||||
)
|
||||
m.Registry.MustRegister(m.MobileClientLoadDuration)
|
||||
|
||||
m.MobileClientChannelSwitchDuration = prometheus.NewHistogramVec(
|
||||
prometheus.HistogramOpts{
|
||||
Namespace: MetricsNamespace,
|
||||
Subsystem: MetricsSubsystemClientsMobileApp,
|
||||
Name: "mobile_channel_switch",
|
||||
Help: "Duration of the time taken from when a user clicks on a channel name, and the full channel sreen is loaded (seconds)",
|
||||
Buckets: []float64{0.150, 0.200, 0.300, 0.400, 0.450, 0.500, 0.550, 0.600, 0.750, 1, 2, 3},
|
||||
},
|
||||
[]string{"platform"},
|
||||
)
|
||||
m.Registry.MustRegister(m.MobileClientChannelSwitchDuration)
|
||||
|
||||
m.MobileClientTeamSwitchDuration = prometheus.NewHistogramVec(
|
||||
prometheus.HistogramOpts{
|
||||
Namespace: MetricsNamespace,
|
||||
Subsystem: MetricsSubsystemClientsMobileApp,
|
||||
Name: "mobile_team_switch",
|
||||
Help: "Duration of the time taken from when a user clicks on a team, and the full categories screen is loaded (seconds)",
|
||||
Buckets: []float64{0.150, 0.200, 0.250, 0.300, 0.350, 0.400, 0.500, 0.750, 1, 2, 3},
|
||||
},
|
||||
[]string{"platform"},
|
||||
)
|
||||
m.Registry.MustRegister(m.MobileClientTeamSwitchDuration)
|
||||
|
||||
return m
|
||||
}
|
||||
|
||||
@@ -1764,6 +1805,18 @@ func (mi *MetricsInterfaceImpl) ObserveGlobalThreadsLoadDuration(platform, agent
|
||||
mi.ClientGlobalThreadsLoadDuration.With(prometheus.Labels{"platform": platform, "agent": agent}).Observe(elapsed)
|
||||
}
|
||||
|
||||
func (mi *MetricsInterfaceImpl) ObserveMobileClientLoadDuration(platform string, elapsed float64) {
|
||||
mi.MobileClientLoadDuration.With(prometheus.Labels{"platform": platform}).Observe(elapsed)
|
||||
}
|
||||
|
||||
func (mi *MetricsInterfaceImpl) ObserveMobileClientChannelSwitchDuration(platform string, elapsed float64) {
|
||||
mi.MobileClientChannelSwitchDuration.With(prometheus.Labels{"platform": platform}).Observe(elapsed)
|
||||
}
|
||||
|
||||
func (mi *MetricsInterfaceImpl) ObserveMobileClientTeamSwitchDuration(platform string, elapsed float64) {
|
||||
mi.MobileClientTeamSwitchDuration.With(prometheus.Labels{"platform": platform}).Observe(elapsed)
|
||||
}
|
||||
|
||||
func extractDBCluster(driver, connectionString string) (string, error) {
|
||||
host, err := extractHost(driver, connectionString)
|
||||
if err != nil {
|
||||
|
||||
@@ -176,6 +176,61 @@ func TestPluginMetrics(t *testing.T) {
|
||||
})
|
||||
}
|
||||
|
||||
func TestMobileMetrics(t *testing.T) {
|
||||
th := api4.SetupEnterprise(t, app.StartMetrics)
|
||||
defer th.TearDown()
|
||||
|
||||
configureMetrics(th)
|
||||
mi := th.App.Metrics()
|
||||
|
||||
miImpl, ok := mi.(*MetricsInterfaceImpl)
|
||||
require.True(t, ok, fmt.Sprintf("App.Metrics is not *MetricsInterfaceImpl, but %T", mi))
|
||||
|
||||
ttcc := []struct {
|
||||
name string
|
||||
histogramVec *prometheus.HistogramVec
|
||||
observeFunc func(string, float64)
|
||||
}{
|
||||
{
|
||||
name: "load duration",
|
||||
histogramVec: miImpl.MobileClientLoadDuration,
|
||||
observeFunc: mi.ObserveMobileClientLoadDuration,
|
||||
},
|
||||
{
|
||||
name: "channel switch duration",
|
||||
histogramVec: miImpl.MobileClientChannelSwitchDuration,
|
||||
observeFunc: mi.ObserveMobileClientChannelSwitchDuration,
|
||||
},
|
||||
{
|
||||
name: "team switch duration",
|
||||
histogramVec: miImpl.MobileClientTeamSwitchDuration,
|
||||
observeFunc: mi.ObserveMobileClientTeamSwitchDuration,
|
||||
},
|
||||
}
|
||||
|
||||
for _, tc := range ttcc {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
m := &prometheusModels.Metric{}
|
||||
elapsed := 999.1
|
||||
|
||||
for _, platform := range []string{"ios", "android"} {
|
||||
actualMetric, err := tc.histogramVec.GetMetricWith(prometheus.Labels{"platform": platform})
|
||||
require.NoError(t, err)
|
||||
require.NoError(t, actualMetric.(prometheus.Histogram).Write(m))
|
||||
require.Equal(t, uint64(0), m.Histogram.GetSampleCount())
|
||||
require.Equal(t, 0.0, m.Histogram.GetSampleSum())
|
||||
|
||||
tc.observeFunc(platform, elapsed)
|
||||
actualMetric, err = tc.histogramVec.GetMetricWith(prometheus.Labels{"platform": platform})
|
||||
require.NoError(t, err)
|
||||
require.NoError(t, actualMetric.(prometheus.Histogram).Write(m))
|
||||
require.Equal(t, uint64(1), m.Histogram.GetSampleCount())
|
||||
require.InDelta(t, elapsed, m.Histogram.GetSampleSum(), 0.001)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestExtractDBCluster(t *testing.T) {
|
||||
testCases := []struct {
|
||||
description string
|
||||
|
||||
Ссылка в новой задаче
Block a user