MM-61887: Log the userID if a metric exceeds the last histogram bucket (#29448)
We create a custom histogram metric that logs the userID when the observed value is greater or equal to the last bucket value. This allows us to start tracking the slowest users of a system while at the same time not polluting the Prometheus metrics by storing a userID for every observation. https://mattermost.atlassian.net/browse/MM-61887 ```release-note NONE ```
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
421001c981
Коммит
a6d37fa14c
35
server/enterprise/metrics/histogram_test.go
Обычный файл
35
server/enterprise/metrics/histogram_test.go
Обычный файл
@@ -0,0 +1,35 @@
|
||||
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
||||
// See LICENSE.enterprise for license information.
|
||||
|
||||
package metrics
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/prometheus/client_golang/prometheus"
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"github.com/mattermost/mattermost/server/public/shared/mlog"
|
||||
"github.com/mattermost/mattermost/server/v8/channels/api4"
|
||||
"github.com/mattermost/mattermost/server/v8/channels/testlib"
|
||||
)
|
||||
|
||||
func TestWrappedObserver(t *testing.T) {
|
||||
th := api4.Setup(t)
|
||||
defer th.TearDown()
|
||||
|
||||
h := NewHistogramVec(prometheus.HistogramOpts{
|
||||
Namespace: MetricsNamespace,
|
||||
Subsystem: MetricsSubsystemClientsWeb,
|
||||
Name: "test",
|
||||
Buckets: []float64{0, 5, 10},
|
||||
}, []string{"l1"}, th.TestLogger)
|
||||
|
||||
h.With(prometheus.Labels{"l1": "hello"}, th.BasicUser.Id).Observe(6)
|
||||
require.NoError(t, th.TestLogger.Flush())
|
||||
testlib.AssertNoLog(t, th.LogBuffer, mlog.LvlWarn.Name, "Metric observation exceeded.")
|
||||
|
||||
h.With(prometheus.Labels{"l1": "hello"}, th.BasicUser.Id).Observe(10)
|
||||
require.NoError(t, th.TestLogger.Flush())
|
||||
testlib.AssertLog(t, th.LogBuffer, mlog.LvlWarn.Name, "Metric observation exceeded.")
|
||||
}
|
||||
Ссылка в новой задаче
Block a user